I'm working on a virtual file system which isn't disk based, kind of like /proc. Now I want to create a symlink within it to a target on a ext3 file system. I haven't found any standard documentation on ways to achieve this. What I've guessed so far is that I have to write a function to put in for symlink
in struct inode_operations
. But frankly I'm at a loss even with the function parameters.
If it matters, I started off with this tutorial on LWN: http://lwn.net/Articles/13325/
EDIT: I'm working with libfs, not FUSE at the moment
Symlinks can take two forms: Soft links are similar to shortcuts, and can point to another file or directory in any file system. Hard links are also shortcuts for files and folders, but a hard link cannot be created for a folder or file in a different file system.
A virtual file system (VFS) or virtual filesystem switch is an abstract layer on top of a more concrete file system. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way.
Symbolic links are supported by POSIX and by most Unix-like operating systems, such as FreeBSD, Linux, and macOS. Limited support also exists in Windows 7 and Windows Vista, and to some degree in Windows 2000 and Windows XP in the form of shortcut files.
I know FAT32, as well as FAT16/12 neither support symbolic links nor hard-links. However I came up with this idea: The FAT specification describes that every file is associated with a directory-entry. In my understanding, one could say that a file-entry in a directory somehow or other points to the file's content.
Presumably you're using fuse, if you're not, do :)
All you have to do is implement the getattr function to tell the kernel that the object is a symlink, then implement the readlink function and return the path that the link should link to; the kernel will do the rest.
I was able to accomplish it finally. Here is what I did (some details may differ depending on what the filesystem wants to achieve):
Create inode of the symlink with the S_IFLNK mode and add the target to the i_private field.
Implement follow_link because generic_readlink requires it to be present
static void *sample_follow_link (struct dentry *dentry, struct nameidata *nd) { nd->depth = 0; nd_set_link(nd, (char *)dentry->d_inode->i_private); return NULL; } static struct inode_operations sample_inode_ops = { .readlink = generic_readlink, .follow_link = sample_follow_link, }; ..... //in the function for the dentry and inode creation inode->i_op = sample_inode_ops
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With