]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - misc/partinfo.c
build: quiet LLVM non-literal string format warning
[thirdparty/e2fsprogs.git] / misc / partinfo.c
CommitLineData
134ea28a
TT
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>.
efc6f628 7 *
134ea28a
TT
8 */
9
d1154eb4 10#include "config.h"
134ea28a
TT
11#include <sys/types.h>
12#include <fcntl.h>
bb145b01
TT
13#ifdef HAVE_SYS_IOCTL_H
14#include <sys/ioctl.h>
15#endif
134ea28a 16#include <stdio.h>
134ea28a
TT
17#include <linux/hdreg.h>
18#include <unistd.h>
19#include <stdlib.h>
2740156b 20#include <errno.h>
d9c56d3c 21#include "nls-enable.h"
134ea28a 22
bb145b01
TT
23#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
24#define BLKGETSIZE _IO(0x12,96) /* return device size */
25#endif
26
134ea28a
TT
27int main(int argc, char **argv)
28{
29 struct hd_geometry loc;
e927168e 30 int fd, i;
a9bc79ad 31 unsigned long size;
134ea28a 32
d9c56d3c
TT
33#ifdef ENABLE_NLS
34 setlocale(LC_MESSAGES, "");
14308a53 35 setlocale(LC_CTYPE, "");
d9c56d3c
TT
36 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
37 textdomain(NLS_CAT_NAME);
9d4507c5 38 set_com_err_gettext(gettext);
d9c56d3c 39#endif
134ea28a 40 if (argc == 1) {
df9c01b1 41 fprintf(stderr, _("Usage: %s device...\n\nPrints out the "
fe365fd8
TT
42 "partition information for each given device.\n"
43 "For example: %s /dev/hda\n\n"), argv[0], argv[0]);
134ea28a
TT
44 exit(1);
45 }
efc6f628 46
134ea28a
TT
47 for (i=1; i < argc; i++) {
48 fd = open(argv[i], O_RDONLY);
49
50 if (fd < 0) {
cca95a82
BS
51 fprintf(stderr, _("Cannot open %s: %s"),
52 argv[i], strerror(errno));
134ea28a
TT
53 continue;
54 }
efc6f628 55
134ea28a 56 if (ioctl(fd, HDIO_GETGEO, &loc) < 0) {
cca95a82
BS
57 fprintf(stderr, _("Cannot get geometry of %s: %s"),
58 argv[i], strerror(errno));
134ea28a
TT
59 close(fd);
60 continue;
61 }
efc6f628
TT
62
63
134ea28a 64 if (ioctl(fd, BLKGETSIZE, &size) < 0) {
cca95a82
BS
65 fprintf(stderr, _("Cannot get size of %s: %s"),
66 argv[i], strerror(errno));
134ea28a
TT
67 close(fd);
68 continue;
69 }
efc6f628 70
cca95a82 71 printf(_("%s: h=%3d s=%3d c=%4d start=%8d size=%8lu end=%8d\n"),
efc6f628 72 argv[i],
134ea28a
TT
73 loc.heads, (int)loc.sectors, loc.cylinders,
74 (int)loc.start, size, (int) loc.start + size -1);
75 close(fd);
76 }
77 exit(0);
78}