blob: cdb7591a1cb9ab5e9ed2c34198bbbce6b9b31f88 [file] [log] [blame]
Theodore Ts'o134ea281997-11-28 14:45:09 +00001/*
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'o134ea281997-11-28 14:45:09 +000013#include <linux/hdreg.h>
14#include <unistd.h>
15#include <stdlib.h>
Theodore Ts'o27401561999-09-14 20:11:19 +000016#include <errno.h>
Theodore Ts'od9c56d32000-02-08 00:47:55 +000017#include "nls-enable.h"
Theodore Ts'o134ea281997-11-28 14:45:09 +000018
19void print_error(char *operation, int error, char *device)
20{
Theodore Ts'od9c56d32000-02-08 00:47:55 +000021 fprintf(stderr, _("%s failed for %s: %s\n"), operation, device,
Theodore Ts'o134ea281997-11-28 14:45:09 +000022 strerror(error));
23}
24
25int main(int argc, char **argv)
26{
27 struct hd_geometry loc;
Theodore Ts'oe9271681998-03-09 03:23:51 +000028 int fd, i;
29 long size;
Theodore Ts'o134ea281997-11-28 14:45:09 +000030
Theodore Ts'od9c56d32000-02-08 00:47:55 +000031#ifdef ENABLE_NLS
32 setlocale(LC_MESSAGES, "");
33 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
34 textdomain(NLS_CAT_NAME);
35#endif
Theodore Ts'o134ea281997-11-28 14:45:09 +000036 if (argc == 1) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +000037 fprintf(stderr, _("Usage: %s <dev1> <dev2> <dev3>\n\n"
Theodore Ts'o134ea281997-11-28 14:45:09 +000038 "This program prints out the partition information "
39 "for a set of devices\n"
Theodore Ts'od9c56d32000-02-08 00:47:55 +000040 "A common way to use this program is:\n\n\t"
41 "%s /dev/hda?\n\n"), argv[0], argv[0]);
Theodore Ts'o134ea281997-11-28 14:45:09 +000042 exit(1);
43 }
44
45 for (i=1; i < argc; i++) {
46 fd = open(argv[i], O_RDONLY);
47
48 if (fd < 0) {
Theodore Ts'o27401561999-09-14 20:11:19 +000049 print_error("open", errno, argv[i]);
Theodore Ts'o134ea281997-11-28 14:45:09 +000050 continue;
51 }
52
53 if (ioctl(fd, HDIO_GETGEO, &loc) < 0) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +000054 print_error(_("HDIO_GETGEO ioctl"), errno, argv[i]);
Theodore Ts'o134ea281997-11-28 14:45:09 +000055 close(fd);
56 continue;
57 }
58
59
60 if (ioctl(fd, BLKGETSIZE, &size) < 0) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +000061 print_error(_("BLKGETSIZE ioctl"), errno, argv[i]);
Theodore Ts'o134ea281997-11-28 14:45:09 +000062 close(fd);
63 continue;
64 }
65
66 printf("%s: h=%3d s=%3d c=%4d start=%8d size=%8d end=%8d\n",
67 argv[i],
68 loc.heads, (int)loc.sectors, loc.cylinders,
69 (int)loc.start, size, (int) loc.start + size -1);
70 close(fd);
71 }
72 exit(0);
73}