2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2005-04-24 10:37:59 +05:30
|
|
|
/*
|
|
|
|
* 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>
|
2006-03-08 12:33:27 +05:30
|
|
|
#include <stdlib.h>
|
2005-04-24 10:37:59 +05:30
|
|
|
|
2005-10-20 16:47:48 +05:30
|
|
|
static const char * const os_tab[] =
|
2006-01-25 05:38:53 +05:30
|
|
|
{ "Linux",
|
|
|
|
"Hurd",
|
|
|
|
"Masix",
|
|
|
|
"FreeBSD",
|
2005-04-24 10:37:59 +05:30
|
|
|
"Lites",
|
|
|
|
0 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert an os_type to a string
|
|
|
|
*/
|
|
|
|
char *e2p_os2string(int os_type)
|
|
|
|
{
|
2005-06-11 05:38:50 +05:30
|
|
|
const char *os;
|
|
|
|
char *ret;
|
2005-04-24 10:37:59 +05:30
|
|
|
|
|
|
|
if (os_type <= EXT2_OS_LITES)
|
|
|
|
os = os_tab[os_type];
|
|
|
|
else
|
|
|
|
os = "(unknown os)";
|
|
|
|
|
2006-08-03 21:11:12 +05:30
|
|
|
ret = xstrdup(os);
|
2005-06-11 05:38:50 +05:30
|
|
|
return ret;
|
2005-04-24 10:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert an os_type to a string
|
|
|
|
*/
|
|
|
|
int e2p_string2os(char *str)
|
|
|
|
{
|
2005-10-20 16:47:48 +05:30
|
|
|
const char * const *cpp;
|
2005-06-11 05:38:50 +05:30
|
|
|
int i = 0;
|
2005-04-24 10:37:59 +05:30
|
|
|
|
|
|
|
for (cpp = os_tab; *cpp; cpp++, i++) {
|
|
|
|
if (!strcasecmp(str, *cpp))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TEST_PROGRAM
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2006-01-25 05:38:53 +05:30
|
|
|
char *s;
|
2005-04-24 10:37:59 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
|