summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2002-08-24 00:04:03 -0400
committerTheodore Ts'o <tytso@mit.edu>2002-08-24 00:04:03 -0400
commitf61fc0b5d98ef2455252d596e7b20131526d6762 (patch)
tree0613fb6167f6ce5334e0d8227e082ac344c04835 /lib
parenta3da9d1df7494cd60d9e91643ec2a243855b3bbb (diff)
downloade2fsprogs-f61fc0b5d98ef2455252d596e7b20131526d6762.tar.gz
Add support for the hash_seed and s_def_hash_ver fields in the
superblock. Dumpe2fs can now print out these fields, and they can be modified using debugfs's set_super_value command. Also added to debugfs was the ability to set s_uuid and s_journal_uuid features as well.
Diffstat (limited to 'lib')
-rw-r--r--lib/e2p/ChangeLog12
-rw-r--r--lib/e2p/Makefile.in8
-rw-r--r--lib/e2p/e2p.h4
-rw-r--r--lib/e2p/hashstr.c72
-rw-r--r--lib/e2p/ls.c19
-rw-r--r--lib/e2p/uuid.c11
6 files changed, 112 insertions, 14 deletions
diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog
index e2b1ebca..00cb3db1 100644
--- a/lib/e2p/ChangeLog
+++ b/lib/e2p/ChangeLog
@@ -1,3 +1,15 @@
+2002-08-23 Theodore Ts'o <tytso@mit.edu>
+
+ * ls.c (list_super2): Print the default hash version and the hash
+ seed for the directory indexing. Use the new e2p_uuid2str
+ function to factor out common code.
+
+ * uuid.c (e2p_uuid2str), e2p.h: New utility function which factors
+ out some common code.
+
+ * hashstr.c (e2p_hash2string, e2p_string2hash): New functions
+ which convert the hash algorithm name to and from a string.
+
2002-08-17 Theodore Ts'o <tytso@mit.edu>
* fsetflags.c (fsetflags), fgetflags.c (fgetflags.c), setflags.c
diff --git a/lib/e2p/Makefile.in b/lib/e2p/Makefile.in
index 468d4629..8d20ab19 100644
--- a/lib/e2p/Makefile.in
+++ b/lib/e2p/Makefile.in
@@ -17,14 +17,14 @@ INSTALL = @INSTALL@
all::
OBJS= feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \
- getflags.o getversion.o iod.o ls.o pe.o pf.o ps.o \
- setflags.o setversion.o uuid.o
+ getflags.o getversion.o hashstr.o iod.o ls.o pe.o pf.o ps.o \
+ setflags.o setversion.o uuid.o
SRCS= $(srcdir)/feature.c $(srcdir)/fgetflags.c \
$(srcdir)/fsetflags.c $(srcdir)/fgetversion.c \
$(srcdir)/fsetversion.c $(srcdir)/getflags.c \
- $(srcdir)/getversion.c $(srcdir)/iod.c $(srcdir)/ls.c \
- $(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \
+ $(srcdir)/getversion.c $(srcdir)/hashstr.o $(srcdir)/iod.c \
+ $(srcdir)/ls.c $(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \
$(srcdir)/setflags.c $(srcdir)/setversion.c \
$(srcdir)/uuid.c
diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h
index 9ea24bfb..f4e43981 100644
--- a/lib/e2p/e2p.h
+++ b/lib/e2p/e2p.h
@@ -37,3 +37,7 @@ int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array);
int e2p_is_null_uuid(void *uu);
void e2p_uuid_to_str(void *uu, char *out);
+const char *e2p_uuid2str(void *uu);
+
+const char *e2p_hash2string(int num);
+int e2p_string2hash(char *string);
diff --git a/lib/e2p/hashstr.c b/lib/e2p/hashstr.c
new file mode 100644
index 00000000..c889bd96
--- /dev/null
+++ b/lib/e2p/hashstr.c
@@ -0,0 +1,72 @@
+/*
+ * feature.c --- convert between features and strings
+ *
+ * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
+ *
+ * This file can be redistributed under the terms of the GNU Library General
+ * Public License
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include "e2p.h"
+
+struct hash {
+ int num;
+ const char *string;
+};
+
+static struct hash hash_list[] = {
+ { EXT2_HASH_LEGACY, "legacy" },
+ { EXT2_HASH_HALF_MD4, "half_md4" },
+ { EXT2_HASH_TEA, "tea" },
+ { 0, 0 },
+};
+
+const char *e2p_hash2string(int num)
+{
+ struct hash *p;
+ static char buf[20];
+ char fchar;
+ int fnum;
+
+ for (p = hash_list; p->string; p++) {
+ if (num == p->num)
+ return p->string;
+ }
+ sprintf(buf, "HASHALG_%d", num);
+ return buf;
+}
+
+/*
+ * Returns the hash algorithm, or -1 on error
+ */
+int e2p_string2hash(char *string)
+{
+ struct hash *p;
+ char *eptr;
+ int num;
+
+ for (p = hash_list; p->string; p++) {
+ if (!strcasecmp(string, p->string)) {
+ return p->num;
+ }
+ }
+ if (strncasecmp(string, "HASHALG_", 8))
+ return -1;
+
+ if (string[8] == 0)
+ return -1;
+ num = strtol(string+8, &eptr, 10);
+ if (num > 255 || num < 0)
+ return -1;
+ if (*eptr)
+ return -1;
+ return num;
+}
+
diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c
index e8ca09bc..02388fff 100644
--- a/lib/e2p/ls.c
+++ b/lib/e2p/ls.c
@@ -145,11 +145,7 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
} else
strcpy(buf, "<not available>");
fprintf(f, "Last mounted on: %s\n", buf);
- if (!e2p_is_null_uuid(sb->s_uuid)) {
- e2p_uuid_to_str(sb->s_uuid, buf);
- } else
- strcpy(buf, "<none>");
- fprintf(f, "Filesystem UUID: %s\n", buf);
+ fprintf(f, "Filesystem UUID: %s\n", e2p_uuid2str(sb->s_uuid));
fprintf(f, "Filesystem magic number: 0x%04X\n", sb->s_magic);
fprintf(f, "Filesystem revision #: %d", sb->s_rev_level);
if (sb->s_rev_level == EXT2_GOOD_OLD_REV) {
@@ -212,15 +208,18 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
fprintf(f, "Inode size: %d\n", sb->s_inode_size);
}
if (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
- if (e2p_is_null_uuid(sb->s_journal_uuid)) {
- strcpy(buf, "<none>");
- } else
- e2p_uuid_to_str(sb->s_journal_uuid, buf);
- fprintf(f, "Journal UUID: %s\n", buf);
+ fprintf(f, "Journal UUID: %s\n",
+ e2p_uuid2str(sb->s_journal_uuid));
fprintf(f, "Journal inode: %u\n", sb->s_journal_inum);
fprintf(f, "Journal device: 0x%04x\n", sb->s_journal_dev);
fprintf(f, "First orphan inode: %u\n", sb->s_last_orphan);
}
+ if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
+ fprintf(f, "Default directory hash: %s\n",
+ e2p_hash2string(sb->s_def_hash_version));
+ fprintf(f, "Directory Hash Seed: %s\n",
+ e2p_uuid2str(sb->s_hash_seed));
+ }
}
void list_super (struct ext2_super_block * s)
diff --git a/lib/e2p/uuid.c b/lib/e2p/uuid.c
index 5ccb29ee..fef3b91e 100644
--- a/lib/e2p/uuid.c
+++ b/lib/e2p/uuid.c
@@ -66,3 +66,14 @@ void e2p_uuid_to_str(void *uu, char *out)
uuid.node[0], uuid.node[1], uuid.node[2],
uuid.node[3], uuid.node[4], uuid.node[5]);
}
+
+const char *e2p_uuid2str(void *uu)
+{
+ static char buf[80];
+
+ if (e2p_is_null_uuid(uu))
+ return "<none>";
+ e2p_uuid_to_str(uu, buf);
+ return buf;
+}
+