Introduction to File System

Introduction to File System

FUSE: File system in user space Introduction • Implement simple file system in userspace ls -l sshfs libfuse ssh server VFS FUSE Ext4 • Compatiblity – Linux, FreeBSD, NetBSD, Mac OS X, OpenSolaris, … • Example file systems – Gnome VFS2, unionfs, ftpfs, sshfs, Android sdcard, … How to use • Installation – apt-get install fuse fuse-utils libfuse2 libfuse-dev – Source: http://fuse.sourceforge.net/ • Mount / unmount – sshfs user@host /tmp/fuse – fusermount –u /tmp/fuse Using SSHFS • Setup ssh server – apt-get install ssh • Install sshfs – apt-get install sshfs • Mount sshfs – mkdir /home/user/fusemnt – sshfs user@localhost:/home/user /home/user/fusemnt • Unmount sshfs – fusermount –u /home/user/fusemnt Low-level FUSE interface • FUSE communication channel – /dev/fuse fd = open(“/dev/fuse”, O_RDWR) • Mounting a file system – mount(“/dev/fuse”, mount_point, “fuse”, flags, opts) – opts: “fd=n,…” fuse_in_header • Handling file system requests FS request read() /dev/fuse FUSE UserFS (kernel) write() fuse_out_header FS response FUSE communication example open(“/dev/fuse”) mount(“/dev/fuse”,mntpoint,“fuse”,…) FUSE_INIT User-level FUSE_LOOKUP file system FUSE application FUSE_OPEN (kernel) /dev/fuse ex. sshfs FUSE_READ FUSE_WRITE FUSE_RELEASE FUSE message headers • struct fuse_in_header fuse_in_header – Describes a file system request u32 len – enum fuse_opcode opcode: u32 opcode • init u64 unique • open, read, write u64 nodeid • mknod, mkdir, readlink, symlink, unlink u32 uid • rmdir, rename u32 gid • lookup, forget, getattr, setattr u32 pid • statfs, release, flush u32 padding • opendir, readdir, releasedir fuse_out_header • struct fuse_out_header u32 len s32 error – Return execution result u64 unique Directory access • FUSE_LOOKUP fuse_entry_out – Find file “data” in directory fuse->nodeid u64 nodeid – Returns struct fuse_entry_out u64 generation u64 entry_valid u64 attr_valid • struct fuse_open_in fuse_attr – u32 flags fuse_open_out – Open file identified by fuse->nodeid u64 fh – User defines file handle fh u32 open_flags fuse_release_in • u64 fh struct fuse_release_in u32 flags – Close file fh u32 release – No return _flags u64 lock_owner Read and write • struct fuse_read_in fuse_read_in – Next to fuse_in_header u64 fh u64 offset – Read file (offset, size) u32 size – Send result to /dev/fuse u32 read_flags u64 lock_owner u32 flags • struct fuse_write_in u32 padding – Identical to fuse_read_in – File data comes next to fuse_write_in fuse_write_out – Return fuse_write_out to /dev/fuse u32 size u32 padding Other primitives • Refer to include/fuse_kernel.h – struct fuse_(opcode)_in/out • FUSE for Python – http://sourceforge.net/apps/mediawiki/fuse/index.php?title =SimpleFilesystemHowto • Other language bindings – C++, Java, C#, Go, Haskell, TCL, Perl, Ocaml, Ruby, Lua, … – http://sourceforge.net/apps/mediawiki/fuse/index.php?title =LanguageBindings libfuse: C binding • High-level API – Implements common fuse ⇔ kernel interactions • Mount command-line parsing • Interpret fuse_in_header and build fuse_out_header – Simplifies file system implementation • Developing with libfuse – Include: <fuse.h> – Compile: gcc -Wall `pkg-config fuse --cflags --libs` – Example: /usr/share/doc/libfuse-dev/examples/hello.c – Document: http://fuse.sourceforge.net/doxygen/index.html Implementing FS with libfuse • struct fuse_operations – Define and override file system operations – Example • .open(char *path, struct fuse_file_info *fi) • .read(char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) • fuse_main(argc, argv, &op, user_data) – Mounts the file system – Fetches file system requests and calls defined functions – Returns when unmounted: fusermount –u .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us