DCMD_BLK_PART_DESCRIPTION

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 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
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; see "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:
    PartitionTypeGuid
    The globally unique identifier for the partition type.
    UniquePartitionGuid
    The partition's globally unique identifier.
    StartingLBA
    The starting logical block address.
    EndingLBA
    The ending logical block address, inclusive.
    Attributes
    Flags that indicate attributes, such as read-only.
    PartitionName
    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.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);
}

See also:

DCMD_BLK_PARTENTRY

devctl() in the QNX Neutrino C Library Reference