开发者

Implementing basic file system

开发者 https://www.devze.com 2022-12-18 18:09 出处:网络
As a college project I need to implement a basic file system from within a file. So how do I go about this? What are the things that I would need to know? The requirements include having a daemon proc

As a college project I need to implement a basic file system from within a file. So how do I go about this? What are the things that I would need to know? The requirements include having a daemon process in the background. Also the applications that use t开发者_StackOverflow社区his system need to connect to the server using a Unix domain socket

The file system should have the following capabilities:

  1. List files stored along with their sizes.
  2. Create files
  3. Allow changes to files
  4. Delete files


Check this out if it can help. http://www.geocities.ws/ravikiran_uvs/articles/rkfs.html

If you want to create a file system in user space FUSE can help you. http://fuse.sourceforge.net/


Here is an example of a very, very basic FUSE implementation that is backed by a glorified shared memory segment (xenstore). Its a fork of the original xenstore FUSE file system that I maintain.

You will also find some code to show you how to make Valgrind more helpful when debugging FUSE implementations.

You write functions for open / create / read / write / truncate / getattr / etc and pass them to fuse (line numbers are from the linked example):

   343 static struct fuse_operations const xsfs_ops = {
   344  .getattr = xsfs_getattr,
   345  .mknod = xsfs_mknod,
   346  .mkdir = xsfs_mkdir,
   347  .unlink = xsfs_rm,
   348  .rmdir = xsfs_rmdir,
   349  .truncate = xsfs_truncate,
   350  .open = xsfs_open,
   351  .read = xsfs_read,
   352  .write = xsfs_write,
   353  .readdir = xsfs_readdir,
   354  .create = xsfs_create,
   355  .destroy = xsfs_destroy,
   356  .utime = xsfs_utime,
   357  .symlink = xsfs_symlink,
   358  .init = (void *)xsfs_init
   359 };

As you can see, its extremely self explanatory. A little searching would result in finding many basic file backed examples of FUSE implementations as well.

I highly recommend doing it entirely in user space, unless you have enough time to get familiar enough with the kernel.


A file system is essetially a database for files. The main thing you'll need is a lookup table for storing byte offsets and file lengths. The file names could also be stored in the table or they could be stored in the first few bytes at each offset. It will be far easier on you if you make your file system a fixed size.

This would be similar to how the FAT file system works.

You can also have a look at http://en.wikipedia.org/wiki/Database_storage_structures since at the lowest levels file systems and databases are very similar.


The simplest way to do this would be to build a template for storing data, and parse files into ram, of course, this isn't the most efficient.

Something like...

SOME/LOCATION/Filename >>> contents of the file here, blah blah blah <<< SOME/OTHER/LOCATION/File2Name >>> contents of another file here <<<

Then to list out a directory, using regex find all lines ending in >>>, then parse up to the Xth slash (based on the number of slashes in the searched folder), and do a case (in) sensitive search, based on whether or not you want this to be case sensitive. Of course, as I mentioned loading it into memory, you could search a key->value hashmap, which would probably be a lot simpler.

0

精彩评论

暂无评论...
验证码 换一张
取 消