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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user