CS计算机代考程序代写 file system Last updated: March 9, 2021

Last updated: March 9, 2021
Carleton University School of Computer Science
COMP 3000 (WINTER 2021) OPERATING SYSTEMS TUTORIAL 5
Tasks (Part A)
1. Compile and run 3000test.c. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:
o a regular text file that exists
o a directory
o a symbolic link
o a device file (character or block)
It reports the number of ¡®a¡¯ if the file is a regular file or the link points to a regular file. The length is the logical size.
2. Change 3000test to use rather than stat. How does its behavior change?
lstat() does not resolve a symbolic link. So, it returns the inode of the link itself.
3. Modify3000testsowhenitisgivenasymboliclinkitreportsthenameofthetarget.Use (this notation describes how to access the man page, e.g., ).
First use to check if it¡¯s a symbolic link and then .
4. Aretherefilesordirectoriesthatyoucannotrun3000teston?Canyouconfigurefile/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (nothing can be displayed, except the error msg); 2) whether it can be accessed for the search (no access to file content).
This is where you can improve your understanding of the relationship between inodes and directory entries, and between the inodes and their data blocks.
The permission bits are in the inode, so denied access only applies to data blocks but not the inode.
Likewise, if the directory entry is no accessible (which is like data of the directory inode), there¡¯s no way to find the inode number, not to mention what permission bits are there.
lstat()
readlink(2)
S_ISLNK
readlink()
man 2 readlink
Tasks (Part B)
1. Run and use the ls command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K. Any observations?
This is the case when logical size can be greater than physical size (¡°holes¡± in a file). The first command explicitly writes that many zero¡¯s taking up physical space. The second command skips 31K blocks writing only 1K blocks (note: the skipped blocks are still part of the file size, e.g., if you write to the second byte, there must exist the first byte), where the
dd if=/dev/zero of=foo bs=8192 count=32K

file system does some optimization by only allocating 1K blocks, hence the holes.
2. Runmkfs.ext4foo.Doesfooconsumeanymorespaceorless?Dothesame(mkfs.ext4foo2) to the other file and answer the same question.
mkfs creates the file system structures (e.g., the superblocks) so it writes data to the file, leading to actual allocation of space. This may trigger the optimization (so the OS realizes that there are repeated 0¡¯s), which may potentially make the file smaller (for foo). But for foo2, since it¡¯s already optimized (with holes, no wasted space), extra physical space needs to be allocated to hold what mkfs writes.
3. Create any file in /mnt (e.g., sudo touch test.txt) and run sudo mount foo /mnt. Do you still see the file you just created?
As discussed, mounting over an existing directory (it has to be existing) will not affect its current content. It¡¯s just like redirection or pointing to another file system from there.
4. Rundf.Whatdeviceismountedon/mnt?Whatisthisdevice? You should see the loopback device mounted on /mnt.
5. Runsudoumount/mnt.Whathavegoneawayandwhatisback? See 3 above.
6. Runddif=/dev/zeroof=fooconv=notrunccount=10bs=512.Howdoesthe”conv=notrunc” change dd’s behavior (versus the command in question 2)?
notrunc means, instead of erasing an existing file first (truncating to zero), dd will just overwrite wherever it writes, leaving anywhere not written untouched. This way, you still have the file system created previously but have overwritten part of the primary superblock.
7. Runsudomountfoo/mnt.Whaterrordoyouget?
Well, the file system has been corrupted in the previous step (superblock).
8. What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea) fsck finds the backup superblocks and replaces the corrupted primary one with it.
2