ioctl() IOCTL_STAT use path instead of already open io handle
This commit is contained in:
@ -134,25 +134,29 @@ int32_t SYSCALL5(sys_ioctl, ioh1, cmd1, arg1, arg2, arg3) {
|
|||||||
ret = vobj->read(vobj, buffer, len, off);
|
ret = vobj->read(vobj, buffer, len, off);
|
||||||
} break;
|
} break;
|
||||||
case IOCTL_STAT: {
|
case IOCTL_STAT: {
|
||||||
if (ioh >= PROC_VFSHANDLES_MAX) {
|
const char *opath = (const char *)arg2;
|
||||||
|
|
||||||
|
if (opath == NULL) {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_acquire(&PROCS.spinlock);
|
char mp[IOCTL_MP_MAX];
|
||||||
Proc *proc = PROCS.current;
|
char path[IOCTL_PATH_MAX];
|
||||||
spinlock_release(&PROCS.spinlock);
|
|
||||||
|
|
||||||
VfsObj *vobj = proc->vobjs[ioh];
|
path_parse(opath, mp, path);
|
||||||
|
|
||||||
|
VfsObj *vobj = vfs_open(mp, path, IOCTL_F_READ);
|
||||||
if (vobj == NULL) {
|
if (vobj == NULL) {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_NOENTRY;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
VfsStat stat1;
|
VfsStat stat1;
|
||||||
ret = vobj->stat(vobj, &stat1);
|
ret = vobj->stat(vobj, &stat1);
|
||||||
|
|
||||||
|
vfs_close(vobj);
|
||||||
|
|
||||||
IoctlStat *iostat = (IoctlStat *)arg1;
|
IoctlStat *iostat = (IoctlStat *)arg1;
|
||||||
if (iostat == NULL) {
|
if (iostat == NULL) {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
|
@ -12,6 +12,7 @@ enum {
|
|||||||
IOCTL_READ = 2,
|
IOCTL_READ = 2,
|
||||||
IOCTL_STAT = 3,
|
IOCTL_STAT = 3,
|
||||||
IOCTL_WRITE = 4,
|
IOCTL_WRITE = 4,
|
||||||
|
IOCTL_FETCHDIRENT = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -30,6 +31,11 @@ typedef struct IoctlStat {
|
|||||||
int32_t type;
|
int32_t type;
|
||||||
} IoctlStat;
|
} IoctlStat;
|
||||||
|
|
||||||
|
typedef struct IoctlDirent {
|
||||||
|
IoctlStat stat;
|
||||||
|
char name[0x100];
|
||||||
|
} IoctlDirent;
|
||||||
|
|
||||||
typedef int32_t IOH;
|
typedef int32_t IOH;
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_IOCTL_H_
|
#endif // SHARE_SYSDEFS_IOCTL_H_
|
||||||
|
@ -18,7 +18,7 @@ void fs_fetch(void) {
|
|||||||
|
|
||||||
IoctlStat statbuf; ZERO(&statbuf);
|
IoctlStat statbuf; ZERO(&statbuf);
|
||||||
|
|
||||||
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, 0, 0);
|
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)path, 0);
|
||||||
if (statbuf.type == IOCTLSTAT_FILE) {
|
if (statbuf.type == IOCTLSTAT_FILE) {
|
||||||
uint8_t *buf = umalloc(statbuf.size+1);
|
uint8_t *buf = umalloc(statbuf.size+1);
|
||||||
string_memset(buf, 0, statbuf.size+1);
|
string_memset(buf, 0, statbuf.size+1);
|
||||||
@ -31,5 +31,8 @@ void fs_fetch(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uprintf("%s", buf);
|
uprintf("%s", buf);
|
||||||
|
ufree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ void do_file(char *filepath) {
|
|||||||
|
|
||||||
IoctlStat statbuf; ZERO(&statbuf);
|
IoctlStat statbuf; ZERO(&statbuf);
|
||||||
|
|
||||||
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, 0, 0);
|
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, (uint64_t)filepath, 0);
|
||||||
if (statbuf.type != IOCTLSTAT_FILE) {
|
if (statbuf.type != IOCTLSTAT_FILE) {
|
||||||
LOG(LOG_ERR, "%s is not a file (%d)\n", filepath, statbuf.type);
|
LOG(LOG_ERR, "%s is not a file (%d)\n", filepath, statbuf.type);
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user