Added lfsr_fs_cksum

This just exposes the gcksum to the user, but exposing the gcksum allows
the user to store it externally for an extra layer of protection against
filesystem corruption.

As far as I'm aware this is the only real way to protect against global
rollback issues, which is a problem for any filesystem with logs (aka
any powerloss-resilient filesystem).

This required a comically small amount of code:

           code          stack          ctx
  before: 38492           2624          640
  after:  38500 (+0.0%)   2624 (+0.0%)  640 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-19 12:35:48 -06:00
parent a80694b9a7
commit 109bd4e0ab
3 changed files with 86 additions and 7 deletions
+16
View File
@@ -1306,6 +1306,22 @@ int lfsr_fs_ckmeta(lfs_t *lfs);
int lfsr_fs_ckdata(lfs_t *lfs);
#endif
// Get the current filesystem checksum
//
// This is a checksum of all metadata + data in the filesystem, which
// can be stored externally to provide increased protection against
// filesystem corruption.
//
// Note this checksum is order-sensitive. So while it's unlikely two
// filesystems with different contents will have the same checksum, two
// filesystems with the same contents may not have the same checksum.
//
// Also note this is only a 32-bit checksum. Collisions should be
// expected.
//
// Returns a negative error code on failure.
int lfsr_fs_cksum(lfs_t *lfs, uint32_t *cksum);
#ifdef LFS_GC
// Perform any janitorial work that may be pending
//