pycdlib.pycdlib

Main PyCdlib class and support classes and utilities.

class PyCdlib(always_consistent: bool = False)

The main class for manipulating ISOs.

new(
interchange_level: int = 1,
sys_ident: str = '',
vol_ident: str = '',
set_size: int = 1,
seqnum: int = 1,
log_block_size: int = 2048,
vol_set_ident: str = ' ',
pub_ident_str: str = '',
preparer_ident_str: str = '',
app_ident_str: str = '',
copyright_file: str = '',
abstract_file: str = '',
bibli_file: str = '',
vol_expire_date: float | None = None,
app_use: str = '',
joliet: int | None = None,
rock_ridge: str | None = None,
xa: bool = False,
udf: str | None = None,
) → None

Create a new ISO from scratch.

Parameters:
  • interchange_level – The ISO9660 interchange level to use; this dictates the rules on the names of files. Levels 1, 2, 3, and 4 are supported. Level 1 is the most conservative, and is the default, but level 3 is recommended.

  • sys_ident – The system identification string to use on the new ISO.

  • vol_ident – The volume identification string to use on the new ISO.

  • set_size – The size of the set of ISOs this ISO is a part of.

  • seqnum – The sequence number of the set of this ISO.

  • log_block_size – The logical block size to use for the ISO. Ecma-119 allows 512, 1024, or 2048 (the default). Sizes other than 2048 cannot be combined with UDF or El Torito, and most other ISO tools (though not the Linux kernel) only understand 2048. Note that the Linux isofs driver refuses blocks smaller than its own ‘block=’ mount option, which defaults to 1024, so a 512-byte-block ISO must be mounted with ‘-o block=512’.

  • vol_set_ident – The volume set identification string to use on the new ISO.

  • pub_ident_str – The publisher identification string to use on the new ISO.

  • preparer_ident_str – The preparer identification string to use on the new ISO.

  • app_ident_str – The application identification string to use on the new ISO.

  • copyright_file – The name of a file at the root of the ISO to use as the copyright file.

  • abstract_file – The name of a file at the root of the ISO to use as the abstract file.

  • bibli_file – The name of a file at the root of the ISO to use as the bibliographic file.

  • vol_expire_date – The date that this ISO will expire at.

  • app_use – Arbitrary data that the application can stuff into the primary volume descriptor of this ISO.

  • joliet – An integer that can have the value 1, 2, or 3 for Joliet levels 1, 2, or 3 (3 is by far the most common), or None for no Joliet support (the default). For legacy reasons, this parameter also accepts a boolean, where the value of ‘False’ means no Joliet and a value of ‘True’ means level 3.

  • rock_ridge – Whether to make this ISO have the Rock Ridge extensions or not. The default value of None does not add Rock Ridge extensions. A string value of ‘1.09’, ‘1.10’, or ‘1.12’ adds the specified Rock Ridge version to the ISO. If unsure, pass ‘1.09’ to ensure maximum compatibility.

  • xa – Whether to add the ISO9660 Extended Attribute extensions to this ISO. The default is False.

  • udf – Whether to add UDF support to this ISO. If it is None (the default), no UDF support is added. If it is “2.60”, version 2.60 of the UDF spec is used. All other values are disallowed.

Returns:

Nothing.

open(filename: str, mode: str = 'rb') → None

Open up an existing ISO for inspection and modification.

Parameters:
  • filename – The filename containing the ISO to open up.

  • mode – The mode to use when opening the ISO file; the default is ‘rb’.

Returns:

Nothing.

open_fp(fp: BinaryIO) → None

Open up an existing ISO for inspection and modification. Note that the file object passed in here must stay open for the lifetime of this object, as the PyCdlib class uses it internally to do writing and reading operations. To have PyCdlib manage this automatically, use open() instead.

Parameters:

fp – The file object containing the ISO to open up.

Returns:

Nothing.

get_file_from_iso(
local_path: str,
**kwargs: str | int,
) → None

Fetch a single file from the ISO and write it out to a local file.

