Redesign VFS around handles

This commit is contained in:
2026-02-22 13:57:41 +01:00
parent b571e2dbd3
commit 85872b856b
10 changed files with 210 additions and 196 deletions

21
ce/ce.c
View File

@@ -72,16 +72,15 @@ static void cmd_cat (struct list_node_link* tokens) {
struct list_node_link *token_link, *token_tmp_link;
list_foreach (tokens, token_link, token_tmp_link) {
struct token* token = list_entry (token_link, struct token, tokens_link);
int ret;
ret = open (token->buffer);
int handle = open (token->buffer);
if (ret < 0) {
printf ("ERROR opening %s: %s\n", token->buffer, str_status[-ret]);
if (handle < 0) {
printf ("ERROR opening %s: %s\n", token->buffer, str_status[-handle]);
continue;
}
describe (token->buffer, &desc);
describe (handle, &desc);
if (desc.type != FS_FILE)
goto close1;
@@ -92,21 +91,13 @@ static void cmd_cat (struct list_node_link* tokens) {
goto close1;
memset (buffer, 0, desc.size + 1);
ret = read (token->buffer, 0, (uint8_t*)buffer, desc.size);
if (ret < 0) {
printf ("ERROR reading%s: %s\n", token->buffer, str_status[-ret]);
goto close1;
}
read (handle, 0, (uint8_t*)buffer, desc.size);
printf ("%s\n", buffer);
close1:
if (buffer != NULL)
free (buffer);
close (token->buffer);
close (handle);
}
}