Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 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 | #include <stdio.h> |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 13 | #include <linux/hdreg.h> |
| 14 | #include <unistd.h> |
| 15 | #include <stdlib.h> |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 16 | #include <errno.h> |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 17 | #include "nls-enable.h" |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 18 | |
| 19 | void print_error(char *operation, int error, char *device) |
| 20 | { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 21 | fprintf(stderr, _("%s failed for %s: %s\n"), operation, device, |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 22 | strerror(error)); |
| 23 | } |
| 24 | |
| 25 | int main(int argc, char **argv) |
| 26 | { |
| 27 | struct hd_geometry loc; |
Theodore Ts'o | e927168 | 1998-03-09 03:23:51 +0000 | [diff] [blame] | 28 | int fd, i; |
Theodore Ts'o | a9bc79a | 2001-05-23 22:29:22 +0000 | [diff] [blame] | 29 | unsigned long size; |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 30 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 31 | #ifdef ENABLE_NLS |
| 32 | setlocale(LC_MESSAGES, ""); |
Theodore Ts'o | 14308a5 | 2002-03-05 03:26:52 -0500 | [diff] [blame] | 33 | setlocale(LC_CTYPE, ""); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 34 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 35 | textdomain(NLS_CAT_NAME); |
| 36 | #endif |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 37 | if (argc == 1) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 38 | fprintf(stderr, _("Usage: %s <dev1> <dev2> <dev3>\n\n" |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 39 | "This program prints out the partition information " |
| 40 | "for a set of devices\n" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 41 | "A common way to use this program is:\n\n\t" |
| 42 | "%s /dev/hda?\n\n"), argv[0], argv[0]); |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 43 | exit(1); |
| 44 | } |
| 45 | |
| 46 | for (i=1; i < argc; i++) { |
| 47 | fd = open(argv[i], O_RDONLY); |
| 48 | |
| 49 | if (fd < 0) { |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 50 | print_error("open", errno, argv[i]); |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 51 | continue; |
| 52 | } |
| 53 | |
| 54 | if (ioctl(fd, HDIO_GETGEO, &loc) < 0) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 55 | print_error(_("HDIO_GETGEO ioctl"), errno, argv[i]); |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 56 | close(fd); |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | if (ioctl(fd, BLKGETSIZE, &size) < 0) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 62 | print_error(_("BLKGETSIZE ioctl"), errno, argv[i]); |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 63 | close(fd); |
| 64 | continue; |
| 65 | } |
| 66 | |
Theodore Ts'o | a9bc79a | 2001-05-23 22:29:22 +0000 | [diff] [blame] | 67 | printf("%s: h=%3d s=%3d c=%4d start=%8d size=%8lu end=%8d\n", |
Theodore Ts'o | 134ea28 | 1997-11-28 14:45:09 +0000 | [diff] [blame] | 68 | argv[i], |
| 69 | loc.heads, (int)loc.sectors, loc.cylinders, |
| 70 | (int)loc.start, size, (int) loc.start + size -1); |
| 71 | close(fd); |
| 72 | } |
| 73 | exit(0); |
| 74 | } |