DCMD_BLK_PART_DESCRIPTION

QNX SDP8.0Devctl and Ioctl CommandsDeveloper

Get an extended description of a partition

Synopsis:

#include <sys/dcmd_blk.h>

#define DCMD_BLK_PART_DESCRIPTION   __DIOF(_DCMD_BLK, 3, struct partition_description)

Arguments to devctl():

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

Description:

This command gets an extended description of the partition for the device associated with the given file descriptor.

Input:

None.

Output:

The header dcmd_blk.h defines the struct partition_description structure 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;
        gpt_entry_t gpt;
    }           entry;
};
The gpt.h header defines the struct gpt_entry_t structure and related definitions as follows:
#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];
};
The members include:
scheme
A string that identifies the layout scheme for the partition:
Scheme Constant Value
Personal Computer-style FS_PARTITION_PC "pc\x00\x00"
Globally Unique ID Partition Table FS_PARTITION_GPT "gpt\x00"
index
The index in the partition table.
header
The location of the partition header.
fsdll
A shortened version of the name of the shared object that supports the partition (for example, qnx6 for the Power-Safe filesystem's shared object, fs-qnx6.so).
sequence
The partition enumeration order.
entry
A union that contains partition-specific information:
  • pc — the entry for a PC-style partition:
    boot_ind
    0x80 if the partition is bootable, 0x00 if it isn't.
    beg_head
    The beginning head number.
    beg_sector
    The beginning sector number.
    beg_cylinder
    The beginning cylinder number.
    os_type
    The partition type; refer to Partitions in the Filesystems chapter of the System Architecture guide.
    end_head
    The end head number.
    end_sector
    The end sector number.
    end_cylinder
    The end cylinder number.
    part_offset
    The offset of the partition, in bytes.
    part_size
    The number of sectors in the partition.
  • gpt — the entry for a GUID partition:
    partition_type_guid
    The globally unique identifier for the partition type.
    unique_partition_guid
    The partition's globally unique identifier.
    starting_lba
    The starting logical block address.
    ending_lba
    The ending logical block address, inclusive.
    attributes
    Flags that indicate attributes, such as read-only.
    partition_name
    The name of the partition.

Errors:

The devctl() function can return the following, in addition to the error codes listed in its entry in the C Library Reference:
ENOTTY
The file descriptor is for a raw block device, and hence there's no partition information.

Example:

#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);
}

Related links:

DCMD_BLK_PARTENTRY

devctl() in the QNX OS C Library Reference

Page updated: