Skip to content

Develop#34

Merged
p14c31355 merged 9 commits intomainfrom
develop
Oct 4, 2025
Merged

Develop#34
p14c31355 merged 9 commits intomainfrom
develop

Conversation

@p14c31355
Copy link
Copy Markdown
Owner

Pull Request

Change details

  • New feature
  • Refactoring
  • Bug fix
  • CI / Build settings correction
  • Documentation update

Build / Test Results

$ cargo check     #
$ cargo test      #

p14c31355 and others added 6 commits October 5, 2025 05:00
The `IsoBuilder::build` method has been updated to accept `esp_lba` and `esp_size_sectors` as `Option<u32>`. This provides greater flexibility in ISO image creation, allowing for scenarios where an EFI System Partition (ESP) is not required or its parameters are determined dynamically.

The logic for writing GPT structures and calculating the ISO9660 data start LBA has been adjusted to conditionally handle the presence of ESP parameters.

Additionally, the `build_iso` function now returns the `NamedTempFile` associated with the temporary FAT image. This ensures that the temporary file, which holds the UEFI boot image, is managed by the caller, preventing its premature deletion and ensuring its availability throughout the ISO building process.
This commit refactors parts of the FAT image creation and ISO builder logic to improve code organization and clarity.

In `src/fat.rs`:
- The `copy_to_fat` function has been moved from the `utils` module and made a private helper function within `fat.rs`. This improves encapsulation as the function is only used in this module.

In `src/iso/builder.rs`:
- The `get_lba_for_path` function is simplified by leveraging a new internal helper, making the path resolution logic cleaner and more robust.
- Calls to `seek_and_pad_to_lba` have been replaced with `seek_to_lba`, streamlining the file writing process.
Moved several ISO-related data structures and constants from `src/iso/builder.rs` to new, more specific modules.

The following types and constants were relocated:
- `IsoFile`, `IsoDirectory`, `IsoFsNode` to `src/iso/fs_node.rs`
- `BootInfo`, `BiosBootInfo`, `UefiBootInfo` to `src/iso/boot_info.rs`
- `IsoImage`, `IsoImageFile` to `src/iso/iso_image.rs`
- `ESP_START_LBA` to `src/iso/constants.rs`

This refactoring improves modularity and code organization by separating concerns. `builder.rs` now focuses solely on the ISO image construction logic, while the new modules define their respective data structures, making them more discoverable and reusable. The public API (`src/lib.rs`) has been updated to re-export these types for external use.
This commit modularizes the ISO builder implementation by extracting utility functions into separate modules. The changes include:
- Moving calculation and helper functions to builder_utils module
- Creating iso_writer module for ISO writing operations
- Reorganizing imports to reflect the new module structure
- Improving code organization and maintainability

This refactoring makes the codebase more modular and easier to understand while maintaining the same functionality.
- Replace direct io::Error::new() calls with io_error! macro for better context
- Extract boot catalog entry creation into separate helper functions
- Use get_file_metadata() instead of direct std::fs::metadata() calls
- Simplify BIOS and UEFI boot entry creation
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @p14c31355, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on a substantial refactoring of the ISO image building logic, aiming to enhance modularity, maintainability, and testability. Key components previously co-located in a single builder file have been reorganized into a more granular module structure, separating concerns such as boot information, filesystem node definitions, GPT handling, and core writing operations. Additionally, error handling has been standardized through new utility macros, and the process for creating UEFI bootable ISOs has been refined and thoroughly tested with a new integration test.

