Skip to content

Add IMMED FORMAT UNIT tool + progress poller; fix half-format on slow HDDs#2

Open
mwventures wants to merge 1 commit into
filthyrake:mainfrom
mwventures:immed-format-and-progress
Open

Add IMMED FORMAT UNIT tool + progress poller; fix half-format on slow HDDs#2
mwventures wants to merge 1 commit into
filthyrake:mainfrom
mwventures:immed-format-and-progress

Conversation

@mwventures

Copy link
Copy Markdown

What this adds

Two tools + docs that make the 520→512 reformat reliable on slow multi-TB HDDs (not just SSDs), and explains a failure this repo's README currently notes as a mystery ("status 45 failure but it actually worked").

The problem

The existing formatters send FORMAT UNIT without the IMMED bit, so it blocks until the format finishes. On a fast SSD it can complete before the RAID controller's command timeout (hence "status 45 but worked"). On a slow 7200rpm multi-TB SAS HDD the format takes hours, the controller timeout aborts it with SCSI_IO_FAILED, and the medium is left half-formatted and invalid (SMART self-test = I/O error, controller shows 0 KB / UBad). Note: smartctl can still print 512 bytes / full capacity — that's the intended geometry from the mode page, not proof the medium is good.

The fix

  • mega_format_immed.c — MODE SELECT to 512, then FORMAT UNIT with IMMED=1; returns immediately, formats in the background.
  • mega_progress.c — polls progress via REQUEST SENSE (sense key 0x2 / ASC 0x04 / ASCQ 0x04 → percent complete).
  • README — documents the IMMED issue + half-format mode, and a cold power-cycle option for chassis with no hot-swap backplane (where a warm reboot leaves the drive powered and the controller keeps its stale UGUnsp / 0 KB identity).

Testing

Validated on a Dell PowerEdge T130 / PERC H730 (HBA mode) reformatting 2 TB HGST HMRP2000 7200rpm SAS drives: the non-IMMED path timed out and half-formatted; these tools completed cleanly (~4h/drive) with a full cold power cycle to clear the controller cache. Both tools build clean with -O2 -Wall -Wextra.

Notes

  • Left .github/workflows/build-and-release.yml untouched (didn't want to push CI changes). If you'd like CI to build/package the new tools, add mega_format_immed and mega_progress to the build / test / archive / release lists — happy to include that here.
  • Builds on this repo's existing passthrough approach — thanks for the original tools and write-up.

… slow HDDs

The existing formatters send FORMAT UNIT without the IMMED bit, so the command
blocks until the whole format finishes. On a fast SSD that can complete before
the RAID controller's command timeout (the origin of the "status 45 but it
worked" note); on a slow multi-TB 7200rpm SAS HDD the format takes hours, the
controller timeout aborts it with SCSI_IO_FAILED, and the medium is left
half-formatted and invalid.

Changes:
- mega_format_immed.c: MODE SELECT to 512, then FORMAT UNIT with IMMED=1 so the
  drive returns immediately and formats in the background (reliable on HDDs).
- mega_progress.c: poll background format progress via REQUEST SENSE
  (sense key 0x2 / ASC 0x04 / ASCQ 0x04 -> percent complete).
- README: explain the IMMED issue and half-format failure mode; add a cold
  power-cycle option for chassis without a hot-swap backplane; document the two
  new tools; note validation on a PERC H730 with 2 TB HGST SAS HDDs.

Both tools build clean with -O2 -Wall -Wextra. Approach builds on the existing
passthrough tools in this repo. (CI left untouched; see PR notes for the
suggested build lines.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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