@@ -1005,13 +1005,79 @@ impl ReadDirAllocation {
1005
1005
}
1006
1006
}
1007
1007
1008
+ #[ derive( Debug , Clone , Copy , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
1009
+ pub struct DirIterationTell {
1010
+ tell_result : u32 ,
1011
+ }
1012
+
1008
1013
pub struct ReadDir < ' a , ' b , S : driver:: Storage > {
1009
1014
alloc : RefCell < & ' b mut ReadDirAllocation > ,
1010
1015
fs : & ' b Filesystem < ' a , S > ,
1011
1016
#[ cfg( feature = "dir-entry-path" ) ]
1012
1017
path : PathBuf ,
1013
1018
}
1014
1019
1020
+ impl < ' a , ' b , S : driver:: Storage > ReadDir < ' a , ' b , S > {
1021
+ /// Return the position of the directory
1022
+ ///
1023
+ /// The returned offset is only meant to be consumed by seek and may not make
1024
+ /// sense, but does indicate the current position in the directory iteration.
1025
+ ///
1026
+ /// Returns the position of the directory, which can be returned to using [`seek`](Self::seek).
1027
+ pub fn tell ( & self ) -> Result < DirIterationTell > {
1028
+ let value = unsafe {
1029
+ ll:: lfs_dir_tell (
1030
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1031
+ & mut self . alloc . borrow_mut ( ) . state ,
1032
+ )
1033
+ } ;
1034
+ if value < 0 {
1035
+ Err ( io:: result_from ( ( ) , value) . unwrap_err ( ) )
1036
+ } else {
1037
+ Ok ( DirIterationTell {
1038
+ tell_result : value as u32 ,
1039
+ } )
1040
+ }
1041
+ }
1042
+
1043
+ /// Change the position of the directory
1044
+ ///
1045
+ /// The new off must be a value previous returned from [`tell`](Self::tell) and specifies
1046
+ /// an absolute offset in the directory seek.
1047
+ pub fn seek ( & mut self , state : DirIterationTell ) -> Result < DirIterationTell > {
1048
+ let value = unsafe {
1049
+ ll:: lfs_dir_seek (
1050
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1051
+ & mut self . alloc . borrow_mut ( ) . state ,
1052
+ state. tell_result ,
1053
+ )
1054
+ } ;
1055
+ if value < 0 {
1056
+ Err ( io:: result_from ( ( ) , value) . unwrap_err ( ) )
1057
+ } else {
1058
+ Ok ( DirIterationTell {
1059
+ tell_result : value as u32 ,
1060
+ } )
1061
+ }
1062
+ }
1063
+
1064
+ /// Change the position of the directory to the beginning of the directory
1065
+ pub fn rewind ( & mut self ) -> Result < ( ) > {
1066
+ let res = unsafe {
1067
+ ll:: lfs_dir_rewind (
1068
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1069
+ & mut self . alloc . borrow_mut ( ) . state ,
1070
+ )
1071
+ } ;
1072
+
1073
+ if res < 0 {
1074
+ Err ( io:: result_from ( ( ) , res) . unwrap_err ( ) )
1075
+ } else {
1076
+ Ok ( ( ) )
1077
+ }
1078
+ }
1079
+ }
1080
+
1015
1081
impl < ' a , ' b , S : driver:: Storage > Iterator for ReadDir < ' a , ' b , S > {
1016
1082
type Item = Result < DirEntry > ;
1017
1083
0 commit comments