Skip to content

Add type selection fallback for fs open. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 21, 2025

Right now it is not possible to either force or to pick a filesystem provider that does not have content probing facilities. This patch adds a fallback filesystem provider selection choice screen populated with filesystems that are available but do not probe their contents if no probing filesystem claimed the resource in question.

This fixes NationalSecurityAgency#4448.

Summary by CodeRabbit

  • New Features
    • Introduced a fallback option in the file system browser, allowing users to manually select a file system type when automatic detection fails.
  • Enhancements
    • Improved user experience by preventing duplicate mounting of file systems at the same location.
    • Expanded access to available file system provider information for better transparency in selection dialogs.

Right now it is not possible to either force or to pick a filesystem
provider that does not have content probing facilities.  This patch adds
a fallback filesystem provider selection choice screen populated with
filesystems that are available but do not probe their contents if no
probing filesystem claimed the resource in question.
Copy link

coderabbitai bot commented Apr 21, 2025

Walkthrough

The changes introduce enhancements to Ghidra's filesystem handling. A new method is added to FileSystemService to allow explicit addition of filesystems, ensuring no duplicates at the same location. FileSystemFactoryMgr now exposes a method to retrieve current filesystem provider records. A new marker interface, GFileSystemProbeManual, is introduced to identify filesystem probes that users can manually select. The FileSystemBrowserPlugin is updated to provide a fallback dialog, allowing users to manually choose a filesystem type when automatic detection fails, utilizing the new marker interface and service methods.

Changes

File(s) Change Summary
.../FileSystemService.java Added addFileSystem(GFileSystem fs) method to manage explicit addition of filesystems, preventing duplicates at the same FSRL.
.../factory/FileSystemFactoryMgr.java Added getFileSystemInfoRecs() method to provide external access to a copy of the registered filesystem provider records.
.../factory/GFileSystemProbeManual.java Introduced new marker interface GFileSystemProbeManual, extending GFileSystemProbe, to identify filesystem probes available for manual user selection.
.../FileSystemBrowserPlugin.java Updated to include a fallback chooser dialog for manual filesystem selection using providers marked with GFileSystemProbeManual. Added related logic and supporting imports.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant User
    participant FileSystemBrowserPlugin
    participant FileSystemFactoryMgr
    participant FileSystemService

    User->>FileSystemBrowserPlugin: Open file system
    FileSystemBrowserPlugin->>FileSystemFactoryMgr: Probe for filesystem provider
    alt Provider found
        FileSystemBrowserPlugin->>FileSystemService: Mount filesystem
    else No provider found
        FileSystemBrowserPlugin->>FileSystemFactoryMgr: getFileSystemInfoRecs()
        FileSystemBrowserPlugin->>User: Show fallback chooser dialog
        alt User selects provider
            FileSystemBrowserPlugin->>FileSystemService: Attempt to mount selected filesystem
            alt Already mounted
                FileSystemBrowserPlugin->>FileSystemService: Return existing reference
            else Not mounted
                FileSystemBrowserPlugin->>FileSystemService: Add new filesystem
            end
        else User cancels or mounting fails
            FileSystemBrowserPlugin->>User: Show warning message
        end
    end

Poem

In the warren of files, a new path appears,
For when auto-detect fails, have no fears!
A chooser now hops in, with options anew—
Pick your own probe, let your filesystem through.
Marker interfaces wave their little ears,
And rabbits rejoice: "No more mounting tears!"
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

@visz11
Copy link
Collaborator

visz11 commented Apr 23, 2025

@coderabbitai full review

Copy link

coderabbitai bot commented Apr 23, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FileSystemBrowserPlugin.java (1)

269-303: Well-implemented fallback filesystem selection mechanism.

This method provides a clean implementation for manual filesystem selection:

  • Filters providers that implement the GFileSystemProbeManual interface
  • Sorts them by description for better user experience
  • Handles user selection and filesystem mounting
  • Properly manages resources and checks for existing mounts

Consider adding more detailed error logging if mounting fails, which would help with troubleshooting.

The only suggestion would be to add more specific error logging in the case where mountFileSystem fails but doesn't throw an exception (the case where fs is null at line 292). This would help with troubleshooting problems during manual filesystem selection:

 	if (fs != null) {
 		FileSystemRef fsRef = fsService().getMountedFilesystem(containerFSRL.makeNested(chosenFilesystem.getType()));
 		if (fsRef != null) {
 			fs.close();
 			return fsRef;
 		}
 		fsService().addFileSystem(fs);
 		return fs.getRefManager().create();
+	} else {
+		Msg.debug(this, "Failed to mount filesystem of type " + chosenFilesystem.getType() + 
+			" for " + containerFSRL.getName());
 	}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2abfd4e and 3c12ffa.

📒 Files selected for processing (4)
  • Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/FileSystemService.java (1 hunks)
  • Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/factory/FileSystemFactoryMgr.java (1 hunks)
  • Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/factory/GFileSystemProbeManual.java (1 hunks)
  • Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FileSystemBrowserPlugin.java (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FileSystemBrowserPlugin.java (1)
Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/factory/FileSystemFactoryMgr.java (1)
  • FileSystemFactoryMgr (39-358)
🔇 Additional comments (5)
Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/factory/FileSystemFactoryMgr.java (1)

350-357: Well-implemented accessor for filesystem providers.

This is a clean implementation that safely provides access to the registered filesystem providers by returning a defensive copy of the internal map, which prevents external modification of the internal state.

Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/FileSystemService.java (1)

965-976: Thread-safe implementation to prevent duplicate filesystem mounts.

This implementation correctly synchronizes on the fsInstanceManager and performs a check before adding to prevent duplicate filesystems at the same location. The method complements the existing API and follows the established patterns in the class.

Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/factory/GFileSystemProbeManual.java (1)

1-24: Good design for marker interface.

This marker interface is well-designed to identify filesystem probes that can be manually selected by users. The empty interface pattern is appropriate for this classification purpose, and the documentation clearly explains its intent.

Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FileSystemBrowserPlugin.java (2)

19-46: Required imports added for new functionality.

The new imports support the fallback filesystem selection mechanism and properly maintain code organization.


253-258: Improved user experience with fallback mechanism.

The modified code now calls the fallback chooser before showing a warning, giving users an opportunity to manually select a filesystem when automatic detection fails.

*
* @param fs {@link GFileSystem} to add to the managed filesystems list.
*/
public void addFileSystem(GFileSystem fs) {

Choose a reason for hiding this comment

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

Wouldn't this leak the fs instance being added if it was already mounted?
Probably should close the passed-in fs if already mounted.
Won't be an issue with how you are currently using it because you check for that, but other people calling it could break that assumption.

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.

It is not possible to directly select the type of filesystem when opening it.
4 participants