Add htable_iterator_() accessors
[eleutheria.git] / fileops / disklabel.c
blob239be8d79dcd761363919bad7b83d2d190382788
1 /*
2 * Compile with:
3 * gcc disklabel.c -o disklabel -Wall -W -Wextra -ansi -pedantic
5 * Each disk on a system may contain a disk label which provides
6 * detailed information about the geometry of the disk and the
7 * partitions into which the disk is divided.
9 * A copy of the in-core label for a disk can be obtained with the
10 * DIOCGDINFO ioctl(2); this works with a file descriptor for a block or
11 * character (``raw'') device for any partition of the disk.
13 * For more information consult disklabel(5) man page.
16 #include <fcntl.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <sys/disklabel.h>
21 #include <sys/ioctl.h>
23 int main(int argc, char *argv[])
25 struct disklabel dklbl;
26 int fd;
28 /* Check argument count */
29 if (argc != 2) {
30 fprintf(stderr, "Usage: %s /dev/file\n", argv[0]);
31 exit(EXIT_FAILURE);
34 /* Open device file */
35 if ((fd = open(argv[1], O_RDONLY)) == -1) {
36 perror("open()");
37 exit(EXIT_FAILURE);
40 /* Get disklabel by calling a disk-specific ioctl */
41 if (ioctl(fd, DIOCGDINFO, &dklbl) == -1) {
42 perror("ioctl()");
43 close(fd);
44 exit(EXIT_FAILURE);
47 printf("Disk: %s\n", dklbl.d_typename);
49 return EXIT_SUCCESS;