Skip to content

Revert "chatgpt-cutoff" -- unreviewed HDD rewrite with a live drive-corruption risk - #237

Merged
NathanNeurotic merged 1 commit into
masterfrom
claude/revert-chatgpt-cutoff
Jul 20, 2026
Merged

Revert "chatgpt-cutoff" -- unreviewed HDD rewrite with a live drive-corruption risk#237
NathanNeurotic merged 1 commit into
masterfrom
claude/revert-chatgpt-cutoff

Conversation

@NathanNeurotic

@NathanNeurotic NathanNeurotic commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Why revert now

d14f3e73 went directly to master (no PR, no review) and shipped to testers via Rolling on 07-18. Its goals are good — APA + BDM-ATA coexistence, R3Z-style module residency — and they'll be re-landed properly. But as shipped:

1. Live drive-corruption risk (the urgent one). It deleted hddDetectNonSonyFileSystem() — upstream's exFAT/MBR/GPT safety guard — and now loads the APA driver ps2hdd.irx unconditionally on any disk, trusting an unverified claim that its init is read-only for non-APA disks. The guard's own comment says loading APA modules on a non-APA disk "runs the risk of corrupting the HDD as it will try to write APA partition data," and this fork has a real exFAT-corruption report in its history. That cannot sit on the rolling build.

2. FifthFox's "401: HardDisk Drive not detected" every boot (slim SCPH-700012, reported 07-19 on the build containing this commit): the old loader latched a failure once per session; the rewrite resets hddModulesLoading = 0 on failure so every later probe re-fires the toast. It also removed the F-12 load reconcile, so a config carrying both HDD flags now activates the APA probe where it was previously force-disabled — new 401 exposure on HDD-less consoles.

3. HDD_APA_UNAVAILABLE is a one-way latch with no re-probe — one transient hddCheck() hiccup permanently hides the APA tab for the session: a brand-new way to produce exactly the "APA games not listing" bug it set out to fix.

4. IO-thread mutation of menuItem.visible (GUI state), a hard 1-second DelayThread on every first HDD load, a 250×10ms busy-wait, and repo pollution (ChatGPT report + 11 PNGs at the repo root).

What happens to the good ideas

  • The xhdd/bdmfs_fatfs auto-mount theory for Vapor's APA bug is being investigated properly (wLaunchELF-R3Z3N + NHDDL as references, per maintainer direction).
  • hddResetModuleState/bdmResetModuleState on sysReset and the gDeinitAtaSelected park-suppression are candidates to re-land as reviewed PRs.

Clean make clean build, exit 0.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a boot notification when HDD settings are automatically reconciled.
    • HDD device settings now prevent incompatible APA and BDM combinations.
  • Bug Fixes

    • Improved HDD startup and shutdown handling.
    • Added safeguards to avoid loading APA support on incompatible disk formats.
    • Improved partition detection, mounting, and recovery behavior.
    • Ensured device stop and cleanup operations run more reliably.
  • Documentation

    • Removed the HDD audit report from the repository.

…th a live drive-corruption risk

This reverts commit d14f3e7 (direct push, no PR, no review), which rolled to testers on 07-18. The
GOALS are good and will be re-landed properly -- APA + BDM-ATA coexistence on the shared ATA stack
(R3Z-style, the audit report's xhdd/bdmfs_fatfs auto-mount theory for Vapor's APA listing bug is worth
pursuing), module-state reset across sysReset, and the gDeinitAtaSelected park-suppression. But the
execution ships several regressions and one unacceptable risk:

1. DRIVE-CORRUPTION RISK (the reason this cannot wait): it deleted hddDetectNonSonyFileSystem(), the
   upstream exFAT/MBR/GPT safety guard, and now loads the APA driver ps2hdd.irx UNCONDITIONALLY on any
   disk -- trusting an unverified claim that its init is read-only for non-APA disks. The guard's own
   comment: loading APA modules on a non-APA disk "runs the risk of corrupting the HDD as it will try
   to write APA partition data." This fork has a real exFAT-corruption report in its history. An
   unreviewed removal of an upstream data-safety guard cannot sit on the rolling build.

