Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/dmdevfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,17 @@ static int configure_drivers(dmfsi_context_t ctx, const char* driver_name, const
}

driver_node_t* driver_node = configure_driver(module_name, config_ctx);

// Third priority: if driver with filename-based name failed and we have a parent directory name,
// try using the parent directory name as fallback
if (driver_node == NULL && driver_name != NULL && module_name[0] != '\0' &&
strcmp(module_name, driver_name) != 0)
{
DMOD_LOG_INFO("Driver '%s' not found, trying fallback to parent directory name '%s'\n",
module_name, driver_name);
driver_node = configure_driver(driver_name, config_ctx);
}

dmini_destroy(config_ctx);
if (driver_node == NULL)
{
Expand Down Expand Up @@ -1012,14 +1023,16 @@ static dmini_context_t read_driver_for_config(const char* config_path, char* dri
return NULL;
}

const char* name = dmini_get_string(ctx, "main", "driver_name", default_driver);
// First priority: check if driver_name is explicitly set in INI file
const char* name = dmini_get_string(ctx, "main", "driver_name", NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot why NULL here instead of the default driver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using NULL here is critical for the fallback logic to work correctly. If we passed default_driver (the parent directory name), dmini_get_string would return default_driver whenever the driver_name key doesn't exist in the INI file. This would make the condition if(name != NULL) on line 1028 always true, and we'd skip the filename-based logic on lines 1035-1043.

With NULL, the priority order works as designed:

  1. If INI has driver_name → use it (lines 1027-1032)
  2. Otherwise → extract from filename (lines 1035-1043)
  3. If that driver fails to load → fallback to parent directory (lines 843-848 in configure_drivers)

The default_driver parameter is used later in the actual driver loading fallback, not during the INI parsing phase.

if(name != NULL)
{
strncpy(driver_name, name, name_size);
driver_name[name_size - 1] = '\0';
return ctx;
}

// Second priority: use filename (without .ini extension)
read_base_name(config_path, driver_name, name_size);

// cut the `.ini` extension if present
Expand Down