MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / FindDir

Method FindDir

Kernel/src/fs/ext2.cpp:952–1049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

950 }
951
952 FsNode* Ext2Volume::FindDir(Ext2Node* node, char* name){
953 if((node->flags & FS_NODE_TYPE) != FS_NODE_DIRECTORY){
954 return nullptr;
955 }
956
957 if(node->inode < 1){
958 Log::Warning("[Ext2] ReadDir: Invalid inode: %d", node->inode);
959 return nullptr;
960 }
961
962 ext2_inode_t& ino = node->e2inode;
963
964 uint8_t buffer[blocksize];
965 uint32_t currentBlockIndex = 0;
966 uint32_t blockOffset = 0;
967 uint32_t totalOffset = 0;
968
969 ext2_directory_entry_t* e2dirent = (ext2_directory_entry_t*)buffer;
970
971 if(ReadBlockCached(GetInodeBlock(currentBlockIndex, ino), buffer)){
972 Log::Info("[Ext2] Failed to read block %d", GetInodeBlock(currentBlockIndex, ino));
973 return nullptr;
974 }
975
976 while(currentBlockIndex < ino.blockCount / (blocksize / 512)){
977 if(e2dirent->recordLength < 8) {
978 IF_DEBUG(debugLevelExt2 >= DebugLevelNormal, {
979 Log::Warning("[Ext2] Error (inode: %d) record length of directory entry is invalid (value: %d)!", node->inode, e2dirent->recordLength);
980 });
981 break;
982 }
983
984 if(e2dirent->inode > 0){
985 IF_DEBUG(debugLevelExt2 >= DebugLevelVerbose, {
986 char buf[e2dirent->nameLength + 1];
987 strncpy(buf, e2dirent->name, e2dirent->nameLength);
988 buf[e2dirent->nameLength] = 0;
989 Log::Info("Checking name '%s' (name len %d), inode %d, len %d (parent inode: %d)", buf, e2dirent->nameLength, e2dirent->inode, e2dirent->recordLength, node->inode);
990 });
991
992 if(strlen(name) == e2dirent->nameLength && strncmp(name, e2dirent->name, e2dirent->nameLength) == 0){
993 break;
994 }
995 }
996
997 blockOffset += e2dirent->recordLength;
998 totalOffset += e2dirent->recordLength;
999
1000 if(totalOffset > ino.size) return nullptr;
1001
1002 if(blockOffset >= blocksize){
1003 currentBlockIndex++;
1004
1005 if(currentBlockIndex >= ino.blockCount / (blocksize / 512)){
1006 // End of dir
1007 return nullptr;
1008 }
1009

Callers

nothing calls this directly

Calls 10

WarningFunction · 0.85
InfoFunction · 0.85
strncpyFunction · 0.85
strlenFunction · 0.85
strncmpFunction · 0.85
ErrorFunction · 0.85
AcquireReadMethod · 0.80
ReleaseReadMethod · 0.80
getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected