+2002-08-23 Theodore Ts'o <tytso@mit.edu>
+
+ * 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 <tytso@mit.edu>
* icheck.c (do_icheck): Check to see if the block is listed as
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 },
{ "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 },
{ "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 }
};
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;
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);
}
}
+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
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
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);
--- /dev/null
+/*
+ * 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;
+}
+
} 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) {
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)
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;
+}
+