by josefbacik · 10y ago · 0 comments
The way I understand the article's proposal is this:
1. Create new symlink pointing to desired file (assumed to already exist in a stable state).
2. Move new symlink over old symlink.
They exist as directory entries with a small in-directory content only, thus syncing the directory they exist in is sufficient to persist them.
See e.g. https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Symb...
The fact that it does or does not should actually be in the documentation IMHO; probably a good enhancement request.
POSIX does (for some strange reason) permit a symbolic link to have an "inode" (well, d_ino), but there is no way to open this "inode", and no UNIX implementations to my knowledge do this.
Edit: If you want to fsync the symlink you can do an open with nofollow iirc (on my phone so I can't check) so you get the actual symlink and not its target.
HOWEVER, looking into it it seems that the target may actually be stored in the inode. This mean the symlink, though a file, has no contents and thus requires no fsync. Does this sound about right?
No they don't.
First of all, POSIX doesn't use the term "inode number" but "file serial number" which is silly wankery since there's no way to access a file using its "file serial number". They might as well say it was "implementation defined".
Secondly, POSIX used to specify[1] that their inode was "unspecified" because UNIX systems don't store symbolic links in separate inodes, but in the directory that contains them. Now, POSIX specifies symbolic links do have a "file serial number"[2], which could be implemented as a separate file block (confusingly Linux calls this an "inode" which has nothing to do with what UNIX called an inode -- a better term might be "virtual inode" but Linux uses that for something else entirely...)
To this end, I think the only sensible interpretation is the original one: UNIX symbolic links don't have inodes, and POSIX symbolic links might as well have a "hash" of the file contents in the "file serial number" since you can't do anything with it anyway.
[1]: http://pubs.opengroup.org/onlinepubs/009695399/functions/rea...
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/re...
> HOWEVER, looking into it it seems that the target may actually be stored in the inode. This mean the symlink, though a file, has no contents and thus requires no fsync. Does this sound about right?
You have to fsync() the directory that contains the symlink.