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