Parameters:
  • local_path – The local file to write to.

  • blocksize – The number of bytes in each transfer.

  • iso_path – The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path).

  • rr_path – The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path).

  • joliet_path – The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path).

  • udf_path – The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path).

Returns:

Nothing.

get_file_from_iso_fp(
outfp: BinaryIO,
**kwargs: str | int,
) → None

Fetch a single file from the ISO and write it out to the file object.

Parameters:
  • outfp – The file object to write data to.

  • blocksize – The number of bytes in each transfer.

  • iso_path – The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path).

  • rr_path – The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path).

  • joliet_path – The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path).

  • udf_path – The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path).

Returns:

Nothing.

get_file_byte_extents(
**kwargs: str,
) → List[Tuple[int, int]]

Get the byte offsets and lengths of the contiguous runs of data that back a file on the ISO.

Most users do NOT need this method. For ordinary file extraction, use get_file_from_iso() / get_file_from_iso_fp(). This method is intended for advanced callers that need to address file data directly inside an ISO image without extracting it – for example, telling a downstream tool the absolute byte ranges of a kernel or initrd within an .iso so the bytes can be read in place rather than copied out.

The returned list contains one (byte_offset, length) tuple per contiguous run of bytes used by the file, in file order, so that concatenating the runs yields the file’s content. Most files consist of a single contiguous run; multi-extent ISO9660 files (>4GB) and UDF files with multiple allocation descriptors can return more than one entry.

The offsets reflect the on-disk layout of the ISO: after open() / open_fp() they correspond to positions in the source ISO; for an ISO produced by new() they are valid only after a successful write_fp().

Parameters:
  • iso_path – The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path).

  • rr_path – The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path).

  • joliet_path – The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path).

  • udf_path – The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path).

Returns:

A list of (byte_offset, length) tuples in file order.

get_and_write(
iso_path: str,
local_path: str,
blocksize: int = 8192,
) → None

Deprecated since version 1.20.0: Use get_file_from_iso() instead.

Fetch a single file from the ISO and write it out to the specified file. Note that this will overwrite the contents of the local file if it already exists. Also note that ‘iso_path’ must be an absolute path to the file. Finally, the ‘iso_path’ can be an ISO9660 path, a Rock Ridge path, or a Joliet path. In the case of ambiguity, the Joliet path is tried first, followed by the ISO9660 path, followed by the Rock Ridge path. It is recommended to use the get_file_from_iso() API instead to resolve this ambiguity.

Parameters:
  • iso_path – The absolute path to the file to get data from.

  • local_path – The local filename to write the contents to.

  • blocksize – The blocksize to use when copying data; the default is 8192.

Returns:

Nothing.

get_and_write_fp(
iso_path: str,
outfp: BinaryIO,
blocksize: int = 8192,
) → None

Deprecated since version 1.20.0: Use get_file_from_iso_fp() instead.

Fetch a single file from the ISO and write it out to the file object. Note that ‘iso_path’ must be an absolute path to the file. Also note that the ‘iso_path’ can be an ISO9660 path, a Rock Ridge path, or a Joliet path. In the case of ambiguity, the Joliet path is tried first, followed by the ISO9660 path, followed by the Rock Ridge path. It is recommended to use the get_file_from_iso_fp() API instead to resolve this ambiguity.

Parameters:
  • iso_path – The absolute path to the file to get data from.

  • outfp – The file object to write data to.

  • blocksize – The blocksize to use when copying data; the default is 8192.

Returns:

Nothing.

write(
filename: str,
blocksize: int = 32768,
progress_cb: Callable[[int, int, Any], None] | None = None,
progress_opaque: Any | None = None,
) → None

Write a properly formatted ISO out to the filename passed in. This also goes by the name of ‘mastering’.

Parameters:
  • filename – The filename to write the data to.

  • blocksize – The blocksize to use when copying data; the default is 32768.

  • progress_cb – If not None, a function to call as the write call does its work. The callback function must have a signature of: def func(done, total, opaque).

  • progress_opaque – User data to be passed to the progress callback; the default is None.

Returns:

Nothing.

