Added detection/handling of unknown file types

This adds a couple things so our unknown file types don't just cause our
filesystem to fall over:

- lfsr_mount now prints a warning on any unknown file types found at
  mount time. Since we're already iterating over all files to find
  orphans, this is basically free.

- Added LFS_TYPE_UNKNOWN to represent files with an unknown/unsupported
  type. This is now returned by lfsr_stat/lfsr_dir_read for files of any
  unknow type.

- Added LFS_ERR_NOTSUP. This is now returned by functions that attempt
  to modify a file of unknown type, and my have more use cases in the
  future.

  It's tempting to allow remove/rename on unknown file types, but since
  we don't know what data structures these may be referencing, doing so
  would likely leak storage. Or worse. Shrubs for example would just
  explode if you only moved the metadata entry.

This also adds test_incompat_unknown to test these cases.

Code changes are minimal, though there are a number of extra conditions
to check for unknown file types. The lfsr_mount condition is
particularly fun as it should be completely optimized out when debug
statements are disabled:

           code          stack
  before: 33670           2592
  after:  33710 (+0.1%)   2592 (+0.0%)
This commit is contained in:
Christopher Haster
2024-06-09 13:12:27 -05:00
parent 1e41fc07fe
commit 7fad472af5
3 changed files with 156 additions and 14 deletions
+3 -1
View File
@@ -94,6 +94,8 @@ typedef int32_t lfsr_sdid_t;
// valid positive return values
enum lfs_error {
LFS_ERR_OK = 0, // No error
LFS_ERR_INVAL = -22, // Invalid parameter
LFS_ERR_NOTSUP = -95, // Operation not supported
LFS_ERR_IO = -5, // Error during device operation
LFS_ERR_CORRUPT = -84, // Corrupted
LFS_ERR_NOENT = -2, // No directory entry
@@ -102,7 +104,6 @@ enum lfs_error {
LFS_ERR_ISDIR = -21, // Entry is a dir
LFS_ERR_NOTEMPTY = -39, // Dir is not empty
LFS_ERR_FBIG = -27, // File too large
LFS_ERR_INVAL = -22, // Invalid parameter
LFS_ERR_NOSPC = -28, // No space left on device
LFS_ERR_NOMEM = -12, // No more memory available
LFS_ERR_NOATTR = -61, // No data/attr available
@@ -113,6 +114,7 @@ enum lfs_error {
// File types
enum lfs_type {
// file types
LFS_TYPE_UNKNOWN = 0,
LFS_TYPE_REG = 1,
LFS_TYPE_DIR = 2,