Skip to content

Fix mount point selection to return longest match instead of first match#48

Merged
JohnAmadis merged 3 commits into
developfrom
copilot/fix-get-mount-point-bug
Feb 8, 2026
Merged

Fix mount point selection to return longest match instead of first match#48
JohnAmadis merged 3 commits into
developfrom
copilot/fix-get-mount-point-bug

Conversation

Copilot AI commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

get_mount_point_for_path returns the first matching mount point instead of the most specific one. With mounts at / and /configs, path /configs/app.conf incorrectly resolves to /.

Changes

  • Algorithm: Track longest matching mount point instead of returning first match
  • Boundary validation: Ensure matches occur at path boundaries only (character after mount point must be / or \0)
    • Prevents /config from matching /configs/file
  • Root mount handling: Special case for / to match any absolute path

Example

// Before: First match wins
Path: /configs/app.conf
Mounts: [/, /configs]
Result: / ❌

// After: Longest match wins
Path: /configs/app.conf  
Mounts: [/, /configs]
Result: /configs

The boundary check also prevents false matches:

Path: /configs/file
Mounts: [/, /config, /configs]
Result: /configs (not /config) ✅
Original prompt

This section details on the original issue you should resolve

<issue_title>Błąd w funkcji get_mount_point_for_path</issue_title>
<issue_description>get_mount_point_for_path nie działa prawidłowo - jeśli mamy pod indeksem 0 ścieżkę / a pod indeksem 1 ścieżkę /configs i chcemy mount-point dla path=/configs to zwróci nam tę z indeksu 0 zamiast ten z indeksu 1. Możesz podejrzeć sobie jak to jest rozwiązane tutaj:
https://bitbucket.org/chocos/chocos/src/develop/Source/system/core/src/fs/oc_vfs.c

static MountedEntry_t GetMountedFileSystem( const char * Path , bool WithParentDirs )
{
    MountedEntry_t  mountedEntry = NULL;
    oC_UInt_t       pathLength   = strlen(Path);

    oC_List_Foreach(MountedEntries,mounted)
    {
        oC_UInt_t mountPointLength = strlen(mounted->MountedPoint);

        if(
            (WithParentDirs && pathLength >= mountPointLength && strncmp(mounted->MountedPoint,Path,mountPointLength)==0) ||
            (!WithParentDirs && pathLength == mountPointLength && strcmp(mounted->MountedPoint,Path)==0)
            )
        {
            mountedEntry = mounted;
            break;
        }
    }

    return mountedEntry;
}

Może Ci to pomoże
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 8, 2026 10:13
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug in get_mount_point_for_path function Fix mount point selection to return longest match instead of first match Feb 8, 2026
Copilot AI requested a review from JohnAmadis February 8, 2026 10:19
@JohnAmadis JohnAmadis marked this pull request as ready for review February 8, 2026 10:20
@JohnAmadis JohnAmadis merged commit 90ca809 into develop Feb 8, 2026
1 check 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.

Błąd w funkcji get_mount_point_for_path

2 participants