Break ioctl() up into smaller syscalls

This commit is contained in:
2025-10-14 20:05:41 +02:00
parent c34a253d11
commit 406434fed0
21 changed files with 375 additions and 320 deletions

View File

@ -56,26 +56,24 @@ void set_config(void) {
}
void do_file(char *filepath) {
int32_t ret;
int32_t ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)filepath, IOCTL_F_READ, 0);
if (ioh < 0) {
LOG(LOG_ERR, "Could not open %s: %s\n", filepath, ERRSTRING(ioh));
int32_t h = fs_openf(filepath, FS_OF_READ);
if (h < 0) {
LOG(LOG_ERR, "Could not open %s: %s\n", filepath, ERRSTRING(h));
return;
}
IoctlStat statbuf; ZERO(&statbuf);
FsStat statbuf; ZERO(&statbuf);
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)filepath, 0);
if (statbuf.type != IOCTLSTAT_FILE) {
fs_stat(filepath, &statbuf);
if (statbuf.type != FSSTAT_FILE) {
LOG(LOG_ERR, "%s is not a file (%d)\n", filepath, statbuf.type);
return;
}
uint8_t *buf = umalloc(statbuf.size+1);
string_memset(buf, 0, statbuf.size+1);
if ((ret = ioctl(ioh, IOCTL_READ, (uint64_t)buf, statbuf.size, 0)) < 0) {
LOG(LOG_ERR, "Could not read %s (%d): %s\n", filepath, ioh, ERRSTRING(ioh));
if (fs_read(h, buf, statbuf.size, 0) < 0) {
LOG(LOG_ERR, "Could not read %s (%d): %s\n", filepath, h, ERRSTRING(h));
goto done;
}
@ -89,7 +87,7 @@ void do_file(char *filepath) {
done:
ufree(buf);
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
fs_closef(h);
}
void do_mode_interactive(void) {