Dropped LFSR_TYPE_UNKNOWN

Returning the actual on-disk file type is probably more useful for users
as this gives them more information.

I was originally concerned about collisions with future internal types,
LFS_TYPE_TRAVERSAL, etc, needed for internal opened-list tracking, but
it turns out we can avoid problems by starting internal types at 0x80,
since on-disk file types are only 7-bits.

Code changes:

           code          stack
  before: 33710           2592
  after:  33694 (-0.0%)   2592 (+0.0%)
This commit is contained in:
Christopher Haster
2024-06-09 13:55:50 -05:00
parent 7fad472af5
commit 9886ebf51e
3 changed files with 4 additions and 9 deletions
+1 -5
View File
@@ -9607,11 +9607,7 @@ static int lfsr_stat_(lfs_t *lfs, const lfsr_mdir_t *mdir,
lfsr_tag_t tag, lfsr_data_t name,
struct lfs_info *info) {
// get file type from the tag
if (tag == LFSR_TAG_REG || tag == LFSR_TAG_DIR) {
info->type = lfsr_tag_subtype(tag);
} else {
info->type = LFS_TYPE_UNKNOWN;
}
info->type = lfsr_tag_subtype(tag);
// read the file name
LFS_ASSERT(lfsr_data_size(name) <= LFS_NAME_MAX);
-1
View File
@@ -114,7 +114,6 @@ enum lfs_error {
// File types
enum lfs_type {
// file types
LFS_TYPE_UNKNOWN = 0,
LFS_TYPE_REG = 1,
LFS_TYPE_DIR = 2,
+3 -3
View File
@@ -359,11 +359,11 @@ code = '''
// mount
lfsr_mount(&lfs, CFG) => 0;
// our file should appear as unknown
// our file should appear as an unknown type
struct lfs_info info;
lfsr_stat(&lfs, "b", &info) => 0;
assert(strcmp(info.name, "b") == 0);
assert(info.type == LFS_TYPE_UNKNOWN);
assert(info.type == 0x13);
assert(info.size == 0);
lfsr_dir_t dir;
@@ -382,7 +382,7 @@ code = '''
assert(info.size == strlen("hi a!"));
lfsr_dir_read(&lfs, &dir, &info) => 0;
assert(strcmp(info.name, "b") == 0);
assert(info.type == LFS_TYPE_UNKNOWN);
assert(info.type == 0x13);
assert(info.size == 0);
lfsr_dir_read(&lfs, &dir, &info) => 0;
assert(strcmp(info.name, "c") == 0);