Don't go into infinite loop on fs error, print file attributes as letters.

This commit is contained in:
2019-11-07 02:51:55 +03:00
parent 34cdc3ca09
commit fa542ce8a1
9 changed files with 3759 additions and 3694 deletions

52
kofu.c
View File

@@ -67,6 +67,15 @@ const char *get_f70_status_name(f70status s) {
} }
} }
void convert_f70_file_attr(uint32_t attr, char s[KF_ATTR_CNT+1]) {
s[0] = (attr & KF_READONLY) ? 'r' : '-';
s[1] = (attr & KF_HIDDEN) ? 'h' : '-';
s[2] = (attr & KF_SYSTEM) ? 's' : '-';
s[3] = (attr & KF_LABEL) ? 'l' : '-';
s[4] = (attr & KF_FOLDER) ? 'f' : '-';
s[5] = '\0';
}
void print_f70_status(f70ret_t *r, int use_ebx) { void print_f70_status(f70ret_t *r, int use_ebx) {
printf("status = %d %s", r->status, get_f70_status_name(r->status)); printf("status = %d %s", r->status, get_f70_status_name(r->status));
if (use_ebx && (r->status == F70_ERROR_SUCCESS || r->status == F70_ERROR_END_OF_FILE)) if (use_ebx && (r->status == F70_ERROR_SUCCESS || r->status == F70_ERROR_END_OF_FILE))
@@ -203,13 +212,17 @@ void ls_range(f70s1arg_t *f70) {
f70->offset += f70->size; f70->offset += f70->size;
print_f70_status(&r, 1); print_f70_status(&r, 1);
f70s1info_t *dir = f70->buf; f70s1info_t *dir = f70->buf;
assert(r.count <= f70->size); int ok = (r.count <= f70->size);
assert(dir->cnt == r.count); ok &= (dir->cnt == r.count);
assert((r.status == F70_ERROR_SUCCESS && r.count == f70->size) || ok &= (r.status == F70_ERROR_SUCCESS && r.count == f70->size)
(r.status == F70_ERROR_END_OF_FILE && r.count < f70->size) || (r.status == F70_ERROR_END_OF_FILE && r.count < f70->size);
); assert(ok);
if (!ok)
break;
for (size_t i = 0; i < dir->cnt; i++) { for (size_t i = 0; i < dir->cnt; i++) {
printf("%s\n", dir->bdfes[i].name); char fattr[KF_ATTR_CNT+1];
convert_f70_file_attr(dir->bdfes[i].attr, fattr);
printf("%s %s\n", fattr, dir->bdfes[i].name);
} }
if (r.status == F70_ERROR_END_OF_FILE) { if (r.status == F70_ERROR_END_OF_FILE) {
break; break;
@@ -222,18 +235,21 @@ void ls_all(f70s1arg_t *f70) {
while (true) { while (true) {
kos_lfn(f70, &r); kos_lfn(f70, &r);
print_f70_status(&r, 1); print_f70_status(&r, 1);
if (r.status != F70_ERROR_SUCCESS && r.status != F70_ERROR_END_OF_FILE) { assert((r.status == F70_ERROR_SUCCESS && r.count == f70->size)
abort(); || (r.status == F70_ERROR_END_OF_FILE && r.count < f70->size));
}
f70s1info_t *dir = f70->buf; f70s1info_t *dir = f70->buf;
f70->offset += dir->cnt; f70->offset += dir->cnt;
assert(r.count <= f70->size); int ok = (r.count <= f70->size);
assert(dir->cnt == r.count); ok &= (dir->cnt == r.count);
assert((r.status == F70_ERROR_SUCCESS && r.count == f70->size) || ok &= (r.status == F70_ERROR_SUCCESS && r.count == f70->size)
(r.status == F70_ERROR_END_OF_FILE && r.count < f70->size) || (r.status == F70_ERROR_END_OF_FILE && r.count < f70->size);
); assert(ok);
if (!ok)
break;
for (size_t i = 0; i < dir->cnt; i++) { for (size_t i = 0; i < dir->cnt; i++) {
printf("%s\n", dir->bdfes[i].name); char fattr[KF_ATTR_CNT+1];
convert_f70_file_attr(dir->bdfes[i].attr, fattr);
printf("%s %s\n", fattr, dir->bdfes[i].name);
} }
if (r.status == F70_ERROR_END_OF_FILE) { if (r.status == F70_ERROR_END_OF_FILE) {
break; break;
@@ -269,8 +285,10 @@ void kofu_stat(int argc, const char **argv) {
print_f70_status(&r, 0); print_f70_status(&r, 0);
if (r.status != F70_ERROR_SUCCESS) if (r.status != F70_ERROR_SUCCESS)
return; return;
printf("attr: 0x%2.2x\n", file.attr); char fattr[KF_ATTR_CNT+1];
if (!file.attr) { // don't show size for dirs convert_f70_file_attr(file.attr, fattr);
printf("attr: %s\n", fattr);
if ((file.attr & KF_FOLDER) == 0) { // don't show size for dirs
printf("size: %llu\n", file.size); printf("size: %llu\n", file.size);
} }

View File

@@ -87,6 +87,7 @@ typedef struct {
#define KF_SYSTEM 0x04 #define KF_SYSTEM 0x04
#define KF_LABEL 0x08 #define KF_LABEL 0x08
#define KF_FOLDER 0x10 #define KF_FOLDER 0x10
#define KF_ATTR_CNT 5
#define HASH_SIZE 32 #define HASH_SIZE 32
typedef struct { typedef struct {

View File

@@ -1,7 +1,7 @@
FASM=fasm FASM=fasm
CC=gcc CC=gcc
WARNINGS=-Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wjump-misses-init -Wshadow -Wformat=2 -Wswitch -Wswitch-enum #-Wconversion -Wsign-conversion WARNINGS=-Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wjump-misses-init -Wshadow -Wformat=2 -Wswitch -Wswitch-enum #-Wconversion -Wsign-conversion
CFLAGS=$(WARNINGS) -g -O0 -D_FILE_OFFSET_BITS=64 -Wno-address-of-packed-member CFLAGS=$(WARNINGS) -g -O0 -D_FILE_OFFSET_BITS=64 -Wno-address-of-packed-member -DNDEBUG
CFLAGS_32=-m32 CFLAGS_32=-m32
LDFLAGS= LDFLAGS=
LDFLAGS_32=-m32 LDFLAGS_32=-m32

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -4,4 +4,6 @@ ls /hd0/1/block
ls /hd0/1/leaf ls /hd0/1/leaf
ls /hd0/1/node ls /hd0/1/node
ls /hd0/1/btree ls /hd0/1/btree
ls /hd0/1/sf/.
ls /hd0/1/sf/..
disk_del hd0 disk_del hd0

View File

@@ -1,24 +1,44 @@
/> disk_add ../img/s512_xfs_v4_ftype0_b4k_n2b.img hd0 /> disk_add ../img/s512_xfs_v4_ftype0_b4k_n2b.img hd0
/hd0/1: xfs /hd0/1: xfs
#stat /hd0/1/sf/. /> stat /hd0/1/sf/.
status = 0 success
attr: ----f
/> stat /hd0/1/sf/.. /> stat /hd0/1/sf/..
status = 0 success status = 0 success
attr: 0x10 attr: ----f
/> stat /hd0/1/sf///
status = 0 success
attr: ----f
/> stat /hd0/1/sf///.
status = 0 success
attr: ----f
/> stat /hd0/1/sf///..
status = 0 success
attr: ----f
/> stat /hd0/1/sf/../sf
status = 0 success
attr: ----f
/> stat /hd0/1/sf/../sf/
status = 0 success
attr: ----f
#stat /hd0/1/sf///..//sf
#stat /hd0/1/sf///..//sf/
/> stat /hd0/1/sf/d0000000000_ /> stat /hd0/1/sf/d0000000000_
status = 0 success status = 0 success
attr: 0x10 attr: ----f
/> stat /hd0/1/sf/d0000000001_x /> stat /hd0/1/sf/d0000000001_x
status = 0 success status = 0 success
attr: 0x10 attr: ----f
/> stat /hd0/1/sf/d0000000002_xx /> stat /hd0/1/sf/d0000000002_xx
status = 0 success status = 0 success
attr: 0x10 attr: ----f
/> stat /hd0/1/sf/d0000000003_xxx /> stat /hd0/1/sf/d0000000003_xxx
status = 5 file_not_found status = 5 file_not_found
/> cd /hd0/1/sf /> cd /hd0/1/sf
sf> stat d0000000001_x sf> stat d0000000001_x
status = 0 success status = 0 success
attr: 0x10 attr: ----f
sf> stat d0000000003_xxx sf> stat d0000000003_xxx
status = 5 file_not_found status = 5 file_not_found

View File

@@ -1,6 +1,14 @@
disk_add ../img/s512_xfs_v4_ftype0_b4k_n2b.img hd0 disk_add ../img/s512_xfs_v4_ftype0_b4k_n2b.img hd0
#stat /hd0/1/sf/. stat /hd0/1/sf/.
stat /hd0/1/sf/.. stat /hd0/1/sf/..
stat /hd0/1/sf///
stat /hd0/1/sf///.
stat /hd0/1/sf///..
stat /hd0/1/sf/../sf
stat /hd0/1/sf/../sf/
#stat /hd0/1/sf///..//sf
#stat /hd0/1/sf///..//sf/
stat /hd0/1/sf/d0000000000_ stat /hd0/1/sf/d0000000000_
stat /hd0/1/sf/d0000000001_x stat /hd0/1/sf/d0000000001_x
stat /hd0/1/sf/d0000000002_xx stat /hd0/1/sf/d0000000002_xx