2. FifthFox's "401: HardDisk Drive not detected" on every boot (SCPH-700012 slim, reported 07-19 on
   the rolling build that contains this commit): the old loader LATCHED a failure once per session
   (load count stayed >= 1 -> later calls returned BUSYLOADING silently); the rewrite resets
   hddModulesLoading = 0 on failure so every later probe re-fires the error toast. It also removed the
   F-12 APA/BDM-ATA load reconcile, so a config carrying both flags now activates the APA probe where
   it was previously force-disabled -- new 401 exposure on HDD-less consoles.

3. HDD_APA_UNAVAILABLE is a one-way latch with NO re-probe path: one transient hddCheck() hiccup
   permanently hides the APA tab for the session -- a brand-new way to produce exactly the "APA games
   not listing" bug this commit set out to fix.

4. hddNeedsUpdate flips menuItem.visible (GUI state) from the IO thread; a hard 1-second DelayThread
   in every first HDD module load; a 250x10ms busy-wait; and repo pollution (a ChatGPT audit report +
   11 PNGs committed to the repository root).

The wins return as reviewed, build-verified PRs on top of this revert.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change restructures HDD module loading and teardown, adds partition-format safeguards, reconciles conflicting APA and BDM HDD settings, updates device-setting interlocks and boot notifications, removes obsolete ATA-state APIs, and deletes the audit report.

Changes

HDD backend lifecycle

Layer / File(s) Summary
Module loading and filesystem safeguards
include/hddsupport.h, src/hddsupport.c, src/opl.c
HDD loading now uses reference counting, detects non-APA partitions before APA/PFS support loading, and simplifies initialization and configuration probing.
Teardown and public API cleanup
include/bdmsupport.h, include/hddsupport.h, include/opl.h, src/bdmsupport.c, src/hddsupport.c, src/opl.c
Obsolete reset and ATA-selection APIs are removed; shutdown uses device-root fallback handling and reference-counted DEV9 cleanup.
HDD menu updates
src/hddsupport.c
HDD update and game-list paths no longer require APA-ready state or APA visibility gating.

Configuration and GUI reconciliation

Layer / File(s) Summary
Backend setting reconciliation
include/opl.h, src/opl.c
Conflicting BDM HDD and APA HDD settings are normalized, persisted, and exposed through showHddReconcilePopup.
GUI interlocks and notification rendering
src/gui.c
Device settings dynamically disable incompatible HDD options, and reconciliation is displayed as a one-shot localized notification.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant _loadConfig
  participant CONFIG_OPL
  participant guiShowNotifications
  _loadConfig->>_loadConfig: detect conflicting HDD backend settings
  _loadConfig->>CONFIG_OPL: persist corrected settings
  _loadConfig->>guiShowNotifications: set reconciliation popup flag
  guiShowNotifications-->>_loadConfig: clear popup after timeout
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes a revert of the HDD rewrite and highlights the safety-risk motivation behind the change.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/revert-chatgpt-cutoff

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors HDD and BDM module management in OPL to resolve conflicts between APA and BDM-ATA backends, introducing mutual exclusivity in the GUI and adding safety checks to prevent loading APA modules on MBR/GPT drives. However, several critical issues were identified in the review: removing the module state resets during a system reset causes desynchronization that breaks subsequent device access; the new filesystem detection logic incorrectly blocks the initialization and formatting of blank or unformatted drives; and a failure in module loading leaves the load count in an invalid state, permanently preventing future retries.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/opl.c
Comment on lines 2654 to 2655
sysReset();
hddResetModuleState();
bdmResetModuleState();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Deleting hddResetModuleState() and bdmResetModuleState() from the reset() function causes a critical desynchronization between the EE-side module loading state and the actual IOP state after an in-process sysReset() (such as when exiting the NBD server). Since the IOP is reset, all loaded modules are gone, but the EE-side variables (like hddModulesLoaded and iUSBModLoaded) still remain. Consequently, subsequent attempts to access BDM or HDD devices will skip loading the required modules, rendering these devices completely non-functional. Please restore these functions and their calls in reset().

Suggested change
sysReset();
hddResetModuleState();
bdmResetModuleState();
sysReset();
hddResetModuleState();
bdmResetModuleState();
References
  1. When handling removable media or card swaps, ensure that static loading or caching flags are reset when the media is removed or absent.

