Commit 79a2831
authored
Implement simplefs_file_ops:open (#56)
In the registration of simplefs_file_ops callbacks, there is no open
operation, which may lead to creating unexpected space. This commit
adds an open operation to handle file truncation when opening files
with O_WRONLY, O_RDWR, and O_TRUNC flags. This prevents unintended
space allocation by ensuring proper truncation of files.
The implementation checks the flags associated with the file opening
mode and performs truncation if the file is being opened for write or
read/write and the O_TRUNC flag is set. Truncation is achieved by
reading the file's index block from disk, iterating over the data block
pointers, releasing the associated data blocks, and updating the
inode metadata (size and block count).
Close #551 parent 2ee1fc1 commit 79a2831
1 file changed
+49
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
248 | 296 | | |
249 | 297 | | |
250 | 298 | | |
| |||
262 | 310 | | |
263 | 311 | | |
264 | 312 | | |
| 313 | + | |
265 | 314 | | |
0 commit comments