xv6 file system - pages.cs.wisc.edupages.cs.wisc.edu › ~gerald › cs537 › fall17 › handouts...

8
Xv6 File System Zhewen Song 11/28/2017

Upload: others

Post on 02-Feb-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

  • Xv6FileSystemZhewenSong11/28/2017

  • FileSystemLayoutinxv6

    Unused | Superblock | Inodes ... | Unused | Bitmap | Data ...

  • Inode ofaregularfileinxv6

    type = 2majorminornlinksizeaddr 1...

    addr 12indirect addr 1

    ...addr 128

    data

    data

    data

    data

    ...

    64 Bytes512 Bytes

    512 Bytes

    What’sthemaximumpossiblesizeofaregularfile?

    ...

  • Inode ofadirectoryinxv6

    type = 1majorminornlinksizeaddr 1...

    addr 12indirect addr 1

    ...addr 128

    dirent 1...

    dirent 32

    dirent 1...

    dirent 32

    dirent 1...

    dirent 32

    dirent 1...

    dirent 32

    ...

    ...

    64 Bytes512 Bytes

    512 Bytes

    Howmanyfiles/subdirectoriescanadirectoryhaveatmost?

  • Bitmapinxv6

    • Eachbitinthebitmapisassociatedwithablock,NOTaninode.• Althoughtheveryfirstblockisunused,itisalwaysmarkedas1inthefirstbitofthebitmap,andsoarealltheblockswheretheinodes andbitmapitselfreside.• Bitmapisgroupedinbyte.• Intelx86processorsuselittle-endian.• Example:• ff c2 => 1111 1111 1100 0010

    7 6 5 4 3 2 1 0 | 15 14 13 12 11 10 9 8

  • Demos

    • Howtobuildyourownfilesystemimageandreflectinxv6• Closerlookatmkfs.c

    • Howxv6fileschangetheimage• Closerlookatfs.img with xxd• Sometrickseditingfileimageswithvim:

    • :%!xxd toopentheimage;:%!xxd –r tosavechanges

    • Howtoreadimage?– mmap()!

  • Demos• UsingGDB,gothroughtheentirewritesystemcall.• Keymethodstounderstand:

    • writei() in kernel/sysfile.c• bmap() inkernel/fs.c• bread(), bwrite() in kernel/bio.c

    • Howdoesxv6normallyhandlelargefiles?• Whatdowedotohandlesmallfileshere?