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

Method FindDir

Kernel/src/fs/fat32.cpp:238–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236 }
237
238 FsNode* Fat32Volume::FindDir(Fat32Node* node, char* name){
239 unsigned lfnCount = 0;
240
241 uint32_t cluster = node->inode;
242 int clusterCount = 0;
243
244 fat_entry_t* dirEntries = (fat_entry_t*)ReadClusterChain(cluster, &clusterCount);
245
246 List<int> foundEntries;
247 List<int> foundEntriesLfnCount;
248
249 fat_lfn_entry_t** lfnEntries;
250 Fat32Node* _node = nullptr;
251
252 for(unsigned i = 0; i < static_cast<unsigned>(clusterCount) * clusterSizeBytes; i++){
253 if(dirEntries[i].filename[0] == 0) return nullptr; // No Directory Entry at index
254 else if (dirEntries[i].filename[0] == 0xE5) {
255 lfnCount = 0;
256 continue; // Unused Entry
257 }
258 else if (dirEntries[i].attributes == 0x0F) lfnCount++; // Long File Name Entry
259 else if (dirEntries[i].attributes & 0x08 /*Volume ID*/){
260 lfnCount = 0;
261 continue;
262 } else {
263 char* _name = (char*)kmalloc(128);
264 if(lfnCount){
265 lfnEntries = (fat_lfn_entry_t**)kmalloc(sizeof(fat_lfn_entry_t*) * lfnCount);
266
267 for(unsigned k = 0; k < lfnCount; k++){
268 fat_lfn_entry_t* lfnEntry = (fat_lfn_entry_t*)(&dirEntries[i - k - 1]);
269
270 lfnEntries[k] = lfnEntry;
271 }
272
273 GetLongFilename(_name, lfnEntries, lfnCount);
274
275 kfree(lfnEntries);
276 } else {
277 strncpy(_name, (char*)dirEntries[i].filename, 8);
278 while(strchr(_name, ' ')) *strchr(_name, ' ') = 0; // Remove Spaces
279 if(strchr((char*)dirEntries[i].ext, ' ') != (char*)dirEntries[i].ext){
280 strncpy(_name + strlen(_name), ".", 1);
281 strncpy(_name + strlen(_name), (char*)dirEntries[i].ext, 3);
282 }
283 }
284
285 if(strcmp(_name, name) == 0){
286 uint64_t clusterNum = (((uint32_t)dirEntries[i].highClusterNum) << 16) | dirEntries[i].lowClusterNum;
287 if(clusterNum == bootRecord->ebr.rootClusterNum || clusterNum == 0)
288 return mountPoint; // Root Directory
289 _node = new Fat32Node();
290 _node->size = dirEntries[i].fileSize;
291 _node->inode = clusterNum;
292 if(dirEntries[i].attributes & FAT_ATTR_DIRECTORY) _node->flags = FS_NODE_DIRECTORY;
293 else _node->flags = FS_NODE_FILE;
294 break;
295 }

Callers

nothing calls this directly

Calls 7

kmallocFunction · 0.85
GetLongFilenameFunction · 0.85
kfreeFunction · 0.85
strncpyFunction · 0.85
strchrFunction · 0.85
strlenFunction · 0.85
strcmpFunction · 0.85

Tested by

no test coverage detected