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>
21 #include "nls-enable.h"
23 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
24 #define BLKGETSIZE _IO(0x12,96) /* return device size */
27 int main(int argc, char **argv)
29 struct hd_geometry loc;
34 setlocale(LC_MESSAGES, "");
35 setlocale(LC_CTYPE, "");
36 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
37 textdomain(NLS_CAT_NAME);
38 set_com_err_gettext(gettext);
41 fprintf(stderr, _("Usage: %s device...\n\nPrints out the "
42 "partition information for each given device.\n"
43 "For example: %s /dev/hda\n\n"), argv[0], argv[0]);
47 for (i=1; i < argc; i++) {
48 fd = open(argv[i], O_RDONLY);
51 fprintf(stderr, _("Cannot open %s: %s"),
52 argv[i], strerror(errno));
56 if (ioctl(fd, HDIO_GETGEO, &loc) < 0) {
57 fprintf(stderr, _("Cannot get geometry of %s: %s"),
58 argv[i], strerror(errno));
64 if (ioctl(fd, BLKGETSIZE, &size) < 0) {
65 fprintf(stderr, _("Cannot get size of %s: %s"),
66 argv[i], strerror(errno));
71 printf(_("%s: h=%3d s=%3d c=%4d start=%8d size=%8lu end=%8d\n"),
73 loc.heads, (int)loc.sectors, loc.cylinders,
74 (int)loc.start, size, (int) loc.start + size -1);