mirror of
https://github.com/drasko/codezero.git
synced 2026-02-12 09:53:16 +01:00
Seem to have fixed dirbuf allocation.
Dirbuf allocation was broken, fixed it. Added more comments on reading directories. Issues: fs0 ought to check buf address for sys_readdir(). Currently test0 is passing an area on its stack and fs0 is writing the data to its own address space (i.e. an area on its own stack.)
This commit is contained in:
@@ -52,11 +52,12 @@ int memfs_write_block(struct vnode *v, int blknum, void *buf)
|
||||
* this use, its meant for retrieving an unknown inode under the vnode with valid vnum.
|
||||
* here we already have the inode.
|
||||
*/
|
||||
int memfs_file_read_write(struct vnode *v, unsigned long pfn,
|
||||
unsigned long npages, void *buf, int wr)
|
||||
int memfs_file_read_write(struct vnode *v, unsigned int pfn,
|
||||
unsigned int npages, void *buf, int wr)
|
||||
{
|
||||
struct memfs_inode *i;
|
||||
struct memfs_superblock *memfs_sb;
|
||||
unsigned int start, end, count;
|
||||
u32 blocksize;
|
||||
|
||||
/* Don't support different block and page sizes for now */
|
||||
@@ -79,17 +80,16 @@ int memfs_file_read_write(struct vnode *v, unsigned long pfn,
|
||||
|
||||
/* Read-specific operations */
|
||||
if (!wr) {
|
||||
/* Check if read is beyond EOF */
|
||||
if ((pfn + npages) > __pfn(v->size)) {
|
||||
printf("%s: Trying to read beyond end of file: %x-%x\n",
|
||||
__FUNCTION__, pfn, pfn + npages);
|
||||
return -EINVAL; /* Same error that posix llseek returns */
|
||||
}
|
||||
/* Find read boundaries from expected range and file's current range */
|
||||
start = pfn < __pfn(v->size) ? pfn : __pfn(v->size);
|
||||
end = pfn + npages < __pfn(v->size) ? pfn + npages : __pfn(v->size);
|
||||
count = end - start;
|
||||
|
||||
/* Copy the data from inode blocks into page buffer */
|
||||
for (int x = pfn, bufpage = 0; x < pfn + npages; x++, bufpage++)
|
||||
for (int x = start, bufpage = 0; x < end; x++, bufpage++)
|
||||
memcpy(((void *)buf) + (bufpage * blocksize),
|
||||
&i->block[x], blocksize);
|
||||
return (int)(count * blocksize);
|
||||
} else { /* Write-specific operations */
|
||||
/* Is the write beyond current file size? */
|
||||
if (v->size < ((pfn + npages) * (blocksize))) {
|
||||
@@ -121,8 +121,7 @@ int memfs_file_read_write(struct vnode *v, unsigned long pfn,
|
||||
for (int x = pfn, bufpage = 0; x < pfn + npages; x++, bufpage++)
|
||||
memcpy(i->block[x], ((void *)buf) + (bufpage * blocksize), blocksize);
|
||||
}
|
||||
|
||||
return npages * blocksize;
|
||||
return (int)(npages * blocksize);
|
||||
}
|
||||
|
||||
int memfs_file_write(struct vnode *v, unsigned long pfn, unsigned long npages, void *buf)
|
||||
|
||||
@@ -127,6 +127,7 @@ struct vnode *memfs_alloc_vnode(struct superblock *sb)
|
||||
/* Associate memfs-specific fields with vnode */
|
||||
v->ops = memfs_vnode_operations;
|
||||
v->fops = memfs_file_operations;
|
||||
v->sb = sb;
|
||||
|
||||
/* Return the vnode */
|
||||
return v;
|
||||
@@ -315,7 +316,10 @@ int memfs_vnode_readdir(struct vnode *v)
|
||||
return 0;
|
||||
|
||||
/* This is as big as a page */
|
||||
v->dirbuf.buffer = vfs_alloc_dirpage();
|
||||
if (IS_ERR(v->dirbuf.buffer = vfs_alloc_dirpage(v))) {
|
||||
printf("%s: Could not allocate dirbuf.\n", __FUNCTION__);
|
||||
return (int)v->dirbuf.buffer;
|
||||
}
|
||||
v->dirbuf.npages = 1;
|
||||
|
||||
/*
|
||||
|
||||
@@ -277,6 +277,7 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
if (count < dirent_size)
|
||||
return 0;
|
||||
|
||||
printf("%s: Filling in . (curdir)\n", __TASKNAME__);
|
||||
fill_dirent(buf, v->vnum, nbytes, ".");
|
||||
nbytes += dirent_size;
|
||||
buf += dirent_size;
|
||||
@@ -285,11 +286,13 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
if (count < dirent_size)
|
||||
return 0;
|
||||
|
||||
printf("%s: Filling in .. (pardir)\n", __TASKNAME__);
|
||||
fill_dirent(buf, d->parent->vnode->vnum, nbytes, "..");
|
||||
nbytes += dirent_size;
|
||||
buf += dirent_size;
|
||||
count -= dirent_size;
|
||||
|
||||
printf("%s: Filling in other dir contents\n", __TASKNAME__);
|
||||
/* Copy fs-specific dir to buf in struct dirent format */
|
||||
if ((total = v->ops.filldir(buf, v, count)) < 0) {
|
||||
l4_ipc_return(total);
|
||||
|
||||
Reference in New Issue
Block a user