Skip to content

Develop#16

Merged
p14c31355 merged 18 commits intomainfrom
develop
Sep 20, 2025
Merged

Develop#16
p14c31355 merged 18 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 p14c31355 self-assigned this Sep 20, 2025
@p14c31355 p14c31355 added the enhancement New feature or request label Sep 20, 2025
@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 significantly refactors the ISO image creation logic to properly embed a KERNEL.EFI file within the generated ISO, alongside the existing BOOTX64.EFI bootloader. It also includes a critical bug fix for the El Torito boot catalog checksum calculation and improves the dynamic sizing of directory entries for a more robust ISO 9660 structure.

Highlights

  • El Torito Boot Catalog Checksum Fix: Corrected the BOOT_CATALOG_CHECKSUM_OFFSET in src/iso/boot_catalog.rs from 28 to 2, ensuring accurate checksum calculation for the El Torito boot catalog validation entry. This resolves a potential bug in the boot catalog generation.
  • Kernel Inclusion in ISO: Modified the ISO creation process in src/iso/iso.rs to explicitly include a KERNEL.EFI file alongside BOOTX64.EFI within the ISO's BOOT directory. This allows for a more complete and functional bootable ISO image.
  • Dynamic Directory Sizing and Structure: Refactored the ISO directory entry generation logic to dynamically calculate and update directory sizes (for root, EFI, and BOOT directories). This improves the robustness and correctness of the ISO 9660 file system structure, especially with the addition of new files.
  • API Update for Kernel Path: The create_iso_from_img function signature in src/iso/iso.rs was updated to accept a kernel_path parameter, and its call site in src/lib.rs was adjusted accordingly to pass the new argument.
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

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 pull request introduces significant refactoring and bug fixes, primarily in the ISO creation logic. The changes to correctly include the kernel file and fix a critical bug in the boot catalog checksum calculation are excellent improvements. My review focuses on the src/iso/iso.rs file, where I've identified opportunities to enhance code efficiency, clarity, and correctness. Specifically, I've pointed out a redundant and potentially buggy write operation for the BOOT directory, some inefficient size calculations, and non-English comments that affect maintainability. Addressing these points will further strengthen the codebase.

Comment thread src/iso/iso.rs
Comment thread src/iso/iso.rs Outdated

