summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2002-10-15 17:43:43 -0400
committerTheodore Ts'o <tytso@mit.edu>2002-10-15 17:43:43 -0400
commita0c3fd5e4cdc2e0b032c9ace89d960a622069c32 (patch)
tree6a0b62c8dfe194fcfeda904be2e33221e5b45174 /lib
parent3e69906495d5898849a6154b0311b5d4a84a27ae (diff)
downloade2fsprogs-a0c3fd5e4cdc2e0b032c9ace89d960a622069c32.tar.gz
Add support for new feature in ext2/3 filesystems; a default mount options field
in the superblock. Added the tune2fs '-o' option to set this field.
Diffstat (limited to 'lib')
-rw-r--r--lib/e2p/ChangeLog8
-rw-r--r--lib/e2p/Makefile.in10
-rw-r--r--lib/e2p/e2p.h4
-rw-r--r--lib/e2p/ls.c19
-rw-r--r--lib/e2p/mntopts.c131
-rw-r--r--lib/ext2fs/ChangeLog4
-rw-r--r--lib/ext2fs/ext2_fs.h12
7 files changed, 182 insertions, 6 deletions
diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog
index 79714d4c..ba6c7f99 100644
--- a/lib/e2p/ChangeLog
+++ b/lib/e2p/ChangeLog
@@ -1,3 +1,11 @@
+2002-10-15 <tytso@snap.thunk.org>
+
+ * ls.c (print_mntopts, list_super2): Print any default mount
+ options which the filesystem might have.
+
+ * e2p.h, mntopts.c: New function which converts back and forth
+ between strings and default mount options.
+
2001-09-24 Theodore Tso <tytso@mit.edu>
* Release of E2fsprogs 1.29
diff --git a/lib/e2p/Makefile.in b/lib/e2p/Makefile.in
index 8d20ab19..f78223e8 100644
--- a/lib/e2p/Makefile.in
+++ b/lib/e2p/Makefile.in
@@ -17,16 +17,16 @@ INSTALL = @INSTALL@
all::
OBJS= feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \
- getflags.o getversion.o hashstr.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 mntopts.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)/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
+ $(srcdir)/ls.c (srcdir)/mntopts.o $(srcdir)/pe.c \
+ $(srcdir)/pf.c $(srcdir)/ps.c $(srcdir)/setflags.c \
+ $(srcdir)/setversion.c $(srcdir)/uuid.c
HFILES= e2p.h
diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h
index f4e43981..d76155ce 100644
--- a/lib/e2p/e2p.h
+++ b/lib/e2p/e2p.h
@@ -41,3 +41,7 @@ const char *e2p_uuid2str(void *uu);
const char *e2p_hash2string(int num);
int e2p_string2hash(char *string);
+
+const char *e2p_mntopt2string(int compat, unsigned int mask);
+int e2p_string2mntopt(char *string, unsigned int *mask);
+int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok);
diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c
index 02388fff..c18e0fff 100644
--- a/lib/e2p/ls.c
+++ b/lib/e2p/ls.c
@@ -112,6 +112,24 @@ static void print_features(struct ext2_super_block * s, FILE *f)
#endif
}
+static void print_mntopts(struct ext2_super_block * s, FILE *f)
+{
+#ifdef EXT2_DYNAMIC_REV
+ int i, printed=0;
+ __u32 mask = s->s_default_mount_opts, m;
+
+ fprintf(f, "Default mount options: ");
+ for (i=0,m=1; i < 32; i++, m<<=1) {
+ if (mask & m) {
+ fprintf(f, " %s", e2p_mntopt2string(i, m));
+ printed++;
+ }
+ }
+ if (printed == 0)
+ fprintf(f, " (none)");
+ fprintf(f, "\n");
+#endif
+}
#ifndef EXT2_INODE_SIZE
@@ -157,6 +175,7 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
} else
fprintf(f, " (unknown)\n");
print_features(sb, f);
+ print_mntopts(sb, f);
fprintf(f, "Filesystem state: ");
print_fs_state (f, sb->s_state);
fprintf(f, "\n");
diff --git a/lib/e2p/mntopts.c b/lib/e2p/mntopts.c
new file mode 100644
index 00000000..5db363e2
--- /dev/null
+++ b/lib/e2p/mntopts.c
@@ -0,0 +1,131 @@
+/*
+ * mountopts.c --- convert between default mount options and strings
+ *
+ * Copyright (C) 2002 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 mntopt {
+ unsigned int mask;
+ const char *string;
+};
+
+static struct mntopt mntopt_list[] = {
+ { EXT2_DEFM_DEBUG, "debug" },
+ { EXT2_DEFM_BSDGROUPS, "bsdgroups" },
+ { EXT2_DEFM_XATTR_USER, "user_xattr" },
+ { EXT2_DEFM_ACL, "acl" },
+ { EXT2_DEFM_UID16, "uid16" },
+ { 0, 0 },
+};
+
+const char *e2p_mntopt2string(int compat, unsigned int mask)
+{
+ struct mntopt *f;
+ static char buf[20];
+ int fnum;
+
+ for (f = mntopt_list; f->string; f++) {
+ if (mask == f->mask)
+ return f->string;
+ }
+ for (fnum = 0; mask >>= 1; fnum++);
+ sprintf(buf, "MNTOPT_%d", fnum);
+ return buf;
+}
+
+int e2p_string2mntopt(char *string, unsigned int *mask)
+{
+ struct mntopt *f;
+ char *eptr;
+ int num;
+
+ for (f = mntopt_list; f->string; f++) {
+ if (!strcasecmp(string, f->string)) {
+ *mask = f->mask;
+ return 0;
+ }
+ }
+ if (strncasecmp(string, "MNTOPT_", 8))
+ return 1;
+
+ if (string[8] == 0)
+ return 1;
+ num = strtol(string+8, &eptr, 10);
+ if (num > 32 || num < 0)
+ return 1;
+ if (*eptr)
+ return 1;
+ *mask = 1 << num;
+ return 0;
+}
+
+static char *skip_over_blanks(char *cp)
+{
+ while (*cp && isspace(*cp))
+ cp++;
+ return cp;
+}
+
+static char *skip_over_word(char *cp)
+{
+ while (*cp && !isspace(*cp) && *cp != ',')
+ cp++;
+ return cp;
+}
+
+/*
+ * Edit a mntopt set array as requested by the user. The ok
+ * parameter, if non-zero, allows the application to limit what
+ * mntopts the user is allowed to set or clear using this function.
+ */
+int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
+{
+ char *cp, *buf, *next;
+ int neg;
+ unsigned int mask;
+
+ buf = malloc(strlen(str)+1);
+ if (!buf)
+ return 1;
+ strcpy(buf, str);
+ cp = buf;
+ while (cp && *cp) {
+ neg = 0;
+ cp = skip_over_blanks(cp);
+ next = skip_over_word(cp);
+ if (*next == 0)
+ next = 0;
+ else
+ *next = 0;
+ switch (*cp) {
+ case '-':
+ case '^':
+ neg++;
+ case '+':
+ cp++;
+ break;
+ }
+ if (e2p_string2mntopt(cp, &mask))
+ return 1;
+ if (ok && !(ok & mask))
+ return 1;
+ if (neg)
+ *mntopts &= ~mask;
+ else
+ *mntopts |= mask;
+ cp = next ? next+1 : 0;
+ }
+ return 0;
+}
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 3aea116e..a12a6084 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,7 @@
+2002-10-15 <tytso@snap.thunk.org>
+
+ * ext2_fs.h: Add new field in superblock for default mount options.
+
2002-10-13 Theodore Ts'o <tytso@mit.edu>
* ext2fs.h: Add #include of header files necessary for ext2fs.h to
diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index f2c4ac32..56fabbf3 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -438,7 +438,8 @@ struct ext2_super_block {
__u8 s_def_hash_version; /* Default hash version to use */
__u8 s_reserved_char_pad;
__u16 s_reserved_word_pad;
- __u32 s_reserved[192]; /* Padding to the end of the block */
+ __u32 s_default_mount_opts;
+ __u32 s_reserved[191]; /* Padding to the end of the block */
};
/*
@@ -501,6 +502,15 @@ struct ext2_super_block {
#define EXT2_DEF_RESGID 0
/*
+ * Default mount options
+ */
+#define EXT2_DEFM_DEBUG 0x0001
+#define EXT2_DEFM_BSDGROUPS 0x0002
+#define EXT2_DEFM_XATTR_USER 0x0004
+#define EXT2_DEFM_ACL 0x0008
+#define EXT2_DEFM_UID16 0x0010
+
+/*
* Structure of a directory entry
*/
#define EXT2_NAME_LEN 255