Magellan Linux

Annotation of /trunk/mkinitrd-magellan/klibc/usr/kinit/fstype/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1297 - (hide annotations) (download)
Fri May 27 15:12:11 2011 UTC (12 years, 11 months ago) by niro
File MIME type: text/plain
File size: 1084 byte(s)
-updated to klibc-1.5.22 with mntproc definitions patch included
1 niro 532 /*
2     * by rmk
3     *
4     * Detect filesystem type (on stdin) and output strings for two
5     * environment variables:
6     * FSTYPE - filesystem type
7     * FSSIZE - filesystem size (if known)
8     *
9     * We currently detect (in order):
10     * gzip, cramfs, romfs, xfs, minix, ext3, ext2, reiserfs, jfs
11     *
12     * MINIX, ext3 and Reiserfs bits are currently untested.
13     */
14    
15     #include <stdio.h>
16     #include <fcntl.h>
17     #include <unistd.h>
18     #include <string.h>
19     #include <stdlib.h>
20     #include "fstype.h"
21    
22     char *progname;
23    
24     int main(int argc, char *argv[])
25     {
26     int fd = 0;
27     int rv;
28     const char *fstype;
29     const char *file = "stdin";
30     unsigned long long bytes;
31    
32     progname = argv[0];
33    
34     if (argc > 2) {
35     fprintf(stderr, "Usage: %s [file]\n", progname);
36     return 1;
37     }
38    
39     if (argc > 1 && !(argv[1][0] == '-' && argv[1][1] == '\0')) {
40     fd = open(file = argv[1], O_RDONLY);
41     if (fd < 0) {
42     perror(argv[1]);
43     return 2;
44     }
45     }
46    
47     rv = identify_fs(fd, &fstype, &bytes, 0);
48     if (rv == -1) {
49     perror(file);
50     return 2;
51     }
52    
53     fstype = fstype ? fstype : "unknown";
54    
55     fprintf(stdout, "FSTYPE=%s\nFSSIZE=%llu\n", fstype, bytes);
56     return rv;
57     }