write_fp(
outfp: BinaryIO,
blocksize: int = 32768,
progress_cb: Callable[[int, int, Any], None] | None = None,
progress_opaque: Any | None = None,
) → None

Write a properly formatted ISO out to the file object passed in. This also goes by the name of ‘mastering’.

Parameters:
  • outfp – The file object to write the data to.

  • blocksize – The blocksize to use when copying data; the default is 32768.

  • progress_cb – If not None, a function to call as the write call does its work. The callback function must have a signature of: def func(done, total, opaque).

  • progress_opaque – User data to be passed to the progress callback; the default is None.

Returns:

Nothing.

add_fp(
fp: BinaryIO,
length: int,
iso_path: str | None = None,
rr_name: str | None = None,
joliet_path: str | None = None,
file_mode: int | None = None,
udf_path: str | None = None,
creation_time: float | None = None,
) → None

Add a file to the ISO. If the ISO is a Rock Ridge one, then a Rock Ridge name must also be provided. If the ISO is a Joliet one, then a Joliet path may also be provided; while it is optional to do so, it is highly recommended. Note that the caller must ensure that ‘fp’ remains open for the lifetime of the PyCdlib object, as the PyCdlib class uses the file descriptor internally when writing (mastering) the ISO. To have PyCdlib manage this automatically, use add_file() instead.

Parameters:
  • fp – The file object to use for the contents of the new file.

  • length – The length of the data for the new file.

  • iso_path – The ISO9660 absolute path to the file destination on the ISO.

  • rr_name – The Rock Ridge name of the file destination on the ISO.

  • joliet_path – The Joliet absolute path to the file destination on the ISO.

  • file_mode – The POSIX file_mode to apply to this file. This only applies if this is a Rock Ridge ISO. If this is None (the default), the permissions from the original file are used.

  • udf_path – The UDF absolute path to the file destination on the ISO.

  • creation_time – Optional creation time, in seconds since the epoch. Stored on Rock Ridge TF (CREATION timestamp) and on UDF (forces an Extended File Entry, which has the on-disk slot). Plain ISO9660 and Joliet have no creation-time field, so when supplied this value requires that at least one of iso_path (with Rock Ridge enabled) or udf_path is also supplied.

Returns:

Nothing.

add_file(
filename: str,
iso_path: str | None = None,
rr_name: str | None = None,
joliet_path: str | None = None,
file_mode: int | None = None,
udf_path: str | None = None,
creation_time: float | None = None,
) → None

Add a file to the ISO. If the ISO is a Rock Ridge one, then a Rock Ridge name must also be provided. If the ISO is a Joliet one, then a Joliet path may also be provided; while it is optional to do so, it is highly recommended.

Parameters:
  • filename – The filename to use for the data contents for the new file.

  • iso_path – The ISO9660 absolute path to the file destination on the ISO.

  • rr_name – The Rock Ridge name of the file destination on the ISO.

  • joliet_path – The Joliet absolute path to the file destination on the ISO.

  • file_mode – The POSIX file_mode to apply to this file. This only applies if this is a Rock Ridge ISO. If this is None (the default), the permissions from the original file are used.

  • udf_path – The UDF absolute path to the file destination on the ISO.

  • creation_time – Optional creation time, in seconds since the epoch. See add_fp() for storage rules.

Returns:

Nothing.

modify_file_in_place(
fp: BinaryIO,
length: int,
iso_path: str | None = None,
rr_name: str | None = None,
joliet_path: str | None = None,
udf_path: str | None = None,
rr_path: str | None = None,
) → None

Deprecated since version 1.20.0: Use pycdlib.inplaceeditor.InPlaceEditor instead.

Modify a file in place on the ISO.

Parameters:
  • fp – The file object to use for the contents of the new file.

  • length – The length of the new data for the file.

  • iso_path – The ISO9660 absolute path to the file destination on the ISO.

  • rr_name – Ignored. Earlier versions accepted this parameter but never used it; pass rr_path to address a file via its Rock Ridge path.

  • joliet_path – The Joliet absolute path to the file destination on the ISO. Ignored when iso_path is given, for backwards compatibility.

  • udf_path – The UDF absolute path to the file destination on the ISO. Ignored when iso_path is given, for backwards compatibility.

  • rr_path – The Rock Ridge absolute path to the file destination on the ISO. Only valid when iso_path is not given.

Returns:

Nothing.

update_file_contents_fp(
fp: BinaryIO,
length: int,
iso_path: str | None = None,
rr_path: str | None = None,
joliet_path: str | None = None,
udf_path: str | None = None,
) → None

Replace the contents of an existing file on the ISO with new content read from fp, deferring all disk writes to the next write_fp() call.

Exactly one of iso_path, rr_path, joliet_path, or udf_path must be provided to identify the target file. The update propagates to every linked record (ISO9660 / Joliet / UDF) automatically because they share the same Inode.

The caller is responsible for keeping fp open for the lifetime of this PyCdlib object (until close() runs), the same way add_fp() requires.

Parameters:
  • fp – A file-like object containing the new contents.

  • length – The length of the new contents.

  • iso_path – The ISO9660 absolute path to the file destination on the ISO.

  • rr_path – The Rock Ridge absolute path to the file destination on the ISO.

  • joliet_path – The Joliet absolute path to the file destination on the ISO.

  • udf_path – The UDF absolute path to the file destination on the ISO.

Returns:

Nothing.

update_file_contents(
filename: str,
iso_path: str | None = None,
rr_path: str | None = None,
joliet_path: str | None = None,
udf_path: str | None = None,
) → None

Replace the contents of an existing file on the ISO with the contents of filename on the local filesystem, deferring all disk writes to the next write_fp() call.

This method has the same semantics as update_file_contents_fp(), except that pycdlib opens filename and manages its lifetime, the same way add_file() does relative to add_fp(). The file is closed when close() is called on the PyCdlib object.

Parameters:
  • filename – The local filename whose contents replace the target file’s contents.

  • iso_path – The ISO9660 absolute path to the file destination on the ISO.

  • rr_path – The Rock Ridge absolute path to the file destination on the ISO.

  • joliet_path – The Joliet absolute path to the file destination on the ISO.

  • udf_path – The UDF absolute path to the file destination on the ISO.

Returns:

Nothing.

Add a hard link to the ISO. Hard links are alternate names for the same file contents that don’t take up any additional space on the ISO. This API can be used to create hard links between two files on the ISO9660 filesystem, between two files on the Joliet filesystem, between two files on the UDF filesystem, or between any two of those filesystems. In all cases, exactly one old path must be specified, and exactly one new path must be specified.

A file’s identity is its data: every path to it, in every context, is a link to that data. add_fp() and add_file() create one link per path they are given, this method adds one more, and the links can be removed one at a time with rm_hard_link() or all at once with rm_file(). The data is dropped when its last link goes. These APIs may be mixed freely.

Parameters:
  • iso_old_path – The old path on the ISO9660 filesystem to link from.

  • iso_new_path – The new path on the ISO9660 filesystem to link to.

  • joliet_old_path – The old path on the Joliet filesystem to link from.

  • joliet_new_path – The new path on the Joliet filesystem to link to.

  • rr_name – The Rock Ridge name to use for the new file if this is a Rock Ridge ISO and the new path is on the ISO9660 filesystem.

  • boot_catalog_old – Use the El Torito boot catalog as the old path.

  • udf_old_path – The old path on the UDF filesystem to link from.

  • udf_new_path – The new path on the UDF filesystem to link to.

  • creation_time – Optional creation time, in seconds since the epoch, for the newly-created link. See add_fp() for storage rules: requires iso_new_path on a Rock Ridge ISO or udf_new_path.

Returns:

Nothing.

Remove a hard link from the ISO. If the number of links to a piece of data drops to zero, then the contents will be removed from the ISO. Exactly one of an ISO9660 path, a Joliet path, or a UDF path must be passed to this API. Thus, this interface can be used to hide a file from one filesystem while leaving it visible in the others, or to hide it from all of them while another reference to the data remains, such as an El Torito boot entry.

A file’s identity is its data: every path to it, in every context, is a link to that data. This method removes one link, while rm_file() removes every link to the same data at once, including any added with add_hard_link(). These APIs may be mixed freely.

Parameters:
  • iso_path – The ISO link path to remove.

  • joliet_path – The Joliet link path to remove.

  • udf_path – The UDF link path to remove.

Returns:

Nothing.

add_directory(
iso_path: str | None = None,
rr_name: str | None = None,
joliet_path: str | None = None,
file_mode: int | None = None,
udf_path: str | None = None,
creation_time: float | None = None,
) → None

Add a directory to the ISO. At least one of an iso_path, joliet_path, or udf_path must be provided. Providing joliet_path on a non-Joliet ISO, or udf_path on a non-UDF ISO, is an error. If the ISO contains Rock Ridge, then a Rock Ridge name must be provided.

Parameters:
  • iso_path – The ISO9660 absolute path to use for the directory.

  • rr_name – The Rock Ridge name to use for the directory.

  • joliet_path – The Joliet absolute path to use for the directory.

  • file_mode – The POSIX file mode to use for the directory. This only applies for Rock Ridge ISOs.

  • udf_path – The UDF absolute path to use for the directory.

  • creation_time – Optional creation time, in seconds since the epoch. See add_fp() for storage rules.

Returns:

Nothing.

add_joliet_directory(joliet_path: str) → None

Deprecated since version 1.20.0: Use add_directory() with the joliet_path argument instead.

Add a directory to the Joliet portion of the ISO. Since Joliet occupies a completely different context than ISO9660, this method can be invoked to create a completely different directory structure in the Joliet context, though that is generally not advised. It is recommended to use the ‘joliet_path’ argument of add_directory() instead of this method.

Parameters:

joliet_path – The Joliet directory to create.

Returns:

Nothing.

rm_file(
iso_path: str | None = None,
rr_name: str | None = None,
joliet_path: str | None = None,
udf_path: str | None = None,
) → None

Remove a file from the ISO. This removes the data and the listing of the file from all contexts, even when only one path is given (to only remove it from a single context, use rm_hard_link() instead).

The contexts are tied together by the file’s data extent, and a zero-byte file has none. For an ISO opened from disk, a zero-byte file therefore only has its entry in the given context removed, so this method must be called once per context (ISO9660, Joliet, UDF) to remove it completely. Zero-byte files added during this session are removed from every context in one call.

Parameters:
  • iso_path – The path to the file to remove.

  • rr_name – Ignored. Earlier versions accepted this parameter but never used it; the file is identified by iso_path, joliet_path, or udf_path.

  • joliet_path – The Joliet path to the file to remove.

  • udf_path – The UDF path to the file to remove.

Returns:

Nothing.

rm_directory(
iso_path: str | None = None,
rr_name: str | None = None,
joliet_path: str | None = None,
udf_path: str | None = None,
) → None

Remove a directory from the ISO. The directory must be empty.

Parameters:
  • iso_path – The path to the directory to remove.

  • rr_name – Ignored. Earlier versions accepted this parameter but never used it; the directory is identified by iso_path, joliet_path, or udf_path.

  • joliet_path – The Joliet path to the directory to remove.

  • udf_path – The UDF absolute path to the directory to remove.

Returns:

Nothing.

rm_joliet_directory(joliet_path: str) → None

Deprecated since version 1.20.0: Use rm_directory() with the joliet_path argument instead.

Remove a Joliet directory from the ISO. It is recommended to use the ‘joliet_path’ parameter to rm_directory() instead.

Parameters:

joliet_path – The Joliet path to the directory to remove.

Returns:

Nothing.

add_eltorito(
bootfile_path: str,
bootcatfile: str | None = None,
rr_bootcatname: str | None = None,
joliet_bootcatfile: str | None = None,
boot_load_size: int | None = None,
platform_id: int = 0,
boot_info_table: bool = False,
efi: bool = False,
media_name: str = 'noemul',
bootable: bool = True,
boot_load_seg: int = 0,
udf_bootcatfile: str | None = None,
) → None

Add an El Torito Boot Record, and associated files, to the ISO. The file that will be used as the bootfile must be passed into this function and must already be present on the ISO.

