aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/e2p/ostype.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/e2p/ostype.c')
-rw-r--r--e2fsprogs/e2p/ostype.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/e2fsprogs/e2p/ostype.c b/e2fsprogs/e2p/ostype.c
new file mode 100644
index 000000000..fe6597dd5
--- /dev/null
+++ b/e2fsprogs/e2p/ostype.c
@@ -0,0 +1,73 @@
1/*
2 * getostype.c - Get the Filesystem OS type
3 *
4 * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
5 *
6 * This file can be redistributed under the terms of the GNU Library General
7 * Public License
8 */
9
10#include "e2p.h"
11#include <string.h>
12
13const char *os_tab[] =
14 { "Linux",
15 "Hurd",
16 "Masix",
17 "FreeBSD",
18 "Lites",
19 0 };
20
21/*
22 * Convert an os_type to a string
23 */
24char *e2p_os2string(int os_type)
25{
26 const char *os;
27 char *ret;
28
29 if (os_type <= EXT2_OS_LITES)
30 os = os_tab[os_type];
31 else
32 os = "(unknown os)";
33
34 ret = malloc(strlen(os)+1);
35 strcpy(ret, os);
36 return ret;
37}
38
39/*
40 * Convert an os_type to a string
41 */
42int e2p_string2os(char *str)
43{
44 const char **cpp;
45 int i = 0;
46
47 for (cpp = os_tab; *cpp; cpp++, i++) {
48 if (!strcasecmp(str, *cpp))
49 return i;
50 }
51 return -1;
52}
53
54#ifdef TEST_PROGRAM
55int main(int argc, char **argv)
56{
57 char *s;
58 int i, os;
59
60 for (i=0; i <= EXT2_OS_LITES; i++) {
61 s = e2p_os2string(i);
62 os = e2p_string2os(s);
63 printf("%d: %s (%d)\n", i, s, os);
64 if (i != os) {
65 fprintf(stderr, "Failure!\n");
66 exit(1);
67 }
68 }
69 exit(0);
70}
71#endif
72
73