Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.

Similar presentations


Presentation on theme: "Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008."— Presentation transcript:

1 Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008

2 Agenda Brief to VFS (Virtual File System) FUSE (File system in USEr space) “Hello world file system” programming tutorial Demo: a simple fuse file system example

3 Why VFS is needed Brief to VFS (Virtual File System) (1/3) User AP Ext2/3 FAT32 mount as /mnt/ext2 mount as /mnt/FAT32 #cp /mnt/ext2/data /mnt/FAT32/data Kernel User AP should know about every IO functions of each file systems to feed the need completing every IO operations. A common interface for user AP to call IO functions is necessary. 1. Call ext2_read( ) to get data from /mnt/ext2 1 2. Call FAT32_write( ) to write data to /mnt/FAT32 2 User space Kernel space

4 How VFS works Brief to VFS (Virtual File System) (2/3) User AP Ext2/3 mount as /mnt/ext2 FAT32 mount as /mnt/FAT32 #cp /mnt/ext2/data /mnt/FAT32/data Kernel User space Kernel space VFS Providing a common interface for every IO functions. register_filesystem( ) 2. Call write( ) to write data to /mnt/FAT32 2 1. Call read( ) to get data from /mnt/ext2 1

5 Issues developers shall address Hard work for kernel-programming (as drivers) Brief to VFS (Virtual File System) (3/3) User AP Ext2/3 mount as /mnt/ext2 FAT32 mount as /mnt/FAT32 Kernel User space Kernel space VFS Special-purpose File System ext2_read( ) ext2_write( ) ext2_open( ) Other necessary IO functions FAT32_read( ) FAT32_write( ) FAT32_open( ) Other necessary IO functions NewFS_read( ) NewFS_write( ) NewFS_open( ) Other necessary IO functions Kernel VFS

6 The role FUSE plays Programming a file system in user-space FUSE (File system in USEr space) (1/4) User AP Ext2/3 FAT32 User space Kernel space FUSE Kernel VFS User-level program register_filesystem( ) FUSE_read( ) FUSE_write( ) FUSE_open( ) Other necessary IO functions Been implemented by FUSE Left for developers to complete the IO functions

7 How user-level file system works FUSE (File system in USEr space) (2/4) User AP Ext2/3 FAT32 User space Kernel space FUSE Kernel VFS User-level program mount as /mnt/user_level_fs #cat /mnt/user_level_fs/data 1.Call open( ) & read( ) 2.Bypass the IO call to FUSE module 3.Diver the IO call to upper level 4.User-level program open( ) & read( ) are invoked 5.Return the result to user AP 1 2 3 4 5

8 FUSE (File system in USEr space) (3/4) FUSE-based file system: FTPFS Scenario: list the files on the remote FTP server User AP User space Kernel space Kernel VFS FTPFS user-level program FUSE mount as /mnt/ftpfs register_filesystem( ) Remote FTP server Connection establish User command: ls /mnt/ftpfs Bypass to user-level program FTP command: LS Return requested data

9 How to install FUSE package How to build and execute FUSE program FUSE (File system in USEr space) (4/4) # gcc fuse_example.c – o fuse_example -D_FILE_OFFSET_BITS=64 – lfuse #./fuse_example /mnt/mount_point # tar zxvf fuse-2.7.3.tar.gz # cd fuse-2.7.3 #./configure # make # make install

10 “Hello world file system” programming tutorial (1/) Main function and function pointers static struct fuse_operations hello_oper = {.getattr= hello_getattr,.readdir= hello_readdir,.open= hello_open,.read= hello_read, }; int main(int argc, char *argv[]) { return fuse_main(argc, argv, &hello_oper, NULL); } Been implemented by developer IO operations left for developers to implement

11 “Hello world file system” programming tutorial (2/) static const char *hello_path = "/hello"; static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { (void) offset; (void) fi; if (strcmp(path, "/") != 0) return -ENOENT; filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, hello_path + 1, NULL, 0); return 0; } # cd /mnt/mount_point ls  getattr( ), access( ), and readdir( ) are called. Relative pathBuffer storing items in directory... hello # #

12 “Hello world file system” programming tutorial (3/) # cd /mnt/mount_point # static const char *hello_path = "/hello"; static const char *hello_str = "Hello World!\n"; static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){ size_t len; (void) fi; if(strcmp(path, hello_path) != 0) return -ENOENT; len = strlen(hello_str); if (offset < len) { if (offset + size > len) size = len - offset; memcpy(buf, hello_str + offset, size); } else size = 0; return size; } cat hello  getattr( ), access( ), and read( ) are called. Relative pathBuffer storing read-out data Hello World! #

13 Demo: a simple fuse file system example

14 File system operations interface FUSE specified initdestroystatfsmknodcreate openreadwriteaccesslock truncateftruncatebmapreleasefsync unlinkflushmkdiropendirreaddir releasedirrmdirfsyncdirutimeutimens renamelinksymlinkreadlinkgetattr fgetattrsetxattrgetxattrlistxattrremovexattr chmodchown initdestroystatfslookupmknod createopenreadwriteaccess bmapgetlksetlkreleasefsync unlinkflushmkdiropendirreaddir releasedirrmdirfsyncdirchmodchown linksymlinkreadlinkgetattrsetattr setxattrgetxattrlistxattrremovexattrforget Common operations: Low-level operations:


Download ppt "Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008."

Similar presentations


Ads by Google