Parameters:
  • bootfile_path – The file to use as the boot file; it must already exist on this ISO.

  • bootcatfile – The fake file to use as the boot catalog entry; set to BOOT.CAT;1 by default.

  • rr_bootcatname – The Rock Ridge name for the fake file to use as the boot catalog entry; set to ‘boot.cat’ by default.

  • joliet_bootcatfile – The Joliet name for the fake file to use as the boot catalog entry; set to ‘boot.cat’ by default.

  • boot_load_size – The number of sectors to use for the boot entry; if set to None (the default), the number of sectors will be calculated.

  • platform_id – The platform ID to set for the El Torito entry; 0 is for x86, 1 is for Power PC, 2 is for Mac, and 0xef is for UEFI. 0 is the default.

  • boot_info_table – Whether to add a boot info table to the ISO. The default is False.

  • efi – Whether this is an EFI entry for El Torito. The default is False.

  • media_name – The name of the media type, one of ‘noemul’, ‘floppy’, or ‘hdemul’.

  • bootable – Whether the boot media is bootable. The default is True.

  • boot_load_seg – The load segment address of the boot image.

  • udf_bootcatfile – The name of the boot.cat file on the UDF filesystem.

Returns:

Nothing.

rm_eltorito() → None

Remove the El Torito boot record (and Boot Catalog) from the ISO.

Returns:

Nothing.

Add a symlink from rr_symlink_name to the rr_path. The ISO must have either Rock Ridge or UDF support (or both).

Parameters:
  • symlink_path – The ISO9660 path of the symlink itself on the ISO.

  • rr_symlink_name – The Rock Ridge name of the symlink itself on the ISO.

  • rr_path – The path that the symlink points to on the Rock Ridge part of the ISO.

  • joliet_path – The Joliet path of the symlink (if this ISO has Joliet).

  • udf_symlink_path – The UDF path of the symlink itself on the ISO.

  • udf_target – The UDF name of the entry on the ISO that the symlink points to.

  • creation_time – Optional creation time, in seconds since the epoch. See add_fp() for storage rules. At least one of a Rock Ridge symlink (rr_symlink_name + rr_path) or a UDF symlink (udf_symlink_path + udf_target) must be supplied to store it.

Returns:

Nothing.

list_dir(
iso_path: str,
joliet: bool = False,
) → Generator

Deprecated since version 1.20.0: Use list_children() instead.

Generate a list of all of the file/directory objects in the specified location on the ISO. It is recommended to use the list_children() API instead.

Parameters:
  • iso_path – The path on the ISO to look up information for.

  • joliet – Whether to look for the path in the Joliet portion of the ISO.

Yields:

Children of this path.

Returns:

Nothing.

list_children(**kwargs: str) → Generator

Generate a list of all of the file/directory objects in the specified location on the ISO.

Parameters:
  • iso_path – The absolute path on the ISO to list the children for.

  • rr_path – The absolute Rock Ridge path on the ISO to list the children for.

  • joliet_path – The absolute Joliet path on the ISO to list the children for.

  • udf_path – The absolute UDF path on the ISO to list the children for.

Yields:

Children of this path. For iso_path, rr_path, and joliet_path these are dr.DirectoryRecord objects, including the ‘dot’ and ‘dotdot’ entries; for udf_path these are udf.UDFFileEntry objects, and the UDF ‘parent’ entry (which has no File Entry) is omitted.

Returns:

Nothing.

get_entry(
iso_path: str,
joliet: bool = False,
) → DirectoryRecord

Deprecated since version 1.20.0: Use get_record() instead.

Get the directory record for a particular path. It is recommended to use the get_record() API instead.

Parameters:
  • iso_path – The path on the ISO to look up information for.

  • joliet – Whether to look for the path in the Joliet portion of the ISO.

Returns:

A dr.DirectoryRecord object representing the path.

get_record(
**kwargs: str,
) → dr.DirectoryRecord | udfmod.UDFFileEntry

Get the directory record for a particular path.

