mirror of
https://github.com/drasko/codezero.git
synced 2026-10-01 09:39:27 +02:00
incomplete changes for sys_write/sys_close
This commit is contained in:
@@ -254,6 +254,10 @@ int memfs_vnode_mknod(struct vnode *v, char *dirname, unsigned int mode)
|
|||||||
strncpy((char *)memfsd->name, dirname, MEMFS_DNAME_MAX);
|
strncpy((char *)memfsd->name, dirname, MEMFS_DNAME_MAX);
|
||||||
memfsd->name[MEMFS_DNAME_MAX - 1] = '\0';
|
memfsd->name[MEMFS_DNAME_MAX - 1] = '\0';
|
||||||
|
|
||||||
|
BUG(); /* FIXME: Fix this issue. */
|
||||||
|
/* Write the updated directory buffer back to disk */
|
||||||
|
v->fops.write(v, 0, 1, v->dirbuf.buffer);
|
||||||
|
|
||||||
/* Update parent vnode */
|
/* Update parent vnode */
|
||||||
v->size += sizeof(*memfsd);
|
v->size += sizeof(*memfsd);
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,19 @@ int sys_open(l4id_t sender, const char *pathname, int flags, unsigned int mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sys_close(l4id_t sender, int fd)
|
||||||
|
{
|
||||||
|
struct vnode *v;
|
||||||
|
|
||||||
|
/* Get the task */
|
||||||
|
BUG_ON(!(task = find_task(sender)));
|
||||||
|
|
||||||
|
/* Lookup vnode */
|
||||||
|
if (!(v = vfs_lookup_byvnum(vfs_root.pivot->sb, vnum)))
|
||||||
|
return -EINVAL; /* No such vnode */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int sys_mkdir(l4id_t sender, const char *pathname, unsigned int mode)
|
int sys_mkdir(l4id_t sender, const char *pathname, unsigned int mode)
|
||||||
{
|
{
|
||||||
struct tcb *task;
|
struct tcb *task;
|
||||||
|
|||||||
+10
-2
@@ -59,16 +59,24 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum)
|
|||||||
*/
|
*/
|
||||||
struct vnode *vfs_lookup_bypath(struct tcb *task, char *path)
|
struct vnode *vfs_lookup_bypath(struct tcb *task, char *path)
|
||||||
{
|
{
|
||||||
/* If it's the root or current dir, we already got it. */
|
struct vnode *vnstart;
|
||||||
|
|
||||||
|
/* Is it the root or current directory? If so, we already got it. */
|
||||||
if (!strcmp(path, "/"))
|
if (!strcmp(path, "/"))
|
||||||
return task->rootdir;
|
return task->rootdir;
|
||||||
if (!strcmp(path, "."))
|
if (!strcmp(path, "."))
|
||||||
return task->curdir;
|
return task->curdir;
|
||||||
|
|
||||||
|
/* Do we start from root or curdir? */
|
||||||
|
if (path[0] == '/')
|
||||||
|
vnstart = task->rootdir;
|
||||||
|
else
|
||||||
|
vnstart = task->curdir;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This does vfs cache + fs lookup.
|
* This does vfs cache + fs lookup.
|
||||||
*/
|
*/
|
||||||
return generic_vnode_lookup(task->rootdir, path);
|
return generic_vnode_lookup(vnstart, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfs_mount_root(struct superblock *sb)
|
int vfs_mount_root(struct superblock *sb)
|
||||||
|
|||||||
+24
-5
@@ -145,8 +145,8 @@ struct page *find_page(struct vm_file *f, unsigned long pfn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This reads-in a range of pages from a file just like a page fault,
|
* This reads-in a range of pages from a file and populates the page cache
|
||||||
* but its not in the page fault path.
|
* just like a page fault, but its not in the page fault path.
|
||||||
*/
|
*/
|
||||||
int read_file_pages(struct vm_file *vmfile, unsigned long pfn_start,
|
int read_file_pages(struct vm_file *vmfile, unsigned long pfn_start,
|
||||||
unsigned long pfn_end)
|
unsigned long pfn_end)
|
||||||
@@ -192,8 +192,8 @@ int sys_read(l4id_t sender, int fd, void *buf, int count)
|
|||||||
{
|
{
|
||||||
unsigned long foff_pfn_start, foff_pfn_end;
|
unsigned long foff_pfn_start, foff_pfn_end;
|
||||||
struct vm_file *vmfile;
|
struct vm_file *vmfile;
|
||||||
struct tcb *t;
|
|
||||||
unsigned long cursor;
|
unsigned long cursor;
|
||||||
|
struct tcb *t;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
BUG_ON(!(t = find_task(sender)));
|
BUG_ON(!(t = find_task(sender)));
|
||||||
@@ -215,9 +215,8 @@ int sys_read(l4id_t sender, int fd, void *buf, int count)
|
|||||||
* FIXME: If vmfiles are mapped contiguously on mm0, then these reads
|
* FIXME: If vmfiles are mapped contiguously on mm0, then these reads
|
||||||
* can be implemented as a straightforward copy as below.
|
* can be implemented as a straightforward copy as below.
|
||||||
*
|
*
|
||||||
* The problem is that in-memrory file pages are usually non-contiguous.
|
* The problem is that in-memory file pages are usually non-contiguous.
|
||||||
* memcpy(buf, (void *)(vmfile->base + cursor), count);
|
* memcpy(buf, (void *)(vmfile->base + cursor), count);
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -225,6 +224,26 @@ int sys_read(l4id_t sender, int fd, void *buf, int count)
|
|||||||
|
|
||||||
int sys_write(l4id_t sender, int fd, void *buf, int count)
|
int sys_write(l4id_t sender, int fd, void *buf, int count)
|
||||||
{
|
{
|
||||||
|
unsigned long foff_pfn_start, foff_pfn_end;
|
||||||
|
struct vm_file *vmfile;
|
||||||
|
unsigned long cursor;
|
||||||
|
struct tcb *t;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
BUG_ON(!(t = find_task(sender)));
|
||||||
|
|
||||||
|
/* TODO: Check user buffer and count validity */
|
||||||
|
if (fd < 0 || fd > TASK_OFILES_MAX)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
vmfile = t->fd[fd].vmfile;
|
||||||
|
cursor = t->fd[fd].cursor;
|
||||||
|
|
||||||
|
foff_pfn_start = __pfn(cursor);
|
||||||
|
foff_pfn_end = __pfn(page_align_up(cursor + count));
|
||||||
|
|
||||||
|
if ((err = write_file_pages(vmfile, foff_pfn_start, foff_pfn_end) < 0))
|
||||||
|
return err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user