![Page 1: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/1.jpg)
Project 6
File System
![Page 2: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/2.jpg)
Administra5ve
• No Design Review – A “design document” instead
• Final project – No collabora5on with peers!
• Due on January 15 (Dean’s Date) • No precept next week – Find me in the fishbowl
• Office hours per my schedule
2
![Page 3: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/3.jpg)
Overview
• Implement a UNIX-‐like file system – In a 1MB file!
• Determined by FS_SIZE
3
![Page 4: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/4.jpg)
API
• Disk format • File – open, close, read, write, seek – link & unlink (which is how you delete a file) – stat
• Directory opera5ons – make, remove
• Shell – ls & chdir (cd)
4
![Page 5: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/5.jpg)
Don’t Worry About
• Permissions – Access Control Lists (ACLs)
• Concurrency
5
![Page 6: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/6.jpg)
Disk Layout
Space between divisions is not representa5ve of actual size
This project in a 1MB file named “disk”
6
![Page 7: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/7.jpg)
Contains metadata about the disk Examples: • Size • # of inodes • # of data blocks • Where inodes start • Where data blocks start • Etc..
7
![Page 8: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/8.jpg)
Where do I go to find …? inode array
direct
inode
metadata
indirect
Only direct for this project
8
![Page 9: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/9.jpg)
inode Metadata
Examples • File or directory? • Link count • Size • Etc..
9
![Page 10: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/10.jpg)
fs_init
• A “constructor” for the FS code • block_init
10
![Page 11: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/11.jpg)
fs_mkfs
• “Makes” a file system – Write super block – Mark inodes and data blocks to be free – Create root directory – Ini5alize file descriptor table
11
![Page 12: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/12.jpg)
File Crea5on & Dele5on
• fs_open(), fs_link(), fs_unlink() • open: create a new file if it does not exists • link: hard link to a file – create a link to an exis5ng file – hard vs. sok link?
• unlink: – delete a file if link count == 0 – delete directory entry
12
![Page 13: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/13.jpg)
File Access
• open: open exis5ng file (allocate file descriptor)
• read: read bytes from open file • write: write bytes to open file • lseek: change posi5on in file • close: free file descriptor
13
![Page 14: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/14.jpg)
fs_lseek() Seman5cs
• Our fs_lseek() only takes two arguments – fd, offset
• Unix lseek() takes three – fd, offset, whence
• Whence: SEEK_SET, SEEK_CUR, SEEK_END • Our fs_lseek() assumes SEEK_SET • What if lseek() wants to seek past the end of the file?
14
![Page 15: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/15.jpg)
Directories, part 1
• Like a file: List of files and directories – Name to inode number mapping
• Can read it like a file – Use exis5ng file I/O func5ons to do directory manipula5on
• Avoid duplicate efforts internally • Always has at least two entries – “..” parent directory – “.” current directory
15
![Page 16: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/16.jpg)
Directories, part 2
• mkdir: make a directory – create an entry in parent directory – create two directories: “..” and “.”
• rmdir: remove directory if empty • chdir: change the current directory – For rela5ve path names only
16
![Page 17: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/17.jpg)
Example fs_mkdir int fs_mkdir(char *file_name) {
if (file_name exists) return ERROR; /* allocate inode */ /* allocate data blocks */ /* set directory entries for “..” & “.” */ /* set inode entries appropriately */ /* update parent */ return SUCCESS
} 17
![Page 18: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/18.jpg)
FAQ
18
![Page 19: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/19.jpg)
Absolute Path names
• Do we need to support absolute path names? – I.e., when I am in “/foo”, do I need to support: chdir /bar/tmp/?
• No – Otherwise, you would have to support absolute path names everywhere: open, link, mkdir, etc.
19
![Page 20: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/20.jpg)
Removing a Directory
• Do I need to support recursive directory removal? – I.e., remove all the subdirectories and files contained in a directory I am going to delete?
• No – Return an error if directory is not empty
20
![Page 21: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/21.jpg)
File System Check (fsck) • Not required • Useful for debugging • Verifies integrity of: – Superblock magic number – Block alloca5ons – Inode alloca5ons – Block Alloca5on Map – Directory content – Etc.
21
![Page 22: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/22.jpg)
Implemen5ng the Project
• In Linux – Uses a file to simulate a disk – Code is provided (*Fake files) – “make lnxsh” – “./lnxsh”
• Shell supports – System calls for File System – Commands like “ls”, “cat foo”, “create foo200”
• ~1,000 lines of code 22
![Page 23: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/23.jpg)
Tes5ng
• A python script to use in tes5ng will be provided • Mul5ple tests that each – Execute the shell – Open an exis5ng file system (or format a new one) – Write commands to shell (cat foo) – Read output from shell (ABCDEFGHIJKL) – Exit
• You should write your own test cases – Submit them with your code
23
![Page 24: Project6( - cs.princeton.edu · Tesng(• A(python(scriptto(use(in(tes5ng(will(be(provided(• Mul5ple(tests(thateach(– Execute(the(shell(– Open(an(exis5ng(file(system((or(formatanew(one)](https://reader033.vdocuments.us/reader033/viewer/2022060520/604e7b6f6272aa430e6f3bca/html5/thumbnails/24.jpg)
Design Document
• Sec5ons on project page • ~85 of them • I like diagrams • PDF • Submit together with your implementa5on
24