4 * Originally written by Alain Knaff, <alknaff@innet.lu>.
6 * Cleaned up by Theodore Ts'o, <tytso@mit.edu>.
11 #include <sys/types.h>
13 #ifdef HAVE_SYS_IOCTL_H
14 #include <sys/ioctl.h>
17 #include <linux/hdreg.h>
22 #include "support/nls-enable.h"
23 #include "et/com_err.h"
25 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
26 #define BLKGETSIZE _IO(0x12,96) /* return device size */
29 int main(int argc, char **argv)
31 struct hd_geometry loc;
36 setlocale(LC_MESSAGES, "");
37 setlocale(LC_CTYPE, "");
38 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
39 textdomain(NLS_CAT_NAME);
40 set_com_err_gettext(gettext);
43 fprintf(stderr, _("Usage: %s device...\n\nPrints out the "
44 "partition information for each given device.\n"
45 "For example: %s /dev/hda\n\n"), argv[0], argv[0]);
49 for (i=1; i < argc; i++) {
50 fd = open(argv[i], O_RDONLY);
53 fprintf(stderr, _("Cannot open %s: %s"),
54 argv[i], strerror(errno));
58 if (ioctl(fd, HDIO_GETGEO, &loc) < 0) {
59 fprintf(stderr, _("Cannot get geometry of %s: %s"),
60 argv[i], strerror(errno));
66 if (ioctl(fd, BLKGETSIZE, &size) < 0) {
67 fprintf(stderr, _("Cannot get size of %s: %s"),
68 argv[i], strerror(errno));
73 printf(_("%s: h=%3d s=%3d c=%4d start=%8d size=%8lu end=%8d\n"),
75 loc.heads, (int)loc.sectors, loc.cylinders,
76 (int)loc.start, size, (int) loc.start + size -1);