Add comment on how to compile
[eleutheria.git] / fileops / disklabel.c
blobea20809c63d7a0800f4160e58497b26f10f7c4f8
1 /* compile with:
2 gcc disklabel.c -o disklabel -Wall -W -Wextra -ansi -pedantic */
4 #include <fcntl.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <sys/disklabel.h>
9 #include <sys/ioctl.h>
11 int main(int argc, char *argv[])
13 struct disklabel dklbl;
14 int fd;
16 /* check argument count */
17 if (argc != 2) {
18 fprintf(stderr, "usage: %s /dev/file\n", argv[0]);
19 exit(EXIT_FAILURE);
22 /* open device file */
23 if ((fd = open(argv[1], O_RDONLY)) == -1) {
24 perror("open");
25 exit(EXIT_FAILURE);
28 /* get disklabel by calling a disk-specific ioctl */
29 if (ioctl(fd, DIOCGDINFO, &dklbl) == -1) {
30 perror("ioctl");
31 close(fd);
32 exit(EXIT_FAILURE);
35 printf("Disk: %s\n", dklbl.d_typename);
37 return EXIT_SUCCESS;