Skip to content

Commit

Permalink
lxfs: find files deeper in the dir hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 1, 2024
1 parent bfc77ac commit cc0e67a
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions fs/lxfs/src/dirtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ char *pathComponent(char *dest, const char *path, int n) {
int len = 0;
for(int i = 0; i < strlen(path); i++) {
if(path[i] == '/') c++;
if(c > n) {
i++;
if(c >= n) {
while(path[i] == '/') i++;
while(path[i] && (path[i] != '/')) {
dest[len] = path[i];
len++;
Expand Down Expand Up @@ -105,7 +105,7 @@ LXFSDirectoryEntry *lxfsFind(LXFSDirectoryEntry *dest, Mountpoint *mp, const cha
while(i < depth) {
// iterate over each component in the path and search for it in the directory
if(!pathComponent(component, path, i)) return NULL;

next = lxfsReadNextBlock(mp, next, mp->dataBuffer);
if(!next) return NULL;

Expand All @@ -122,15 +122,27 @@ LXFSDirectoryEntry *lxfsFind(LXFSDirectoryEntry *dest, Mountpoint *mp, const cha
// found the file we're looking for
return (LXFSDirectoryEntry *) memcpy(dest, dir, dir->entrySize);
} else {
// found a parent directory
// found a parent component, ensure it is a directory
i++;
luxLogf(KPRINT_LEVEL_WARNING, "TODO: implement directory trees\n");

if(((dir->flags >> LXFS_DIR_TYPE_SHIFT) & LXFS_DIR_TYPE_MASK) != LXFS_DIR_TYPE_DIR)
return NULL;

// and go back to the beginning of the loop but searching for this component
next = dir->block;
goto traverse;
}
}

// advance to the next entry
dir = (LXFSDirectoryEntry *)((uintptr_t)dir + dir->entrySize);
offset += dir->entrySize;
uint16_t oldSize = dir->entrySize;
dir = (LXFSDirectoryEntry *)((uintptr_t)dir + oldSize);
offset += oldSize;

if(!dir->entrySize) {
// file doesn't exist
return NULL;
}

if((offset >= mp->blockSizeBytes) && (next != LXFS_BLOCK_EOF)) {
// copy the second block to the first block
Expand Down

0 comments on commit cc0e67a

Please sign in to comment.