@@ -37,43 +37,62 @@ typedef int64_t mtp_offset;
3737
3838struct fs_entry
3939{
40- uint32_t handle ;
41- uint32_t parent ;
42- uint32_t storage_id ;
43- char * name ;
44- uint32_t flags ;
45- mtp_size size ;
46- uint32_t date ;
47-
48- int file_descriptor ;
49- int watch_descriptor ;
50-
51- fs_entry * next ;
40+ uint32_t handle ;
41+ uint32_t parent ;
42+ uint32_t storage_id ;
43+ char * name ;
44+ uint32_t flags ;
45+ mtp_size size ;
46+ uint32_t date ;
47+
48+ int file_descriptor ;
49+ int watch_descriptor ;
50+
51+ fs_entry * next ;
5252};
5353
5454#define ENTRY_IS_DIR 0x00000001
5555#define ENTRY_IS_DELETED 0x00000002
5656
5757#define _DEF_FS_HANDLES_ 1
58+ #define HASH_TABLE_SIZE 1024 // Configurable table size
5859
59- typedef struct fs_handles_db_
60- {
61- fs_entry * entry_list ;
62- uint32_t next_handle ;
60+ typedef struct hash_node {
61+ fs_entry * * entries ;
62+ uint32_t size ;
63+ uint32_t capacity ;
64+ } hash_node ;
65+
66+ #define POOL_BLOCK_SIZE 1024
67+
68+ typedef struct fs_entry_pool_block {
69+ fs_entry entries [POOL_BLOCK_SIZE ];
70+ struct fs_entry_pool_block * next ;
71+ } fs_entry_pool_block ;
72+
73+ typedef struct fs_handles_db_ {
74+ fs_entry * entry_list ;
75+ hash_node hash_table_by_name [HASH_TABLE_SIZE ]; // Hash table by file name for performance improvement
76+ hash_node hash_table_by_handle [HASH_TABLE_SIZE ]; // Hash table by file handle for performance improvement
77+
78+ uint32_t next_handle ;
79+
80+ fs_entry * search_entry ;
81+ uint32_t handle_search ;
82+ uint32_t storage_search ;
6383
64- fs_entry * search_entry ;
65- uint32_t handle_search ;
66- uint32_t storage_search ;
84+ void * mtp_ctx ;
6785
68- void * mtp_ctx ;
69- }fs_handles_db ;
86+ fs_entry_pool_block * pool_head ; // Memory pool for fs_entry allocation to improve memory handling performance
87+ uint32_t pool_free_count ;
88+ } fs_handles_db ;
7089
7190
7291typedef struct filefoundinfo_
7392{
74- int isdirectory ;
75- char filename [FS_HANDLE_MAX_FILENAME_SIZE + 1 ];
76- mtp_size size ;
93+ int isdirectory ;
94+ char filename [FS_HANDLE_MAX_FILENAME_SIZE + 1 ];
95+ mtp_size size ;
7796}filefoundinfo ;
7897
7998
@@ -100,4 +119,4 @@ int fs_remove_tree( char *folder );
100119
101120int fs_entry_stat (char * path , filefoundinfo * fileinfo );
102121
103- #endif
122+ #endif
0 commit comments