mirror of
https://github.com/drasko/codezero.git
synced 2026-02-27 17:23:13 +01:00
Added sys_stat, sys_fstat and their libposix glue.
This commit is contained in:
@@ -62,4 +62,21 @@
|
||||
#define O_NOATIME 01000000
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
/*
|
||||
* Internal codezero-specific stat structure.
|
||||
* This is converted to posix stat in userspace
|
||||
*/
|
||||
struct kstat {
|
||||
u64 vnum;
|
||||
u32 mode;
|
||||
int links;
|
||||
u16 uid;
|
||||
u16 gid;
|
||||
u64 size;
|
||||
int blksize;
|
||||
u64 atime;
|
||||
u64 mtime;
|
||||
u64 ctime;
|
||||
};
|
||||
|
||||
#endif /* __FS0_STAT_H__ */
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#define __TASKNAME__ __VFSNAME__
|
||||
|
||||
#define TASK_OFILES_MAX 32
|
||||
#define TASK_FILES_MAX 32
|
||||
|
||||
/* Thread control block, fs0 portion */
|
||||
struct tcb {
|
||||
@@ -18,7 +18,7 @@ struct tcb {
|
||||
unsigned long utcb_address;
|
||||
int utcb_mapped; /* Set if we mapped their utcb */
|
||||
struct list_head list;
|
||||
int fd[TASK_OFILES_MAX];
|
||||
int fd[TASK_FILES_MAX];
|
||||
struct id_pool *fdpool;
|
||||
struct vnode *curdir;
|
||||
struct vnode *rootdir;
|
||||
|
||||
@@ -221,6 +221,85 @@ int sys_chdir(l4id_t sender, const char *pathname)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fill_kstat(struct vnode *v, struct kstat *ks)
|
||||
{
|
||||
ks->vnum = (u64)v->vnum;
|
||||
ks->mode = v->mode;
|
||||
ks->links = v->links;
|
||||
ks->uid = v->owner & 0xFFFF;
|
||||
ks->gid = (v->owner >> 16) & 0xFFFF;
|
||||
ks->size = v->size;
|
||||
ks->blksize = v->sb->blocksize;
|
||||
ks->atime = v->atime;
|
||||
ks->mtime = v->mtime;
|
||||
ks->ctime = v->ctime;
|
||||
}
|
||||
|
||||
int sys_fstat(l4id_t sender, int fd, void *statbuf)
|
||||
{
|
||||
struct vnode *v;
|
||||
struct tcb *task;
|
||||
unsigned long vnum;
|
||||
int retval;
|
||||
|
||||
/* Get the task */
|
||||
BUG_ON(!(task = find_task(sender)));
|
||||
|
||||
/* Get the vnum */
|
||||
if (fd < 0 || fd > TASK_FILES_MAX) {
|
||||
l4_ipc_return(-EINVAL);
|
||||
return 0;
|
||||
}
|
||||
vnum = task->fd[fd];
|
||||
|
||||
/* Lookup vnode */
|
||||
if (!(v = vfs_lookup_byvnum(vfs_root.pivot->sb, vnum))) {
|
||||
retval = -EINVAL; /* No such vnode */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fill in the c0-style stat structure */
|
||||
fill_kstat(v, statbuf);
|
||||
|
||||
l4_ipc_return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns codezero-style stat structure which in turn is
|
||||
* converted to posix style stat structure via the libposix
|
||||
* library in userspace.
|
||||
*/
|
||||
int sys_stat(l4id_t sender, const char *pathname, void *statbuf)
|
||||
{
|
||||
struct vnode *v;
|
||||
struct tcb *task;
|
||||
struct pathdata *pdata;
|
||||
|
||||
/* Get the task */
|
||||
BUG_ON(!(task = find_task(sender)));
|
||||
|
||||
/* Parse path data */
|
||||
if (IS_ERR(pdata = pathdata_parse(pathname,
|
||||
alloca(strlen(pathname) + 1),
|
||||
task))) {
|
||||
l4_ipc_return((int)pdata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get the vnode */
|
||||
if (IS_ERR(v = vfs_lookup_bypath(pdata))) {
|
||||
l4_ipc_return((int)v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fill in the c0-style stat structure */
|
||||
fill_kstat(v, statbuf);
|
||||
|
||||
l4_ipc_return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note this can be solely called by the pager and is not the posix read call.
|
||||
* That call is in the pager. This merely supplies the pages the pager needs
|
||||
@@ -387,7 +466,7 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fd < 0 || fd > TASK_OFILES_MAX) {
|
||||
if (fd < 0 || fd > TASK_FILES_MAX) {
|
||||
l4_ipc_return(-EBADF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ struct tcb *create_tcb(void)
|
||||
if (!(t = kmalloc(sizeof(*t))))
|
||||
return PTR_ERR(-ENOMEM);
|
||||
|
||||
t->fdpool = id_pool_new_init(TASK_OFILES_MAX);
|
||||
t->fdpool = id_pool_new_init(TASK_FILES_MAX);
|
||||
INIT_LIST_HEAD(&t->list);
|
||||
list_add_tail(&t->list, &tcb_head.list);
|
||||
tcb_head.total++;
|
||||
|
||||
Reference in New Issue
Block a user