Contents of /trunk/mkinitrd-magellan/klibc/usr/kinit/fstype/main.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1103 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1103 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* |
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 <errno.h> |
20 | #include <stdlib.h> |
21 | #include "fstype.h" |
22 | |
23 | char *progname; |
24 | |
25 | int main(int argc, char *argv[]) |
26 | { |
27 | int fd = 0; |
28 | int rv; |
29 | const char *fstype; |
30 | const char *file = "stdin"; |
31 | unsigned long long bytes; |
32 | |
33 | progname = argv[0]; |
34 | |
35 | if (argc > 2) { |
36 | fprintf(stderr, "Usage: %s [file]\n", progname); |
37 | return 1; |
38 | } |
39 | |
40 | if (argc > 1 && !(argv[1][0] == '-' && argv[1][1] == '\0')) { |
41 | fd = open(file = argv[1], O_RDONLY); |
42 | if (fd < 0) { |
43 | perror(argv[1]); |
44 | return 2; |
45 | } |
46 | } |
47 | |
48 | rv = identify_fs(fd, &fstype, &bytes, 0); |
49 | if (rv == -1) { |
50 | perror(file); |
51 | return 2; |
52 | } |
53 | |
54 | fstype = fstype ? fstype : "unknown"; |
55 | |
56 | fprintf(stdout, "FSTYPE=%s\nFSSIZE=%llu\n", fstype, bytes); |
57 | return rv; |
58 | } |