Skip to content

HDD Manager: repair the zero disk ID on A2 drives from older builds - #457

Merged
NathanNeurotic merged 1 commit into
masterfrom
claude/project-thread-aet0u6
Dec 1, 2026
Merged

NathanNeurotic merged 1 commit into
masterfrom
claude/project-thread-aet0u6

Conversation

@NathanNeurotic

@NathanNeurotic NathanNeurotic commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Requested by NathanNeurotic Ripto · project thread

What

HDD Manager > Options > Repair A2 disk ID... for APA Jail A2 drives formatted by an older build.

Sector 0 is both the APA header and the PC MBR, and the APA checksum covers the MBR's 4-byte disk ID at 0x1B8. Older A2 formats left that ID at 0. Windows treats 0 as "no ID" and may write its own, which breaks the APA checksum, so the PS2 sees a damaged header. #453 made new A2 formats write a non-zero ID; this repairs drives already formatted.

How

  • Asks for confirmation first (same pattern as the existing PSBBN DP repair).
  • hddFormatDiskIdFix (src/hdd_format.c) reads both header sectors and verifies the APA magic, the checksum, the APAJ-A2 marker and the three MBR entries. If any of that fails it refuses and does not guess.
  • If the ID is zero it sets a non-zero ID (time based, 1 if the clock is 0, as the formatter does) and recomputes the APA checksum. Nothing else in the sector changes.
  • The EE adapter (hddFormatDiskId) writes sector 0 only, flushes and reads it back, through the same raw session, volume release and IOP reset the existing relabel repair uses. Partitions, data and GPT are not touched.
  • Not A2, already has an ID, or header does not verify: left alone, with a message saying which.
  • A drive where Windows has already written its own ID has a bad checksum and is refused as well. This does not repair that case.
  • Not built: type E formatting, or any change to formats for other drives.

The APA Jail scheme and the sector 0 layout are Berion's.

Verification

  • Verified: host tests (tests/test_hdd_format.py covers the checksum logic: fresh ID untouched, zero ID fixed with only the ID and checksum changed, bad checksum, bad magic, damaged second sector, Windows-style ID with a bad checksum, wrong marker, type D, plain exFAT and a failed read are refused; test_hdd_format_ui.py checks the dry-run, release and sector-0-only ordering). The related HDD host tests pass.
  • Not verified: the EE code (dash_hdd.c, hdd_format_ps2.c) was not compiled locally, so CI is its first build. Not tested on PCSX2 or a real PS2.

Refs #453


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Added an HDD Manager option to repair a zero disk ID on supported APA Jail A2 drives. The repair checks the drive header, updates the disk ID and checksum, and verifies the write.
    • Drives with an existing ID, unsupported layouts, or invalid headers are left unchanged.
  • Documentation
    • Added instructions and safety details for the disk-ID repair option.

An APA Jail A2 drive formatted by an older build has a zero MBR disk ID at
0x1B8. Windows treats that as no ID and may write its own, which breaks the
APA checksum, so the PS2 sees a damaged header. Newer formats already write a
non-zero ID.

Options > Repair A2 disk ID... asks for confirmation, verifies the APA header
(both header sectors: magic, checksum, A2 marker, the three MBR entries), and
only if the ID is zero writes a non-zero ID and the recomputed APA checksum
into sector 0, then reads it back. Nothing else is written. A drive that is
not A2, already has an ID, or whose header does not verify is left alone.

The APA Jail scheme and the sector 0 layout are Berion's.

Host tests only; not tested on PCSX2 or a real PS2.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 16:53
@NathanNeurotic NathanNeurotic self-assigned this Dec 1, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T16:53:59.197867Z
We couldn’t complete this review. Comment @codex review to try again.
21fd0e0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds validation and repair for zero disk IDs on APA Jail A2 drives. It adds a sector-0 write and readback path, an HDD Manager action, tests, and documentation.

Changes: A2 Disk ID Repair

Layer / File(s) Summary
Disk ID validation and repair data
include/hdd_format.h, src/hdd_format.c, tests/test_hdd_format.py
The new helper validates APA headers and A2 markers. For a zero ID, it returns sector 0 with a non-zero ID and updated checksum. Tests cover repair results and error cases.
Sector write and verification
include/hdd_format.h, src/hdd_format_ps2.c, tests/test_hdd_format_ui.py
The PS2 formatter supports check and apply modes. On apply, it writes sector 0, flushes, reads it back, and verifies the result. Tests check the dry-run and write sequence.
HDD Manager repair action
src/dash_hdd.c, tests/test_hdd_partition_rename.py, docs/hdd-formatting.md, CHANGELOG.md
The HDD Manager adds a repair menu action and worker job. The action checks service state, requests confirmation, reports the result, and refreshes HDD state. The documentation describes the repair conditions and outcomes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant HDDManager
  participant actDiskIdRepair
  participant repairWorker
  participant hddFormatDiskId
  participant APAHDD
  HDDManager->>actDiskIdRepair: Select repair and confirm
  actDiskIdRepair->>repairWorker: Start repair job
  repairWorker->>hddFormatDiskId: Check mode
  hddFormatDiskId->>APAHDD: Read APA header sectors
  repairWorker->>repairWorker: Release mounts when repair is needed
  repairWorker->>hddFormatDiskId: Apply repair
  hddFormatDiskId->>APAHDD: Write and read back sector 0
Loading
Merge Risk: Minimal · up to 21fd0

This adds an opt-in HDD Manager repair that writes only sector 0, only on a verified A2 drive with a zero disk ID, and then reads it back. Its checks, refusal paths and host tests look sound. It has not been compiled for the PS2 target or tried on real hardware, so a quick smoke test there is worthwhile, but nothing found blocks merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a repair for the zero disk ID on A2 drives created by older builds, in the HDD Manager. The summary, the header and checksum checks, the sector-0 write, and the menu a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a repair for the zero disk ID on A2 drives created by older builds, in the HDD Manager. The summary, the header and checksum checks, the sector-0 write, and the menu action all match this scope. The title is specific and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 4a05c208-fe96-4af7-a043-50449e275882
Commits

Reviewing files that changed from the base of the PR and between 11082fe and 21fd0e0.

Files selected for processing: 9

  • CHANGELOG.md
  • docs/hdd-formatting.md
  • include/hdd_format.h
  • src/dash_hdd.c
  • src/hdd_format.c
  • src/hdd_format_ps2.c
  • tests/test_hdd_format.py
  • tests/test_hdd_format_ui.py
  • tests/test_hdd_partition_rename.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: Build Launchstation (ps2build)
Additional context used

Cppcheck (2.22.0)

src/hdd_format.c

[style] 273-273: The function 'hddFormatDiskIdFix' is never used.

(unusedFunction)

src/hdd_format_ps2.c

[style] 188-188: The function 'hddFormatDiskId' is never used.

(unusedFunction)

Ruff (0.17.4)

tests/test_hdd_format.py

[warning] 527-527: Function definition does not bind loop variable image

(B023)

[warning] 527-527: Function definition does not bind loop variable fix

(B023)

[warning] 529-529: Function definition does not bind loop variable image

(B023)

[warning] 531-531: Assertion should be broken down into multiple parts

Break down assertion into multiple parts

(PT018)

[warning] 541-541: Assertion should be broken down into multiple parts

Break down assertion into multiple parts

(PT018)

[warning] 544-544: Assertion should be broken down into multiple parts

Break down assertion into multiple parts

(PT018)

[warning] 546-546: Assertion should be broken down into multiple parts

Break down assertion into multiple parts

(PT018)

tests/test_hdd_format_ui.py

[warning] 310-310: Assertion should be broken down into multiple parts

Break down assertion into multiple parts

(PT018)

Additional comments: 2

tests/test_hdd_format.py: 1

568-568: Functional Correctness

The comment's premise does not hold. The loop returns early for plain APA at line 414, before the disk-ID repair assertions run. Line 568 runs only for the exFAT kind, and -errno.EIO is the intended expectation there. No change to the assertion is needed.

src/hdd_format_ps2.c: 1

200-201: Stability & Availability

The concern does not hold. In the IOP handler, HF_BEGIN returns a negative result only before it detaches a volume. After the detach, the handler unconditionally sets active = 1 and returns 0. The early return in hddFormatDiskId therefore cannot leave a volume detached. actDiskIdRepair also gets no reason to skip its reset on this path.

@NathanNeurotic
NathanNeurotic merged commit 97e947c into master Dec 1, 2026
2 checks passed
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.

3 participants