Highlights

  • Modularization of ISO Builder: The monolithic src/iso/builder.rs has been extensively refactored, with core functionalities and data structures extracted into new, dedicated modules like boot_info, builder_utils, fs_node, gpt (submodule), iso_image, and iso_writer.
  • Improved Error Handling: New macros (io_error!, ensure_path_component!, ensure_boot_image_size_valid!) have been introduced in src/utils.rs to provide more consistent and descriptive error messages across the codebase.
  • Enhanced UEFI Boot Support: The create_fat_image function in src/fat.rs now includes a new helper function copy_to_fat, and the ISO builder's build function has been updated to handle optional ESP LBA and size, improving the flexibility and robustness of UEFI boot image creation.
  • New Integration Test for Isohybrid UEFI: A dedicated integration test (test_create_isohybrid_uefi_iso) has been added to thoroughly verify the correct generation and structure of isohybrid ISOs with UEFI boot capabilities, including checks for boot catalog entries and GPT structures.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a significant and well-executed refactoring. The iso module has been broken down into smaller, more focused sub-modules, which greatly improves code organization, readability, and maintainability. The introduction of helper modules like builder_utils.rs and iso_writer.rs, and the separation of data structures into their own files (boot_info.rs, fs_node.rs, etc.) are excellent changes. The GPT logic is also now much cleaner in its own module. I've found a couple of issues, one of which is critical, but overall this is a very positive change for the codebase.

