Skip to content

Commit 194bad3

Browse files
CopilotJohnAmadis
andcommitted
Section driver_name entries take priority over path-derived driver name
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 9709387 commit 194bad3

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

src/dmdevfs.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct dmfsi_context
7575
// ============================================================================
7676
static int configure_drivers(dmfsi_context_t ctx, const char* driver_name, const char* config_path);
7777
static driver_node_t* configure_driver(const char* driver_name, dmini_context_t config_ctx);
78-
static void configure_section_drivers(dmfsi_context_t ctx, dmini_context_t config_ctx, const char* config_path);
78+
static int configure_section_drivers(dmfsi_context_t ctx, dmini_context_t config_ctx, const char* config_path);
7979
static int unconfigure_drivers(dmfsi_context_t ctx);
8080
static bool is_file(const char* path);
8181
static bool is_driver( const char* name);
@@ -854,20 +854,26 @@ static int configure_drivers(dmfsi_context_t ctx, const char* driver_name, const
854854
continue;
855855
}
856856

857-
driver_node_t* driver_node = configure_driver(module_name, config_ctx);
858-
if (driver_node != NULL)
857+
// Section-specific driver_name entries take priority over the file/directory
858+
// derived driver name. Only configure the main driver when no section-level
859+
// drivers are present in the file.
860+
int section_drivers_added = configure_section_drivers(ctx, config_ctx, full_path);
861+
if (section_drivers_added == 0)
859862
{
860-
if(!dmlist_push_back(ctx->drivers, driver_node))
863+
driver_node_t* driver_node = configure_driver(module_name, config_ctx);
864+
if (driver_node != NULL)
861865
{
862-
DMOD_LOG_ERROR("Failed to add driver to list: %s\n", module_name);
863-
Dmod_Free(driver_node);
866+
if(!dmlist_push_back(ctx->drivers, driver_node))
867+
{
868+
DMOD_LOG_ERROR("Failed to add driver to list: %s\n", module_name);
869+
Dmod_Free(driver_node);
870+
}
871+
}
872+
else
873+
{
874+
DMOD_LOG_ERROR("Failed to configure driver: %s\n", module_name);
864875
}
865876
}
866-
else
867-
{
868-
DMOD_LOG_ERROR("Failed to configure driver: %s\n", module_name);
869-
}
870-
configure_section_drivers(ctx, config_ctx, full_path);
871877
dmini_destroy(config_ctx);
872878
}
873879
else
@@ -956,16 +962,21 @@ static driver_node_t* configure_driver(const char* driver_name, dmini_context_t
956962
* other than "main" that contains a driver_name key, a new driver is configured
957963
* with the INI context restricted to that section via dmini_set_active_section,
958964
* so the driver only sees the keys belonging to its own section.
965+
*
966+
* Returns the number of section-specific drivers that were successfully added.
967+
* A non-zero return value signals to the caller that the file is a multi-driver
968+
* config and no fallback main driver should be configured.
959969
*/
960-
static void configure_section_drivers(dmfsi_context_t ctx, dmini_context_t config_ctx, const char* config_path)
970+
static int configure_section_drivers(dmfsi_context_t ctx, dmini_context_t config_ctx, const char* config_path)
961971
{
962972
void* file = Dmod_FileOpen(config_path, "r");
963973
if (file == NULL)
964974
{
965975
DMOD_LOG_ERROR("Failed to open config file for section scan: %s\n", config_path);
966-
return;
976+
return 0;
967977
}
968978

979+
int num_added = 0;
969980
char line[INI_LINE_BUFFER_SIZE];
970981
while (Dmod_FileReadLine(line, sizeof(line), file) != NULL)
971982
{
@@ -1024,9 +1035,14 @@ static void configure_section_drivers(dmfsi_context_t ctx, dmini_context_t confi
10241035
DMOD_LOG_ERROR("Failed to add driver to list: %s\n", module_name);
10251036
Dmod_Free(driver_node);
10261037
}
1038+
else
1039+
{
1040+
num_added++;
1041+
}
10271042
}
10281043

10291044
Dmod_FileClose(file);
1045+
return num_added;
10301046
}
10311047

10321048
/**

0 commit comments

Comments
 (0)