ioctl() IOCTL_STAT command
This commit is contained in:
@ -10,7 +10,9 @@
|
||||
#include <sysdefs/ipcpipe.h>
|
||||
#include <sysdefs/ioctl.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
#include <dlmalloc/malloc.h>
|
||||
#include <errors.h>
|
||||
#include <util/util.h>
|
||||
|
||||
struct {
|
||||
char *modestr;
|
||||
@ -50,11 +52,31 @@ void process_cmd(char *cmdtext) {
|
||||
}
|
||||
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
||||
IoctlStat statbuf = ZERO(&statbuf);
|
||||
|
||||
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, 0, 0);
|
||||
if (statbuf.type != IOCTLSTAT_FILE) {
|
||||
LOG(LOG_ERR, "%s is not a file (%d)\n", filepath, statbuf.type);
|
||||
return;
|
||||
}
|
||||
uint8_t *buf = dlmalloc(statbuf.size);
|
||||
|
||||
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));
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
dlfree(buf);
|
||||
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
|
||||
}
|
||||
|
||||
void do_mode_interactive(void) {
|
||||
|
Reference in New Issue
Block a user