Pkg.Disk — API for parsing disks

Overview

The Pkg.ISO module contains the API for parsing disks.

Enumerating Partitions

The following code example demonstrates how to parse a disk and enumerate its partitions:

from Pro.Core import *
from Pkg.Disk import *

def enumeratePartitions(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = DiskObject()
    if not obj.Load(c) or not obj.Initialize():
        return
    n = obj.GetPartitionCount()
    for i in range(n):
        pi = obj.GetPartitionInfo(i)
        print(pi)

Module API

Pkg.Disk module API.

Classes:

DiskObject()

This class represents a disk or disk image, providing methods to retrieve partition information and their corresponding data.

PartitionInfo()

This class provides information about a single partition on a disk.

Attributes:

PARTITION_TABLE_TYPE_GPT

Represents a GPT (GUID Partition Table) partition table.

PARTITION_TABLE_TYPE_MBR

Represents an MBR (Master Boot Record) partition table.

PARTITION_TABLE_TYPE_UNKNOWN

Represents an unknown or unrecognized partition table type.

PARTITION_TYPE_BASIC_DATA

Represents a Basic Data partition (common GPT data partition).

PARTITION_TYPE_BOOT

Represents a boot partition (for various OSes).

PARTITION_TYPE_DELL_OEM

Represents a Dell OEM partition.

PARTITION_TYPE_EFI_SYSTEM

Represents an EFI System partition (ESP).

PARTITION_TYPE_EXTENDED

Represents an extended partition.

PARTITION_TYPE_EXTENDED_LBA

Represents an extended partition with LBA addressing.

PARTITION_TYPE_FAT12

Represents a FAT12 partition type.

PARTITION_TYPE_FAT16

Represents a standard FAT16 partition type.

PARTITION_TYPE_FAT16_LBA

Represents a FAT16 partition with LBA addressing.

PARTITION_TYPE_FAT16_SMALL

Represents a small FAT16 partition type (smaller than 32 MB).

PARTITION_TYPE_FAT32

Represents a FAT32 partition type.

PARTITION_TYPE_FAT32_LBA

Represents a FAT32 partition with LBA addressing.

PARTITION_TYPE_FREEBSD_BOOT

Represents a FreeBSD boot partition.

PARTITION_TYPE_FREEBSD_DATA

Represents a FreeBSD data partition.

PARTITION_TYPE_FREEBSD_SWAP

Represents a FreeBSD swap partition.

PARTITION_TYPE_FREEBSD_UFS

Represents a FreeBSD UFS partition.

PARTITION_TYPE_FREEBSD_VINUM

Represents a FreeBSD vinum partition.

PARTITION_TYPE_FREEBSD_ZFS

Represents a FreeBSD ZFS partition.

PARTITION_TYPE_GPT_PROTECTIVE

Represents a protective MBR entry for a GPT disk.

PARTITION_TYPE_HFSPLUS

Represents an HFS+ partition (macOS).

PARTITION_TYPE_HIBERNATION

Represents a partition used for hibernation data.

PARTITION_TYPE_HIDDEN_FAT12

Represents a hidden FAT12 partition.

PARTITION_TYPE_HIDDEN_FAT16

Represents a hidden FAT16 partition (standard).

PARTITION_TYPE_HIDDEN_FAT16_LBA

Represents a hidden FAT16 partition with LBA addressing.

PARTITION_TYPE_HIDDEN_FAT16_SMALL

Represents a hidden FAT16 partition (small, smaller than 32 MB).

PARTITION_TYPE_HIDDEN_FAT32

Represents a hidden FAT32 partition.

PARTITION_TYPE_HIDDEN_FAT32_LBA

Represents a hidden FAT32 partition with LBA addressing.

PARTITION_TYPE_HIDDEN_NTFS

Represents a hidden NTFS partition.

PARTITION_TYPE_IBM_OEM

Represents an IBM OEM partition.

PARTITION_TYPE_LABEL

Represents a partition label or metadata partition (BSD disklabels, etc.).

PARTITION_TYPE_LAPTOP_HIBERNATION

Represents a laptop hibernation partition (vendor-specific).

PARTITION_TYPE_LDM_DATA

Represents Windows LDM data partition.

PARTITION_TYPE_LDM_METADATA

Represents Windows LDM (Logical Disk Manager) metadata partition.

PARTITION_TYPE_LINUX_LVM

Represents a Linux LVM (Logical Volume Manager) partition.

PARTITION_TYPE_LINUX_NATIVE

Represents a Linux native partition (e.g., ext2/3/4).

PARTITION_TYPE_LINUX_RAID

Represents a Linux RAID (mdadm) partition.

PARTITION_TYPE_LINUX_SWAP

Represents a Linux swap partition.

PARTITION_TYPE_MACOSX

Represents a macOS partition (HFS/AFS).

PARTITION_TYPE_MACOSX_BOOT

Represents a macOS boot partition.

PARTITION_TYPE_MACOSX_HFS

Represents a macOS HFS partition type.

PARTITION_TYPE_MICROSOFT_RESERVED

Represents a Microsoft Reserved partition (MSR).

PARTITION_TYPE_MINIX_EARLY_LINUX

Represents an early Linux/Minix partition type.

PARTITION_TYPE_MINIX_OLD

Represents an old Minix partition type.

PARTITION_TYPE_NETBSD_CCD

Represents a NetBSD concatenated disk driver partition.

PARTITION_TYPE_NETBSD_CRYPT

Represents a NetBSD encrypted partition.

PARTITION_TYPE_NETBSD_FFS

Represents a NetBSD FFS (Fast File System) partition.

PARTITION_TYPE_NETBSD_LFS

Represents a NetBSD LFS partition.

PARTITION_TYPE_NETBSD_RAID

Represents a NetBSD RAID partition.

PARTITION_TYPE_NETBSD_SWAP

Represents a NetBSD swap partition.

PARTITION_TYPE_NTFS

Represents an NTFS partition type (also sometimes shown as HPFS/NTFS).

PARTITION_TYPE_NTFT

Represents an NTFT partition (used in older Windows fault-tolerant setups).

PARTITION_TYPE_RAID

Represents a generic RAID partition.

PARTITION_TYPE_RAID_OFFLINE

Represents an offline or inactive RAID partition.

PARTITION_TYPE_UFS

Represents a generic UFS partition.

PARTITION_TYPE_UNKNOWN

Represents an unknown or unclassified partition type.

PARTITION_TYPE_UNUSED

Represents an unused (empty) partition slot.

PARTITION_TYPE_VENDOR_RECOVERY

Represents a vendor-specific recovery partition.

PARTITION_TYPE_VMWARE_FS

Represents a VMware file system partition.

PARTITION_TYPE_VMWARE_SWAP

Represents a VMware swap partition.

PARTITION_TYPE_WINDOWS_DYNAMIC

Represents a Windows dynamic disk partition.

PARTITION_TYPE_WINDOWS_RECOVERY

Represents a Windows recovery partition.

PARTITION_TYPE_XENIX_ROOT

Represents a Xenix root partition type.

PARTITION_TYPE_XENIX_USR

Represents a Xenix user partition type.

PARTITION_TYPE_ZFS

Represents a generic ZFS partition.

class DiskObject

Bases: Pro.Core.CFFObject

This class represents a disk or disk image, providing methods to retrieve partition information and their corresponding data.

Methods:

GetPartitionCount()

Returns the number of partitions on this disk.

GetPartitionData(i_or_partition)

Retrieves the data of the specified partition.

GetPartitionInfo(i)

Retrieves partition information for the partition at the specified index.

GetPartitionTableType()

Returns the partition table type (e.g., PARTITION_TABLE_TYPE_MBR).

GetPartitionTableTypeName()

Returns the name of the partition table type as a string (e.g., “MBR”, “GPT”).

GetSectorSize()

Returns the sector size in bytes for this disk.

GetPartitionCount()int
Returns

Returns the number of partitions on this disk.

Return type

int

See also GetPartitionInfo() and GetPartitionData().

GetPartitionData(i_or_partition: Union[int, Pkg.Disk.PartitionInfo])Pro.Core.NTContainer

Retrieves the data of the specified partition.

Parameters

i_or_partition (Union[int, PartitionInfo]) – The partition index or a PartitionInfo object.

Returns

Returns the data if successful; otherwise returns an invalid Pro.Core.NTContainer() instance.

Return type

NTContainer

See also GetPartitionCount() and GetPartitionInfo().

GetPartitionInfo(i: int)Optional[Pkg.Disk.PartitionInfo]

Retrieves partition information for the partition at the specified index.

Parameters

i (int) – The zero-based index of the partition.

Returns

Returns a PartitionInfo object if found; otherwise returns None.

Return type

Optional[PartitionInfo]

See also GetPartitionCount() and GetPartitionData().

GetPartitionTableType()int
Returns

Returns the partition table type (e.g., PARTITION_TABLE_TYPE_MBR).

Return type

int

See also GetPartitionTableTypeName().

GetPartitionTableTypeName()str
Returns

Returns the name of the partition table type as a string (e.g., “MBR”, “GPT”).

Return type

str

See also GetPartitionTableType().

GetSectorSize()int
Returns

Returns the sector size in bytes for this disk.

Return type

int

PARTITION_TABLE_TYPE_GPT

Represents a GPT (GUID Partition Table) partition table.

PARTITION_TABLE_TYPE_MBR

Represents an MBR (Master Boot Record) partition table.

PARTITION_TABLE_TYPE_UNKNOWN

Represents an unknown or unrecognized partition table type.

PARTITION_TYPE_BASIC_DATA

Represents a Basic Data partition (common GPT data partition).

PARTITION_TYPE_BOOT

Represents a boot partition (for various OSes).

PARTITION_TYPE_DELL_OEM

Represents a Dell OEM partition.

PARTITION_TYPE_EFI_SYSTEM

Represents an EFI System partition (ESP).

PARTITION_TYPE_EXTENDED

Represents an extended partition.

PARTITION_TYPE_EXTENDED_LBA

Represents an extended partition with LBA addressing.

PARTITION_TYPE_FAT12

Represents a FAT12 partition type.

PARTITION_TYPE_FAT16

Represents a standard FAT16 partition type.

PARTITION_TYPE_FAT16_LBA

Represents a FAT16 partition with LBA addressing.

PARTITION_TYPE_FAT16_SMALL

Represents a small FAT16 partition type (smaller than 32 MB).

PARTITION_TYPE_FAT32

Represents a FAT32 partition type.

PARTITION_TYPE_FAT32_LBA

Represents a FAT32 partition with LBA addressing.

PARTITION_TYPE_FREEBSD_BOOT

Represents a FreeBSD boot partition.

PARTITION_TYPE_FREEBSD_DATA

Represents a FreeBSD data partition.

PARTITION_TYPE_FREEBSD_SWAP

Represents a FreeBSD swap partition.

PARTITION_TYPE_FREEBSD_UFS

Represents a FreeBSD UFS partition.

PARTITION_TYPE_FREEBSD_VINUM

Represents a FreeBSD vinum partition.

PARTITION_TYPE_FREEBSD_ZFS

Represents a FreeBSD ZFS partition.

PARTITION_TYPE_GPT_PROTECTIVE

Represents a protective MBR entry for a GPT disk.

PARTITION_TYPE_HFSPLUS

Represents an HFS+ partition (macOS).

PARTITION_TYPE_HIBERNATION

Represents a partition used for hibernation data.

PARTITION_TYPE_HIDDEN_FAT12

Represents a hidden FAT12 partition.

PARTITION_TYPE_HIDDEN_FAT16

Represents a hidden FAT16 partition (standard).

PARTITION_TYPE_HIDDEN_FAT16_LBA

Represents a hidden FAT16 partition with LBA addressing.

PARTITION_TYPE_HIDDEN_FAT16_SMALL

Represents a hidden FAT16 partition (small, smaller than 32 MB).

PARTITION_TYPE_HIDDEN_FAT32

Represents a hidden FAT32 partition.

PARTITION_TYPE_HIDDEN_FAT32_LBA

Represents a hidden FAT32 partition with LBA addressing.

PARTITION_TYPE_HIDDEN_NTFS

Represents a hidden NTFS partition.

PARTITION_TYPE_IBM_OEM

Represents an IBM OEM partition.

PARTITION_TYPE_LABEL

Represents a partition label or metadata partition (BSD disklabels, etc.).

PARTITION_TYPE_LAPTOP_HIBERNATION

Represents a laptop hibernation partition (vendor-specific).

PARTITION_TYPE_LDM_DATA

Represents Windows LDM data partition.

PARTITION_TYPE_LDM_METADATA

Represents Windows LDM (Logical Disk Manager) metadata partition.

PARTITION_TYPE_LINUX_LVM

Represents a Linux LVM (Logical Volume Manager) partition.

PARTITION_TYPE_LINUX_NATIVE

Represents a Linux native partition (e.g., ext2/3/4).

PARTITION_TYPE_LINUX_RAID

Represents a Linux RAID (mdadm) partition.

PARTITION_TYPE_LINUX_SWAP

Represents a Linux swap partition.

PARTITION_TYPE_MACOSX

Represents a macOS partition (HFS/AFS).

PARTITION_TYPE_MACOSX_BOOT

Represents a macOS boot partition.

PARTITION_TYPE_MACOSX_HFS

Represents a macOS HFS partition type.

PARTITION_TYPE_MICROSOFT_RESERVED

Represents a Microsoft Reserved partition (MSR).

PARTITION_TYPE_MINIX_EARLY_LINUX

Represents an early Linux/Minix partition type.

PARTITION_TYPE_MINIX_OLD

Represents an old Minix partition type.

PARTITION_TYPE_NETBSD_CCD

Represents a NetBSD concatenated disk driver partition.

PARTITION_TYPE_NETBSD_CRYPT

Represents a NetBSD encrypted partition.

PARTITION_TYPE_NETBSD_FFS

Represents a NetBSD FFS (Fast File System) partition.

PARTITION_TYPE_NETBSD_LFS

Represents a NetBSD LFS partition.

PARTITION_TYPE_NETBSD_RAID

Represents a NetBSD RAID partition.

PARTITION_TYPE_NETBSD_SWAP

Represents a NetBSD swap partition.

PARTITION_TYPE_NTFS

Represents an NTFS partition type (also sometimes shown as HPFS/NTFS).

PARTITION_TYPE_NTFT

Represents an NTFT partition (used in older Windows fault-tolerant setups).

PARTITION_TYPE_RAID

Represents a generic RAID partition.

PARTITION_TYPE_RAID_OFFLINE

Represents an offline or inactive RAID partition.

PARTITION_TYPE_UFS

Represents a generic UFS partition.

PARTITION_TYPE_UNKNOWN

Represents an unknown or unclassified partition type.

PARTITION_TYPE_UNUSED

Represents an unused (empty) partition slot.

PARTITION_TYPE_VENDOR_RECOVERY

Represents a vendor-specific recovery partition.

PARTITION_TYPE_VMWARE_FS

Represents a VMware file system partition.

PARTITION_TYPE_VMWARE_SWAP

Represents a VMware swap partition.

PARTITION_TYPE_WINDOWS_DYNAMIC

Represents a Windows dynamic disk partition.

PARTITION_TYPE_WINDOWS_RECOVERY

Represents a Windows recovery partition.

PARTITION_TYPE_XENIX_ROOT

Represents a Xenix root partition type.

PARTITION_TYPE_XENIX_USR

Represents a Xenix user partition type.

PARTITION_TYPE_ZFS

Represents a generic ZFS partition.

class PartitionInfo

This class provides information about a single partition on a disk.

Methods:

TypeToString()

Converts the numeric partition type into a human-readable string.

Attributes:

first_sector

The first sector (LBA) of this partition.

format

The file system format identified for this partition (e.g., NTFS, EXT).

last_sector

The last sector (LBA) of this partition.

offset

The byte offset of this partition from the start of the disk.

raw_type

The raw type or signature as found in the partition table, if available.

sector_count

The total number of sectors in this partition.

size

The size of this partition in bytes.

type

The numeric partition type (e.g., FAT, NTFS, etc.).

TypeToString()str

Converts the numeric partition type into a human-readable string.

Returns

Returns a string describing the partition type.

Return type

str

first_sector

The first sector (LBA) of this partition.

format

The file system format identified for this partition (e.g., NTFS, EXT).

last_sector

The last sector (LBA) of this partition.

offset

The byte offset of this partition from the start of the disk.

raw_type

The raw type or signature as found in the partition table, if available.

sector_count

The total number of sectors in this partition.

size

The size of this partition in bytes.

type

The numeric partition type (e.g., FAT, NTFS, etc.).