// Define structs with placeholder sizes first
let mut boot_dir_entries_structs_with_kernel = vec![
// 名前を変更
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.

medium

This comment is in Japanese. For consistency and readability in an English-language project, it's best to write all comments in English. If this is a temporary note for development, it should be removed. This also applies to other Japanese comments in this file (e.g., lines 63, 91, 202).

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

/gemini review

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 pull request refactors the ISO creation logic, notably to include the kernel as a separate file within the ISO structure. While the refactoring adds new functionality and improves code comments, it also introduces several critical and high-severity issues. There's a bug in the boot catalog checksum calculation that will likely prevent booting. The new logic for calculating directory sizes in the ISO is flawed and will create a corrupt filesystem. Additionally, there's significant architectural confusion in lib.rs regarding the boot strategy, resulting in dead code and redundant operations. I've provided detailed comments and suggestions to address these issues.

Comment thread src/iso/boot_catalog.rs Outdated
pub const BOOT_CATALOG_EFI_PLATFORM_ID: u8 = 0xEF;
pub const ID_FIELD_OFFSET: usize = 4;
pub const BOOT_CATALOG_CHECKSUM_OFFSET: usize = 28;
pub const BOOT_CATALOG_CHECKSUM_OFFSET: usize = 2;
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 offset for the boot catalog checksum is incorrect. According to the El Torito specification, the 16-bit checksum for the validation entry should be at offset 28 (0x1C). It has been changed to 2, which corresponds to a reserved field. This will result in a malformed boot catalog and will likely cause the boot process to fail.

Suggested change
pub const BOOT_CATALOG_CHECKSUM_OFFSET: usize = 2;
pub const BOOT_CATALOG_CHECKSUM_OFFSET: usize = 28;

Comment thread src/iso/iso.rs Outdated
Comment on lines +129 to +139
// Update sizes in the structs
boot_dir_entries_structs_with_kernel[0].size = boot_dir_final_size;
boot_dir_entries_structs_with_kernel[1].size = efi_dir_size; // Parent is EFI dir

efi_dir_entries_structs[0].size = efi_dir_size;
efi_dir_entries_structs[1].size = root_dir_size; // Parent is root dir
efi_dir_entries_structs[2].size = boot_dir_final_size; // Child is BOOT dir

root_dir_entries_structs[0].size = root_dir_size;
root_dir_entries_structs[1].size = root_dir_size; // Parent is itself
root_dir_entries_structs[2].size = efi_dir_size; // Child is EFI dir
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.

high

The directory sizes (root_dir_size, efi_dir_size, boot_dir_final_size) are being calculated based on the unpadded length of the directory records. However, the size field in an ISO 9660 directory entry must reflect the total size of the directory's extent, which is padded to a sector boundary. For instance, root_dir_content is padded to ISO_SECTOR_SIZE on line 159, so root_dir_size should be ISO_SECTOR_SIZE as u32, not the unpadded length. This discrepancy will lead to a corrupted or unreadable ISO image because the filesystem metadata will not match the actual layout on disk. This issue applies to all directory size calculations in this block.

Comment thread src/lib.rs
Comment on lines +28 to +33
create_iso_from_img(
iso_path,
loader_path,
kernel_path,
boot_img_sectors as u32 * 512,
)?;
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.

high

This change introduces significant architectural confusion. The code now calls create_fat_image to generate a FAT image containing the bootloader and kernel, but this image is immediately discarded. Instead, create_iso_from_img is called with the raw loader and kernel paths, suggesting a different boot strategy where files are placed directly on the ISO filesystem.

This leaves dead code (create_fat_image call) and makes the overall boot strategy unclear. Please clarify the intended architecture:

  1. FAT Image as Boot Image: If the goal is to use a FAT image, create_iso_from_img should be called with the path to the generated FAT image, and it probably shouldn't handle the kernel separately.
  2. Plain Files in ISO: If the goal is to have plain files in the ISO, the call to create_fat_image (lines 18-23) is unnecessary and should be removed.

The current implementation is misleading and inefficient.

Comment thread src/iso/iso.rs Outdated
Comment on lines +199 to +208
// Re-calculate final BOOT directory size and re-pad
let final_boot_dir_bytes = boot_dir_entries_structs_final
.iter()
.flat_map(|e| e.to_bytes())
.collect::<Vec<u8>>();
let pad_sectors = final_boot_dir_bytes.len().div_ceil(ISO_SECTOR_SIZE);
let mut final_boot_dir = final_boot_dir_bytes;
final_boot_dir.resize(pad_sectors * ISO_SECTOR_SIZE, 0);
iso.seek(SeekFrom::Start(22 * ISO_SECTOR_SIZE as u64))?;
iso.write_all(&final_boot_dir)?;
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.

medium

This block of code appears to be redundant. It recalculates the BOOT directory content, pads it, and rewrites it to the same location (LBA 22) it was just written to at lines 172-183. The boot_dir_entries_structs_final variable has not changed between the two writes. This redundant operation is inefficient and makes the code harder to understand. This block should be removed.

@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini review

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 pull request refactors the ISO creation logic, notably to include the kernel as a separate file in the ISO. While the refactoring improves some aspects of code structure, it introduces several critical bugs. The boot catalog checksum calculation is incorrect, which will likely prevent booting. The kernel's location (LBA) within the ISO is miscalculated due to a unit mismatch. Most critically, the main library function was not updated correctly and fails to use the generated FAT boot image, instead passing the raw loader file to the ISO creation function. I've also noted some redundant and potentially buggy logic in the directory writing process. These issues need to be addressed to ensure a correctly structured and bootable ISO is produced.

Comment thread src/iso/boot_catalog.rs Outdated
Comment thread src/iso/iso.rs Outdated
Comment thread src/lib.rs
Comment thread src/iso/iso.rs Outdated
Comment on lines +179 to +188
// Re-calculate final BOOT directory size and re-pad
let final_boot_dir_bytes = boot_dir_entries_structs_final
.iter()
.flat_map(|e| e.to_bytes())
.collect::<Vec<u8>>();
let pad_sectors = final_boot_dir_bytes.len().div_ceil(ISO_SECTOR_SIZE);
let mut final_boot_dir = final_boot_dir_bytes;
final_boot_dir.resize(pad_sectors * ISO_SECTOR_SIZE, 0);
iso.seek(SeekFrom::Start(22 * ISO_SECTOR_SIZE as u64))?;
iso.write_all(&final_boot_dir)?;
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.

high

This block of code re-calculates and re-writes the BOOT directory content, but it appears to be redundant. The boot_dir_entries_structs_final data structure is the same one used to write the directory initially in lines 152-163. This rewrite is a no-op and adds unnecessary complexity. This block can be safely removed.

p14c31355 and others added 5 commits September 20, 2025 15:20
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini review

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 pull request introduces a significant and valuable refactoring of the ISO creation logic, along with important bug fixes. The changes correct a checksum calculation error in the El Torito boot catalog and fix a critical bug where the wrong file was being embedded into the ISO. The code for creating directory structures is now much cleaner and more maintainable. Overall, these changes greatly improve the correctness and quality of the codebase. I have one minor suggestion to clean up some unused variables introduced during the refactoring.

Comment thread src/iso/iso.rs Outdated
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 focuses on enhancing the ISO image generation utility by integrating a kernel image into the bootable ISO and refining the El Torito boot catalog creation. It addresses several identified issues related to checksum calculations and directory structuring, resulting in a more robust and functionally complete ISO output. The changes primarily involve refactoring existing code for clarity and correctness, and extending functionality to support the inclusion of a kernel.

Highlights

  • El Torito Boot Catalog Refinement: The logic for generating the El Torito boot catalog has been improved for clarity and correctness. This includes adding detailed documentation comments, renaming internal variables for better readability, and reordering checksum calculation and signature placement within the validation entry. Crucially, the checksum calculation loop was corrected to iterate over all 32 bytes, ensuring adherence to the specification.
  • Kernel Inclusion in ISO: The ISO creation process now explicitly supports embedding a KERNEL.EFI file alongside the BOOTX64.EFI bootloader. The create_iso_from_img function's signature was updated to accept a kernel_path, and the ISO structure now includes the kernel at a calculated logical block address (LBA), making the generated ISO a more complete bootable image.
  • Refactored Directory Entry Handling: The creation of ISO 9660 directory entries for the Root, EFI, and BOOT directories has been refactored. Directory entries are now defined as IsoDirEntry structs, and their byte representations are collected and written to the ISO. This change improves the organization and maintainability of the directory generation logic, and addresses previous concerns about directory size calculations by ensuring proper padding.
  • Main Function Call Update: The create_disk_and_iso function in src/lib.rs has been updated to correctly pass the kernel_path and the padded size of the FAT boot image to the create_iso_from_img function, aligning the top-level call with the enhanced ISO creation capabilities.
Changelog
  • src/iso/boot_catalog.rs
    • Added documentation comments for constants and the write_boot_catalog function.
    • Renamed local variable cat to catalog for improved readability.
    • Reordered checksum calculation and signature placement within the validation entry.
    • Corrected the checksum calculation loop range from (0..30) to (0..32) to ensure all 32 bytes are included.
    • Added inline comments to clarify the structure of validation and boot entries.
  • src/iso/iso.rs
    • Modified the create_iso_from_img function signature to accept a kernel_path argument.
    • Updated the function's documentation to reflect the new kernel_path parameter.
    • Introduced calculations for kernel_size, kernel_sectors, and kernel_lba for kernel placement.
    • Refactored ISO 9660 directory entry creation (Root, EFI, BOOT) using IsoDirEntry structs.
    • Explicitly added KERNEL.EFI as an entry within the BOOT directory.
    • Added logic to copy the KERNEL.EFI file content into the ISO at its calculated LBA.
    • Simplified padding logic after copying the FAT boot image and at the end of the ISO.
    • Improved the error message for an ISO image that exceeds the maximum size.
    • Removed redundant comments.
  • src/lib.rs
    • Modified the call to create_iso_from_img to pass the new kernel_path argument.
    • Adjusted the fat_img_actual_size argument to correctly use the padded size of the FAT image (fat_img_padded_size).
    • Removed previously calculated boot_img_size and boot_img_sectors as they are no longer directly used in the create_iso_from_img call.
Activity
  • gemini-code-assist[bot] provided an initial summary of changes.
  • p14c31355 requested a review multiple times.
  • gemini-code-assist[bot] reported an error during one review attempt.
  • gemini-code-assist[bot] provided several review comments, highlighting issues such as redundant BOOT directory writes, incorrect El Torito checksum calculation, architectural confusion regarding FAT image usage, inefficient directory size calculations, and unit mismatches in LBA calculations. Many of these issues appear to have been addressed in the current changes.

@p14c31355 p14c31355 merged commit de52363 into main Sep 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant