vfs Rewrite IOCTL_STAT so that it doesnt require an already open handle

This commit is contained in:
2025-10-03 01:00:09 +02:00
parent 2cfd3ee2fa
commit de20efa0f3
7 changed files with 71 additions and 44 deletions

View File

@ -10,29 +10,33 @@ void fs_fetch(void) {
char *path = *(args()+1);
IOH ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)path, IOCTL_F_READ, 0);
if (ioh < 0) {
uprintf("fs: could not open %s\n", path);
IoctlStat statbuf; ZERO(&statbuf);
if (ioctl(IOCTL_NOHANDLE, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)path, 0) != E_OK) {
uprintf("fs: could not stat %s\n", path);
return;
}
IoctlStat statbuf; ZERO(&statbuf);
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)path, 0);
if (statbuf.type == IOCTLSTAT_FILE) {
IOH ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)path, IOCTL_F_READ, 0);
if (ioh < 0) {
uprintf("fs: could not open %s\n", path);
return;
}
uint8_t *buf = umalloc(statbuf.size+1);
string_memset(buf, 0, statbuf.size+1);
if (ioctl(ioh, IOCTL_READ, (uint64_t)buf, statbuf.size, 0) < 0) {
uprintf("fs: coult not read %s\n", path);
ufree(buf);
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
goto donefile;
return;
}
uprintf("%s", buf);
donefile:
ufree(buf);
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
} else if (statbuf.type == IOCTLSTAT_DIR) {
uprintf("entries = %zu\n", statbuf.size);
}
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
}