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

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

description

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/ext Call FAT32_write( ) to write data to /mnt/FAT32 2 User space Kernel space

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

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

Introduction to FUSEIntroduction to FUSE(File system in USEr space)(File system in USEr space)

Speaker: Zong-shuo JhengDate: March 14, 2008

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

AgendaAgenda

• 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

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

• Why VFS is needed

Brief to VFS (Virtual File System) (1/3)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 spaceKernel space

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

• How VFS works

Brief to VFS (Virtual File System) (2/3)Brief to VFS (Virtual File System) (2/3)

User AP

Ext2/3mount as /mnt/ext2

FAT32mount as /mnt/FAT32

#cp /mnt/ext2/data /mnt/FAT32/data

Kernel

User spaceKernel space

VFS

Providing a common interface for every IO functions.

register_filesystem( )

register_filesystem( )

2. Call write( ) to write data to /mnt/FAT32

2

1. Call read( ) to get data from /mnt/ext2

1

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

• Issues developers shall address • Hard work for kernel-programming (as drivers)

Brief to VFS (Virtual File System) (3/3)Brief to VFS (Virtual File System) (3/3)

User AP

Ext2/3mount as /mnt/ext2

FAT32mount as /mnt/FAT32

Kernel

User spaceKernel space

VFS

Special-purposeFile 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

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

• The role FUSE plays• Programming a file system in user-space

FUSE (File system in USEr space) (1/4)FUSE (File system in USEr space) (1/4)

User AP

Ext2/3

FAT32

User spaceKernel 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

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

• How user-level file system works

FUSE (File system in USEr space) (2/4)FUSE (File system in USEr space) (2/4)

User AP

Ext2/3

FAT32

User spaceKernel 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 module3.Diver the IO call to upper level 4.User-level program open( ) & read( ) are invoked5.Return the result to user AP

1

2

3

4

5

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

FUSE (File system in USEr space) (3/4)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 spaceKernel space

Kernel

VFS

FTPFSuser-levelprogram

FUSEmount as /mnt/ftpfs

register_filesystem( )

RemoteFTP server

Connection establishUser command: ls /mnt/ftpfs

Bypass to user-level program

FTP command: LSReturn requested data

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

• How to install FUSE package

• How to build and execute FUSE program

FUSE (File system in USEr space) (4/4)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

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

““Hello world file system” programming Hello world file system” programming tutorial (1/)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

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

““Hello world file system” programming Hello world file system” programming tutorial (2/)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_pointls getattr( ), access( ), and readdir( )

are called.

Relative path Buffer storing items in directory

. .. hello#

#

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

““Hello world file system” programming Hello world file system” programming tutorial (3/)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 path Buffer storing read-out data

Hello World!#

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

Demo: a simple fuse file system exampleDemo: a simple fuse file system example

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

File system operations interface File system operations interface FUSE specifiedFUSE specified

init destroy statfs mknod createopen read write access lock

truncate ftruncate bmap release fsyncunlink flush mkdir opendir readdir

releasedir rmdir fsyncdir utime utimensrename link symlink readlink getattrfgetattr setxattr getxattr listxattr removexattrchmod chown

init destroy statfs lookup mknodcreate open read write accessbmap getlk setlk release fsyncunlink flush mkdir opendir readdir

releasedir rmdir fsyncdir chmod chownlink symlink readlink getattr setattr

setxattr getxattr listxattr removexattr forget

Common operations:

Low-level operations: