Skip to content

Conversation

@cleverca22
Copy link
Contributor

@cleverca22 cleverca22 commented Aug 20, 2021

currently lacks the ability to deal with files with more then 4 extents
lacks the ability to deal with filesystems over 2^32 blocks long
only tested on files with 1 extent

based on reading https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout

#include "ext2_priv.h"

#define LOCAL_TRACE 0
#define LOCAL_TRACE 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal here, but make sure there's a CL that turns this back off at the end.

blocknum_t block;

LTRACEF("inode %p, fileblock %u\n", inode, fileblock);
if (inode->i_flags & 0x80000) { // inode is stored using extents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, should probably move this into a dump routine that is turned off with LOCAL_TRACE.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a LE32 as well?

} else {
cookie->cursor = pos;
}
strncpy(ent_out->name, ent->name, MIN(ent->name_len, FS_MAX_FILE_LEN));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC 11 gives a cryptic warning here:
lib/fs/ext2/dir.c:285:5: error: ‘strncpy’ output may be truncated copying between 0 and 64 bytes from a string of length 254 [-Werror=stringop-truncation]
285 | strncpy(ent_out->name, ent->name, MIN(ent->name_len, FS_MAX_FILE_LEN));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
size_t tocopy = MIN(ent->name_len, FS_MAX_FILE_LEN - 1);
memcpy(ent_out->name, ent->name, tocopy);
ent_out->name[tocopy + 1] = 0;

return ERR_NOT_FOUND;
}

buf = malloc(EXT2_BLOCK_SIZE(cookie->fs->sb));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferably find algorithm that does't need to malloc a buffer, but in the short term check for failure to malloc and abort.

lacks the ability to deal with files with more then 4 extents

todo: listing the root dir when mounted at / still fails

fix block group descriptor handling for ext4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants