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.
20 #include <sys/disklabel.h>
21 #include <sys/ioctl.h>
23 int main(int argc
, char *argv
[])
25 struct disklabel dklbl
;
28 /* Check argument count */
30 fprintf(stderr
, "Usage: %s /dev/file\n", argv
[0]);
34 /* Open device file */
35 if ((fd
= open(argv
[1], O_RDONLY
)) == -1) {
40 /* Get disklabel by calling a disk-specific ioctl */
41 if (ioctl(fd
, DIOCGDINFO
, &dklbl
) == -1) {
47 printf("Disk: %s\n", dklbl
.d_typename
);