My VFS design
Posted: Wed Nov 19, 2008 12:16 am
I just wanted to run this by the smarted people than me here.
My VFS uses inodes to represent all things (character and block devices, directories, files). In each inode is a pointer to the parent inode, a dummy child inode, and the next inode in the current level/directory.
The dummy child is present only in a directory. If the inode doesn't represent a directory, that pointer is 0. The dummy child's next pointer is 0 if the directory is empty, and points to the first visible file if one exists. Therfore, adding files is just manipulating a linked list.
The inode also has a 'mountpointer' pointer. That points to the root inode of a filesystem when it gets mounted. Simply, if the inode is a mountpoint, mount_ptr is set. Otherwise it's not a mount point.
The lookup function looks up file 'name' inside inode 'i'. It loops through i->child->next....->next... until it reaches the end of the linked list. If it finds the file, it returns the inode.
One thing that I realized was "Well, this works if all the filesystems are in memory...but in a large FS on disk this could become a problem. So I added a flag to struct inode. The 'dynamic' flag is set if some of it's child inodes could be on disk. If it can't find them through normal lookup, it calls the inode's lookup function. Thus a filesystem must only load a root inode and a dummy child. This seems like it will work in my mind.
My question is, are there any problems you might foresee? I may post more stuff later when I get time (kinda outta time right now...)
-JL
My VFS uses inodes to represent all things (character and block devices, directories, files). In each inode is a pointer to the parent inode, a dummy child inode, and the next inode in the current level/directory.
The dummy child is present only in a directory. If the inode doesn't represent a directory, that pointer is 0. The dummy child's next pointer is 0 if the directory is empty, and points to the first visible file if one exists. Therfore, adding files is just manipulating a linked list.
The inode also has a 'mountpointer' pointer. That points to the root inode of a filesystem when it gets mounted. Simply, if the inode is a mountpoint, mount_ptr is set. Otherwise it's not a mount point.
The lookup function looks up file 'name' inside inode 'i'. It loops through i->child->next....->next... until it reaches the end of the linked list. If it finds the file, it returns the inode.
One thing that I realized was "Well, this works if all the filesystems are in memory...but in a large FS on disk this could become a problem. So I added a flag to struct inode. The 'dynamic' flag is set if some of it's child inodes could be on disk. If it can't find them through normal lookup, it calls the inode's lookup function. Thus a filesystem must only load a root inode and a dummy child. This seems like it will work in my mind.
My question is, are there any problems you might foresee? I may post more stuff later when I get time (kinda outta time right now...)
-JL