Posted: Thu May 24, 2007 5:56 am
Once your OS has booted the first thing you are ever likely to read from disk is the root directory, which on a FAT system will be in a fixed location, and in UNIX style systems there would presumably be a cluster number stored in the super block which would enable you to locate it. Any directory further down in the directory tree will then be read or written to in much the same way as any other file (which is what directories are). When, say, somebody wants to open a file in the root directory the file system will need to allocate a structure for that file. What needs to go in that structure is something you will soon find out when you begin to write the FS driver, but would be likely to include, for example, the current offset into the file a pointer to the files i/o buffer, and a pointer to any loaded inodes related to the file. Having done that it would need to go to the directory, look up the files entry, locate the first inode (in a Unix type system), and call the device driver to read that from disk. The inode will have pointers to other inodes if it is anything other that a very small file, and also a list of the clusters where the first part of the file is to be found. When the user wants to read the file it will then use that list of clusters to locate the file on disk, and then call the device driver to read those clusters into the buffer whose address you have stored in the FILE structure.