diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index ac5cab1e..edced334 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,3 +1,9 @@ +2002-08-23 Theodore Ts'o + + * setsuper.c: Add support for the fields s_uuid, s_journal_uuid, + s_hash_seed, s_def_hash_version. Add routines for parsing + UUID's and hash algorithm identifiers. + 2002-08-16 Theodore Ts'o * icheck.c (do_icheck): Check to see if the block is listed as diff --git a/debugfs/setsuper.c b/debugfs/setsuper.c index ce574d0b..5870770d 100644 --- a/debugfs/setsuper.c +++ b/debugfs/setsuper.c @@ -30,6 +30,8 @@ struct super_set_info { static errcode_t parse_uint(struct super_set_info *info, char *arg); static errcode_t parse_int(struct super_set_info *info, char *arg); static errcode_t parse_string(struct super_set_info *info, char *arg); +static errcode_t parse_uuid(struct super_set_info *info, char *arg); +static errcode_t parse_hashalg(struct super_set_info *info, char *arg); static struct super_set_info super_fields[] = { { "inodes_count", &set_sb.s_inodes_count, 4, parse_uint }, @@ -63,7 +65,7 @@ static struct super_set_info super_fields[] = { { "feature_compat", &set_sb.s_feature_compat, 4, parse_uint }, { "feature_incompat", &set_sb.s_feature_incompat, 4, parse_uint }, { "feature_ro_compat", &set_sb.s_feature_ro_compat, 4, parse_uint }, - /* __u8 s_uuid[16]; */ + { "uuid", &set_sb.s_uuid, 16, parse_uuid }, { "volume_name", &set_sb.s_volume_name, 16, parse_string }, { "last_mounted", &set_sb.s_last_mounted, 64, parse_string }, { "lastcheck", &set_sb.s_lastcheck, 4, parse_uint }, @@ -73,11 +75,12 @@ static struct super_set_info super_fields[] = { { "prealloc_dir_blocks", &set_sb.s_prealloc_dir_blocks, 1, parse_uint }, /* s_padding1 */ - /* s_journal_uuid */ + { "journal_uuid", &set_sb.s_journal_uuid, 16, parse_uuid }, { "journal_inum", &set_sb.s_journal_inum, 4, parse_uint }, { "journal_dev", &set_sb.s_journal_dev, 4, parse_uint }, { "last_orphan", &set_sb.s_last_orphan, 4, parse_uint }, - + { "hash_seed", &set_sb.s_hash_seed, 16, parse_uuid }, + { "def_hash_version", &set_sb.s_def_hash_version, 1, parse_hashalg }, { 0, 0, 0, 0 } }; @@ -169,6 +172,39 @@ static errcode_t parse_string(struct super_set_info *info, char *arg) return 0; } +static errcode_t parse_uuid(struct super_set_info *info, char *arg) +{ + char * p = (char *) info->ptr; + + if ((strcasecmp(arg, "null") == 0) || + (strcasecmp(arg, "clear") == 0)) { + uuid_clear(p); + } else if (strcasecmp(arg, "time") == 0) { + uuid_generate_time(p); + } else if (strcasecmp(arg, "random") == 0) { + uuid_generate(p); + } else if (uuid_parse(arg, p)) { + fprintf(stderr, "Invalid UUID format: %s\n", arg); + return EINVAL; + } + return 0; +} + +static errcode_t parse_hashalg(struct super_set_info *info, char *arg) +{ + int hashv; + unsigned char *p = (unsigned char *) info->ptr; + + hashv = e2p_string2hash(arg); + if (hashv < 0) { + fprintf(stderr, "Invalid hash algorithm: %s\n", arg); + return EINVAL; + } + *p = hashv; + return 0; +} + + static void print_possible_fields(void) { struct super_set_info *ss; @@ -183,6 +219,10 @@ static void print_possible_fields(void) type = "integer"; else if (ss->func == parse_uint) type = "unsigned integer"; + else if (ss->func == parse_uuid) + type = "UUID"; + else if (ss->func == parse_hashalg) + type = "hash algorithm"; printf("\t%-20s\t%s\n", ss->name, type); } } 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 + + * 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 * 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 + * + * This file can be redistributed under the terms of the GNU Library General + * Public License + * + */ + +#include +#include +#include +#include +#include + +#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, ""); 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, ""); - 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, ""); - } 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 ""; + e2p_uuid_to_str(uu, buf); + return buf; +} +