OSDN Git Service

Make ext2 utils available to all builds
[android-x86/external-e2fsprogs.git] / misc / partinfo.c
1 /*
2  * partinfo.c
3  *
4  * Originally written by Alain Knaff, <alknaff@innet.lu>.
5  *
6  * Cleaned up by Theodore Ts'o, <tytso@mit.edu>.
7  *
8  */
9
10 #include <sys/types.h>
11 #include <fcntl.h>
12 #ifdef HAVE_SYS_IOCTL_H
13 #include <sys/ioctl.h>
14 #endif
15 #include <stdio.h>
16 #include <linux/hdreg.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <errno.h>
20 #include "nls-enable.h"
21
22 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
23 #define BLKGETSIZE _IO(0x12,96) /* return device size */
24 #endif
25
26 int main(int argc, char **argv)
27 {
28         struct hd_geometry loc;
29         int fd, i;
30         unsigned long size;
31
32 #ifdef ENABLE_NLS
33         setlocale(LC_MESSAGES, "");
34         setlocale(LC_CTYPE, "");
35         bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
36         textdomain(NLS_CAT_NAME);
37 #endif
38         if (argc == 1) {
39                 fprintf(stderr, _("Usage:  %s device...\n\nPrints out the "
40                         "partition information for each given device.\n"
41                         "For example: %s /dev/hda\n\n"), argv[0], argv[0]);
42                 exit(1);
43         }
44
45         for (i=1; i < argc; i++) {
46                 fd = open(argv[i], O_RDONLY);
47
48                 if (fd < 0) {
49                         fprintf(stderr, _("Cannot open %s: %s"),
50                                 argv[i], strerror(errno));
51                         continue;
52                 }
53
54                 if (ioctl(fd, HDIO_GETGEO, &loc) < 0) {
55                         fprintf(stderr, _("Cannot get geometry of %s: %s"),
56                                 argv[i], strerror(errno));
57                         close(fd);
58                         continue;
59                 }
60
61
62                 if (ioctl(fd, BLKGETSIZE, &size) < 0) {
63                         fprintf(stderr, _("Cannot get size of %s: %s"),
64                                 argv[i], strerror(errno));
65                         close(fd);
66                         continue;
67                 }
68
69                 printf(_("%s: h=%3d s=%3d c=%4d   start=%8d size=%8lu end=%8d\n"),
70                        argv[i],
71                        loc.heads, (int)loc.sectors, loc.cylinders,
72                        (int)loc.start, size, (int) loc.start + size -1);
73                 close(fd);
74         }
75         exit(0);
76 }