Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node* Node::findNode(const char* name) {
- if (!isDirectory()) return nullptr;
- // read the direct block to try to find the d_entry with the given name
- // if not found in direct block, go to indirect block and find the d_entry with the given name
- uint32_t currentSize = this->getSize();
- uint8_t* retrieveDir = (uint8_t*) malloc(currentSize);
- this->readAll(0, retrieveDir, currentSize);
- // find the length of the given name
- uint32_t givenLength = 0;
- while (name[givenLength] != '\0') {
- givenLength++;
- }
- givenLength--;
- uint32_t currentByte = 0;
- while (currentByte < currentSize) {
- bool directBlockEntries = true;
- uint32_t currentINumber = 0;
- for (uint32_t i = 0; i < 4; i++) {
- currentINumber = (currentINumber << 8) | ((uint32_t) retrieveDir[currentByte + i]);
- }
- Debug::printf("~~~CURRENT I-number: %d\n", currentByte);
- uint32_t currentNameLength = 0;
- for (uint32_t i = 4; i < 8; i++) {
- currentNameLength = (currentNameLength << 8) | ((uint32_t) retrieveDir[currentByte + i]);
- }
- Debug::printf("~~~CURRENT NAME LENGTH: %d\n", currentNameLength);
- // skip if the lengths of the names are not equal
- if (givenLength != currentNameLength) {
- currentByte += 8 + currentNameLength;
- continue;
- }
- // get the name of the current d_entry
- //char* currentName = (char*) malloc(currentNameLength);
- for (uint32_t i = currentByte + 8; i < currentByte + 8 + currentNameLength; i++) {
- //currentName[i - (currentByte + 8)] = retrieveDir[i];
- if (name[i - (currentByte + 8)] != retrieveDir[i]) {
- currentByte += 8 + currentNameLength;
- //free(currentName);
- directBlockEntries = false;
- }
- }
- if (!directBlockEntries) continue;
- Node* ans = new Node(this->fs, currentINumber);
- free(retrieveDir);
- //free(currentName);
- return ans;
- }
- return nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement