4 * Originally written by Alain Knaff, <alknaff@innet.lu>.
6 * Cleaned up by Theodore Ts'o, <tytso@mit.edu>.
10 #include <sys/types.h>
12 #ifdef HAVE_SYS_IOCTL_H
13 #include <sys/ioctl.h>
16 #include <linux/hdreg.h>
20 #include "nls-enable.h"
22 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
23 #define BLKGETSIZE _IO(0x12,96) /* return device size */
26 void print_error(char *operation, int error, char *device)
28 fprintf(stderr, _("%s failed for %s: %s\n"), operation, device,
32 int main(int argc, char **argv)
34 struct hd_geometry loc;
39 setlocale(LC_MESSAGES, "");
40 setlocale(LC_CTYPE, "");
41 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
42 textdomain(NLS_CAT_NAME);
45 fprintf(stderr, _("Usage: %s device...\n\nPrints out the"
46 "partition information for each given device.\n"),
47 "For example: %s /dev/hda\n\n", argv[0], argv[0]);
51 for (i=1; i < argc; i++) {
52 fd = open(argv[i], O_RDONLY);
55 print_error(_("open"), errno, argv[i]);
59 if (ioctl(fd, HDIO_GETGEO, &loc) < 0) {
60 print_error(_("HDIO_GETGEO ioctl"), errno, argv[i]);
66 if (ioctl(fd, BLKGETSIZE, &size) < 0) {
67 print_error(_("BLKGETSIZE ioctl"), errno, argv[i]);
72 printf("%s: h=%3d s=%3d c=%4d start=%8d size=%8lu end=%8d\n",
74 loc.heads, (int)loc.sectors, loc.cylinders,
75 (int)loc.start, size, (int) loc.start + size -1);