diff options
author | Jan Kara <jack@suse.cz> | 2013-06-08 11:26:14 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-06-08 17:03:05 -0400 |
commit | 70f4632b626e3db94dd02c9dc9b4e643ffb0d048 (patch) | |
tree | 6f7ad3c02d23f684771c8144e393670543c53533 /e2fsck/pass3.c | |
parent | bd78b1dae99b0f0d3c5456478c320f5ac0a98584 (diff) | |
download | e2fsprogs-70f4632b626e3db94dd02c9dc9b4e643ffb0d048.tar.gz |
libext2fs: provide functions to safely access name_len and file_type
Accessing name_len (and file_type) in ext4_dir_entry structure is
somewhat problematic because on big endian architecture we need to now
whether we are really dealing with ext4_dir_entry (which has u16
name_len which needs byte swapping) or ext4_dir_entry_2 (which has u8
name_len which must not be byte swapped).
Currently the code is somewhat surprising and name_len is always
treated as u16 and byte swapped (flag EXT2_DIRBLOCK_V2_STRUCT isn't
ever used) and then masking of name_len is used to access real
name_len or file_type. Doing things this way in applications using
libext2fs is unexpected to say the least (more natural is to type
struct ext4_dir_entry * to struct ext4_dir_entry_2 * but that gives
wrong results on big endian architectures. So provide helper functions
that give endian-safe access to these fields. Also convert users in
e2fsprogs to use these functions.
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'e2fsck/pass3.c')
-rw-r--r-- | e2fsck/pass3.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c index a379e9b5..193ec1c0 100644 --- a/e2fsck/pass3.c +++ b/e2fsck/pass3.c @@ -612,7 +612,7 @@ static int fix_dotdot_proc(struct ext2_dir_entry *dirent, errcode_t retval; struct problem_context pctx; - if ((dirent->name_len & 0xFF) != 2) + if (ext2fs_dirent_name_len(dirent) != 2) return 0; if (strncmp(dirent->name, "..", 2)) return 0; @@ -632,10 +632,9 @@ static int fix_dotdot_proc(struct ext2_dir_entry *dirent, dirent->inode = fp->parent; if (fp->ctx->fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_FILETYPE) - dirent->name_len = (dirent->name_len & 0xFF) | - (EXT2_FT_DIR << 8); + ext2fs_dirent_set_file_type(dirent, EXT2_FT_DIR); else - dirent->name_len = dirent->name_len & 0xFF; + ext2fs_dirent_set_file_type(dirent, EXT2_FT_UNKNOWN); fp->done++; return DIRENT_ABORT | DIRENT_CHANGED; |