Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial code to support ext4 #303

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

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

lib/fs/ext2/dir.c Show resolved Hide resolved
lib/fs/ext2/dir.c Outdated Show resolved Hide resolved
@@ -12,14 +12,24 @@
#include <lk/err.h>
#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.

lib/fs/ext2/ext2.c Outdated Show resolved Hide resolved
lib/fs/ext2/ext4_fs.h Show resolved Hide resolved
@@ -128,30 +128,57 @@ static blocknum_t file_block_to_fs_block(ext2_t *ext2, struct ext2_inode *inode,
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?

lib/fs/ext2/dir.c Show resolved Hide resolved
lib/fs/ext2/dir.c Outdated Show resolved Hide resolved
} 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.

lib/fs/ext2/io.c Outdated Show resolved Hide resolved
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