Get an extended description of a partition
#include <sys/dcmd_blk.h> #define DCMD_BLK_PART_DESCRIPTION __DIOF(_DCMD_BLK, 3, struct partition_description)
Argument | Value |
---|---|
filedes | A file descriptor that you obtained by opening the device. |
dcmd | DCMD_BLK_PART_DESCRIPTION |
dev_data_ptr | A pointer to a struct partition_description that the device can fill in (see below) |
n_bytes | sizeof(struct partition_description) |
dev_info_ptr | NULL |
This command gets an extended description of the partition for the device associated with the given file descriptor.
None.
The struct partition_description structure is defined as follows:
struct partition_description { char scheme[4]; uint32_t index; uint64_t header; char fsdll[16]; uint32_t sequence; char reserved[92]; union { struct part_pc_entry { uint8_t boot_ind; uint8_t beg_head; uint8_t beg_sector; uint8_t beg_cylinder; uint8_t os_type; uint8_t end_head; uint8_t end_sector; uint8_t end_cylinder; uint32_t part_offset; uint32_t part_size; } pc; struct part_gpt_entry { uint8_t PartitionTypeGuid[16]; uint8_t UniquePartitionGuid[16]; uint64_t StartingLBA; uint64_t EndingLBA; uint64_t Attributes; uint16_t PartitionName[36]; } gpt; } entry; };
The members include:
Scheme | Constant | Value |
---|---|---|
Personal Computer-style | FS_PARTITION_PC | "pc\x00\x00" |
Globally Unique ID Partition Table | FS_PARTITION_GPT | "gpt\x00" |
The devctl() function can return the following, in addition to the error codes listed in its entry in the C Library Reference:
#include <stdio.h> #include <stdlib.h> #include <devctl.h> #include <sys/dcmd_blk.h> #include <errno.h> #include <string.h> #include <fcntl.h> int main (void) { int fd; int ret; struct partition_description pd; uint64_t slba, elba; fd = open ("/dev/hd0t179", O_RDONLY); if (fd == -1) { perror ("open() failed"); return (EXIT_FAILURE); } /* Determine the partition's start and end LBAs. */ ret = devctl(fd, DCMD_BLK_PART_DESCRIPTION, &pd, sizeof pd, NULL); if (ret == EOK) { if (strcmp(pd.scheme, FS_PARTITION_PC) == 0) { printf ("PC: "); slba = pd.entry.pc.part_offset; elba = pd.entry.pc.part_offset + pd.entry.pc.part_size - 1; } else if (strcmp(pd.scheme, FS_PARTITION_GPT) == 0) { printf ("GPT: "); slba = pd.entry.gpt.StartingLBA; elba = pd.entry.gpt.EndingLBA; } printf ("start: %lld end: %lld\n", slba, elba); } else { printf ("DCMD_BLK_PART_DESCRIPTION failed: %s\n", strerror(ret) ); return (EXIT_FAILURE); } return (EXIT_SUCCESS); }