summaryrefslogtreecommitdiff
path: root/e2fsck/rehash.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2006-11-11 22:32:35 -0500
committerTheodore Ts'o <tytso@mit.edu>2006-11-11 22:32:35 -0500
commitf77704e416fca7dbe4cc91abba674d2ae3c14f6f (patch)
tree1a927102301da898881d0dc788d493381f61f463 /e2fsck/rehash.c
parent52325593b1979509dc3f18232b50359e311268cc (diff)
downloade2fsprogs-f77704e416fca7dbe4cc91abba674d2ae3c14f6f.tar.gz
Add directory hashed signed/unsigned hint to superblock
The e2fsprogs and kernel implementation of directory hash tree has a bug which causes the implementation to be dependent on whether characters are signed or unsigned. Platforms such as the PowerPC, Arm, and S/390 have signed characters by default, which means that hash directories on those systems are incompatible with hash directories on other systems, such as the x86. To fix this we add a new flags field to the superblock, and define two new bits in that field to indicate whether or not the directory should be signed or unsigned. If the bits are not set, e2fsck and fixed kernels will set them to the signed/unsigned value of the currently running platform, and then respect those bits when calculating the directory hash. This allows compatibility with current filesystems, as well as allowing cross-architectural compatibility. Addresses Debian Bug: #389772 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'e2fsck/rehash.c')
-rw-r--r--e2fsck/rehash.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
index 727e08c2..4a73ddf5 100644
--- a/e2fsck/rehash.c
+++ b/e2fsck/rehash.c
@@ -88,6 +88,7 @@ static int fill_dir_block(ext2_filsys fs,
struct ext2_dir_entry *dirent;
char *dir;
unsigned int offset, dir_offset;
+ int hash_alg;
if (blockcnt < 0)
return 0;
@@ -107,6 +108,10 @@ static int fill_dir_block(ext2_filsys fs,
if (fd->err)
return BLOCK_ABORT;
}
+ hash_alg = fs->super->s_def_hash_version;
+ if ((hash_alg <= EXT2_HASH_TEA) &&
+ (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
+ hash_alg += 3;
/* While the directory block is "hot", index it. */
dir_offset = 0;
while (dir_offset < fs->blocksize) {
@@ -145,8 +150,7 @@ static int fill_dir_block(ext2_filsys fs,
if (fd->compress)
ent->hash = ent->minor_hash = 0;
else {
- fd->err = ext2fs_dirhash(fs->super->s_def_hash_version,
- dirent->name,
+ fd->err = ext2fs_dirhash(hash_alg, dirent->name,
dirent->name_len & 0xFF,
fs->super->s_hash_seed,
&ent->hash, &ent->minor_hash);
@@ -323,10 +327,16 @@ static int duplicate_search_and_fix(e2fsck_t ctx, ext2_filsys fs,
int fixed = 0;
char new_name[256];
__u16 new_len;
+ int hash_alg;
clear_problem_context(&pctx);
pctx.ino = ino;
+ hash_alg = fs->super->s_def_hash_version;
+ if ((hash_alg <= EXT2_HASH_TEA) &&
+ (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
+ hash_alg += 3;
+
for (i=1; i < fd->num_array; i++) {
ent = fd->harray + i;
prev = ent - 1;
@@ -363,8 +373,7 @@ static int duplicate_search_and_fix(e2fsck_t ctx, ext2_filsys fs,
if (fix_problem(ctx, PR_2_NON_UNIQUE_FILE, &pctx)) {
memcpy(ent->dir->name, new_name, new_len & 0xFF);
ent->dir->name_len = new_len;
- ext2fs_dirhash(fs->super->s_def_hash_version,
- ent->dir->name,
+ ext2fs_dirhash(hash_alg, ent->dir->name,
ent->dir->name_len & 0xFF,
fs->super->s_hash_seed,
&ent->hash, &ent->minor_hash);