Break ioctl() up into smaller syscalls
This commit is contained in:
@ -44,15 +44,15 @@ void fs_fetch(void) {
|
||||
FS_FETCH_CONFIG.types = false;
|
||||
}
|
||||
|
||||
IoctlStat statbuf; ZERO(&statbuf);
|
||||
if (ioctl(IOCTL_NOHANDLE, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)path, 0) != E_OK) {
|
||||
FsStat statbuf; ZERO(&statbuf);
|
||||
if (fs_stat(path, &statbuf) != E_OK) {
|
||||
uprintf("fs: could not stat %s\n", path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (statbuf.type == IOCTLSTAT_FILE) {
|
||||
IOH ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)path, IOCTL_F_READ, 0);
|
||||
if (ioh < 0) {
|
||||
if (statbuf.type == FSSTAT_FILE) {
|
||||
int32_t h = fs_openf(path, FS_OF_READ);
|
||||
if (h < 0) {
|
||||
uprintf("fs: could not open %s\n", path);
|
||||
return;
|
||||
}
|
||||
@ -60,7 +60,7 @@ void fs_fetch(void) {
|
||||
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) {
|
||||
if (fs_read(h, buf, statbuf.size, 0)) {
|
||||
uprintf("fs: coult not read %s\n", path);
|
||||
goto donefile;
|
||||
return;
|
||||
@ -69,14 +69,14 @@ void fs_fetch(void) {
|
||||
uprintf("%s", buf);
|
||||
donefile:
|
||||
ufree(buf);
|
||||
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
|
||||
} else if (statbuf.type == IOCTLSTAT_DIR) {
|
||||
IoctlDirent *dirents = (IoctlDirent *)umalloc(statbuf.size * sizeof(*dirents));
|
||||
fs_closef(h);
|
||||
} else if (statbuf.type == FSSTAT_DIR) {
|
||||
FsDirent *dirents = (FsDirent *)umalloc(statbuf.size * sizeof(*dirents));
|
||||
|
||||
for (size_t i = 0; i < statbuf.size; i++) {
|
||||
ioctl(IOCTL_NOHANDLE, IOCTL_FETCHDIRENT, (uint64_t)path, (uint64_t)&dirents[i], i);
|
||||
fs_fetchdirent(path, &dirents[i], i);
|
||||
|
||||
IoctlDirent *dirent = &dirents[i];
|
||||
FsDirent *dirent = &dirents[i];
|
||||
|
||||
if (FS_FETCH_CONFIG.names) {
|
||||
if (FS_FETCH_CONFIG.plain) {
|
||||
@ -87,7 +87,7 @@ void fs_fetch(void) {
|
||||
}
|
||||
|
||||
if (FS_FETCH_CONFIG.sizes) {
|
||||
if (dirent->stat.type == IOCTLSTAT_FILE) {
|
||||
if (dirent->stat.type == FSSTAT_FILE) {
|
||||
if (FS_FETCH_CONFIG.humsz) {
|
||||
char *membuf = umalloc(20);
|
||||
|
||||
@ -105,7 +105,7 @@ void fs_fetch(void) {
|
||||
uprintf("%-15zu ", dirent->stat.size);
|
||||
}
|
||||
}
|
||||
} else if (dirent->stat.type == IOCTLSTAT_DIR) {
|
||||
} else if (dirent->stat.type == FSSTAT_DIR) {
|
||||
if (FS_FETCH_CONFIG.plain) {
|
||||
uprintf("- ");
|
||||
} else {
|
||||
@ -115,9 +115,9 @@ void fs_fetch(void) {
|
||||
}
|
||||
|
||||
if (FS_FETCH_CONFIG.types) {
|
||||
if (dirent->stat.type == IOCTLSTAT_FILE) {
|
||||
if (dirent->stat.type == FSSTAT_FILE) {
|
||||
uprintf("%c ", 'F');
|
||||
} else if (dirent->stat.type == IOCTLSTAT_DIR) {
|
||||
} else if (dirent->stat.type == FSSTAT_DIR) {
|
||||
uprintf("%c ", 'D');
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ void fs_mkd(void) {
|
||||
|
||||
char *path = *(args()+1);
|
||||
|
||||
int32_t r = ioctl(IOCTL_NOHANDLE, IOCTL_MKDIR, (uint64_t)path, 0, 0);
|
||||
int32_t r = fs_mkdir(path);
|
||||
if (r != E_OK) {
|
||||
uprintf("fs: could not create %s\n", path);
|
||||
}
|
||||
|
||||
@ -26,15 +26,15 @@ void fs_mkf(void) {
|
||||
uprintf("fs mkf: Could not parse args: %d\n", ret);
|
||||
}
|
||||
|
||||
IOH ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)path, IOCTL_F_MAKE | IOCTL_F_WRITE, 0);
|
||||
if (ioh < 0) {
|
||||
int32_t h = fs_openf(path, FS_OF_MAKE | FS_OF_WRITE);
|
||||
if (h < 0) {
|
||||
uprintf("fs mkf: could not create %s\n", path);
|
||||
return;
|
||||
}
|
||||
if (FS_MKF_CONFIG.write != NULL) {
|
||||
if (ioctl(ioh, IOCTL_WRITE, (uint64_t)FS_MKF_CONFIG.write, string_len(FS_MKF_CONFIG.write), 0) < 0) {
|
||||
if (fs_write(h, (const uint8_t *)FS_MKF_CONFIG.write, string_len(FS_MKF_CONFIG.write), 0) < 0) {
|
||||
uprintf("fs mkf: could not write to %s\n", path);
|
||||
}
|
||||
}
|
||||
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
|
||||
fs_closef(h);
|
||||
}
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
int showtree(char *root, int indent) {
|
||||
#define INDENT() for (size_t i = 0; i < indent; i++) uprintf(" ")
|
||||
|
||||
IoctlStat statbuf; ZERO(&statbuf);
|
||||
if (ioctl(IOCTL_NOHANDLE, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)root, 0) != E_OK) {
|
||||
FsStat statbuf; ZERO(&statbuf);
|
||||
if (fs_stat(root, &statbuf) != E_OK) {
|
||||
uprintf("fs: could not stat %s\n", root);
|
||||
return -1;
|
||||
}
|
||||
@ -18,16 +18,16 @@ int showtree(char *root, int indent) {
|
||||
}
|
||||
|
||||
|
||||
if (statbuf.type == IOCTLSTAT_FILE) {
|
||||
if (statbuf.type == FSSTAT_FILE) {
|
||||
return 0;
|
||||
}
|
||||
if (statbuf.type == IOCTLSTAT_DIR) {
|
||||
IoctlDirent *dirents = (IoctlDirent *)umalloc(statbuf.size * sizeof(*dirents));
|
||||
if (statbuf.type == FSSTAT_DIR) {
|
||||
FsDirent *dirents = (FsDirent *)umalloc(statbuf.size * sizeof(*dirents));
|
||||
|
||||
for (size_t i = 0; i < statbuf.size; i++) {
|
||||
ioctl(IOCTL_NOHANDLE, IOCTL_FETCHDIRENT, (uint64_t)root, (uint64_t)&dirents[i], i);
|
||||
fs_fetchdirent(root, &dirents[i], i);
|
||||
|
||||
IoctlDirent *dirent = &dirents[i];
|
||||
FsDirent *dirent = &dirents[i];
|
||||
|
||||
if (string_strcmp(dirent->name, ".") == 0 || string_strcmp(dirent->name, "..") == 0) {
|
||||
continue;
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user