Pkg.Disk
— 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:
This class represents a disk or disk image, providing methods to retrieve partition information and their corresponding data.
This class provides information about a single partition on a disk.
Attributes:
Represents a GPT (GUID Partition Table) partition table.
Represents an MBR (Master Boot Record) partition table.
Represents an unknown or unrecognized partition table type.
Represents a Basic Data partition (common GPT data partition).
Represents a boot partition (for various OSes).
Represents a Dell OEM partition.
Represents an EFI System partition (ESP).
Represents an extended partition.
Represents an extended partition with LBA addressing.
Represents a FAT12 partition type.
Represents a standard FAT16 partition type.
Represents a FAT16 partition with LBA addressing.
Represents a small FAT16 partition type (smaller than 32 MB).
Represents a FAT32 partition type.
Represents a FAT32 partition with LBA addressing.
Represents a FreeBSD boot partition.
Represents a FreeBSD data partition.
Represents a FreeBSD swap partition.
Represents a FreeBSD UFS partition.
Represents a FreeBSD vinum partition.
Represents a FreeBSD ZFS partition.
Represents a protective MBR entry for a GPT disk.
Represents an HFS+ partition (macOS).
Represents a partition used for hibernation data.
Represents a hidden FAT12 partition.
Represents a hidden FAT16 partition (standard).
Represents a hidden FAT16 partition with LBA addressing.
Represents a hidden FAT16 partition (small, smaller than 32 MB).
Represents a hidden FAT32 partition.
Represents a hidden FAT32 partition with LBA addressing.
Represents a hidden NTFS partition.
Represents an IBM OEM partition.
Represents a partition label or metadata partition (BSD disklabels, etc.).
Represents a laptop hibernation partition (vendor-specific).
Represents Windows LDM data partition.
Represents Windows LDM (Logical Disk Manager) metadata partition.
Represents a Linux LVM (Logical Volume Manager) partition.
Represents a Linux native partition (e.g., ext2/3/4).
Represents a Linux RAID (mdadm) partition.
Represents a Linux swap partition.
Represents a macOS partition (HFS/AFS).
Represents a macOS boot partition.
Represents a macOS HFS partition type.
Represents a Microsoft Reserved partition (MSR).
Represents an early Linux/Minix partition type.
Represents an old Minix partition type.
Represents a NetBSD concatenated disk driver partition.
Represents a NetBSD encrypted partition.
Represents a NetBSD FFS (Fast File System) partition.
Represents a NetBSD LFS partition.
Represents a NetBSD RAID partition.
Represents a NetBSD swap partition.
Represents an NTFS partition type (also sometimes shown as HPFS/NTFS).
Represents an NTFT partition (used in older Windows fault-tolerant setups).
Represents a generic RAID partition.
Represents an offline or inactive RAID partition.
Represents a generic UFS partition.
Represents an unknown or unclassified partition type.
Represents an unused (empty) partition slot.
Represents a vendor-specific recovery partition.
Represents a VMware file system partition.
Represents a VMware swap partition.
Represents a Windows dynamic disk partition.
Represents a Windows recovery partition.
Represents a Xenix root partition type.
Represents a Xenix user partition type.
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:
Returns the number of partitions on this disk.
GetPartitionData
(i_or_partition)Retrieves the data of the specified partition.
Retrieves partition information for the partition at the specified index.
Returns the partition table type (e.g.,
PARTITION_TABLE_TYPE_MBR
).Returns the name of the partition table type as a string (e.g., “MBR”, “GPT”).
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()
andGetPartitionData()
.
- 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
See also
GetPartitionCount()
andGetPartitionInfo()
.
- 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 returnsNone
.- Return type
Optional[PartitionInfo]
See also
GetPartitionCount()
andGetPartitionData()
.
- 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:
Converts the numeric partition type into a human-readable string.
Attributes:
The first sector (LBA) of this partition.
The file system format identified for this partition (e.g., NTFS, EXT).
The last sector (LBA) of this partition.
The byte offset of this partition from the start of the disk.
The raw type or signature as found in the partition table, if available.
The total number of sectors in this partition.
The size of this partition in bytes.
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.).