Parameters:
  • iso_path – The absolute path on the ISO9660 filesystem to get the record for.

  • rr_path – The absolute path on the Rock Ridge filesystem to get the record for.

  • joliet_path – The absolute path on the Joliet filesystem to get the record for.

  • udf_path – The absolute path on the UDF filesystem to get the record for.

Returns:

An object that represents the path. This may be a dr.DirectoryRecord object (in the cases of iso_path, rr_path, or joliet_path), or a udf.UDFFileEntry object (in the case of udf_path).

add_isohybrid(
part_entry: int = 1,
mbr_id: int | None = None,
part_offset: int = 0,
geometry_sectors: int = 32,
geometry_heads: int = 64,
part_type: int | None = None,
mac: bool = False,
efi: bool | None = None,
) → None

Make an ISO a ‘hybrid’, which means that it can be booted either from a CD or from more traditional media (like a USB stick). This requires that the ISO already have El Torito, and will use the El Torito boot file as a bootable image. That image must contain a certain signature in order to work as a hybrid (if using syslinux, this generally means the isohdpfx.bin files).

Parameters:
  • part_entry – The partition entry to use; one by default.

  • mbr_id – The mbr_id to use. If set to None (the default), a random one will be generated.

  • part_offset – The partition offset to use; zero by default.

  • geometry_sectors – The number of sectors to assign; thirty-two by default.

  • geometry_heads – The number of heads to assign; sixty-four by default.

  • part_type – The partition type to assign; twenty-three by default, but will automatically be set to 0 if mac or efi are True.

  • mac – Add support for Mac; False by default.

  • efi – Add support for EFI; False by default, but will automatically be set to True if mac is True.

Returns:

Nothing.

rm_isohybrid() → None

Remove the ‘hybridization’ of an ISO, making it a traditional ISO again. This means the ISO will no longer be able to be copied and booted off of traditional media (like USB sticks).

Returns:

Nothing.

full_path_from_dirrecord(
rec: dr.DirectoryRecord | udfmod.UDFFileEntry,
rockridge: bool = False,
encoding: str | None = None,
) → str

Get the absolute path of a directory record.

Parameters:
  • rec – The directory record to get the full path for.

  • rockridge – Whether to get the rock ridge full path.

  • encoding – The encoding to decode the on-disk file identifiers with. When None, defaults to ‘utf-8’ for ISO9660 and Rock Ridge records, ‘utf-16_be’ for Joliet records, and the UDF file_ident’s own encoding for UDF. Pass a non-None value when walking an ISO whose names are in a different encoding, such as shift_jis.

Returns:

A string representing the absolute path to the file on the ISO.

duplicate_pvd() → None

Add a duplicate PVD to the ISO. This is a mostly useless feature allowed by Ecma-119 to have duplicate PVDs to avoid possible corruption.

Returns:

Nothing.

set_hidden(
iso_path: str | None = None,
rr_path: str | None = None,
joliet_path: str | None = None,
) → None

Set the ISO9660 hidden attribute on a file or directory. This will cause the file or directory not to show up when listing entries on the ISO. Exactly one of iso_path, rr_path, or joliet_path must be specified.

Parameters:
  • iso_path – The path on the ISO to set the hidden bit on.

  • rr_path – The Rock Ridge path on the ISO to set the hidden bit on.

  • joliet_path – The Joliet path on the ISO to set the hidden bit on.

Returns:

Nothing.

clear_hidden(
iso_path: str | None = None,
rr_path: str | None = None,
joliet_path: str | None = None,
) → None

Clear the ISO9660 hidden attribute on a file or directory. This will cause the file or directory to show up when listing entries on the ISO. Exactly one of iso_path, rr_path, or joliet_path must be specified.

Parameters:
  • iso_path – The path on the ISO to clear the hidden bit from.

  • rr_path – The Rock Ridge path on the ISO to clear the hidden bit from.

  • joliet_path – The Joliet path on the ISO to clear the hidden bit from.

Returns:

Nothing.

force_consistency() → None

