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