@@ -809,10 +809,12 @@ static int lfs_dir_fetchwith(lfs_t *lfs,
809
809
lfs_crc (& crc , & dir -> rev , sizeof (dir -> rev ));
810
810
dir -> rev = lfs_fromle32 (dir -> rev );
811
811
812
+ lfs_dir_t temp = * dir ;
813
+
812
814
while (true) {
813
815
// extract next tag
814
816
lfs_tag_t tag ;
815
- int err = lfs_bd_read (lfs , dir -> pair [0 ], off , & tag , sizeof (tag ));
817
+ int err = lfs_bd_read (lfs , temp . pair [0 ], off , & tag , sizeof (tag ));
816
818
if (err ) {
817
819
return err ;
818
820
}
@@ -831,18 +833,18 @@ static int lfs_dir_fetchwith(lfs_t *lfs,
831
833
break ;
832
834
}
833
835
834
- //printf("tag r %#010x (%x:%x %03x %03x %03x)\n", tag, dir-> pair[0], off+sizeof(tag), lfs_tag_type(tag), lfs_tag_id(tag), lfs_tag_size(tag));
836
+ //printf("tag r %#010x (%x:%x %03x %03x %03x)\n", tag, temp. pair[0], off+sizeof(tag), lfs_tag_type(tag), lfs_tag_id(tag), lfs_tag_size(tag));
835
837
if (lfs_tag_type (tag ) == LFS_TYPE_CRC ) {
836
838
// check the crc entry
837
839
uint32_t dcrc ;
838
- int err = lfs_bd_read (lfs , dir -> pair [0 ],
840
+ int err = lfs_bd_read (lfs , temp . pair [0 ],
839
841
off + sizeof (tag ), & dcrc , sizeof (dcrc ));
840
842
if (err ) {
841
843
return err ;
842
844
}
843
845
844
846
if (crc != lfs_fromle32 (dcrc )) {
845
- if (off == sizeof (dir -> rev )) {
847
+ if (off == sizeof (temp . rev )) {
846
848
// try other block
847
849
break ;
848
850
} else {
@@ -852,49 +854,50 @@ static int lfs_dir_fetchwith(lfs_t *lfs,
852
854
}
853
855
}
854
856
855
- dir -> off = off + sizeof (tag )+ lfs_tag_size (tag );
856
- dir -> etag = tag ;
857
+ temp . off = off + sizeof (tag )+ lfs_tag_size (tag );
858
+ temp . etag = tag ;
857
859
crc = 0xffffffff ;
860
+ * dir = temp ;
858
861
} else {
859
- err = lfs_bd_crc (lfs , dir -> pair [0 ],
862
+ err = lfs_bd_crc (lfs , temp . pair [0 ],
860
863
off + sizeof (tag ), lfs_tag_size (tag ), & crc );
861
864
if (err ) {
862
865
return err ;
863
866
}
864
867
865
868
if (lfs_tag_type (tag ) == LFS_TYPE_SOFTTAIL ||
866
869
lfs_tag_type (tag ) == LFS_TYPE_HARDTAIL ) {
867
- dir -> split = lfs_tag_type (tag ) == LFS_TYPE_HARDTAIL ;
868
- err = lfs_bd_read (lfs , dir -> pair [0 ], off + sizeof (tag ),
869
- dir -> tail , sizeof (dir -> tail ));
870
+ temp . split = lfs_tag_type (tag ) == LFS_TYPE_HARDTAIL ;
871
+ err = lfs_bd_read (lfs , temp . pair [0 ], off + sizeof (tag ),
872
+ temp . tail , sizeof (temp . tail ));
870
873
if (err ) {
871
874
return err ;
872
875
}
873
876
} else if (lfs_tag_type (tag ) == LFS_TYPE_MOVE ) {
874
877
// TODO handle moves correctly?
875
- dir -> moveid = lfs_tag_id (tag );
878
+ temp . moveid = lfs_tag_id (tag );
876
879
} else {
877
880
if (lfs_tag_id (tag ) < 0x1ff &&
878
- lfs_tag_id (tag ) >= dir -> count ) {
879
- dir -> count = lfs_tag_id (tag )+ 1 ;
881
+ lfs_tag_id (tag ) >= temp . count ) {
882
+ temp . count = lfs_tag_id (tag )+ 1 ;
880
883
}
881
884
882
885
if (lfs_tag_type (tag ) == LFS_TYPE_DELETE ) {
883
- dir -> count -= 1 ;
884
- if (dir -> moveid != -1 ) {
885
- //printf("RENAME DEL %d (%d)\n", lfs_tag_id(tag), dir-> moveid);
886
+ temp . count -= 1 ;
887
+ if (temp . moveid != -1 ) {
888
+ //printf("RENAME DEL %d (%d)\n", lfs_tag_id(tag), temp. moveid);
886
889
}
887
- if (lfs_tag_id (tag ) == dir -> moveid ) {
888
- dir -> moveid = -1 ;
889
- } else if (lfs_tag_id (tag ) < dir -> moveid ) {
890
- dir -> moveid -= 1 ;
890
+ if (lfs_tag_id (tag ) == temp . moveid ) {
891
+ temp . moveid = -1 ;
892
+ } else if (lfs_tag_id (tag ) < temp . moveid ) {
893
+ temp . moveid -= 1 ;
891
894
}
892
895
}
893
896
894
897
if (cb ) {
895
898
err = cb (lfs , data , (lfs_entry_t ){
896
899
(tag | 0x80000000 ),
897
- .u .d .block = dir -> pair [0 ],
900
+ .u .d .block = temp . pair [0 ],
898
901
.u .d .off = off + sizeof (tag )});
899
902
if (err ) {
900
903
return err ;
@@ -1617,6 +1620,17 @@ static int lfs_dir_getinfo(lfs_t *lfs, lfs_dir_t *dir,
1617
1620
return 0 ;
1618
1621
}
1619
1622
1623
+ if (id == dir -> moveid ) {
1624
+ int moved = lfs_moved (lfs , dir , dir -> moveid );
1625
+ if (moved < 0 ) {
1626
+ return moved ;
1627
+ }
1628
+
1629
+ if (moved ) {
1630
+ return LFS_ERR_NOENT ;
1631
+ }
1632
+ }
1633
+
1620
1634
lfs_entry_t entry ;
1621
1635
int err = lfs_dir_getentry (lfs , dir , 0x701ff000 ,
1622
1636
lfs_mktag (LFS_TYPE_REG , id , 0 ), & entry );
@@ -4680,8 +4694,9 @@ static int lfs_moved(lfs_t *lfs, lfs_dir_t *fromdir, uint16_t fromid) {
4680
4694
// grab entry pair we're looking for
4681
4695
fromdir -> moveid = -1 ;
4682
4696
lfs_entry_t fromentry ;
4683
- int err = lfs_dir_getentry (lfs , fromdir , 0x43dff000 ,
4684
- lfs_mktag (LFS_STRUCT_DIR , fromid , 0 ), & fromentry );
4697
+ // TODO what about inline files?
4698
+ int err = lfs_dir_getentry (lfs , fromdir , 0x401ff000 ,
4699
+ lfs_mktag (LFS_TYPE_REG , fromid , 0 ), & fromentry );
4685
4700
fromdir -> moveid = fromid ;
4686
4701
if (err ) {
4687
4702
return err ;
0 commit comments