For datablock allocation, we can use bitmask vector and linear search or B+ tree
1. bitmask vector and linear search
2. B+ tree
2.Implementation
http://www.farhadsaberi.com/linux_freebsd/image/unix_file_system.gif
//NOTE: 1. "Datablock" -> INode -> File -> Direcotry struct DataBlock { char data[DATA_BLOCK_SIZE]; }; DataBlock dataBlocks[NUM_DATA_BLOCKS]; //NOTE: 2. Datablock -> "INode" -> File -> Direcotry struct INode { std::vector.3 Similar Onesdatablocks; }; //NOTE: 3. Datablock -> INode -> "File" -> Direcotry std::map mapFromName; struct MetaData { int size; Date last_modified, created; char extra_attributes; } struct FSBase; struct File : public FSBase { private: std::vector * nodes; MetaData metaData; }; //NOTE: 4. Datablock -> INode -> File -> "Direcotry" Srtuct Directory :public FSBase { std::vector content; }; std::vector dataBlockUsed(); struct FileSystem { init(); mount( FileSystem* ); unmount( FileSystem* ); File createFile( const char* name ){ ... } Directory createDirectory( const char* name ) { ... } // mapFromName to find INode corresponding to file void openFile( File *file, FileMode mode){ ... } void closeFile( File *file){ ... } void writeToFile( File* file, void *data , int num ) { ... } void readFromFile( File* file, void *res, int numBytes, int position ){ ... } };
No comments:
Post a Comment