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.
19 #include <sys/disklabel.h>
20 #include <sys/ioctl.h>
22 int main(int argc
, char *argv
[])
24 struct disklabel dklbl
;
27 /* check argument count */
29 fprintf(stderr
, "usage: %s /dev/file\n", argv
[0]);
33 /* open device file */
34 if ((fd
= open(argv
[1], O_RDONLY
)) == -1) {
39 /* get disklabel by calling a disk-specific ioctl */
40 if (ioctl(fd
, DIOCGDINFO
, &dklbl
) == -1) {
46 printf("Disk: %s\n", dklbl
.d_typename
);