'How to check if a filesystem supports hard links in linux?

What's going on here is I have a construct that goes something like this:

    if (link(source, intermediate))
    {
        if (pathconf(dirname(source), _PC_LINK_MAX) == 1)
        {
            /* do atomic algorithm that only works if the filesystem does not support hard links */
        }
        else
        {
            var errno = Marshal.GetLastWin32Error();
            var ci = new System.ComponentModel.Win32Exception();
            throw new IOException(ci.Message, errno);
        }
    } else {
        /* continue atomic algorithm that only works if the filesystem supports hard links */
    }

pathconf(mountpoint, _PC_LINK_MAX); returns 127 on a FAT filesystem. You gotta be kidding me.

So I've got to find another way to check if links are definitely not supported on the target filesystem. Locking onto EPERM is inadequate.

Yes, this question has always been in C# with P/Invokes for libc functions. Yes, I've had to write them down as I needed them.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source