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