@@ -46,7 +46,7 @@ static int lfs2_get_mode(int flags) {
46
46
ret |= flags & VFS_READ ? LFS2_O_RDONLY : 0 ;
47
47
ret = flags & VFS_WRITE ? LFS2_O_WRONLY : 0 ;
48
48
ret |= flags & VFS_APPEND ? LFS2_O_APPEND : 0 ;
49
- ret |= flags & VFS_CREATE ? LFS2_O_CREAT : 0 ;
49
+ ret |= flags & VFS_CREATE ? LFS2_O_CREAT | LFS2_O_TRUNC : 0 ;
50
50
51
51
return ret ;
52
52
}
@@ -65,26 +65,29 @@ static int fatfs_get_mode(int flags) {
65
65
66
66
67
67
void * vfs_stream_open (const char * path , int flags ) {
68
- ESP_LOGI (TAG , "vfs_stream_open: path=%s, mode=%d\n " , path , flags );
68
+ ESP_LOGI (TAG , "vfs_stream_open: path=%s, mode=%d" , path , flags );
69
69
70
70
vfs_stream_t * vfs = calloc (1 , sizeof (vfs_stream_t ));
71
71
72
- const char * path_out ;
72
+ const char * path_out = { '\0' } ;
73
73
mp_vfs_mount_t * existing_mount = mp_vfs_lookup_path (path , & path_out );
74
74
if (existing_mount == MP_VFS_NONE || existing_mount == MP_VFS_ROOT ) {
75
75
ESP_LOGE (TAG , "No vfs mount" );
76
76
goto _vfs_init_exit ;
77
77
}
78
78
79
- if (strstr (path , "flash" )) {
79
+ if (strstr (path_out , "flash" )) {
80
80
ESP_LOGD (TAG , "in flash" );
81
81
vfs -> lfs2 = & ((mp_obj_vfs_lfs2_t * )MP_OBJ_TO_PTR (existing_mount -> obj ))-> lfs ;
82
- } else if (strstr (path , "system" )) {
82
+ } else if (strstr (path_out , "system" )) {
83
83
ESP_LOGD (TAG , "in system" );
84
84
vfs -> lfs2 = & ((mp_obj_vfs_lfs2_t * )MP_OBJ_TO_PTR (existing_mount -> obj ))-> lfs ;
85
- } else if (strstr (path , "sd" )) {
85
+ } else if (strstr (path_out , "sd" )) {
86
86
ESP_LOGD (TAG , "in sd" );
87
87
vfs -> fatfs = & ((fs_user_mount_t * )MP_OBJ_TO_PTR (existing_mount -> obj ))-> fatfs ;
88
+ } else {
89
+ ESP_LOGI (TAG , "default in flash" );
90
+ vfs -> lfs2 = & ((mp_obj_vfs_lfs2_t * )MP_OBJ_TO_PTR (existing_mount -> obj ))-> lfs ;
88
91
}
89
92
90
93
if (vfs -> lfs2 ) {
@@ -128,9 +131,9 @@ void *vfs_stream_open(const char *path, int flags) {
128
131
}
129
132
130
133
131
- uint32_t vfs_stream_read (void * file_p , void * buf , uint32_t btr ) {
134
+ int32_t vfs_stream_read (void * file_p , void * buf , uint32_t btr ) {
132
135
vfs_stream_t * vfs = file_p ;
133
- uint32_t br = 0 ;
136
+ int32_t br = 0 ;
134
137
135
138
if (vfs -> lfs2 ) {
136
139
br = lfs2_file_read (vfs -> lfs2 , vfs -> file .lfs2_file , (uint8_t * )buf , btr );
@@ -214,6 +217,10 @@ int32_t vfs_stream_tell(void *file_p) {
214
217
void vfs_stream_close (void * file_p ) {
215
218
vfs_stream_t * vfs = file_p ;
216
219
220
+ if (vfs == NULL ) {
221
+ return ;
222
+ }
223
+
217
224
if (vfs -> lfs2 ) {
218
225
lfs2_file_close (vfs -> lfs2 , vfs -> file .lfs2_file );
219
226
free (vfs -> file .lfs2_file );
0 commit comments