@@ -138,6 +138,7 @@ fn main() {
138
138
. open_file_in_dir ( & mut volume, & root_dir, FILE_TO_WRITE , Mode :: ReadOnly )
139
139
. unwrap ( ) ;
140
140
println ! ( "\n Reading from file {}\n " , FILE_TO_WRITE ) ;
141
+ let mut csum = 0 ;
141
142
println ! ( "FILE STARTS:" ) ;
142
143
while !f. eof ( ) {
143
144
let mut buffer = [ 0u8 ; 32 ] ;
@@ -147,9 +148,11 @@ fn main() {
147
148
print ! ( "\\ n" ) ;
148
149
}
149
150
print ! ( "{}" , * b as char ) ;
151
+ csum += u32:: from ( * b) ;
150
152
}
151
153
}
152
154
println ! ( "EOF\n " ) ;
155
+ let mut file_size = f. length ( ) as usize ;
153
156
volume_mgr. close_file ( & volume, f) . unwrap ( ) ;
154
157
155
158
let mut f = volume_mgr
@@ -161,15 +164,20 @@ fn main() {
161
164
println ! ( "\n Appending to file" ) ;
162
165
let num_written1 = volume_mgr. write ( & mut volume, & mut f, & buffer1[ ..] ) . unwrap ( ) ;
163
166
let num_written = volume_mgr. write ( & mut volume, & mut f, & buffer[ ..] ) . unwrap ( ) ;
164
- println ! ( "Number of bytes written: {}\n " , num_written + num_written1) ;
165
-
166
- f. seek_from_start ( 0 ) . unwrap ( ) ;
167
- println ! ( "\t Finding {}..." , FILE_TO_WRITE ) ;
167
+ for b in & buffer1[ ..] {
168
+ csum += u32:: from ( * b) ;
169
+ }
170
+ for b in & buffer[ ..] {
171
+ csum += u32:: from ( * b) ;
172
+ }
168
173
println ! (
169
- "\t Found {}?: {:?}" ,
170
- FILE_TO_WRITE ,
171
- volume_mgr. find_directory_entry( & volume, & root_dir, FILE_TO_WRITE )
174
+ "Number of bytes appendedß: {}\n " ,
175
+ num_written + num_written1
172
176
) ;
177
+ file_size += num_written;
178
+ file_size += num_written1;
179
+
180
+ f. seek_from_start ( 0 ) . unwrap ( ) ;
173
181
println ! ( "\n FILE STARTS:" ) ;
174
182
while !f. eof ( ) {
175
183
let mut buffer = [ 0u8 ; 32 ] ;
@@ -184,6 +192,35 @@ fn main() {
184
192
println ! ( "EOF" ) ;
185
193
volume_mgr. close_file ( & volume, f) . unwrap ( ) ;
186
194
195
+ println ! ( "\t Finding {}..." , FILE_TO_WRITE ) ;
196
+ let dir_ent = volume_mgr
197
+ . find_directory_entry ( & volume, & root_dir, FILE_TO_WRITE )
198
+ . unwrap ( ) ;
199
+ println ! ( "\t Found {}?: {:?}" , FILE_TO_WRITE , dir_ent) ;
200
+ assert_eq ! ( dir_ent. size as usize , file_size) ;
201
+ let mut f = volume_mgr
202
+ . open_file_in_dir ( & mut volume, & root_dir, FILE_TO_WRITE , Mode :: ReadWriteAppend )
203
+ . unwrap ( ) ;
204
+ println ! ( "\n Reading from file {}\n " , FILE_TO_WRITE ) ;
205
+ println ! ( "FILE STARTS:" ) ;
206
+ let mut csum2 = 0 ;
207
+ while !f. eof ( ) {
208
+ let mut buffer = [ 0u8 ; 32 ] ;
209
+ let num_read = volume_mgr. read ( & volume, & mut f, & mut buffer) . unwrap ( ) ;
210
+ for b in & buffer[ 0 ..num_read] {
211
+ if * b == 10 {
212
+ print ! ( "\\ n" ) ;
213
+ }
214
+ print ! ( "{}" , * b as char ) ;
215
+ csum2 += u32:: from ( * b) ;
216
+ }
217
+ }
218
+ println ! ( "EOF\n " ) ;
219
+ assert_eq ! ( f. length( ) as usize , file_size) ;
220
+ volume_mgr. close_file ( & volume, f) . unwrap ( ) ;
221
+
222
+ assert_eq ! ( csum, csum2) ;
223
+
187
224
println ! ( "\n Truncating file" ) ;
188
225
let mut f = volume_mgr
189
226
. open_file_in_dir (
0 commit comments