Skip to content

Commit 7729fbf

Browse files
CopilotJohnAmadis
andcommitted
Fix directory listing for /dev subdirectories
read_driver_parent_directory() was generating paths without a leading '/' (e.g. "dmgpio8/") while DMVFS passes paths with a leading '/' (e.g. "/dmgpio8"). This caused all path comparisons in is_directory() and related functions to fail, resulting in: dmdevfs: [ERROR] Directory not found: /dmgpio8 dmdevfs: [ERROR] File not found: /dmgpio8 Fix: - read_driver_parent_directory: add leading '/' to non-root parent paths ("/%s%u/" and "/%sx/" instead of "%s%u/" and "%sx/") - read_next_subdir_name: when listing from root '/', skip the leading '/' now present in full_path before extracting the next component Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 9670163 commit 7729fbf

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/dmdevfs.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,16 +1161,16 @@ static void read_dir_name_from_path(const char* path, char* dir_name, size_t nam
11611161

11621162
/**
11631163
* @brief Extract the first path component of full_path that comes after base_path
1164-
* @param base_path The directory currently being listed (e.g., "/" or "foo/")
1165-
* @param full_path The driver's parent directory path (e.g., "foo/bar/")
1164+
* @param base_path The directory currently being listed (e.g., "/" or "/foo")
1165+
* @param full_path The driver's parent directory path (e.g., "/foo/bar/")
11661166
* @param dir_name Output buffer for the immediate subdirectory name
11671167
* @param name_size Size of the output buffer
11681168
*
11691169
* Examples:
1170-
* - base="/", full="dmgpio8/" -> "dmgpio8"
1171-
* - base="/", full="a/b/c/" -> "a"
1172-
* - base="a/", full="a/b/c/" -> "b"
1173-
* - base="a/b/", full="a/b/c/" -> "c"
1170+
* - base="/", full="/dmgpio8/" -> "dmgpio8"
1171+
* - base="/", full="/a/b/c/" -> "a"
1172+
* - base="/a", full="/a/b/c/" -> "b"
1173+
* - base="/a/b", full="/a/b/c/" -> "c"
11741174
*/
11751175
static void read_next_subdir_name(const char* base_path, const char* full_path, char* dir_name, size_t name_size)
11761176
{
@@ -1193,8 +1193,8 @@ static void read_next_subdir_name(const char* base_path, const char* full_path,
11931193
const char* start;
11941194
if (base_len == 1 && base_path[0] == '/')
11951195
{
1196-
// Base is the root directory; full_path has no leading slash
1197-
start = full_path;
1196+
// Base is the root directory; skip the leading '/' in full_path if present
1197+
start = (full_path[0] == '/') ? full_path + 1 : full_path;
11981198
}
11991199
else
12001200
{
@@ -1327,11 +1327,11 @@ static int read_driver_parent_directory( const driver_node_t* node, char* path_b
13271327
bool minor_given = (node->dev_num.flags & DMDRVI_NUM_MINOR) != 0;
13281328
if(major_given && minor_given)
13291329
{
1330-
Dmod_SnPrintf(path_buffer, buffer_size, "%s%u/", driver_name, node->dev_num.major);
1330+
Dmod_SnPrintf(path_buffer, buffer_size, "/%s%u/", driver_name, node->dev_num.major);
13311331
}
13321332
else if(minor_given)
13331333
{
1334-
Dmod_SnPrintf(path_buffer, buffer_size, "%sx/", driver_name);
1334+
Dmod_SnPrintf(path_buffer, buffer_size, "/%sx/", driver_name);
13351335
}
13361336
else
13371337
{

0 commit comments

Comments
 (0)