| Updated: October 28, 2024 |
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.
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;
gpt_entry_t gpt;
} entry;
};
#define GUID_NBYTES 16 typedef struct { uint8_t byte[GUID_NBYTES]; } guid_t; #define GPT_PARTN_NAME_SIZE_UCL2 36 struct gpt_entry_t { guid_t partition_type_guid; guid_t unique_partition_guid; uint64_t starting_lba; uint64_t ending_lba; uint64_t attributes; uint16_t partition_name[GPT_PARTN_NAME_SIZE_UCL2]; };
| Scheme | Constant | Value |
|---|---|---|
| Personal Computer-style | FS_PARTITION_PC | "pc\x00\x00" |
| Globally Unique ID Partition Table | FS_PARTITION_GPT | "gpt\x00" |
#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.starting_lba; elba = pd.entry.gpt.ending_lba; } 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); }