#include <PFS_Main.h>
Collaboration diagram for PFS_Main:

Public Member Functions | |
| unsigned int | getSUPERBLOCKSIZEInByte () |
| SuperBlock * | getSuperBlock () |
| PFS_Directory * | findDirectory (const char *path, unsigned long long blockNumber) |
| PFS_File * | findFile (const char *path, unsigned long long blockNumber) |
| char | getSeparator () |
| void | setCurrentDirectoryBlockNo (unsigned long long) |
| unsigned long long | getCurrentDirectoryBlockNo () |
| unsigned int | readBlock (unsigned char *data, unsigned long long blockNumber, unsigned int numberOfByte=BLOCKSIZE) |
| unsigned int | readBlock (char *data, unsigned long long blockNumber, unsigned int numberOfByte=BLOCKSIZE) |
| void | printFSCache () |
Static Public Member Functions | |
| static PFS_Main * | getPFSMain () |
Protected Member Functions | |
| PFS_Main (unsigned int partitionOffset) | |
Private Attributes | |
| SuperBlock * | superBlock |
| unsigned long long | currentDirectoryBlockNo |
|
|
Definition at line 12 of file PFS_Main.cpp. References blockCaches, BLOCKSIZE, CACHE_SIZE_IN_BLOCK, currentDirectoryBlockNo, SuperBlock::getRootDirectoryLink(), kmalloc(), and superBlock. 00013 {
00014 superBlock = new SuperBlock(partitionOffset);
00015 currentDirectoryBlockNo = superBlock->getRootDirectoryLink();
00016 blockCaches = (char *) kmalloc(CACHE_SIZE_IN_BLOCK * BLOCKSIZE);
00017 }
|
|
||||||||||||
|
Definition at line 44 of file PFS_Main.cpp. References charAt(), free(), PFS_Directory::getFileOrDirectoryLink(), PFS_Directory::getName(), PFS_Directory::getNumberOfDirectory(), PFS_Directory::getNumberOfFile(), getSeparator(), kmalloc(), NUMBER_OF_FILEORDIRECTORYLINKS, print(), strcmp(), strcpy(), strlen(), and strncpy(). 00045 {
00047 if (strlen(path) == 0) {
00048 return NULL;
00049 } else if (path[0] == getSeparator() && strlen(path) == 1) {
00050 PFS_Directory *returnDir = new(blockNumber) PFS_Directory;
00051 return returnDir;
00052 }
00054 PFS_Directory dir(blockNumber);
00055 if (path[0] == getSeparator()) {
00056 path++;
00057 }
00058
00059 int tokenLength = charAt((char *) path, getSeparator());
00060 char *tokenName;
00061 bool lastDir;
00062 if (tokenLength == -1 || tokenLength == strlen(path) - 1) {
00063 // file name
00064 lastDir = true;
00065 tokenName = (char *) kmalloc(strlen(path) + 1);
00066 strcpy(tokenName, path);
00067 tokenName[strlen(path)] = '\0';
00068 } else {
00069 // dir name
00070 lastDir = false;
00071 tokenName = (char *) kmalloc(tokenLength + 1);
00072 strncpy(tokenName, path, tokenLength);
00073 tokenName[tokenLength] = '\0';
00074 }
00075
00076 if (dir.getNumberOfFile() + dir.getNumberOfDirectory() >= NUMBER_OF_FILEORDIRECTORYLINKS) {
00077 print("PFS_Main::findDirectory error, too large number of file and number of directory = %d\n", dir.getNumberOfFile() + dir.getNumberOfDirectory());
00078 return NULL;
00079 }
00080
00081 for (unsigned long long x = 0; x < dir.getNumberOfFile() + dir.getNumberOfDirectory(); x++) {
00082 if (lastDir) {
00083 if (dir.getFileOrDirectoryLink(x).id == 1 && dir.getFileOrDirectoryLink(x).link != 0) {
00084 PFS_Directory *returnDir = new(dir.getFileOrDirectoryLink(x).link) PFS_Directory;
00085
00086 if (strcmp(tokenName, returnDir->getName()) == 0) {
00087 return returnDir;
00088 }
00089
00090 free(returnDir);
00091 }
00092 } else {
00093 if (dir.getFileOrDirectoryLink(x).id == 1 && dir.getFileOrDirectoryLink(x).link != 0) {
00094 PFS_Directory dir2(dir.getFileOrDirectoryLink(x).link);
00095 if (strcmp(tokenName, dir2.getName()) == 0) {
00096 //print("recursive\n");
00097 //print("dir=%s\n", dir2.getName());
00098 return findDirectory(path + tokenLength, dir.getFileOrDirectoryLink(x).link);
00099 }
00100 }
00101 }
00102 }
00103 return NULL;
00104 }
|
|
||||||||||||
|
Definition at line 106 of file PFS_Main.cpp. References charAt(), free(), PFS_Directory::getFileOrDirectoryLink(), PFS_Directory::getName(), PFS_File::getName(), PFS_Directory::getNumberOfDirectory(), PFS_Directory::getNumberOfFile(), getSeparator(), kmalloc(), NUMBER_OF_FILEORDIRECTORYLINKS, print(), strcmp(), strcpy(), strlen(), and strncpy(). 00107 {
00108
00110 if (path[strlen(path) - 1] == getSeparator()) {
00111 return NULL;
00112 } else if (strlen(path) == 0) {
00113 return NULL;
00114 }
00116 if (path[0] == getSeparator()) {
00117 path++;
00118 }
00119 // search file in directory
00120 PFS_Directory dir(blockNumber);
00121
00122 int tokenLength = charAt((char *) path, getSeparator());
00123 char *tokenName;
00124 bool isFile;
00125 if (tokenLength == -1) {
00126 // file name
00127 isFile = true;
00128 tokenName = (char *) kmalloc(strlen(path) + 1);
00129 strcpy(tokenName, path);
00130 tokenName[strlen(path)] = '\0';
00131 } else {
00132 // dir name
00133 isFile = false;
00134 tokenName = (char *) kmalloc(tokenLength + 1);
00135 strncpy(tokenName, path, tokenLength);
00136 tokenName[tokenLength] = '\0';
00137 }
00138 if (dir.getNumberOfFile() + dir.getNumberOfDirectory() >= NUMBER_OF_FILEORDIRECTORYLINKS) {
00139 print("PFS_Main::findFile error, too large number of file and number of directory = %d\n", dir.getNumberOfFile() + dir.getNumberOfDirectory());
00140 return NULL;
00141 }
00142
00143 for (unsigned long long x = 0; x < dir.getNumberOfFile() + dir.getNumberOfDirectory(); x++) {
00144 if (isFile) {
00145 if (dir.getFileOrDirectoryLink(x).id == 0 && dir.getFileOrDirectoryLink(x).link != 0) {
00146 PFS_File *file = new(dir.getFileOrDirectoryLink(x).link) PFS_File;
00147 if (strcmp(tokenName, file->getName()) == 0) {
00148 return file;
00149 }
00150 free(file);
00151 }
00152 } else {
00153 if (dir.getFileOrDirectoryLink(x).id == 1 && dir.getFileOrDirectoryLink(x).link != 0) {
00154 PFS_Directory dir2(dir.getFileOrDirectoryLink(x).link);
00155 if (strcmp(tokenName, dir2.getName()) == 0) {
00156 //print("recursive\n");
00157 //print("dir=%s\n", dir2.getName());
00158 return findFile(path + tokenLength, dir.getFileOrDirectoryLink(x).link);
00159 }
00160 }
00161 }
00162 }
00163 //print("errorrrrrrrrrr\n");
00164 return NULL;
00165 }
|
|
|
Definition at line 39 of file PFS_Main.cpp. References currentDirectoryBlockNo. 00040 {
00041 return currentDirectoryBlockNo;
00042 }
|
|
|
Definition at line 167 of file PFS_Main.cpp. References PARTITIONOFFSET. Referenced by cd(), fopen(), PFS_File::fread(), PFS_File::loadBlock(), PFS_Directory::loadBlock(), opendir(), printFSCache(), pshell(), and start_peter(). 00168 {
00169 static PFS_Main pFS_Main(PARTITIONOFFSET);
00170 return &pFS_Main;
00171 }
|
|
|
Definition at line 29 of file PFS_Main.cpp. Referenced by findDirectory(), and findFile(). 00030 {
00031 return '/';
00032 }
|
|
|
Definition at line 19 of file PFS_Main.cpp. References superBlock. 00020 {
00021 return superBlock;
00022 }
|
|
|
Definition at line 24 of file PFS_Main.cpp. References SUPERBLOCKSIZE. 00025 {
00026 return SUPERBLOCKSIZE;
00027 }
|
|
|
Definition at line 226 of file PFS_Main.cpp. References blockCacheSize, blockCacheTail, blockIDCaches, and print(). 00227 {
00228 print("cache size=%d\n", blockCacheSize);
00229 print("cache tail=%d\n", blockCacheTail);
00230 for (int x = 0; x < blockCacheSize; x++) {
00231 print("blockIDCaches=%llu\n", blockIDCaches[x]);
00232 }
00233 }
|
|
||||||||||||||||
|
Definition at line 221 of file PFS_Main.cpp. References readBlock(). 00222 {
00223 return readBlock((unsigned char *) data, blockNumber);
00224 }
|
|
||||||||||||||||
|
Definition at line 180 of file PFS_Main.cpp. References blockCaches, blockCacheSize, blockCacheTail, blockIDCaches, BLOCKSIZE, CACHE_SIZE_IN_BLOCK, PARTITIONOFFSET, print(), readSector(), strncpy(), and SUPERBLOCKSIZE. Referenced by readBlock(). 00181 {
00182 // check the block is exist in the cache or not
00183 for (int x = 0; x < blockCacheSize; x++) {
00184 if (blockIDCaches[x] == blockNumber) {
00185 strncpy(data, blockCaches + x * BLOCKSIZE, numberOfByte);
00186 if (numberOfByte != BLOCKSIZE) {
00187 print("PFS_Main::readBlock error 1, numberOfByte=%u\n", numberOfByte);
00188 while (1);
00189 }
00190 return numberOfByte;
00191 }
00192 }
00193 // end check the block is exist in the cache or not
00194 unsigned int byteRead = readSector(PARTITIONOFFSET / 512, 0,
00195 0 + blockNumber * 8 + SUPERBLOCKSIZE / 512, data,
00196 numberOfByte);
00197 // put it in cache
00198 if (blockCacheSize < CACHE_SIZE_IN_BLOCK) {
00199 blockCacheSize++;
00200 }
00201 blockCacheTail++;
00202 if (blockCacheTail == CACHE_SIZE_IN_BLOCK) {
00203 blockCacheTail = 0;
00204 }
00205 strncpy(blockCaches + blockCacheTail * BLOCKSIZE, data, numberOfByte);
00206 if (numberOfByte != BLOCKSIZE) {
00207 print("PFS_Main::readBlock 2, numberOfByte=%u\n", numberOfByte);
00208 while (1);
00209 }
00210 blockIDCaches[blockCacheTail] = blockNumber;
00211
00212 // end put it in cache
00213 return byteRead;
00214 }
|
|
|
Definition at line 34 of file PFS_Main.cpp. 00035 {
00036 this->currentDirectoryBlockNo = currentDirectoryBlockNo;
00037 }
|
|
|
Definition at line 4 of file PFS_Main.h. Referenced by getCurrentDirectoryBlockNo(), and PFS_Main(). |
|
|
Definition at line 3 of file PFS_Main.h. Referenced by getSuperBlock(), and PFS_Main(). |
1.4.2