Comment thread src/iso/fs_node.rs Outdated
Comment on lines +43 to +49
/// Returns the name of the node.
pub fn name(&self) -> String {
match self {
IsoFsNode::File(file) => file.path.file_name().unwrap().to_str().unwrap().to_string(),
IsoFsNode::Directory(dir) => dir.children.get(".").unwrap().name(), // This is a bit of a hack, assuming "." is always present and is the directory name
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The name() method for IsoFsNode::Directory is implemented in a way that will cause a panic. It tries to access dir.children.get("."), but the in-memory IsoDirectory representation does not contain . or .. entries; these are synthesized during ISO creation. This will result in an unwrap() on a None value. Even if it didn't panic, it would lead to infinite recursion as it would call name() on itself.

Since a node's name is determined by its key in the parent's children map, a node doesn't inherently know its own name. Given this method is not used elsewhere, the safest and cleanest solution is to remove it.

Comment thread src/iso/builder_utils.rs Outdated
p14c31355 and others added 3 commits October 5, 2025 06:58
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini summary

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request undertakes a significant refactoring of the ISO image creation process, aiming to improve the overall architecture and robustness of the isobemak crate. By breaking down a previously monolithic builder into a suite of specialized modules, the changes enhance modularity, making the codebase easier to understand, maintain, and extend. Alongside this structural overhaul, the PR introduces standardized error handling mechanisms and refines the creation of UEFI bootable images, particularly for isohybrid scenarios. A new, dedicated integration test ensures the reliability of these critical boot functionalities.

Highlights

  • Modularization of ISO Builder: The core ISO image building logic has been extensively refactored, moving functionalities and data structures from a single large file into new, dedicated modules for boot information, filesystem nodes, GPT handling, and writing operations. This significantly improves code organization and maintainability.
  • Improved Error Handling: New utility macros (io_error!, ensure_path_component!, ensure_boot_image_size_valid!) have been introduced to standardize and enhance error reporting across the codebase, providing more consistent and descriptive error messages.
  • Enhanced UEFI Boot Support: The process for creating UEFI bootable ISOs, particularly isohybrid images, has been refined. This includes a new helper function for copying files to FAT filesystems and updates to the ISO builder to handle optional EFI System Partition (ESP) LBA and size, making UEFI boot image creation more robust.
  • New Integration Test for Isohybrid UEFI: A comprehensive integration test (test_create_isohybrid_uefi_iso) has been added to thoroughly verify the correct generation and structural integrity of isohybrid ISOs with UEFI boot capabilities, including checks for boot catalog entries and GPT structures.
Changelog
  • src/fat.rs
    • Moved copy_to_fat function into src/fat.rs and made it private.
    • Updated create_fat_image to use the new copy_to_fat function and adjusted FileSystem::new call.
    • Changed utils::ISO_SECTOR_SIZE to crate::utils::ISO_SECTOR_SIZE for correct pathing.
  • src/iso/boot_info.rs
    • Added new file defining BootInfo, BiosBootInfo, and UefiBootInfo structs for high-level boot configuration.
  • src/iso/builder.rs
    • Extensively refactored, removing many functions and structs, now imported from new modules.
    • Updated add_file to utilize the new io_error! macro and get_file_metadata helper.
    • Modified build function signature to accept optional esp_lba and esp_size_sectors for greater flexibility.
    • Updated build logic to delegate LBA calculation, descriptor writing, boot catalog writing, directory writing, file copying, and finalization to newly created helper functions.
    • Removed internal methods like calculate_lbas, write_descriptors, write_boot_catalog, write_directories, copy_files, finalize, get_lba_for_path, and get_file_size_in_iso as they are now external.
    • Adjusted build_iso function signature and logic to manage the temporary FAT file and return its path.
    • Updated test cases to correctly use the new calculate_lbas and get_lba_for_path from builder_utils.
  • src/iso/builder_utils.rs
    • Added new file containing helper functions extracted from builder.rs, including calculate_lbas, get_lba_for_path, get_file_size_in_iso, get_node_for_path, calculate_sectors_from_size, validate_boot_image_size, create_bios_boot_entry, create_uefi_boot_entry, create_uefi_esp_boot_entry, get_file_metadata, and validate_path_components.
  • src/iso/constants.rs
    • Added new file defining the ESP_START_LBA constant.
  • src/iso/fs_node.rs
    • Added new file defining IsoFile, IsoDirectory, and IsoFsNode enums, representing the ISO filesystem structure.
  • src/iso/gpt.rs
    • Removed file, as GPT-related structures and functions have been moved to a new src/iso/gpt submodule.
  • src/iso/gpt/header.rs
    • Added new file defining the GptHeader struct and its associated methods.
  • src/iso/gpt/main_gpt_functions.rs
    • Added new file containing the main functions for writing GPT structures, including calculate_header_crc32, calculate_partition_array_crc32, write_primary_gpt_structures, write_backup_gpt_structures, and write_gpt_structures.
  • src/iso/gpt/mod.rs
    • Added new file declaring header, main_gpt_functions, and partition_entry as submodules of gpt.
  • src/iso/gpt/partition_entry.rs
    • Added new file defining the GptPartitionEntry struct and EFI_SYSTEM_PARTITION_GUID constant.
  • src/iso/iso_image.rs
    • Added new file defining IsoImageFile and IsoImage structs, representing the overall ISO configuration.
  • src/iso/iso_writer.rs
    • Added new file containing functions responsible for writing ISO components, including write_descriptors, write_boot_catalog_to_iso, write_directories, copy_files, and finalize_iso.
  • src/iso/mod.rs
    • Updated to declare new modules (boot_info, builder_utils, constants, fs_node, gpt, iso_image, iso_writer).
    • Removed ESP_START_LBA constant, which was moved to constants.rs.
  • src/iso/volume_descriptor.rs
    • Replaced seek_and_pad_to_lba with the more precise seek_to_lba.
  • src/lib.rs
    • Updated use statements to reflect the new module structure and re-export relevant types.
    • Modified setup_iso_creation test helper to return IsoImage directly and leverage the create_dummy_files! macro.
    • Updated test_create_custom_iso_example to use the simplified setup_iso_creation.
  • src/utils.rs
    • Removed copy_to_fat function (moved to src/fat.rs).
    • Replaced seek_and_pad_to_lba with seek_to_lba.
    • Introduced new macros: io_error!, ensure_path_component!, ensure_boot_image_size_valid! for consistent error handling.
    • Added test_utils module with create_dummy_file and create_dummy_files! macro for testing utilities.
  • tests/integration.rs
    • Updated use statements to reflect re-exports from lib.rs.
    • Added a new integration test test_create_isohybrid_uefi_iso to verify isohybrid UEFI ISO creation, including detailed checks for boot catalog entries, ESP LBA, and sector counts.
Activity
  • Initial summary provided by gemini-code-assist[bot] to quickly onboard reviewers.
  • gemini-code-assist[bot] identified a critical issue in IsoFsNode::Directory where a name() method would panic due to an unwrap() on a None value, recommending its removal.
  • gemini-code-assist[bot] pointed out a medium priority compilation error caused by an invalid #[macro_use] attribute on a use statement, suggesting a simple use statement as a fix.
  • Author p14c31355 requested a summary of the pull request.

@p14c31355 p14c31355 merged commit cf87b4a into main Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant