summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2005-03-19 01:13:22 -0500
committerTheodore Ts'o <tytso@mit.edu>2005-03-19 01:13:22 -0500
commit63253946309651c1015947d522e2ba4b35a807a5 (patch)
tree80ade4a4dc3091092cddbdbe9c2577a6c810436e /lib
parent06ce1f6b282f2c632b1aabbee07a103d1bc1fa69 (diff)
downloade2fsprogs-63253946309651c1015947d522e2ba4b35a807a5.tar.gz
Add new functions which convert between a string and os_type: e2p_os2string()
and e2p_string2os() in the e2p library.
Diffstat (limited to 'lib')
-rw-r--r--lib/e2p/ChangeLog7
-rw-r--r--lib/e2p/Makefile.in18
-rw-r--r--lib/e2p/e2p.h3
-rw-r--r--lib/e2p/ls.c15
-rw-r--r--lib/e2p/ostype.c73
5 files changed, 101 insertions, 15 deletions
diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog
index 243c86af..a64cd104 100644
--- a/lib/e2p/ChangeLog
+++ b/lib/e2p/ChangeLog
@@ -1,3 +1,10 @@
+2005-03-19 Theodore Ts'o <tytso@mit.edu>
+
+ * ls.c (list_super2): Use the new e2p_os2string() function
+
+ * ostype.c: New file which converts between an integer os_type and
+ a string.
+
2006-02-05 Theodore Ts'o <tytso@mit.edu>
* Release of E2fsprogs 1.36
diff --git a/lib/e2p/Makefile.in b/lib/e2p/Makefile.in
index c91cd88e..f77e7696 100644
--- a/lib/e2p/Makefile.in
+++ b/lib/e2p/Makefile.in
@@ -18,7 +18,8 @@ all:: e2p.pc
OBJS= feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \
getflags.o getversion.o hashstr.o iod.o ls.o mntopts.o \
- parse_num.o pe.o pf.o ps.o setflags.o setversion.o uuid.o
+ parse_num.o pe.o pf.o ps.o setflags.o setversion.o uuid.o \
+ ostype.o
SRCS= $(srcdir)/feature.c $(srcdir)/fgetflags.c \
$(srcdir)/fsetflags.c $(srcdir)/fgetversion.c \
@@ -26,8 +27,8 @@ SRCS= $(srcdir)/feature.c $(srcdir)/fgetflags.c \
$(srcdir)/getversion.c $(srcdir)/hashstr.c $(srcdir)/iod.c \
$(srcdir)/ls.c $(srcdir)/mntopts.c $(srcdir)/parse_num.c \
$(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \
- $(srcdir)/setflags.c $(srcdir)/setversion.c $(srcdir)/uuid.c
-
+ $(srcdir)/setflags.c $(srcdir)/setversion.c $(srcdir)/uuid.c \
+ $(srcdir)/ostype.c
HFILES= e2p.h
LIBRARY= libe2p
@@ -63,6 +64,13 @@ e2p.pc: $(srcdir)/e2p.pc.in $(top_builddir)/config.status
@echo " CONFIG.STATUS $@"
@cd $(top_builddir); CONFIG_FILES=lib/e2p/e2p.pc ./config.status
+tst_ostype: $(srcdir)/ostype.c
+ @echo " LD $@"
+ @$(CC) -DTEST_PROGRAM -o tst_ostype $(srcdir)/ostype.c
+
+check:: tst_ostype
+ ./tst_ostype
+
installdirs::
@echo " MKINSTALLDIRS $(libdir) $(includedir)/e2p"
@$(MKINSTALLDIRS) $(DESTDIR)$(libdir) \
@@ -87,7 +95,8 @@ uninstall::
clean::
$(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* checker/*
- $(RM) -f ../libe2p.a ../libe2p_p.a
+ $(RM) -f ../libe2p.a ../libe2p_p.a tst_ostype
+
mostlyclean:: clean
distclean:: clean
$(RM) -f .depend Makefile e2p.pc \
@@ -132,3 +141,4 @@ setversion.o: $(srcdir)/setversion.c $(srcdir)/e2p.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
uuid.o: $(srcdir)/uuid.c $(top_builddir)/lib/ext2fs/ext2_types.h \
$(srcdir)/e2p.h $(top_srcdir)/lib/ext2fs/ext2_fs.h
+ostype.o: $(srcdir)/ostype.c $(srcdir)/e2p.h
diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h
index 048014f1..d208b46a 100644
--- a/lib/e2p/e2p.h
+++ b/lib/e2p/e2p.h
@@ -47,3 +47,6 @@ int e2p_string2mntopt(char *string, unsigned int *mask);
int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok);
unsigned long parse_num_blocks(const char *arg, int log_block_size);
+
+char *e2p_os2string(int os_type);
+int e2p_string2os(char *str);
diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c
index 0bd74118..e8d9d482 100644
--- a/lib/e2p/ls.c
+++ b/lib/e2p/ls.c
@@ -149,8 +149,7 @@ static void print_mntopts(struct ext2_super_block * s, FILE *f)
void list_super2(struct ext2_super_block * sb, FILE *f)
{
int inode_blocks_per_group;
- char buf[80];
- const char *os;
+ char buf[80], *str;
time_t tm;
inode_blocks_per_group = (((sb->s_inodes_per_group *
@@ -188,15 +187,9 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
fprintf(f, "Errors behavior: ");
print_fs_errors(f, sb->s_errors);
fprintf(f, "\n");
- switch (sb->s_creator_os) {
- case EXT2_OS_LINUX: os = "Linux"; break;
- case EXT2_OS_HURD: os = "GNU/Hurd"; break;
- case EXT2_OS_MASIX: os = "Masix"; break;
- case EXT2_OS_FREEBSD: os = "FreeBSD"; break;
- case EXT2_OS_LITES: os = "Lites"; break;
- default: os = "unknown"; break;
- }
- fprintf(f, "Filesystem OS type: %s\n", os);
+ str = e2p_os2string(sb->s_creator_os);
+ fprintf(f, "Filesystem OS type: %s\n", str);
+ free(str);
fprintf(f, "Inode count: %u\n", sb->s_inodes_count);
fprintf(f, "Block count: %u\n", sb->s_blocks_count);
fprintf(f, "Reserved block count: %u\n", sb->s_r_blocks_count);
diff --git a/lib/e2p/ostype.c b/lib/e2p/ostype.c
new file mode 100644
index 00000000..fe6597dd
--- /dev/null
+++ b/lib/e2p/ostype.c
@@ -0,0 +1,73 @@
+/*
+ * getostype.c - Get the Filesystem OS type
+ *
+ * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
+ *
+ * This file can be redistributed under the terms of the GNU Library General
+ * Public License
+ */
+
+#include "e2p.h"
+#include <string.h>
+
+const char *os_tab[] =
+ { "Linux",
+ "Hurd",
+ "Masix",
+ "FreeBSD",
+ "Lites",
+ 0 };
+
+/*
+ * Convert an os_type to a string
+ */
+char *e2p_os2string(int os_type)
+{
+ const char *os;
+ char *ret;
+
+ if (os_type <= EXT2_OS_LITES)
+ os = os_tab[os_type];
+ else
+ os = "(unknown os)";
+
+ ret = malloc(strlen(os)+1);
+ strcpy(ret, os);
+ return ret;
+}
+
+/*
+ * Convert an os_type to a string
+ */
+int e2p_string2os(char *str)
+{
+ const char **cpp;
+ int i = 0;
+
+ for (cpp = os_tab; *cpp; cpp++, i++) {
+ if (!strcasecmp(str, *cpp))
+ return i;
+ }
+ return -1;
+}
+
+#ifdef TEST_PROGRAM
+int main(int argc, char **argv)
+{
+ char *s;
+ int i, os;
+
+ for (i=0; i <= EXT2_OS_LITES; i++) {
+ s = e2p_os2string(i);
+ os = e2p_string2os(s);
+ printf("%d: %s (%d)\n", i, s, os);
+ if (i != os) {
+ fprintf(stderr, "Failure!\n");
+ exit(1);
+ }
+ }
+ exit(0);
+}
+#endif
+
+