@@ -265,7 +265,7 @@ typedef uint32_t lfs_tag_t;
265
265
typedef int32_t lfs_stag_t ;
266
266
267
267
#define LFS_MKTAG (type , id , size ) \
268
- (((lfs_tag_t)(type) << 22) | ((lfs_tag_t)(id) << 12 ) | (lfs_tag_t)(size))
268
+ (((lfs_tag_t)(type) << 22) | ((lfs_tag_t)(id) << 13 ) | (lfs_tag_t)(size))
269
269
270
270
static inline bool lfs_tag_isvalid (lfs_tag_t tag ) {
271
271
return !(tag & 0x80000000 );
@@ -276,7 +276,7 @@ static inline bool lfs_tag_isuser(lfs_tag_t tag) {
276
276
}
277
277
278
278
static inline bool lfs_tag_isdelete (lfs_tag_t tag ) {
279
- return (tag & 0x00000fff ) == 0xfff ;
279
+ return (( int32_t )( tag << 19 ) >> 19 ) == -1 ;
280
280
}
281
281
282
282
static inline uint16_t lfs_tag_type (lfs_tag_t tag ) {
@@ -288,11 +288,11 @@ static inline uint16_t lfs_tag_subtype(lfs_tag_t tag) {
288
288
}
289
289
290
290
static inline uint16_t lfs_tag_id (lfs_tag_t tag ) {
291
- return (tag & 0x003ff000 ) >> 12 ;
291
+ return (tag & 0x003fe000 ) >> 13 ;
292
292
}
293
293
294
294
static inline lfs_size_t lfs_tag_size (lfs_tag_t tag ) {
295
- return tag & 0x00000fff ;
295
+ return tag & 0x00001fff ;
296
296
}
297
297
298
298
static inline lfs_size_t lfs_tag_dsize (lfs_tag_t tag ) {
@@ -837,14 +837,14 @@ static int lfs_dir_getglobals(lfs_t *lfs, const lfs_mdir_t *dir,
837
837
838
838
static int lfs_dir_getinfo (lfs_t * lfs , lfs_mdir_t * dir ,
839
839
uint16_t id , struct lfs_info * info ) {
840
- if (id == 0x3ff ) {
840
+ if (id == 0x1ff ) {
841
841
// special case for root
842
842
strcpy (info -> name , "/" );
843
843
info -> type = LFS_TYPE_DIR ;
844
844
return 0 ;
845
845
}
846
846
847
- lfs_stag_t tag = lfs_dir_get (lfs , dir , 0x7c3ff000 ,
847
+ lfs_stag_t tag = lfs_dir_get (lfs , dir , 0x7c3fe000 ,
848
848
LFS_MKTAG (LFS_TYPE_NAME , id , lfs -> name_max + 1 ), info -> name );
849
849
if (tag < 0 ) {
850
850
return tag ;
@@ -853,7 +853,7 @@ static int lfs_dir_getinfo(lfs_t *lfs, lfs_mdir_t *dir,
853
853
info -> type = lfs_tag_type (tag );
854
854
855
855
struct lfs_ctz ctz ;
856
- tag = lfs_dir_get (lfs , dir , 0x7c3ff000 ,
856
+ tag = lfs_dir_get (lfs , dir , 0x7c3fe000 ,
857
857
LFS_MKTAG (LFS_TYPE_STRUCT , id , sizeof (ctz )), & ctz );
858
858
if (tag < 0 ) {
859
859
return tag ;
@@ -912,7 +912,7 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs,
912
912
* path = NULL ;
913
913
914
914
// default to root dir
915
- lfs_stag_t tag = LFS_MKTAG (LFS_TYPE_DIR , 0x3ff , 0 );
915
+ lfs_stag_t tag = LFS_MKTAG (LFS_TYPE_DIR , 0x1ff , 0 );
916
916
lfs_block_t pair [2 ] = {lfs -> root [0 ], lfs -> root [1 ]};
917
917
918
918
while (true) {
@@ -968,8 +968,8 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs,
968
968
}
969
969
970
970
// grab the entry data
971
- if (lfs_tag_id (tag ) != 0x3ff ) {
972
- lfs_stag_t res = lfs_dir_get (lfs , dir , 0x7c3ff000 ,
971
+ if (lfs_tag_id (tag ) != 0x1ff ) {
972
+ lfs_stag_t res = lfs_dir_get (lfs , dir , 0x7c3fe000 ,
973
973
LFS_MKTAG (LFS_TYPE_STRUCT , lfs_tag_id (tag ), 8 ), pair );
974
974
if (res < 0 ) {
975
975
return res ;
@@ -978,7 +978,7 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs,
978
978
}
979
979
980
980
// find entry matching name
981
- tag = lfs_dir_findmatch (lfs , dir , pair , false, 0x7c000fff ,
981
+ tag = lfs_dir_findmatch (lfs , dir , pair , false, 0x7c001fff ,
982
982
LFS_MKTAG (LFS_TYPE_NAME , 0 , namelen ),
983
983
lfs_dir_find_match , & (struct lfs_dir_find_match ){
984
984
lfs , name , namelen });
@@ -1046,7 +1046,7 @@ static int lfs_commit_move_match(void *data,
1046
1046
.pair [0 ] = commit -> block ,
1047
1047
.off = commit -> off ,
1048
1048
.etag = commit -> ptag }, NULL ,
1049
- lfs_tag_isuser (tag ) ? 0x7ffff000 : 0x7c3ff000 , tag , 0 ,
1049
+ lfs_tag_isuser (tag ) ? 0x7fffe000 : 0x7c3fe000 , tag , 0 ,
1050
1050
lfs_dir_get_match , & (struct lfs_dir_get_match ){
1051
1051
lfs , NULL , 0 , true});
1052
1052
if (res < 0 && res != LFS_ERR_NOENT ) {
@@ -1089,7 +1089,7 @@ static int lfs_commit_attr(lfs_t *lfs, struct lfs_commit *commit,
1089
1089
if (lfs_tag_type (tag ) == LFS_FROM_MOVE ) {
1090
1090
// special case for moves
1091
1091
return lfs_commit_move (lfs , commit , 1 ,
1092
- 0x003ff000 , LFS_MKTAG (0 , lfs_tag_size (tag ), 0 ),
1092
+ 0x003fe000 , LFS_MKTAG (0 , lfs_tag_size (tag ), 0 ),
1093
1093
LFS_MKTAG (0 , lfs_tag_id (tag ), 0 ) -
1094
1094
LFS_MKTAG (0 , lfs_tag_size (tag ), 0 ),
1095
1095
buffer , NULL );
@@ -1146,7 +1146,7 @@ static int lfs_commit_globals(lfs_t *lfs, struct lfs_commit *commit,
1146
1146
struct lfs_globals * globals ) {
1147
1147
return lfs_commit_attr (lfs , commit ,
1148
1148
LFS_MKTAG (LFS_TYPE_GLOBALS + 2 * globals -> hasmove + globals -> orphans ,
1149
- 0x3ff , 10 ), globals );
1149
+ 0x1ff , 10 ), globals );
1150
1150
}
1151
1151
1152
1152
static int lfs_commit_crc (lfs_t * lfs , struct lfs_commit * commit ,
@@ -1166,8 +1166,8 @@ static int lfs_commit_crc(lfs_t *lfs, struct lfs_commit *commit,
1166
1166
1167
1167
// build crc tag
1168
1168
bool reset = ~lfs_fromle32 (tag ) >> 31 ;
1169
- tag = LFS_MKTAG (LFS_TYPE_CRC + ( compacting << 1 ) + reset ,
1170
- 0x3ff , off - (commit -> off + sizeof (lfs_tag_t )));
1169
+ tag = LFS_MKTAG (LFS_TYPE_CRC + 2 * compacting + reset ,
1170
+ 0x1ff , off - (commit -> off + sizeof (lfs_tag_t )));
1171
1171
1172
1172
// write out crc
1173
1173
uint32_t footer [2 ];
@@ -1267,7 +1267,7 @@ static int lfs_dir_drop(lfs_t *lfs, lfs_mdir_t *dir, const lfs_mdir_t *tail) {
1267
1267
// update pred's tail
1268
1268
return lfs_dir_commit (lfs , dir ,
1269
1269
LFS_MKATTR (LFS_TYPE_TAIL + dir -> split ,
1270
- 0x3ff , dir -> tail , sizeof (dir -> tail ),
1270
+ 0x1ff , dir -> tail , sizeof (dir -> tail ),
1271
1271
NULL ));
1272
1272
}
1273
1273
@@ -1369,7 +1369,7 @@ static int lfs_dir_compact(lfs_t *lfs,
1369
1369
for (uint16_t id = begin ; id < end || commit .off < commit .ack ; id ++ ) {
1370
1370
for (int pass = 0 ; pass < 2 ; pass ++ ) {
1371
1371
err = lfs_commit_move (lfs , & commit , pass ,
1372
- 0x003ff000 , LFS_MKTAG (0 , id , 0 ),
1372
+ 0x003fe000 , LFS_MKTAG (0 , id , 0 ),
1373
1373
- LFS_MKTAG (0 , begin , 0 ),
1374
1374
source , attrs );
1375
1375
if (err && !(splitted && !overcompacting &&
@@ -1419,7 +1419,7 @@ static int lfs_dir_compact(lfs_t *lfs,
1419
1419
lfs_pair_tole32 (dir -> tail );
1420
1420
err = lfs_commit_attr (lfs , & commit ,
1421
1421
LFS_MKTAG (LFS_TYPE_TAIL + dir -> split ,
1422
- 0x3ff , sizeof (dir -> tail )), dir -> tail );
1422
+ 0x1ff , sizeof (dir -> tail )), dir -> tail );
1423
1423
lfs_pair_fromle32 (dir -> tail );
1424
1424
if (err ) {
1425
1425
if (err == LFS_ERR_CORRUPT ) {
@@ -1737,7 +1737,7 @@ int lfs_mkdir(lfs_t *lfs, const char *path) {
1737
1737
cwd .tail [1 ] = dir .pair [1 ];
1738
1738
lfs_pair_tole32 (dir .pair );
1739
1739
err = lfs_dir_commit (lfs , & cwd ,
1740
- LFS_MKATTR (LFS_TYPE_SOFTTAIL , 0x3ff , cwd .tail , sizeof (cwd .tail ),
1740
+ LFS_MKATTR (LFS_TYPE_SOFTTAIL , 0x1ff , cwd .tail , sizeof (cwd .tail ),
1741
1741
LFS_MKATTR (LFS_TYPE_DIRSTRUCT , id , dir .pair , sizeof (dir .pair ),
1742
1742
LFS_MKATTR (LFS_TYPE_DIR , id , path , nlen ,
1743
1743
NULL ))));
@@ -1760,13 +1760,13 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) {
1760
1760
}
1761
1761
1762
1762
lfs_block_t pair [2 ];
1763
- if (lfs_tag_id (tag ) == 0x3ff ) {
1763
+ if (lfs_tag_id (tag ) == 0x1ff ) {
1764
1764
// handle root dir separately
1765
1765
pair [0 ] = lfs -> root [0 ];
1766
1766
pair [1 ] = lfs -> root [1 ];
1767
1767
} else {
1768
1768
// get dir pair from parent
1769
- lfs_stag_t res = lfs_dir_get (lfs , & dir -> m , 0x7c3ff000 ,
1769
+ lfs_stag_t res = lfs_dir_get (lfs , & dir -> m , 0x7c3fe000 ,
1770
1770
LFS_MKTAG (LFS_TYPE_STRUCT , lfs_tag_id (tag ), 8 ), pair );
1771
1771
if (res < 0 ) {
1772
1772
return res ;
@@ -2163,7 +2163,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
2163
2163
file -> flags |= LFS_F_DIRTY ;
2164
2164
} else {
2165
2165
// try to load what's on disk, if it's inlined we'll fix it later
2166
- tag = lfs_dir_get (lfs , & file -> m , 0x7c3ff000 ,
2166
+ tag = lfs_dir_get (lfs , & file -> m , 0x7c3fe000 ,
2167
2167
LFS_MKTAG (LFS_TYPE_STRUCT , file -> id , 8 ), & file -> ctz );
2168
2168
if (tag < 0 ) {
2169
2169
err = tag ;
@@ -2175,7 +2175,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
2175
2175
// fetch attrs
2176
2176
for (const struct lfs_attr * a = file -> cfg -> attrs ; a ; a = a -> next ) {
2177
2177
if ((file -> flags & 3 ) != LFS_O_WRONLY ) {
2178
- lfs_stag_t res = lfs_dir_get (lfs , & file -> m , 0x7ffff000 ,
2178
+ lfs_stag_t res = lfs_dir_get (lfs , & file -> m , 0x7fffe000 ,
2179
2179
LFS_MKTAG (0x100 | a -> type , file -> id , a -> size ), a -> buffer );
2180
2180
if (res < 0 && res != LFS_ERR_NOENT ) {
2181
2181
err = res ;
@@ -2218,7 +2218,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
2218
2218
2219
2219
// don't always read (may be new/trunc file)
2220
2220
if (file -> ctz .size > 0 ) {
2221
- lfs_stag_t res = lfs_dir_get (lfs , & file -> m , 0x7c3ff000 ,
2221
+ lfs_stag_t res = lfs_dir_get (lfs , & file -> m , 0x7c3fe000 ,
2222
2222
LFS_MKTAG (LFS_TYPE_STRUCT , file -> id , file -> ctz .size ),
2223
2223
file -> cache .buffer );
2224
2224
if (res < 0 ) {
@@ -2778,7 +2778,7 @@ int lfs_remove(lfs_t *lfs, const char *path) {
2778
2778
if (lfs_tag_type (tag ) == LFS_TYPE_DIR ) {
2779
2779
// must be empty before removal
2780
2780
lfs_block_t pair [2 ];
2781
- lfs_stag_t res = lfs_dir_get (lfs , & cwd , 0x7c3ff000 ,
2781
+ lfs_stag_t res = lfs_dir_get (lfs , & cwd , 0x7c3fe000 ,
2782
2782
LFS_MKTAG (LFS_TYPE_STRUCT , lfs_tag_id (tag ), 8 ), pair );
2783
2783
if (res < 0 ) {
2784
2784
return res ;
@@ -2862,7 +2862,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
2862
2862
} else if (lfs_tag_type (prevtag ) == LFS_TYPE_DIR ) {
2863
2863
// must be empty before removal
2864
2864
lfs_block_t prevpair [2 ];
2865
- lfs_stag_t res = lfs_dir_get (lfs , & newcwd , 0x7c3ff000 ,
2865
+ lfs_stag_t res = lfs_dir_get (lfs , & newcwd , 0x7c3fe000 ,
2866
2866
LFS_MKTAG (LFS_TYPE_STRUCT , newid , 8 ), prevpair );
2867
2867
if (res < 0 ) {
2868
2868
return res ;
@@ -2933,7 +2933,7 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
2933
2933
}
2934
2934
2935
2935
uint16_t id = lfs_tag_id (res );
2936
- if (id == 0x3ff ) {
2936
+ if (id == 0x1ff ) {
2937
2937
// special case for root
2938
2938
id = 0 ;
2939
2939
int err = lfs_dir_fetch (lfs , & cwd , lfs -> root );
@@ -2942,7 +2942,7 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
2942
2942
}
2943
2943
}
2944
2944
2945
- res = lfs_dir_get (lfs , & cwd , 0x7ffff000 ,
2945
+ res = lfs_dir_get (lfs , & cwd , 0x7fffe000 ,
2946
2946
LFS_MKTAG (0x100 | type , id , lfs_min (size , lfs -> attr_max )),
2947
2947
buffer );
2948
2948
if (res < 0 ) {
@@ -2964,7 +2964,7 @@ static int lfs_commitattr(lfs_t *lfs, const char *path,
2964
2964
}
2965
2965
2966
2966
uint16_t id = lfs_tag_id (res );
2967
- if (id == 0x3ff ) {
2967
+ if (id == 0x1ff ) {
2968
2968
// special case for root
2969
2969
id = 0 ;
2970
2970
int err = lfs_dir_fetch (lfs , & cwd , lfs -> root );
@@ -2988,7 +2988,7 @@ int lfs_setattr(lfs_t *lfs, const char *path,
2988
2988
}
2989
2989
2990
2990
int lfs_removeattr (lfs_t * lfs , const char * path , uint8_t type ) {
2991
- return lfs_commitattr (lfs , path , type , NULL , LFS_ATTR_MAX + 1 );
2991
+ return lfs_commitattr (lfs , path , type , NULL , 0x1fff );
2992
2992
}
2993
2993
2994
2994
@@ -3290,7 +3290,7 @@ int lfs_fs_traverse(lfs_t *lfs,
3290
3290
3291
3291
for (uint16_t id = 0 ; id < dir .count ; id ++ ) {
3292
3292
struct lfs_ctz ctz ;
3293
- lfs_stag_t tag = lfs_dir_get (lfs , & dir , 0x7c3ff000 ,
3293
+ lfs_stag_t tag = lfs_dir_get (lfs , & dir , 0x7c3fe000 ,
3294
3294
LFS_MKTAG (LFS_TYPE_STRUCT , id , sizeof (ctz )), & ctz );
3295
3295
if (tag < 0 ) {
3296
3296
if (tag == LFS_ERR_NOENT ) {
@@ -3393,7 +3393,7 @@ static lfs_stag_t lfs_fs_parent(lfs_t *lfs, const lfs_block_t pair[2],
3393
3393
for (int i = 0 ; i < 2 ; i ++ ) {
3394
3394
struct lfs_fs_parent_match match = {lfs , {pair [0 ], pair [1 ]}};
3395
3395
lfs_stag_t tag = lfs_dir_findmatch (lfs , parent ,
3396
- (const lfs_block_t [2 ]){0 , 1 }, true, 0x7fc00fff ,
3396
+ (const lfs_block_t [2 ]){0 , 1 }, true, 0x7fc01fff ,
3397
3397
LFS_MKTAG (LFS_TYPE_DIRSTRUCT , 0 , 8 ),
3398
3398
lfs_fs_parent_match , & match );
3399
3399
if (tag != LFS_ERR_NOENT ) {
@@ -3458,7 +3458,7 @@ static int lfs_fs_relocate(lfs_t *lfs,
3458
3458
parent .tail [1 ] = newpair [1 ];
3459
3459
err = lfs_dir_commit (lfs , & parent ,
3460
3460
LFS_MKATTR (LFS_TYPE_TAIL + parent .split ,
3461
- 0x3ff , parent .tail , sizeof (parent .tail ),
3461
+ 0x1ff , parent .tail , sizeof (parent .tail ),
3462
3462
NULL ));
3463
3463
if (err ) {
3464
3464
return err ;
@@ -3532,7 +3532,7 @@ static int lfs_fs_deorphan(lfs_t *lfs) {
3532
3532
}
3533
3533
3534
3534
lfs_block_t pair [2 ];
3535
- lfs_stag_t res = lfs_dir_get (lfs , & parent , 0x7ffff000 , tag , pair );
3535
+ lfs_stag_t res = lfs_dir_get (lfs , & parent , 0x7fffe000 , tag , pair );
3536
3536
if (res < 0 ) {
3537
3537
return res ;
3538
3538
}
@@ -3547,7 +3547,7 @@ static int lfs_fs_deorphan(lfs_t *lfs) {
3547
3547
pdir .tail [1 ] = pair [1 ];
3548
3548
err = lfs_dir_commit (lfs , & pdir ,
3549
3549
LFS_MKATTR (LFS_TYPE_SOFTTAIL ,
3550
- 0x3ff , pdir .tail , sizeof (pdir .tail ),
3550
+ 0x1ff , pdir .tail , sizeof (pdir .tail ),
3551
3551
NULL ));
3552
3552
if (err ) {
3553
3553
return err ;
0 commit comments