@@ -287,7 +287,7 @@ static inline uint16_t lfs_tag_type(lfs_tag_t tag) {
287
287
}
288
288
289
289
static inline uint16_t lfs_tag_subtype (lfs_tag_t tag ) {
290
- return ((tag & 0x7c000000 ) >> 26 ) << 4 ;
290
+ return ((tag & 0x78000000 ) >> 26 ) << 4 ;
291
291
}
292
292
293
293
static inline uint16_t lfs_tag_id (lfs_tag_t tag ) {
@@ -531,7 +531,7 @@ static int lfs_dir_traverse(lfs_t *lfs,
531
531
}
532
532
}
533
533
534
- if (lfs_tag_subtype (tag ) == LFS_TYPE_NAME ) {
534
+ if (lfs_tag_subtype (tag ) == LFS_TYPE_CREATE ) {
535
535
// found where something was created
536
536
if (lfs_tag_id (tag ) == lfs_tag_id (matchtag - matchdiff )) {
537
537
break ;
@@ -673,7 +673,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs,
673
673
}
674
674
675
675
// check for special tags
676
- if (lfs_tag_subtype (tag ) == LFS_TYPE_NAME ) {
676
+ if (lfs_tag_subtype (tag ) == LFS_TYPE_CREATE ) {
677
677
temp .count += 1 ;
678
678
679
679
if (tempfoundtag &&
@@ -822,7 +822,7 @@ static lfs_stag_t lfs_dir_get(lfs_t *lfs, const lfs_mdir_t *dir,
822
822
static int lfs_dir_getglobals (lfs_t * lfs , const lfs_mdir_t * dir ,
823
823
struct lfs_globals * globals ) {
824
824
struct lfs_globals locals ;
825
- lfs_stag_t res = lfs_dir_get (lfs , dir , 0x7c000000 ,
825
+ lfs_stag_t res = lfs_dir_get (lfs , dir , 0x78000000 ,
826
826
LFS_MKTAG (LFS_TYPE_GLOBALS , 0 , 10 ), & locals );
827
827
if (res < 0 && res != LFS_ERR_NOENT ) {
828
828
return res ;
@@ -848,15 +848,15 @@ static int lfs_dir_getinfo(lfs_t *lfs, lfs_mdir_t *dir,
848
848
}
849
849
850
850
lfs_stag_t tag = lfs_dir_get (lfs , dir , 0x7c3fe000 ,
851
- LFS_MKTAG (LFS_TYPE_NAME , id , lfs -> name_max + 1 ), info -> name );
851
+ LFS_MKTAG (LFS_TYPE_DIR , id , lfs -> name_max + 1 ), info -> name );
852
852
if (tag < 0 ) {
853
853
return tag ;
854
854
}
855
855
856
856
info -> type = lfs_tag_type (tag );
857
857
858
858
struct lfs_ctz ctz ;
859
- tag = lfs_dir_get (lfs , dir , 0x7c3fe000 ,
859
+ tag = lfs_dir_get (lfs , dir , 0x783fe000 ,
860
860
LFS_MKTAG (LFS_TYPE_STRUCT , id , sizeof (ctz )), & ctz );
861
861
if (tag < 0 ) {
862
862
return tag ;
@@ -893,13 +893,12 @@ static int lfs_dir_find_match(void *data,
893
893
}
894
894
895
895
// found match?
896
- if (res == 0 && (name -> size == lfs_tag_size (tag ) ||
897
- lfs_tag_type (tag ) == LFS_TYPE_SUPERBLOCK )) {
896
+ if (res == 0 && name -> size == lfs_tag_size (tag )) {
898
897
return tag ;
899
898
}
900
899
901
900
// a greater name found, exit early
902
- if (res == 2 && lfs_tag_type (tag ) != LFS_TYPE_SUPERBLOCK ) {
901
+ if (res > 1 && lfs_tag_type (tag ) != LFS_TYPE_SUPERBLOCK ) {
903
902
return tag | 0x1fff ;
904
903
}
905
904
@@ -969,7 +968,7 @@ static int lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
969
968
970
969
// grab the entry data
971
970
if (lfs_tag_id (tag ) != 0x1ff ) {
972
- lfs_stag_t res = lfs_dir_get (lfs , dir , 0x7c3fe000 ,
971
+ lfs_stag_t res = lfs_dir_get (lfs , dir , 0x783fe000 ,
973
972
LFS_MKTAG (LFS_TYPE_STRUCT , lfs_tag_id (tag ), 8 ), dir -> tail );
974
973
if (res < 0 ) {
975
974
return res ;
@@ -980,7 +979,7 @@ static int lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
980
979
// find entry matching name
981
980
while (true) {
982
981
tag = lfs_dir_fetchmatch (lfs , dir , dir -> tail ,
983
- 0x7c000000 , LFS_MKTAG (LFS_TYPE_NAME , 0 , namelen ),
982
+ 0x7c000000 , LFS_MKTAG (LFS_TYPE_DIR , 0 , namelen ),
984
983
lfs_dir_find_match , & (struct lfs_dir_find_match ){
985
984
lfs , name , namelen });
986
985
if (tag < 0 ) {
@@ -1059,7 +1058,7 @@ static int lfs_commit_move_match(void *data,
1059
1058
struct lfs_commit * commit = move -> commit ;
1060
1059
1061
1060
if (move -> pass == 0 ) {
1062
- if (lfs_tag_subtype (tag ) != LFS_TYPE_NAME ) {
1061
+ if (lfs_tag_subtype (tag ) != LFS_TYPE_CREATE ) {
1063
1062
return 0 ;
1064
1063
}
1065
1064
} else {
@@ -1068,7 +1067,7 @@ static int lfs_commit_move_match(void *data,
1068
1067
.pair [0 ] = commit -> block ,
1069
1068
.off = commit -> off ,
1070
1069
.etag = commit -> ptag }, NULL ,
1071
- lfs_tag_isuser (tag ) ? 0x7fffe000 : 0x7c3fe000 , tag , 0 ,
1070
+ lfs_tag_isuser (tag ) ? 0x7fffe000 : 0x783fe000 , tag , 0 ,
1072
1071
lfs_dir_get_match , & (struct lfs_dir_get_match ){
1073
1072
lfs , NULL , 0 , true});
1074
1073
if (res < 0 && res != LFS_ERR_NOENT ) {
@@ -1578,7 +1577,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir,
1578
1577
lfs_tag_t createtag = 0xffffffff ;
1579
1578
int attrcount = 0 ;
1580
1579
for (const struct lfs_mattr * a = attrs ; a ; a = a -> next ) {
1581
- if (lfs_tag_subtype (a -> tag ) == LFS_TYPE_NAME ) {
1580
+ if (lfs_tag_subtype (a -> tag ) == LFS_TYPE_CREATE ) {
1582
1581
dir -> count += 1 ;
1583
1582
createtag = a -> tag ;
1584
1583
} else if (lfs_tag_subtype (a -> tag ) == LFS_TYPE_DELETE ) {
@@ -1795,7 +1794,7 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) {
1795
1794
pair [1 ] = lfs -> root [1 ];
1796
1795
} else {
1797
1796
// get dir pair from parent
1798
- lfs_stag_t res = lfs_dir_get (lfs , & dir -> m , 0x7c3fe000 ,
1797
+ lfs_stag_t res = lfs_dir_get (lfs , & dir -> m , 0x783fe000 ,
1799
1798
LFS_MKTAG (LFS_TYPE_STRUCT , lfs_tag_id (tag ), 8 ), pair );
1800
1799
if (res < 0 ) {
1801
1800
return res ;
@@ -2190,7 +2189,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
2190
2189
file -> flags |= LFS_F_DIRTY ;
2191
2190
} else {
2192
2191
// try to load what's on disk, if it's inlined we'll fix it later
2193
- tag = lfs_dir_get (lfs , & file -> m , 0x7c3fe000 ,
2192
+ tag = lfs_dir_get (lfs , & file -> m , 0x783fe000 ,
2194
2193
LFS_MKTAG (LFS_TYPE_STRUCT , file -> id , 8 ), & file -> ctz );
2195
2194
if (tag < 0 ) {
2196
2195
err = tag ;
@@ -2245,7 +2244,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
2245
2244
2246
2245
// don't always read (may be new/trunc file)
2247
2246
if (file -> ctz .size > 0 ) {
2248
- lfs_stag_t res = lfs_dir_get (lfs , & file -> m , 0x7c3fe000 ,
2247
+ lfs_stag_t res = lfs_dir_get (lfs , & file -> m , 0x783fe000 ,
2249
2248
LFS_MKTAG (LFS_TYPE_STRUCT , file -> id , file -> ctz .size ),
2250
2249
file -> cache .buffer );
2251
2250
if (res < 0 ) {
@@ -2800,7 +2799,7 @@ int lfs_remove(lfs_t *lfs, const char *path) {
2800
2799
if (lfs_tag_type (tag ) == LFS_TYPE_DIR ) {
2801
2800
// must be empty before removal
2802
2801
lfs_block_t pair [2 ];
2803
- lfs_stag_t res = lfs_dir_get (lfs , & cwd , 0x7c3fe000 ,
2802
+ lfs_stag_t res = lfs_dir_get (lfs , & cwd , 0x783fe000 ,
2804
2803
LFS_MKTAG (LFS_TYPE_STRUCT , lfs_tag_id (tag ), 8 ), pair );
2805
2804
if (res < 0 ) {
2806
2805
return res ;
@@ -2880,7 +2879,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
2880
2879
} else if (lfs_tag_type (prevtag ) == LFS_TYPE_DIR ) {
2881
2880
// must be empty before removal
2882
2881
lfs_block_t prevpair [2 ];
2883
- lfs_stag_t res = lfs_dir_get (lfs , & newcwd , 0x7c3fe000 ,
2882
+ lfs_stag_t res = lfs_dir_get (lfs , & newcwd , 0x783fe000 ,
2884
2883
LFS_MKTAG (LFS_TYPE_STRUCT , newid , 8 ), prevpair );
2885
2884
if (res < 0 ) {
2886
2885
return res ;
@@ -3139,9 +3138,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
3139
3138
3140
3139
// write one superblock
3141
3140
lfs_superblock_t superblock = {
3142
- .magic = {"littlefs" },
3143
- .version = LFS_DISK_VERSION ,
3144
-
3141
+ .version = LFS_DISK_VERSION ,
3145
3142
.block_size = lfs -> cfg -> block_size ,
3146
3143
.block_count = lfs -> cfg -> block_count ,
3147
3144
.name_max = lfs -> name_max ,
@@ -3151,8 +3148,10 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
3151
3148
3152
3149
lfs_superblock_tole32 (& superblock );
3153
3150
err = lfs_dir_commit (lfs , & root ,
3154
- LFS_MKATTR (LFS_TYPE_SUPERBLOCK , 0 , & superblock , sizeof (superblock ),
3155
- NULL ));
3151
+ LFS_MKATTR (LFS_TYPE_INLINESTRUCT , 0 ,
3152
+ & superblock , sizeof (superblock ),
3153
+ LFS_MKATTR (LFS_TYPE_SUPERBLOCK , 0 , "littlefs" , 8 ,
3154
+ NULL )));
3156
3155
if (err ) {
3157
3156
goto cleanup ;
3158
3157
}
@@ -3178,7 +3177,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
3178
3177
lfs_mdir_t dir = {.tail = {0 , 1 }};
3179
3178
while (!lfs_pair_isnull (dir .tail )) {
3180
3179
// fetch next block in tail list
3181
- lfs_stag_t tag = lfs_dir_fetchmatch (lfs , & dir , dir .tail , 0x7fc00000 ,
3180
+ lfs_stag_t tag = lfs_dir_fetchmatch (lfs , & dir , dir .tail , 0x7fffe000 ,
3182
3181
LFS_MKTAG (LFS_TYPE_SUPERBLOCK , 0 , 8 ),
3183
3182
lfs_dir_find_match , & (struct lfs_dir_find_match ){
3184
3183
lfs , "littlefs" , 8 });
@@ -3195,8 +3194,8 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
3195
3194
3196
3195
// grab superblock
3197
3196
lfs_superblock_t superblock ;
3198
- tag = lfs_dir_get (lfs , & dir , 0x7f800000 ,
3199
- LFS_MKTAG (LFS_TYPE_SUPERBLOCK , 0 , sizeof (superblock )),
3197
+ tag = lfs_dir_get (lfs , & dir , 0x7fffe000 ,
3198
+ LFS_MKTAG (LFS_TYPE_INLINESTRUCT , 0 , sizeof (superblock )),
3200
3199
& superblock );
3201
3200
if (tag < 0 ) {
3202
3201
err = tag ;
@@ -3248,7 +3247,6 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
3248
3247
3249
3248
lfs -> attr_max = superblock .attr_max ;
3250
3249
}
3251
-
3252
3250
}
3253
3251
3254
3252
// has globals?
@@ -3258,6 +3256,12 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
3258
3256
}
3259
3257
}
3260
3258
3259
+ // found superblock?
3260
+ if (lfs_pair_isnull (lfs -> root )) {
3261
+ err = LFS_ERR_INVAL ;
3262
+ goto cleanup ;
3263
+ }
3264
+
3261
3265
// update littlefs with globals
3262
3266
lfs_global_fromle32 (& lfs -> locals );
3263
3267
lfs_global_xor (& lfs -> globals , & lfs -> locals );
@@ -3306,7 +3310,7 @@ int lfs_fs_traverse(lfs_t *lfs,
3306
3310
3307
3311
for (uint16_t id = 0 ; id < dir .count ; id ++ ) {
3308
3312
struct lfs_ctz ctz ;
3309
- lfs_stag_t tag = lfs_dir_get (lfs , & dir , 0x7c3fe000 ,
3313
+ lfs_stag_t tag = lfs_dir_get (lfs , & dir , 0x783fe000 ,
3310
3314
LFS_MKTAG (LFS_TYPE_STRUCT , id , sizeof (ctz )), & ctz );
3311
3315
if (tag < 0 ) {
3312
3316
if (tag == LFS_ERR_NOENT ) {
0 commit comments