Don't go into infinite loop on fs error, print file attributes as letters.
This commit is contained in:
52
kofu.c
52
kofu.c
@@ -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) {
|
||||
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))
|
||||
@@ -203,13 +212,17 @@ void ls_range(f70s1arg_t *f70) {
|
||||
f70->offset += f70->size;
|
||||
print_f70_status(&r, 1);
|
||||
f70s1info_t *dir = f70->buf;
|
||||
assert(r.count <= f70->size);
|
||||
assert(dir->cnt == r.count);
|
||||
assert((r.status == F70_ERROR_SUCCESS && r.count == f70->size) ||
|
||||
(r.status == F70_ERROR_END_OF_FILE && r.count < f70->size)
|
||||
);
|
||||
int ok = (r.count <= f70->size);
|
||||
ok &= (dir->cnt == r.count);
|
||||
ok &= (r.status == F70_ERROR_SUCCESS && 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++) {
|
||||
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) {
|
||||
break;
|
||||
@@ -222,18 +235,21 @@ void ls_all(f70s1arg_t *f70) {
|
||||
while (true) {
|
||||
kos_lfn(f70, &r);
|
||||
print_f70_status(&r, 1);
|
||||
if (r.status != F70_ERROR_SUCCESS && r.status != F70_ERROR_END_OF_FILE) {
|
||||
abort();
|
||||
}
|
||||
assert((r.status == F70_ERROR_SUCCESS && r.count == f70->size)
|
||||
|| (r.status == F70_ERROR_END_OF_FILE && r.count < f70->size));
|
||||
f70s1info_t *dir = f70->buf;
|
||||
f70->offset += dir->cnt;
|
||||
assert(r.count <= f70->size);
|
||||
assert(dir->cnt == r.count);
|
||||
assert((r.status == F70_ERROR_SUCCESS && r.count == f70->size) ||
|
||||
(r.status == F70_ERROR_END_OF_FILE && r.count < f70->size)
|
||||
);
|
||||
int ok = (r.count <= f70->size);
|
||||
ok &= (dir->cnt == r.count);
|
||||
ok &= (r.status == F70_ERROR_SUCCESS && 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++) {
|
||||
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) {
|
||||
break;
|
||||
@@ -269,8 +285,10 @@ void kofu_stat(int argc, const char **argv) {
|
||||
print_f70_status(&r, 0);
|
||||
if (r.status != F70_ERROR_SUCCESS)
|
||||
return;
|
||||
printf("attr: 0x%2.2x\n", file.attr);
|
||||
if (!file.attr) { // don't show size for dirs
|
||||
char fattr[KF_ATTR_CNT+1];
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -87,6 +87,7 @@ typedef struct {
|
||||
#define KF_SYSTEM 0x04
|
||||
#define KF_LABEL 0x08
|
||||
#define KF_FOLDER 0x10
|
||||
#define KF_ATTR_CNT 5
|
||||
|
||||
#define HASH_SIZE 32
|
||||
typedef struct {
|
||||
|
2
makefile
2
makefile
@@ -1,7 +1,7 @@
|
||||
FASM=fasm
|
||||
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
|
||||
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
|
||||
LDFLAGS=
|
||||
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
@@ -4,4 +4,6 @@ ls /hd0/1/block
|
||||
ls /hd0/1/leaf
|
||||
ls /hd0/1/node
|
||||
ls /hd0/1/btree
|
||||
ls /hd0/1/sf/.
|
||||
ls /hd0/1/sf/..
|
||||
disk_del hd0
|
||||
|
@@ -1,24 +1,44 @@
|
||||
/> disk_add ../img/s512_xfs_v4_ftype0_b4k_n2b.img hd0
|
||||
/hd0/1: xfs
|
||||
#stat /hd0/1/sf/.
|
||||
/> stat /hd0/1/sf/.
|
||||
status = 0 success
|
||||
attr: ----f
|
||||
/> stat /hd0/1/sf/..
|
||||
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_
|
||||
status = 0 success
|
||||
attr: 0x10
|
||||
attr: ----f
|
||||
/> stat /hd0/1/sf/d0000000001_x
|
||||
status = 0 success
|
||||
attr: 0x10
|
||||
attr: ----f
|
||||
/> stat /hd0/1/sf/d0000000002_xx
|
||||
status = 0 success
|
||||
attr: 0x10
|
||||
attr: ----f
|
||||
/> stat /hd0/1/sf/d0000000003_xxx
|
||||
status = 5 file_not_found
|
||||
|
||||
/> cd /hd0/1/sf
|
||||
sf> stat d0000000001_x
|
||||
status = 0 success
|
||||
attr: 0x10
|
||||
attr: ----f
|
||||
sf> stat d0000000003_xxx
|
||||
status = 5 file_not_found
|
||||
|
@@ -1,6 +1,14 @@
|
||||
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/../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/d0000000001_x
|
||||
stat /hd0/1/sf/d0000000002_xx
|
||||
|
Reference in New Issue
Block a user