foo/
|
+-----+---+---+--------+
| | | |
bar/ baz/ info.txt hello.c
| |
img.png |
|
+--------+-------+-------+-------+
| | | | |
meme.gif run.sh items.csv main.s letter.docx
open
/ close
- open (or create) / close a
fileread
/ write
- read / write bytes from/to
filelseek
fsync
rename
stat
link
unlink
mkdir
rmdir
opendir
/ readdir
/
closedir
+---------------------------------------------------------------+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+---------------------------------------------------------------+
0 31
What is stored in blocks?
+---------------------------------------------------------------+
| | | | | | | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|
+---------------------------------------------------------------+
0 31
+---------------------------------------------------------------+
| | | |I|I|I|I|I|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|
+---------------------------------------------------------------+
0 31
+---------------------------------------------------------------+
| |i|d|I|I|I|I|I|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|
+---------------------------------------------------------------+
0 31
+---------------------------------------------------------------+
|S|i|d|I|I|I|I|I|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|
+---------------------------------------------------------------+
0 31
Each inode has an i-number (a low-level identifier) - its index in the inode table
Given an index, it’s straightforward to calculate the location of an inode on a disk (its sector):
blk = (inumber * sizeof(inode_t)) / blockSize
sector = ((blk * blockSize) + inodeStartAddr) / sectorSize
Contains an array of block pointers (addresses) for the file:
foo.txt: +-+
+------>| |
+-+ | |-|
| |------+ | |
|-| |-|
| |-----+ +---->| |
|-| | | |-|
| |-----|--|---->| |
+-+ | | |-|
+--|---->| |
bar.txt: | |-|
+-+ | | |
| |----+ | |-|
|-| | | | |
| |----|---+ |-|
+-+ +-------->| |
+-+
Example inode contents (ext2):
Size | Name | Purpose |
---|---|---|
2 | mode | can this file be read/written/executed? |
2 | uid | who owns this file? |
4 | size | how many bytes are in this file? |
4 | time | what time was this file last accessed? |
4 | ctime | what time was this file created? |
4 | mtime | what time was this file last modified? |
4 | dtime | what time was this inode deleted? |
2 | gid | which group does this file belong to? |
2 | links_count | how many hard links are there to this file? |
4 | blocks | how many blocks have been allocated to this file? |
4 | flags | how should ext2 use this inode? |
4 | osd1 | an OS-dependent field |
60 | block | a set of disk pointers (15 total for 32-bit) |
4 | generation | file version (used by NFS) |
4 | file_acl | a new permissions model beyond mode bits |
4 | dir_acl | called access control lists |
Note: There’s a limited number of pointers (e.g., 15 above)
What to do when a file is bigger than 10 blocks?
→ Indirection - Multi-level index
14 + (4K / 4) = 14 + 1024 = 1038
pointers, which
means our files can have 1038 * 4K = 4152K
(roughly
4M)1038
(single indirection) and an additional
1024 * 1024
pointers/
) has a set i-numberinum |
reclen |
strlen |
name |
---|---|---|---|
5 | 12 | 2 | . |
2 | 12 | 3 | .. |
12 | 12 | 4 | foo |
13 | 12 | 4 | bar |
24 | 36 | 28 | foobar_is_a_pretty_longname |
With our FS, what is the number of I/O when accessing a file?