L11: Naming - Plan Last xv6 lecture Quiz next week Wrap up bcache+icache Names Concurrency - Layered picture UNIX FS API ------ hierachical names ----- directories ------ inodes ------ blocks - Explain directories each process has a current working directory (p->cwd) a file can have multiple names directory representation (14 chars, followed by inumber) dirloopup why iget doesn't take lock? what is the invariant for the inode returned for iget? what is the implication for ilock? - Finish homework L10 echo > a 11 ialloc (create 5220, ialloc 4202, bread 4002, bget 3966, iderw 3854) 11 iupdate OMIT (create 5227, iupdate 4227) 29 writei OMIT ("/a" dirent; create 4237, dirlink 4652, writei 4552) Question: why are the writes in this order? Question: what happens if concurrent create? echo > a (nothing) Question: how to allocate a block? echo x > a 28 balloc (writei 4552, bmap 4410, balloc 4104) 574 writei ("x") 11 iupdate (length, writei 4578) 574 writei ("\n") 11 iupdate (length) Question: what if concurrent app writes to same file? (in prev example) filewrite 4922, ilock 4302 Question: when can inode and blocks be freed? rm a 29 writei OMIT ("/a" dirent; sys_unlink 5185) 11 iupdate (link count; sys_unlink 5194) 574 bzero (sys_unlink 5195, iunlockput 4374, iput 4352, itrunc 4361, bfree 4130, bzero 4089) 28 bfree (4145) 11 iupdate (length; itrunc 4480) 11 iupdate (type=free; iput 4363) Question: why are the writes in this order? Question: what happens when concurrent unlink? mkdir d 11 ialloc (d's inode) 11 iupdate (create) 2 iupdate (/'s link count) 28 balloc (d's content, for . and ..) 574 writei (.) 11 iupdate (writei) 574 writei (..) 11 iupdate (writei) 29 writei (/ dirent) rm d 29 writei (/ dirent) 2 iupdate (/ link count) 11 iupdate (d's link count now 0) 574 bzero (d's dirent block) 28 bfree (d's dirent block) 11 iupdate (length; itrunc) 11 iupdate (type=free; iput) Question: why must directories be empty for before they are allowed to be removed? - Names pathnames namei is tricky we want concurrency (potentially many disk reads!) multiple objects involved (e.g., parent directory and file) concurrent changes to name space - Hard versus symbolic links symbolic links what changes necessary to xv6 cycles? why have both hard and symbolic links? - UNIX API: - shared offset between parent and child (file table) - TOCTOU problems