Skip to content

Instantly share code, notes, and snippets.

- sector_ofs: Which byte in a sector we want to start reading from/writing to
- min_left: Lesser of remaining bytes in inode or remaining bytes in sector.
- chunk_size: If min_left is less than the SIZE number of bytes we want to write, only read/write min_left by setting chunk_size to min_left, and then load in next sector and continue reading/writing. Else set chunk_size to SIZE
Okay, so I'm getting mixed up with what pointers we have to pass in for allocating singly and doubly indirect blocks. So if we have
block_sector_t *sing_indirect and block_sector_t *doub_indirect, to allocate singly indirect blocks:
1. We call free_map_alloc(1, sing_indirect), which will make *sing_indirect equal a block_sector_t struct
2. Then, we call block_read(fs, *sing_indirect, buf) to get the sector of memory that sing_direct references.
3. Call free_map_alloc(1, &(buf + i)) where i is a multiple of 4, which fills buf with i block_sector_t structs.
4. Call block_write(fs_device, buf + i, zeros), where zeros is a sector of zeros, and i is a multiple of 4.
5. Call block_write(fs_deivce, *sing_indirect, buf), which writes 512 bytes worth of block_sector_t structs into the sector that
sing_indirect references.
-How do we implement writing data to indirect pointers?
-In inode_disk, do we still need the start field, because can’t we just get direct_pointer[0], and that’s the start of the file?
- If we comment out start, then do we need to have another member/field in our struct to make sure inode_disk is exactly 512 bytes?
-When preventing race conditions for directory entries, should you acquire one lock before traversing directories,
and then acquire a separate lock when we actually create the file/dir itself? When do we acquire locks for creating directories?