Using FUSE to Create Your Own Filesystem [PDF]

Feb 21, 2009 - Today's Agenda. Super Brief Filesystem Basics. FUSE. Basics. Examples. Future. Building Your Own Filesyst

3 downloads 11 Views 188KB Size

Recommend Stories


Create Your Own Dystopia
Every block of stone has a statue inside it and it is the task of the sculptor to discover it. Mich

Create Your Own Smoothie
I want to sing like the birds sing, not worrying about who hears or what they think. Rumi

Create your own neural network!
Stop acting so small. You are the universe in ecstatic motion. Rumi

Create Your Own Custom Flag!
If your life's work can be accomplished in your lifetime, you're not thinking big enough. Wes Jacks

HOWTO Create Your Own Distribution
Be who you needed when you were younger. Anonymous

Create your own diary using the Collins Spec Builder
Don't fear change. The surprise is the only way to new discoveries. Be playful! Gordana Biernat

Create your own quit-smoking plan
Happiness doesn't result from what we get, but from what we give. Ben Carson

Create Your Own Home Made Soap
Ask yourself: Where am I making my life more complicated or difficult than it has to be? Next

1_BT-Create Your Own Future.pdf - Work for yourself in your own [PDF]
Page 10. Step On Your Own Accelerator. If you are like me, you are impatient about getting results. Once you have decided to do something new or different, ...... You free yourself from the Law of Accident by living your life by design. Instead of th

How To Create Your Own Workable, Profitable Price Book
Make yourself a priority once in a while. It's not selfish. It's necessary. Anonymous

Idea Transcript


Using FUSE to  Create Your Own  Filesystem James Shewmaker SCALE 7x 21 Feb 2009

Today’s Agenda  

Super Brief Filesystem Basics FUSE   Basics  Examples  Future

 Building Your Own Filesystem

Quick and Dirty  The Right Way 

Filesystem Basics 

Layers  Filesystem 

Block size, free blocklist, free inode list

 Filename 

Connects file’s name to inode or block

 Metadata (inodes) 

Last modified/access/created/changed

 Data 

List of blocks that contain the file’s content

FUSE Basics 

FUSE is a kernel module that provides  userland access to filesystem features  Takes care of all of the system library calls for 

filesystem operations  Effectively allows for significant control of  what “data” is and how to interact with it  Comes in library so you can call with C,  Python, etc.

FUSE in practice GmailFS  (libgmail, python­fuse)  sshFS (C)  Various others including http, ftp, etc.  If you aren't careful, you create a filesystem  that needs a filesystem to support it 

Necessary FUSE Default Attributes # Set Default Attributes class MyStat(fuse.Stat): def __init__(self): self.st_mode = stat.S_IFDIR || 0755 self.st_ino = 0 self.st_dev = 0 self.st_nlink = 2 self.st_uid = 0 self.st_gid = 0 self.st_size = 4096 self.st_atime = 0 self.st_mtime = 0 self.st_ctime = 0

FUSE Core Functions              

def def def def def def def def def def def def def def

getattr(self, path): readdir(self, path, offset): mknod(self, path, mode, dev): unlink(self, path): read(self, path, size, offset): write(self, path, buf, offset): release(self, path, flags): open(self, path, flags): truncate(self, path, size): utime(self, path, times): mkdir(self, path, mode): rmdir(self, path): rename(self, pathfrom, pathto): fsync(self, path, isfsyncfile):

HelloFS 

Just to prove we can make anything a FS



/usr/share/doc/python­fuse/examples/hello.py



Only creates a “hello” file in root of FS



Contents are 13 bytes: Hello world!



Use this as a template and build in small steps,  testing _every_ change

HelloFS source highlights 

class HelloFS(Fuse):



    def getattr(self, path):



        st = MyStat()



        if path == '/':



            st.st_mode = stat.S_IFDIR | 0755



            st.st_nlink = 2



        elif path == hello_path:



            st.st_mode = stat.S_IFREG | 0444



            st.st_nlink = 1



            st.st_size = len(hello_str)

HelloFS source highlights (2) 

    def readdir(self, path, offset):



        for r in  '.', '..', hello_path[1:]:



            yield fuse.Direntry(r)

 

    def open(self, path, flags):



        if path != hello_path:



            return ­errno.ENOENT



        accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR



        if (flags & accmode) != os.O_RDONLY:



            return ­errno.EACCES

HelloFS source highlights (3) 

    def read(self, path, size, offset):



        if path != hello_path:



            return ­errno.ENOENT



        slen = len(hello_str)



        if offset  slen:



                size = slen ­ offset



            buf = hello_str[offset:offset+size]



        else:



            buf = ''



        return buf

Making HelloFS writable 

Write the “write” function  Start with simple “What do I want to do?” 

questions Overwrite a file  Append to a file  Write bytes at an offset in a file 

 Remember to stop and regression test each 

time or you will go postal

Making HelloFS writable (2) 

Don't forget the “close” function  This is where things trip up  FUSE has no “close” function!

“flush”  “release” 

 Critical to take the baby steps

Simple First  Grow Complexity  Don't forget to test what used to work 

Other Ideas 

Wrote a simple replacement for /dev/tcp:  mknod opens up netcat  read and write tweaked to read/write bytes to 

STD IN/OUT  Only works for quick and dirty packet slinging Should write in “safer” I/O  Better off to use python libs instead of I/O to netcat 

 It takes a lot of effort to reinvent netcat as a 

filesystem so I'm not finished yet (Marchish?)

Other Ideas (2) Favorite filesystem that lacks one feature?  Create a filesystem that overloads that  feature  Pass regular activity on through  Examples 

 Add your own transaction logging to FAT  Filesystem rootkit tricks (lie about reads)

Other Ideas that I Can't Show 

StegoFS  Created in August, 2008  Used Forward Error Correction (FEC) and 

Steganographic techniques encode bytes in  video  Survives conversion/compression of YouTube  Used Imagemajick and ffmpeg  High Latency!  Unreleased because of patents on similar FEC

For More Info Read the examples in  /usr/share/doc/examples/fuse  http://apps.sourceforge.net/mediawiki/fuse /index.php?title=SimpleFilesystemHowto   This and other presentations at  http://bluenotch.com/resources/   SCALE in Subject: [email protected]

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.