Autumn 2021
Jerry Cain
PDF
Thanks to Chris Gregg for providing this lovely overview motivating the study of this particular filesystem!
Just like RAM, hard drives (or, more likely these days, solid state drives) provide us with a contiguous stretch of memory where we can store information.
Thanks to Ryan Eberhardt for the illustrations and most of the text used in these slides.
class Drive {
public:
size_t getNumSectors() const;
void readSector(size_t num, void *data) const;
void writeSector(size_t num, const void *data);
};
Drive d;
char data[512];
d.readSector(5, data);
Drive d;
char data[512];
bzero(data, sizeof(data));
d.writeSector(12, data);
Drive d;
int numbers[512/sizeof(int)];
d.readSector(100, numbers);
numbers[0] = 110;
d.writeSector(100, numbers);
struct inode { bool allocated = false; /* other fields */ };
Drive d;
inode inodes[512/sizeof(inode)];
d.readSector(2, inodes);
for (size_t i = 0; i < 512/sizeof(inode); i++) {
if (!inodes[i].allocated) {
inodes[i].allocated = true;
d.writeSector(2, inodes);
return i;
}
}
return -1;
/usr/class/cs110/WWW/index.html
—to seemingly magic numbers that incidentally identify where the corresponding inodes sit in the inode table.assign1
solution resides in a file named /usr/class/cs110/staff/master_repos/assign1/imdb.cc
. At 51 characters, the name wouldn't fit in an inode./usr/class/cs110/example.txt
. First, we find the inode for the file /
(which by design is always associated with inumber 1). We search inode 1's payload for the token usr
and its companion inumber. Let's say it's at inode 5. Then, we get inode 5's contents and search for the token class
in the same way. From there, we look up the token cs110
and then example.txt
.