Added lfsr_file_ckmeta/ckdata

These are basically the same as lfsr_fs_ckmeta/ckdata but limited to a
single file. They may be useful when you need to validate a file but
don't want to bother validating the entire filesystem:

  // Check a file for metadata errors
  int lfsr_file_ckmeta(lfs_t *lfs, lfsr_file_t *file);

  // Check a file for metadata + data errors
  int lfsr_file_ckdata(lfs_t *lfs, lfsr_file_t *file);

I've also added test_ck to test these and added some more
lfsr_fs_ckmeta/ckdata tests there. These currently just test simple
full-block clobbering, but we should eventually test more interesting
error patterns.

Unfortunately lfsr_file_ckmeta/ckdata can't reuse the internal
lfsr_mtree_traverse in quite the same way lfsr_fs_ckmeta/ckdata can, so
they're actually a bit more expensive. Though keep in mind with
link-time gc you won't pay the cost unless you call these functions:

           code          stack
  before: 36024           2696
  after:  36368 (+1.0%)   2664 (-1.2%)

Oh, and the multiple calls to lfsr_btree/bshrub_traverse apparently
uninlined it out of lfsr_mtree_traverse, saving the stack cost in the
stack hot-path... Yay?
This commit is contained in:
Christopher Haster
2024-07-26 14:10:22 -05:00
parent e812ac4a8c
commit e2c238c30d
5 changed files with 524 additions and 0 deletions
+12
View File
@@ -1013,6 +1013,18 @@ int lfsr_file_rewind(lfs_t *lfs, lfsr_file_t *file);
//lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file);
lfs_soff_t lfsr_file_size(lfs_t *lfs, lfsr_file_t *file);
// Check a file for metadata errors
//
// Returns LFS_ERR_CORRUPT if a checksum mismatch is found, or a negative
// error code on failure.
int lfsr_file_ckmeta(lfs_t *lfs, lfsr_file_t *file);
// Check a file for metadata + data errors
//
// Returns LFS_ERR_CORRUPT if a checksum mismatch is found, or a negative
// error code on failure.
int lfsr_file_ckdata(lfs_t *lfs, lfsr_file_t *file);
/// Directory operations ///