VFS: How d you guys handle mountpoints?
Posted: Wed Apr 22, 2015 6:49 am
Glidix currently has a VFS with all the typical UNIX features (except symlinks, which are to be implemented soon). However, I'm starting to think that my implementation is not the best.
The main problem with it is that it may not necessarily be the most efficient, and this stems mainly from how it stores mountpoints. When you mount a filesystem, it is assigned a "prefix"; for example, if I might my CD-ROM at /media/cdrom, the kernel will add the following structure to a linked list:
Where "prefix" will be "/media/cdrom/" (i.e. all paths starting with "/media/cdrom/" are on this filesystem). When trying to resolve the path "/media/cdrom/my_files/hello.txt", it will see that it begins with "/media/cdrom/" and therefore successfully detect that it is on that filesystem; then, the rest of the path, "my_files/hello.txt" is followed, by calling fs->openroot(), which returns a "Dir" structure, and the system will repeadetly call dir->next() until "my_files" is found, then it will call dir->opendir() which returns another Dir, and eventually it finds the file (if it exists of course).
But this means that the only way processes can have working directories is if they just store their paths, and that path must be strcat()ed with every relative path used, and a lot of pointless directory-traversing will then happen... but otherwise, of course, it wouldn't know which filesystem to go on, if a subdirectory of the working directory is a mountpoint.
How does your OS store mountpoints? I can think of another way: to just store the device (st_dev) and inode (st_inode) of each mountpoint, and redirect all operations on such inodes to the root of the filesystem. But the problem would be that /initrd, /dev, etc must be mounted before the root filesystem, but they are on the root filesystem. I could mount some kind of "ramfs" on the root, then unmount everything and mount the proper filesystems.
But before doing this I wanted to see how other OSes do this. I can't find any information on how linux stores this either.
The main problem with it is that it may not necessarily be the most efficient, and this stems mainly from how it stores mountpoints. When you mount a filesystem, it is assigned a "prefix"; for example, if I might my CD-ROM at /media/cdrom, the kernel will add the following structure to a linked list:
Code: Select all
typedef struct _MountPoint
{
char prefix[512];
FileSystem *fs;
struct _MountPoint *prev;
struct _MountPoint *next;
} MountPoint;
But this means that the only way processes can have working directories is if they just store their paths, and that path must be strcat()ed with every relative path used, and a lot of pointless directory-traversing will then happen... but otherwise, of course, it wouldn't know which filesystem to go on, if a subdirectory of the working directory is a mountpoint.
How does your OS store mountpoints? I can think of another way: to just store the device (st_dev) and inode (st_inode) of each mountpoint, and redirect all operations on such inodes to the root of the filesystem. But the problem would be that /initrd, /dev, etc must be mounted before the root filesystem, but they are on the root filesystem. I could mount some kind of "ramfs" on the root, then unmount everything and mount the proper filesystems.
But before doing this I wanted to see how other OSes do this. I can't find any information on how linux stores this either.