@@ -51,8 +51,8 @@ typedef struct
5151struct dmfsi_context
5252{
5353 uint32_t magic ;
54- const char * config_path ; // Path with the configuration files
55- dmlist_context_t * drivers ; // List of loaded drivers
54+ char * config_path ; // Path with the configuration files
55+ dmlist_context_t * drivers ; // List of loaded drivers
5656};
5757
5858
@@ -75,6 +75,7 @@ static int compare_driver(const void* data, const void* user_data );
7575static bool is_directory ( dmfsi_context_t ctx , const char * path );
7676static driver_node_t * get_next_driver_node ( dmfsi_context_t ctx , driver_node_t * current , const char * dir_path );
7777
78+ static driver_node_t * find_driver_node ( dmfsi_context_t ctx , const char * path );
7879static int driver_stat ( driver_node_t * context , const char * path , dmdrvi_stat_t * stat );
7980
8081// ============================================================================
@@ -498,8 +499,24 @@ dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _stat, (dmfsi_context_t ctx,
498499 return DMFSI_ERR_INVALID ;
499500 }
500501
501- // TODO: Implement stat
502- return DMFSI_ERR_GENERAL ;
502+ driver_node_t * driver_node = find_driver_node (ctx , path );
503+ if (driver_node == NULL )
504+ {
505+ DMOD_LOG_ERROR ("File not found in stat: %s\n" , path );
506+ return DMFSI_ERR_NOT_FOUND ;
507+ }
508+
509+ dmdrvi_stat_t driver_stat_buf ;
510+ int res = driver_stat (driver_node , path , & driver_stat_buf );
511+ if (res != 0 )
512+ {
513+ DMOD_LOG_ERROR ("Failed to get file stats for: %s\n" , path );
514+ return DMFSI_ERR_GENERAL ;
515+ }
516+
517+ stat -> size = driver_stat_buf .size ;
518+ stat -> attr = driver_stat_buf .mode ;
519+ return DMFSI_OK ;
503520}
504521
505522/**
@@ -863,15 +880,15 @@ static int read_driver_node_path( const driver_node_t* node, char* path_buffer,
863880 */
864881static int compare_driver_directory ( const void * data , const void * user_data )
865882{
866- const directory_node_t * node = (const directory_node_t * )data ;
883+ const driver_node_t * node = (const driver_node_t * )data ;
867884 const char * path = (const char * )user_data ;
868885 if (node == NULL || path == NULL )
869886 {
870887 return 0 ;
871888 }
872889
873890 char directory_path [MAX_PATH_LENGTH ] = {0 };
874- if (read_driver_parent_directory (node , path , sizeof (directory_path )) != 0 )
891+ if (read_driver_parent_directory (node , directory_path , sizeof (directory_path )) != 0 )
875892 {
876893 return -1 ;
877894 }
@@ -935,6 +952,14 @@ static driver_node_t* get_next_driver_node( dmfsi_context_t ctx, driver_node_t*
935952 return dmlist_find_next (ctx -> drivers , current , path , compare_driver_directory );
936953}
937954
955+ /**
956+ * @brief Find a driver node by its path
957+ */
958+ static driver_node_t * find_driver_node ( dmfsi_context_t ctx , const char * path )
959+ {
960+ return dmlist_find (ctx -> drivers , path , compare_driver_node_path );
961+ }
962+
938963/**
939964 * @brief Get file statistics from a driver
940965 */
0 commit comments