Week 11.a CS3650 03/18 2024 https://naizhengtan.github.io/24spring/ 1. FS interface 2. Lab4: fs3650 ------ 1. FS interfaces --statfs - report file system statistics --fstat - get attributes of a file/directory --readdir - enumerate entries in a directory --read - read data from a file --rename - rename a file --chmod - change file permissions --creat - create a new (empty) file --mkdir - create new (empty) directory --unlink - remove a file --rmdir - remove a directory --write - write to a file --truncate - delete the contents of a file --utime - change access and modification times Question: What syscalls do the following cmd use? ("strace" is used to track syscalls: $ strace [CMD] 2>&1 | grep 'statfs\|fstat\|readdir\|read\|rename\|chmod\|creat\|mkdir\|unlink\|rmdir\|write\|truncate\|utime\|open\|close' ) Question: "$ df"? Question: "$ cat file"? Question: "$ mkdir dir1"? 2. CS3650 File System (lab4) [this is an (almost) duplication of the lab4 instructions.] - a Unix-like fs -- that is read only -- with many simplifications -- for example, dirs are no deeper than 10 A. fs3650 disk - an abstract disk (the overall system format) -- a block is 4KB +-------+----------+------------------------+ | super | root dir | data blocks ... | | block | inode | | +-------+----------+------------------------+ block 0 1 2 3 ... - talk to the disk? -- read or write one or multiple blocks [see handout] B. important data structures ** superblock [see handout] ** file and inode [see handout] -- metadata [or stat, see full file metadata: https://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html] -- uid, gid: user and group of this file -- mode (see below) -- ctime: changed time, time of last status (metadata) change -- mtime: modified time, time of last data modification (fs3650 skips the access time in Unix) -- size: file size in bytes -- ptrs [draw on board] ** mode (uint32_t) Question: how does fs3650 tell if an inode is a file or a dir? [see handout] |<-- S_IFMT --->| |<-- user ->|<- group ->|<- world ->| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | F | D | | | | | | R | W | X | R | W | X | R | W | X | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ -- R: read -- W: write -- X: execute -- F bit: 0100000 (the 16th bit from right) -- D bit: 0040000 (the 15th bit from right) ** directory -- recall that directory is used to map name to #inode [see handout] [draw on board as well] --Question: how many files can appear in one directory? fs3650 only supports using 1 data block (our choice). [answer: one fs_dirent is 32B (see handout) one data block is 4KB. fs3650 chooses to use only 1 data block for dir, so the max files in one dir is 4KB/32B=128. ] C. critical functionalities ** path walk input: a path (a string, char *path) output: inode number (int) --how? for example, "/a/b/c/file" [answer: 1. split path to tokens: ["a", "b", "c", "file"] 2. starting from root dir (block 1) 3. find "a" in "/" (block 1) 4. get "a"'s inode 5. get "b" in "/a/" 6. ... ] ** get attributes of a file (fs_getattr) run "$ ls -l": -rwxrw-r-- 1 usr grp 5558 Jul 27 2023 llvm.sh ^ ^ ^ ^ ^ ^ ^ | | | | | | | permission #link| group | modified date | user size (byte) file name Question: where are these attributes stored in fs? [answer: inode] how to get these? by fs_getattr ** read data from a file (fs_read) --how? for example, "read("/a/file", buf, len, offset)" (pseudocode) [answer: 1. path walk to find the file's inode 2. find offset's block (all data blocks compose a linear space) 3. read len bytes ] Question: how many block_reads does the "read(/a/file", buf, 10, 4096)" consume? [answer: 7 blocks - root inode - root data block - "/a" inode - "/a" data block - "/a/file" inode - "/a/file"'s first data block - "/a/file"'s second data block ]