Comment thread src/hddsupport.c
Comment on lines +316 to +320
if (hddDetectNonSonyFileSystem() != 0) {
// Drive is MBR/GPT style, or unknown, bail out or risk corrupting the drive.
LOG("HDDSUPPORT LoadSupportModules bailing out early...\n");
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using hddDetectNonSonyFileSystem() != 0 as a bailout condition prevents loading the APA/PFS modules on completely blank or unformatted hard drives, as they will return -1 (unrecognized partition data). This makes it impossible for OPL to detect, format, or initialize new drives. Additionally, any transient read error will also cause a silent bailout without displaying a proper error message to the user. Changing the check to == 1 ensures that we only bail out when we are certain of a non-Sony filesystem (MBR or GPT), while allowing blank/unformatted drives to proceed to hddCheck() where they can be properly handled and formatted.

Suggested change
if (hddDetectNonSonyFileSystem() != 0) {
// Drive is MBR/GPT style, or unknown, bail out or risk corrupting the drive.
LOG("HDDSUPPORT LoadSupportModules bailing out early...\n");
return;
}
if (hddDetectNonSonyFileSystem() == 1) {
// Drive is MBR/GPT style, bail out or risk corrupting the drive.
LOG("HDDSUPPORT LoadSupportModules bailing out early...\n");
return;
}

Comment thread src/hddsupport.c
Comment on lines +223 to +230
if (retLoadModule < 0) {
LOG("HDD: No HardDisk Drive detected.\n");
setErrorMessageWithCode(_STR_HDD_NOT_CONNECTED_ERROR, ERROR_HDD_IF_NOT_DETECTED);
retStatus = HDD_LOADMODULES_STATUS_ERROR;
} else {
retStatus = HDD_LOADMODULES_STATUS_NOERROR;
hddModulesLoaded = 1;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

If retLoadModule < 0 (module loading fails), hddModulesLoadCount is left at 1 (or incremented). On any subsequent call to hddLoadModules(), the function will enter the else block, increment the count, and permanently return HDD_LOADMODULES_STATUS_BUSYLOADING without ever attempting to reload the modules. This prevents the user from retrying HDD initialization if the first attempt failed. Resetting hddModulesLoadCount = 0 on failure resolves this issue and allows future retries.

Suggested change
if (retLoadModule < 0) {
LOG("HDD: No HardDisk Drive detected.\n");
setErrorMessageWithCode(_STR_HDD_NOT_CONNECTED_ERROR, ERROR_HDD_IF_NOT_DETECTED);
retStatus = HDD_LOADMODULES_STATUS_ERROR;
} else {
retStatus = HDD_LOADMODULES_STATUS_NOERROR;
hddModulesLoaded = 1;
}
if (retLoadModule < 0) {
LOG("HDD: No HardDisk Drive detected.\n");
setErrorMessageWithCode(_STR_HDD_NOT_CONNECTED_ERROR, ERROR_HDD_IF_NOT_DETECTED);
retStatus = HDD_LOADMODULES_STATUS_ERROR;
hddModulesLoadCount = 0;
} else {
retStatus = HDD_LOADMODULES_STATUS_NOERROR;
hddModulesLoaded = 1;
}
References
  1. When handling removable media or card swaps, ensure that static loading or caching flags are reset when the media is removed or absent.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/opl.c (1)

2652-2657: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear the module-loaded flags on reset. sysReset() only reboots the IOP and resets the DEV9 bookkeeping; the EE-side HDD/BDM load flags stay set and still gate reloads. After reset(), a later load path can skip reloading modules that the IOP just dropped.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/opl.c` around lines 2652 - 2657, Update reset() to clear the EE-side
HDD/BDM module-loaded flags after sysReset(), so subsequent load paths reload
modules dropped by the IOP; preserve the existing mcInit(MC_TYPE_XMC) behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hddsupport.c`:
- Line 242: Update hddDetectNonSonyFileSystem to use internal linkage by
declaring it static, and change its empty parameter list to (void). Keep its
existing behavior unchanged.
- Around line 198-239: In the failure branch of the hdd module-loading function,
reset hddModulesLoadCount to zero so subsequent calls can retry instead of
remaining busy. Also unwind any partial module-loading state created by the
current load attempt, ensuring hddModulesLoaded remains false and any
successfully loaded modules are cleaned up using the existing unload mechanism.

---

Outside diff comments:
In `@src/opl.c`:
- Around line 2652-2657: Update reset() to clear the EE-side HDD/BDM
module-loaded flags after sysReset(), so subsequent load paths reload modules
dropped by the IOP; preserve the existing mcInit(MC_TYPE_XMC) behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c7989bbe-8c47-43ec-9a81-f7b29e5d0ff9

📥 Commits

Reviewing files that changed from the base of the PR and between d14f3e7 and 31a9b31.

⛔ Files ignored due to path filters (11)
  • delivered/eth.png is excluded by !**/*.png
  • delivered/fav.png is excluded by !**/*.png
  • delivered/hdd.png is excluded by !**/*.png
  • delivered/hdd_bd.png is excluded by !**/*.png
  • delivered/ilk_bd.png is excluded by !**/*.png
  • delivered/m4s_bd.png is excluded by !**/*.png
  • delivered/mmce.png is excluded by !**/*.png
  • delivered/udp_bd.png is excluded by !**/*.png
  • delivered/udp_fs.png is excluded by !**/*.png
  • delivered/usb.png is excluded by !**/*.png
  • delivered/usb_bd.png is excluded by !**/*.png
📒 Files selected for processing (8)
  • REPORT_RIPTOPL_VCD_THEMES_IGR_AUDIT.md
  • include/bdmsupport.h
  • include/hddsupport.h
  • include/opl.h
  • src/bdmsupport.c
  • src/gui.c
  • src/hddsupport.c
  • src/opl.c
💤 Files with no reviewable changes (2)
  • REPORT_RIPTOPL_VCD_THEMES_IGR_AUDIT.md
  • include/bdmsupport.h
📜 Review details
⏰ Context from checks skipped due to timeout. (19)
  • GitHub Check: merge-variants
  • GitHub Check: merge-debug-ps2dev-latest
  • GitHub Check: build-variants-ps2dev-latest (EXTRA_FEATURES=0, PADEMU=0)
  • GitHub Check: build-debug (DTL_T10000=1, :v20250725-2)
  • GitHub Check: build
  • GitHub Check: build-debug-ps2dev-latest (iopcore_debug)
  • GitHub Check: build-debug (eesio_debug, :v20250725-2)
  • GitHub Check: build-variants-ps2dev-latest (EXTRA_FEATURES=1, PADEMU=1)
  • GitHub Check: build-debug (ingame_ppctty_debug, :v20250725-2)
  • GitHub Check: build-debug-ps2dev-latest (DTL_T10000=1)
  • GitHub Check: build-debug (iopcore_ppctty_debug, :v20250725-2)
  • GitHub Check: build-variants (EXTRA_FEATURES=1, PADEMU=0)
  • GitHub Check: build-variants (EXTRA_FEATURES=0, PADEMU=0)
  • GitHub Check: build-variants-ps2dev-latest (EXTRA_FEATURES=1, PADEMU=0)
  • GitHub Check: build-debug-ps2dev-latest (iopcore_ppctty_debug)
  • GitHub Check: build-debug-ps2dev-latest (eesio_debug)
  • GitHub Check: build-debug (ingame_debug, :v20250725-2)
  • GitHub Check: build-variants (EXTRA_FEATURES=1, PADEMU=1)
  • GitHub Check: build-ps2dev-latest
🧰 Additional context used
🪛 ast-grep (0.44.1)
src/hddsupport.c

[warning] 245-245: Multiplication in an allocation size can overflow and under-allocate; use calloc (which checks for overflow) or validate the product before allocating.
Context: malloc(512 * 2)
Note: [CWE-190] Integer Overflow or Wraparound.

(alloc-size-overflow-c)

🪛 Cppcheck (2.21.0)
src/hddsupport.c

[style] 242-242: The function 'hddDetectNonSonyFileSystem' should have static linkage since it is not used outside of its translation unit.

(staticFunction)


[style] 287-287: The function 'hddLoadSupportModules' should have static linkage since it is not used outside of its translation unit.

(staticFunction)

🔇 Additional comments (13)
include/hddsupport.h (1)

94-94: LGTM!

src/hddsupport.c (2)

287-366: LGTM!


1139-1191: LGTM!

src/opl.c (4)

198-199: LGTM!


1337-1338: LGTM!


1691-1710: LGTM!


1799-1808: LGTM!

include/opl.h (2)

218-219: LGTM!


260-260: LGTM!

src/gui.c (3)

305-366: LGTM!


1234-1241: LGTM!


1289-1295: LGTM!

src/bdmsupport.c (1)

1330-1351: LGTM!

Comment thread src/hddsupport.c
Comment on lines +198 to +239
if (hddModulesLoadCount == 0) {
// Increment the load count as soon as possible to prevent thread scheduling from allowing another thread to
// call into here and try to double load modules.
hddModulesLoadCount = 1;

// DEV9 must be loaded, as HDD.IRX depends on it. Even if not required by the I/F (i.e. HDPro)
sysInitDev9();
hddDev9RefHeld = 1;
}

// try to detect HD Pro Kit (not the connected HDD),
// if detected it loads the specific ATAD module
hddHDProKitDetected = hddCheckHDProKit();
if (hddHDProKitDetected) {
LOG("[ATAD_HDPRO]:\n");
retLoadModule = sysLoadModuleBuffer(&hdpro_atad_irx, size_hdpro_atad_irx, 0, NULL);
LOG("[XHDD]:\n");
sysLoadModuleBuffer(&xhdd_irx, size_xhdd_irx, 6, "-hdpro");
// try to detect HD Pro Kit (not the connected HDD),
// if detected it loads the specific ATAD module
hddHDProKitDetected = hddCheckHDProKit();
if (hddHDProKitDetected) {
LOG("[ATAD_HDPRO]:\n");
retLoadModule = sysLoadModuleBuffer(&hdpro_atad_irx, size_hdpro_atad_irx, 0, NULL);
LOG("[XHDD]:\n");
sysLoadModuleBuffer(&xhdd_irx, size_xhdd_irx, 6, "-hdpro");
} else {
LOG("[BDM]:\n");
sysLoadModuleBuffer(&bdm_irx, size_bdm_irx, 0, NULL);
LOG("[ATAD]:\n");
retLoadModule = sysLoadModuleBuffer(&ps2atad_irx, size_ps2atad_irx, 0, NULL);
LOG("[XHDD]:\n");
sysLoadModuleBuffer(&xhdd_irx, size_xhdd_irx, 0, NULL);
}

if (retLoadModule < 0) {
LOG("HDD: No HardDisk Drive detected.\n");
setErrorMessageWithCode(_STR_HDD_NOT_CONNECTED_ERROR, ERROR_HDD_IF_NOT_DETECTED);
retStatus = HDD_LOADMODULES_STATUS_ERROR;
} else {
retStatus = HDD_LOADMODULES_STATUS_NOERROR;
hddModulesLoaded = 1;
}
} else {
LOG("[BDM]:\n");
sysLoadModuleBuffer(&bdm_irx, size_bdm_irx, 0, NULL);
LOG("[ATAD]:\n");
retLoadModule = sysLoadModuleBuffer(&ps2atad_irx, size_ps2atad_irx, 0, NULL);
// wLaunchELF-R3Z deliberately leaves a one-second settle window after ATA_BD
// becomes resident and before the APA stack touches it. Both BDM-ATA and APA
// share this same physical driver, so do this once at its first load.
if (retLoadModule >= 0)
DelayThread(1000 * 1000);
LOG("[XHDD]:\n");
sysLoadModuleBuffer(&xhdd_irx, size_xhdd_irx, 0, NULL);
hddModulesLoadCount++;
if (!hddModulesLoaded)
retStatus = HDD_LOADMODULES_STATUS_BUSYLOADING;
}

if (retLoadModule < 0) {
// Leave the attempt retryable without powering DEV9 down. sysShutdownDev9's DDIOC_OFF is a
// terminal hardware stop, not a reversible reference release within the current IOP session.
hddModulesLoading = 0;
LOG("HDD: No HardDisk Drive detected.\n");
setErrorMessageWithCode(_STR_HDD_NOT_CONNECTED_ERROR, ERROR_HDD_IF_NOT_DETECTED);
return HDD_LOADMODULES_STATUS_ERROR;
LOG("HDDSUPPORT LoadModules done\n");
return retStatus;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the relevant file region with line numbers.
sed -n '150,260p' src/hddsupport.c

echo '---'
# Find uses of hddModulesLoadCount / hddModulesLoaded / hddShutdown to understand lifecycle.
rg -n "hddModulesLoadCount|hddModulesLoaded|HDD_LOADMODULES_STATUS_BUSYLOADING|hddShutdown|hddLoadModules" src/hddsupport.c

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 5001


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the rest of the lifecycle around shutdown/reset.
sed -n '260,380p' src/hddsupport.c
echo '---'
sed -n '1120,1215p' src/hddsupport.c

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 8039


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for any reinitialization or rollback of the load counter elsewhere.
rg -n "hddModulesLoadCount\s*=|hddModulesLoaded\s*=|busyloading|load count" src

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 663


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Print the exact load/shutdown functions with line numbers.
nl -ba src/hddsupport.c | sed -n '188,260p'
echo '---'
nl -ba src/hddsupport.c | sed -n '1130,1210p'

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 208


Reset the load counter on the error path

hddModulesLoadCount is set to 1 before loading, but the failure branch never clears it. That leaves later calls stuck in HDD_LOADMODULES_STATUS_BUSYLOADING while hddModulesLoaded is still false, so a transient probe failure can’t retry until shutdown drains the count to zero. Reset the counter here; if any module was already loaded on this path, unwind that state too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hddsupport.c` around lines 198 - 239, In the failure branch of the hdd
module-loading function, reset hddModulesLoadCount to zero so subsequent calls
can retry instead of remaining busy. Also unwind any partial module-loading
state created by the current load attempt, ensuring hddModulesLoaded remains
false and any successfully loaded modules are cleaned up using the existing
unload mechanism.

Comment thread src/hddsupport.c
}

// Returns 1 for MBR/GPT, 0 for APA, and -1 if an error occured
int hddDetectNonSonyFileSystem()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm hddDetectNonSonyFileSystem is TU-local (no header decl, no cross-file use).
rg -nP '\bhddDetectNonSonyFileSystem\b' --type=c --type=cpp -g '*.h'
rg -nP '\bhddDetectNonSonyFileSystem\b' -C2

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 168


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== File list =="
git ls-files | rg '(^|/)hddsupport\.(c|h)$|(^|/)src/.*hddsupport'

echo
echo "== All references to hddDetectNonSonyFileSystem =="
rg -n --hidden --no-messages '\bhddDetectNonSonyFileSystem\b' .

echo
echo "== Outline of src/hddsupport.c =="
ast-grep outline src/hddsupport.c --view expanded || true

echo
echo "== Relevant excerpt from src/hddsupport.c =="
nl -ba src/hddsupport.c | sed -n '220,310p'

echo
echo "== Relevant excerpt from src/hddsupport.h if present =="
if [ -f src/hddsupport.h ]; then nl -ba src/hddsupport.h | sed -n '1,220p'; fi

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 4003


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Files matching hddsupport:\n'
git ls-files | rg 'hddsupport'

printf '\nSearch for the symbol in tracked text files:\n'
rg -n --hidden --no-messages 'hddDetectNonSonyFileSystem' $(git ls-files)

Repository: NathanNeurotic/Open-PS2-Loader

Length of output: 980


Make hddDetectNonSonyFileSystem static — it’s only used within src/hddsupport.c and isn’t declared in include/hddsupport.h, so give it internal linkage and change the empty parameter list to (void).

🧰 Tools
🪛 Cppcheck (2.21.0)

[style] 242-242: The function 'hddDetectNonSonyFileSystem' should have static linkage since it is not used outside of its translation unit.

(staticFunction)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hddsupport.c` at line 242, Update hddDetectNonSonyFileSystem to use
internal linkage by declaring it static, and change its empty parameter list to
(void). Keep its existing behavior unchanged.

Source: Linters/SAST tools

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