Top Banner
Writing flexible filesystems with FUSE-Python Anurag Patel Red Hat, Pune
25

Writing flexible filesystems in FUSE-Python

Jul 15, 2015

Download

Software

Anurag Patel
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Writing flexible filesystems in FUSE-Python

Writing flexible filesystems with

FUSE-Python — Anurag Patel Red Hat, Pune

Page 2: Writing flexible filesystems in FUSE-Python

Also available at

http://xinh.org/fuse-python

Page 3: Writing flexible filesystems in FUSE-Python

Talk overviewUNIX based filesystemsWhat's FUSE?FUSE API overviewToyFSQ&A

Page 4: Writing flexible filesystems in FUSE-Python

On filesystems“One of the real contributions of UNIX has been

the view that everything is a file.”

Page 5: Writing flexible filesystems in FUSE-Python

FilesystemsFS Platform

vfat Windows

hfs+ OS X

ext4 Linux

xfs IRIX, Linux

nfs Linux*

iso9660 CD-ROM

fuse Linux*

# cat /proc/filesystems

Page 6: Writing flexible filesystems in FUSE-Python

FilesSymbol Meaning

d Directory

l Symbolic link

c Character device

b Block device

s Socket

p Named pipe

- Regular file

Page 7: Writing flexible filesystems in FUSE-Python

FUSEFilesystem in USErspace

Page 8: Writing flexible filesystems in FUSE-Python

Virtual memory segregation

Page 9: Writing flexible filesystems in FUSE-Python

Why FUSE?Usable by unprivileged usersEasier development cycleEasy to install (apt-get install sshfs)Multiple language support and bindingsC, C++, Python, Java, Ruby, Perl, Golang, LuaPorted to FreeBSD, Mac OSX, OpenSolaris

Page 10: Writing flexible filesystems in FUSE-Python

FUSE overview

Page 11: Writing flexible filesystems in FUSE-Python

How do I install FUSE?# yum install fuse fuse-python

# apt-get install fuse python-fuse

Page 12: Writing flexible filesystems in FUSE-Python

Loading fuse# modprobe fuse

# lsmod | grep fuse

Page 13: Writing flexible filesystems in FUSE-Python

Filesystem classSubclass fuse.Fuse class and implement a

number of methods.

Page 14: Writing flexible filesystems in FUSE-Python

Mount filesystemInstantiate the Filesystem class and call main()

Page 15: Writing flexible filesystems in FUSE-Python

mount$ python toyfs.py /tmp/toy

Page 16: Writing flexible filesystems in FUSE-Python

getattr(path)Defining this method is mandatory for a working filesystem.

Page 17: Writing flexible filesystems in FUSE-Python

The stat structureMember Description

st_mode Inode protection mode

st_ino File serial number

st_dev Device ID

st_nlink Number of hard links

st_uid User ID of file

st_gid Group ID of file

st_size File size in bytes

st_atime Time of last access

st_mtime Time of last data modification

st_ctime Time of last status change

ref: <sys/stat.h>

Page 18: Writing flexible filesystems in FUSE-Python

$ stat /etc/fstab[anurag@zomg toyfs]$ stat /etc/fstab File: ‘/etc/fstab’ Size: 481 Blocks: 8 IO Block: 4096 regular fileDevice: fd01h/64769d Inode: 259076 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Context: system_u:object_r:etc_t:s0Access: 2015-02-20 14:46:16.248920273 +0530Modify: 2015-02-11 20:42:51.750210844 +0530Change: 2015-02-11 21:56:52.520767293 +0530 Birth: -[anurag@zomg toyfs]$

Page 19: Writing flexible filesystems in FUSE-Python

st_modest.st_mode = stat.S_IFDIR | 0755

Each bit of the output is 0 if the corresponding bitof x AND of y is 0, otherwise it's 1

Page 20: Writing flexible filesystems in FUSE-Python

ST_MODE flagsType Flag

d stat.S_IFDIR

l stat.S_IFLNK

c stat.S_IFCHR

b stat.S_IFBLK

s stat.S_IFSOCK

p stat.S_IFIFO

- stat.S_IFREG

ref: Python stat module

Page 21: Writing flexible filesystems in FUSE-Python

readdir(path)Read directory contents

Page 22: Writing flexible filesystems in FUSE-Python

Reading filesopen(path, flags)

read(path, length, offset)

Page 23: Writing flexible filesystems in FUSE-Python

Filesystem methodsGeneral File operation

getattr(path) open(path, flags)

mkdir(path, mode) create(path, flags, mode)

rename(old, new) read(path, length, offset)

mknod(path, mode, rdev) write(path, buf, offset)

link(target, name) fgetattr(path)

symlink(target, name) ftruncate(path, len)

readlink(path) flush(path)

unlink(path) release(path)

fsinit(self) fsync(path, fdatasync)

Page 24: Writing flexible filesystems in FUSE-Python

FUSE filesystemsfuse-zip, rarfs, mysqlfs, cryptfs, httpfs, sshfs,

imapfs, gmailfs, flickrfs, ntfs-3g, gitfs, and manymany more...