| 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 |
nothing calls this directly
no test coverage detected