mirror of
https://github.com/drasko/codezero.git
synced 2026-01-19 06:13:16 +01:00
More progress on parsing elf files. Fixes to memfs file read/write
Increased inode block pointers to 40. The current maximum allowed (and checked). Updates to file size after every file write ensures subsequent writes can correctly operate using updated file size information (i.e. not try to add more pages that are already present). We cannot do this inside write() because directory writes rely on byte-granularity updates on file buffers, whereas file updates are by page-granularity (currently).
This commit is contained in:
@@ -121,6 +121,7 @@ int memfs_file_read_write(struct vnode *v, unsigned int pfn,
|
||||
for (int x = pfn, bufpage = 0; x < pfn + npages; x++, bufpage++)
|
||||
memcpy(i->block[x], ((void *)buf) + (bufpage * blocksize), blocksize);
|
||||
}
|
||||
|
||||
return (int)(npages * blocksize);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ int pager_open_bypath(struct tcb *pager, char *pathname)
|
||||
struct vnode *v;
|
||||
int retval;
|
||||
|
||||
// printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||
if (pager->tid != PAGER_TID)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -400,6 +400,8 @@ int pager_sys_write(struct tcb *pager, unsigned long vnum, unsigned long f_offse
|
||||
unsigned long npages, void *pagebuf)
|
||||
{
|
||||
struct vnode *v;
|
||||
int ret;
|
||||
int fwrite_end;
|
||||
|
||||
// printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||
|
||||
@@ -417,12 +419,21 @@ int pager_sys_write(struct tcb *pager, unsigned long vnum, unsigned long f_offse
|
||||
printf("%s/%s: Writing to vnode %lu, at pgoff 0x%x, %d pages, buf at 0x%x\n",
|
||||
__TASKNAME__, __FUNCTION__, vnum, f_offset, npages, pagebuf);
|
||||
|
||||
if ((ret = v->fops.write(v, f_offset, npages, pagebuf)) < 0)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* If the file is extended, write silently extends it.
|
||||
* But we expect an explicit pager_update_stats from the
|
||||
* pager to update the new file size on the vnode.
|
||||
* We update the extended size here. Otherwise subsequent write's
|
||||
* may fail by relying on wrong file size.
|
||||
*/
|
||||
return v->fops.write(v, f_offset, npages, pagebuf);
|
||||
fwrite_end = __pfn_to_addr(f_offset) + ret;
|
||||
if (v->size < fwrite_end) {
|
||||
v->size = fwrite_end;
|
||||
v->sb->ops->write_vnode(v->sb, v);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user