Skip to content

fix(radio): exFat directory handling#7485

Open
3djc wants to merge 3 commits into
mainfrom
3djc/fix-exfat
Open

fix(radio): exFat directory handling#7485
3djc wants to merge 3 commits into
mainfrom
3djc/fix-exfat

Conversation

@3djc

@3djc 3djc commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

On exFAT-formatted SD cards the file browser was broken: the ".." (go up) entry never appeared, you couldn't navigate out of a sub-directory, and copy/paste targeted the wrong location. FAT32 cards were unaffected. As exemple, you could not open txt file for reading in SD manager.

Root cause

Two FatFs calls the browsers relied on don't work on exFAT, because exFAT directories carry no on-disk "." / ".." entries:

f_getcwd() always returns / — it rebuilds the path by walking up the ".." chain, which doesn't exist on exFAT
(FatFs documents this: "Cannot do getcwd on exFAT and returns root path").
This broke ".." detection, the current-path display, nested navigation and clipboard paths.

f_chdir("..") is a no-op — with no ".." entry, FatFs "stays there" (ff.c), so "go up" did nothing.

This fixes all of it for both the colorLCD and B&W SD managers.

I have taken great care of not breaking fat32, but I would appreciate some external tests

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed file browser directory navigation by improving full-path construction and syncing the displayed path with the underlying filesystem CWD.
    • Updated SD manager navigation to track the active directory reliably, including correct handling of parent-directory (“..”) behavior.
    • Improved SD card copy/paste so clipboard source/destination paths no longer rely on unreliable current-directory reporting on exFAT-like filesystems.
    • Corrected directory listing handling for the synthesized “..” entry at filesystem boundaries.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 065a43eb-b2fd-4cd8-8c4f-bc0fa5d86e0b

📥 Commits

Reviewing files that changed from the base of the PR and between cc45eb1 and eddfe3b.

📒 Files selected for processing (2)
  • radio/src/gui/colorlcd/libui/file_browser.cpp
  • radio/src/gui/common/stdlcd/radio_sdmanager.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • radio/src/gui/common/stdlcd/radio_sdmanager.cpp
  • radio/src/gui/colorlcd/libui/file_browser.cpp

📝 Walkthrough

Walkthrough

Replaces f_getcwd() usage with tracked path state in FileBrowser and both SD manager flows, and changes sdReadDir() to synthesize ".." from FATFS internal CWD state.

Changes

exFAT Path Tracking Refactor

Layer / File(s) Summary
sdReadDir parent entry synthesis
radio/src/lib_file.cpp
sdReadDir() no longer uses isCwdAtRoot() and instead checks FATFS CWD fields to decide when to synthesize the parent directory entry.
FileBrowser path state and initialization
radio/src/gui/colorlcd/libui/file_browser.h, radio/src/gui/colorlcd/libui/file_browser.cpp
FileBrowser gains tracked current and full-path state, adds setFullPath(), initializes from the requested directory, and removes the file-scope path helpers.
FileBrowser selection and navigation
radio/src/gui/colorlcd/libui/file_browser.cpp
onSelected(), onPress(), fileAction, and onPressLong() now use the tracked path state, with manual ".." handling and f_chdir(nextPath) only committing the new directory after success.
colorlcd SD manager copy/paste
radio/src/gui/colorlcd/radio/radio_sdmanager.cpp
RadioSdManagerPage::fileAction now copies the provided path into clipboard and paste buffers directly instead of calling f_getcwd().
stdlcd SD manager path tracking
radio/src/gui/common/stdlcd/radio_sdmanager.cpp
radio_sdmanager.cpp tracks the current directory in sdManagerPath, initializes it on entry, updates it on directory navigation, and uses it for selection and clipboard path construction.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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
Title check ✅ Passed The title is concise and accurately describes the exFAT directory-handling fix.
Description check ✅ Passed It covers the bug, root cause, impact, and testing note, which is mostly complete for the template.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 3djc/fix-exfat

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

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

@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

🤖 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 `@radio/src/gui/colorlcd/libui/file_browser.cpp`:
- Around line 133-135: In the FileBrowser constructor where currentPath is
initialized, normalize the input directory path by removing any trailing slashes
before assignment to ensure consistent path handling. This prevents double
slashes in full paths and ensures parent directory operations work correctly
from paths like "/A/". Apply the same normalization logic to the path operations
at lines 251-255 that are referenced in the comment to maintain consistency
across all path manipulations in the class.

In `@radio/src/gui/common/stdlcd/radio_sdmanager.cpp`:
- Around line 64-82: The sdManagerChdir function contains hardcoded assumptions
about root path structure, specifically checking sdManagerPath[1] in the descend
case and comparing sep == sdManagerPath in the parent case. Instead of these
hardcoded assumptions, import and use the ROOT_PATH constant from
radio/src/sdcard.h throughout the function. Replace all occurrences of the
hardcoded "/" with ROOT_PATH, and use strlen(ROOT_PATH) to determine root length
rather than assuming it is a single character. Update the root detection logic
in both the ".." case and the path building case to use the ROOT_PATH constant
and its computed length for robust path handling.
🪄 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: CHILL

Plan: Pro Plus

Run ID: 75be2318-0371-4937-bb9d-3827f7485f67

📥 Commits

Reviewing files that changed from the base of the PR and between 66463ec and cc45eb1.

📒 Files selected for processing (5)
  • radio/src/gui/colorlcd/libui/file_browser.cpp
  • radio/src/gui/colorlcd/libui/file_browser.h
  • radio/src/gui/colorlcd/radio/radio_sdmanager.cpp
  • radio/src/gui/common/stdlcd/radio_sdmanager.cpp
  • radio/src/lib_file.cpp

Comment thread radio/src/gui/colorlcd/libui/file_browser.cpp
Comment thread radio/src/gui/common/stdlcd/radio_sdmanager.cpp
@pagrey

pagrey commented Jun 23, 2026

Copy link
Copy Markdown

Tested on a Zorro based on the main branch with FAT32, copy/paste and navigation all works normally.

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.

2 participants