@@ -1491,8 +1491,29 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
1491
1491
mode_t mode )
1492
1492
{
1493
1493
FAR struct littlefs_mountpt_s * fs ;
1494
+ FAR char * path = (FAR char * )relpath ;
1495
+ size_t len = strlen (relpath );
1494
1496
int ret ;
1495
1497
1498
+ /* We need remove all the '/' in the end of relpath */
1499
+
1500
+ if (len > 0 && relpath [len - 1 ] == '/' )
1501
+ {
1502
+ path = lib_get_pathbuffer ();
1503
+ if (path == NULL )
1504
+ {
1505
+ return - ENOMEM ;
1506
+ }
1507
+
1508
+ while (len > 0 && relpath [len - 1 ] == '/' )
1509
+ {
1510
+ len -- ;
1511
+ }
1512
+
1513
+ memcpy (path , relpath , len );
1514
+ path [len ] = '\0' ;
1515
+ }
1516
+
1496
1517
/* Get the mountpoint private data from the inode structure */
1497
1518
1498
1519
fs = mountpt -> i_private ;
@@ -1502,10 +1523,10 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
1502
1523
ret = nxmutex_lock (& fs -> lock );
1503
1524
if (ret < 0 )
1504
1525
{
1505
- return ret ;
1526
+ goto errout ;
1506
1527
}
1507
1528
1508
- ret = lfs_mkdir (& fs -> lfs , relpath );
1529
+ ret = littlefs_convert_result ( lfs_mkdir (& fs -> lfs , path ) );
1509
1530
if (ret >= 0 )
1510
1531
{
1511
1532
struct littlefs_attr_s attr ;
@@ -1517,16 +1538,22 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
1517
1538
attr .at_ctim = 1000000000ull * time .tv_sec + time .tv_nsec ;
1518
1539
attr .at_atim = attr .at_ctim ;
1519
1540
attr .at_mtim = attr .at_ctim ;
1520
- ret = littlefs_convert_result (lfs_setattr (& fs -> lfs , relpath , 0 ,
1541
+ ret = littlefs_convert_result (lfs_setattr (& fs -> lfs , path , 0 ,
1521
1542
& attr , sizeof (attr )));
1522
1543
if (ret < 0 )
1523
1544
{
1524
- lfs_remove (& fs -> lfs , relpath );
1545
+ lfs_remove (& fs -> lfs , path );
1525
1546
}
1526
1547
}
1527
1548
1528
1549
nxmutex_unlock (& fs -> lock );
1529
1550
1551
+ errout :
1552
+ if (path != relpath )
1553
+ {
1554
+ lib_put_pathbuffer (path );
1555
+ }
1556
+
1530
1557
return ret ;
1531
1558
}
1532
1559
0 commit comments