Make sure the ISO object is fully consistent. PyCdlib typically delays doing work until it is necessary, and this detail is usually hidden from users. However, there are times that a user may want a fully consistent view of the ISO without calling one of the methods that forces consistency. This method allows the user to force a consistent view of this object.

Returns:

Nothing.

set_relocated_name(name: str, rr_name: str) → None

Set the name of the relocated directory on a Rock Ridge ISO. The ISO must be a Rock Ridge one, and must not have previously had the relocated name set.

Parameters:
  • name – The name for a relocated directory.

  • rr_name – The Rock Ridge name for a relocated directory.

Returns:

Nothing.

walk(**kwargs: str) → Generator

Walk the entries on the ISO, starting at the given path. One, and only one, of iso_path, rr_path, joliet_path, and udf_path is allowed. Similar to os.walk(), yield a 3-tuple of (path-to-here, dirlist, filelist) for each directory level.

Parameters:
  • iso_path – The absolute ISO path to the starting entry on the ISO.

  • rr_path – The absolute Rock Ridge path to the starting entry on the ISO.

  • joliet_path – The absolute Joliet path to the starting entry on the ISO.

  • udf_path – The absolute UDF path to the starting entry on the ISO.

  • encoding – The encoding to use for returned strings.

Yields:

3-tuples of (path-to-here, dirlist, filelist)

Returns:

Nothing.

open_file_from_iso(
**kwargs: str,
) → PyCdlibIO

Open a file for reading in a context manager. This allows the user to operate on the file in user-defined chunks (utilizing the read() method of the returned context manager).

Parameters:
  • iso_path – The absolute ISO path to the file on the ISO.

  • rr_path – The absolute Rock Ridge path to the file on the ISO.

  • joliet_path – The absolute Joliet path to the file on the ISO.

  • udf_path – The absolute UDF path to the file on the ISO.

Returns:

A PyCdlibIO object allowing access to the file.

has_rock_ridge() → bool

Returns whether this ISO has Rock Ridge extensions.

Returns:

True if this ISO has Rock Ridge extensions, False otherwise.

has_joliet() → bool

Returns whether this ISO has Joliet extensions.

Returns:

True if this ISO has Joliet, False otherwise.

has_udf() → bool

Returns whether this ISO has UDF extensions.

Returns:

True if this ISO has UDF, False otherwise.

get_iso9660_facade() → PyCdlibISO9660

Return a ‘facade’ that simplifies some of the complexities of the PyCdlib class, while giving up some of the full power. This facade only allows manipulation of the ISO9660 portions of the ISO.

Returns:

A PyCdlibISO9660 object that can be used to interact with the ISO.

get_joliet_facade() → PyCdlibJoliet

Return a ‘facade’ that simplifies some of the complexities of the PyCdlib class, while giving up some of the full power. This facade only allows manipulation of the Joliet portions of the ISO.

Returns:

A PyCdlibJoliet object that can be used to interact with the ISO.

get_rock_ridge_facade() → PyCdlibRockRidge

Return a ‘facade’ that simplifies some of the complexities of the PyCdlib class, while giving up some of the full power. This facade only allows manipulation of the Rock Ridge portions of the ISO.

Returns:

A PyCdlibRockRidge object that can be used to interact with the ISO.

get_udf_facade() → PyCdlibUDF

Return a ‘facade’ that simplifies some of the complexities of the PyCdlib class, while giving up some of the full power. This facade only allows manipulation of the UDF portions of the ISO.

Returns:

A PyCdlibUDF object that can be used to interact with the ISO.

file_mode(**kwargs: str) → int | None

Get the POSIX file mode of the file if it is a Rock Ridge file.

Parameters:
  • iso_path – The absolute ISO path to the file on the ISO.

  • rr_path – The absolute Rock Ridge path to the file on the ISO.

  • joliet_path – The absolute Joliet path to the file on the ISO.

  • udf_path – The absolute UDF path to the file on the ISO.

Returns:

An integer representing the POSIX file mode of the file if it is Rock Ridge, or None otherwise.

close() → None

Close the PyCdlib object, and re-initialize the object to the defaults. The object can then be re-used for manipulation of another ISO.

Returns:

Nothing.