@@ -17,22 +17,22 @@ int lfs_statvfs_count(void *p, lfs_block_t b)
17
17
return 0 ;
18
18
}
19
19
20
- // After this function vPortFree () must be called on the returned address after usage!!
20
+ // After this function free () must be called on the returned address after usage!!
21
21
const char * concat_with_cwd (vfs_lfs_struct_t * littlefs , const char * path )
<
F438
code>22 22
{
23
23
char * path_out = NULL ;
24
24
25
25
if (path [0 ] == '/' ) /* Absolute path */
26
26
{
27
- path_out = (char * )pvPortMalloc (strlen (path ) + 1 ); // Count the \0 too
27
+ path_out = (char * )malloc (strlen (path ) + 1 ); // Count the \0 too
28
28
if (path_out != NULL )
29
29
{
30
30
strcpy (path_out , path );
31
31
}
32
32
}
33
33
else
34
34
{
35
- path_out = (char * )pvPortMalloc (strlen (littlefs -> cwd ) + 1 + strlen (path ) + 1 );
35
+ path_out = (char * )malloc (strlen (littlefs -> cwd ) + 1 + strlen (path ) + 1 );
36
36
if (path_out != NULL )
37
37
{
38
38
strcpy (path_out , littlefs -> cwd );
@@ -129,9 +129,8 @@ static int change_cwd(vfs_lfs_struct_t* littlefs, const char* path_in)
129
129
}
130
130
else if (is_valid_directory (littlefs , new_path ))
131
131
{
132
- vPortFree (littlefs -> cwd );
132
+ free (littlefs -> cwd );
133
133
littlefs -> cwd = (char * )new_path ;
134
- MP_STATE_PORT (lfs_cwd ) = littlefs -> cwd ;
135
134
136
135
res = LFS_ERR_OK ;
137
136
}
@@ -353,21 +352,21 @@ void littlefs_prepare_attributes(struct lfs_file_config *cfg)
353
352
{
354
353
// Currently we only have 1 attribute
355
354
cfg -> attr_count = 1 ;
356
- cfg -> attrs = pvPortMalloc (cfg -> attr_count * sizeof (struct lfs_attr ));
355
+ cfg -> attrs = malloc (cfg -> attr_count * sizeof (struct lfs_attr ));
357
356
358
357
// Set attribute for storing the timestamp
359
358
cfg -> attrs [0 ].size = sizeof (lfs_timestamp_attribute_t );
360
359
cfg -> attrs [0 ].type = LFS_ATTRIBUTE_TIMESTAMP ;
361
- cfg -> attrs [0 ].buffer = pvPortMalloc (sizeof (lfs_timestamp_attribute_t ));
360
+ cfg -> attrs [0 ].buffer = malloc (sizeof (lfs_timestamp_attribute_t ));
362
361
363
362
}
364
363
365
364
void littlefs_free_up_attributes (struct lfs_file_config * cfg )
366
365
{
367
366
cfg -> attr_count = 0 ;
368
367
// Currently we only have 1 attribute for timestamp
369
- vPortFree (cfg -> attrs [0 ].buffer );
370
- vPortFree (cfg -> attrs );
368
+ free (cfg -> attrs [0 ].buffer );
369
+ free (cfg -> attrs );
371
370
}
372
371
373
372
@@ -478,18 +477,15 @@ STATIC mp_obj_t littlefs_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args)
478
477
iter -> is_str = is_str_type ;
479
478
480
479
xSemaphoreTake (self -> fs .littlefs .mutex , portMAX_DELAY );
481
- const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
482
- if (path == NULL )
483
- {
484
- res = LFS_ERR_NOMEM ;
485
- }
486
- else
487
- {
488
- res = lfs_dir_open (& self -> fs .littlefs .lfs , & iter -> dir , path );
489
- }
480
+ const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
481
+ if (path == NULL ) {
482
+ res = LFS_ERR_NOMEM ;
483
+ } else {
484
+ res = lfs_dir_open (& self -> fs .littlefs .lfs , & iter -> dir , path );
485
+ }
490
486
xSemaphoreGive (self -> fs .littlefs .mutex );
491
487
492
- vPortFree ((void * )path );
488
+ free ((void * )path );
493
489
494
490
if (res != LFS_ERR_OK ) {
495
491
mp_raise_OSError (littleFsErrorToErrno (res ));
@@ -506,21 +502,18 @@ STATIC mp_obj_t littlefs_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_param) {
506
502
const char * path_in = mp_obj_str_get_str (path_param );
507
503
508
504
xSemaphoreTake (self -> fs .littlefs .mutex , portMAX_DELAY );
509
- const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
510
- if (path == NULL )
511
- {
512
- res = LFS_ERR_NOMEM ;
513
- }
514
- else
515
- {
516
- res = lfs_mkdir (& self -> fs .littlefs .lfs , path );
517
- if (res == LFS_ERR_OK ) {
518
- littlefs_update_timestamp (& self -> fs .littlefs .lfs , path );
519
- }
505
+ const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
506
+ if (path == NULL ) {
507
+ res = LFS_ERR_NOMEM ;
508
+ } else {
509
+ res = lfs_mkdir (& self -> fs .littlefs .lfs , path );
510
+ if (res == LFS_ERR_OK ) {
511
+ littlefs_update_timestamp (& self -> fs .littlefs .lfs , path );
520
512
}
513
+ }
521
514
xSemaphoreGive (self -> fs .littlefs .mutex );
522
515
523
- vPortFree ((void * )path );
516
+ free ((void * )path );
524
517
525
518
if (res != LFS_ERR_OK ) {
526
519
mp_raise_OSError (littleFsErrorToErrno (res ));
@@ -538,18 +531,15 @@ STATIC mp_obj_t littlefs_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_param) {
538
531
const char * path_in = mp_obj_str_get_str (path_param );
539
532
540
533
xSemaphoreTake (self -> fs .littlefs .mutex , portMAX_DELAY );
541
- const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
542
- if (path == NULL )
543
- {
544
- res = LFS_ERR_NOMEM ;
545
- }
546
- else
547
- {
548
- res = lfs_remove (& self -> fs .littlefs .lfs , path );
549
- }
534
+ const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
535
+ if (path == NULL ) {
536
+ res = LFS_ERR_NOMEM ;
537
+ } else {
538
+ res = lfs_remove (& self -> fs .littlefs .lfs , path );
539
+ }
550
540
xSemaphoreGive (self -> fs .littlefs .mutex );
551
541
552
- vPortFree ((void * )path );
542
+ free ((void * )path );
553
543
554
544
if (res != LFS_ERR_OK ) {
555
545
mp_raise_OSError (littleFsErrorToErrno (res ));
@@ -568,21 +558,18 @@ STATIC mp_obj_t littlefs_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_param_in, mp_
568
558
const char * path_out = mp_obj_str_get_str (path_param_out );
569
559
570
560
xSemaphoreTake (self -> fs .littlefs .mutex , portMAX_DELAY );
571
- const char * old_path = concat_with_cwd (& self -> fs .littlefs , path_in );
572
- const char * new_path = concat_with_cwd (& self -> fs .littlefs , path_out );
561
+ const char * old_path = concat_with_cwd (& self -> fs .littlefs , path_in );
562
+ const char * new_path = concat_with_cwd (& self -> fs .littlefs , path_out );
573
563
574
- if (old_path == NULL || new_path == NULL )
575
- {
576
- res = LFS_ERR_NOMEM ;
577
- }
578
- else
579
- {
580
- res = lfs_rename (& self -> fs .littlefs .lfs , old_path , new_path );
581
- }
564
+ if (old_path == NULL || new_path == NULL ) {
565
+ res = LFS_ERR_NOMEM ;
566
+ } else {
567
+ res = lfs_rename (& self -> fs .littlefs .lfs , old_path , new_path );
568
+ }
582
569
xSemaphoreGive (self -> fs .littlefs .mutex );
583
570
584
- vPortFree ((void * )old_path );
585
- vPortFree ((void * )new_path );
571
+ free ((void * )old_path );
572
+ free ((void * )new_path );
586
573
587
574
if (res != LFS_ERR_OK ) {
588
575
mp_raise_OSError (littleFsErrorToErrno (res ));
@@ -633,23 +620,20 @@ STATIC mp_obj_t littlefs_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_param) {
633
620
634
621
635
622
xSemaphoreTake (self -> fs .littlefs .mutex , portMAX_DELAY );
636
- const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
637
- if (path == NULL )
638
- {
639
- res = LFS_ERR_NOMEM ;
640
- }
641
- else if (path [0 ] == 0 || (path [0 ] == '/' && path [1 ] == 0 ))
642
- {
643
- // stat root directory
644
- fno .size = 0 ;
645
- fno .type = LFS_TYPE_DIR ;
646
- } else {
647
- res = littlefs_stat_common_helper (& self -> fs .littlefs .lfs , path , & fno , & ts );
648
- }
623
+ const char * path = concat_with_cwd (& self -> fs .littlefs , path_in );
624
+ if (path == NULL ) {
625
+ res = LFS_ERR_NOMEM ;
626
+ } else if (path [0 ] == 0 || (path [0 ] == '/' && path [1 ] == 0 )) {
627
+ // stat root directory
628
+ fno .size = 0 ;
629
+ fno .type = LFS_TYPE_DIR ;
630
+ } else {
631
+ res = littlefs_stat_common_helper (& self -> fs .littlefs .lfs , path , & fno , & ts );
632
+ }
649
633
650
634
xSemaphoreGive (self -> fs .littlefs .mutex );
651
635
652
- vPortFree ((void * )path );
636
+ free ((void * )path );
653
637
654
638
if (res < LFS_ERR_OK ) {
655
639
mp_raise_OSError (littleFsErrorToErrno (res ));
0 commit comments