mirror of
https://github.com/drasko/codezero.git
synced 2026-03-29 08:19:03 +02:00
mkdir almost working.
Added changes to pathname lookup code so that the root directory special case is handled properly.
This commit is contained in:
@@ -93,7 +93,7 @@ int memfs_file_read_write(struct vnode *v, unsigned int pfn,
|
||||
} else { /* Write-specific operations */
|
||||
/* Is the write beyond current file size? */
|
||||
if (v->size < ((pfn + npages) * (blocksize))) {
|
||||
unsigned long diff = pfn + npages - __pfn(v->size);
|
||||
unsigned long pagediff = pfn + npages - __pfn(v->size);
|
||||
unsigned long holes;
|
||||
|
||||
/*
|
||||
@@ -102,19 +102,18 @@ int memfs_file_read_write(struct vnode *v, unsigned int pfn,
|
||||
*/
|
||||
if (pfn > __pfn(v->size))
|
||||
holes = pfn - __pfn(v->size);
|
||||
else
|
||||
holes = 0;
|
||||
|
||||
/* Allocate new blocks */
|
||||
for (int x = 0; x < diff; x++)
|
||||
if (!(i->block[__pfn(v->size) + x] = memfs_alloc_block(memfs_sb)))
|
||||
for (int x = 0; x < pagediff; x++)
|
||||
if (!(i->block[__pfn(v->size) + x] =
|
||||
memfs_alloc_block(v->sb->fs_super)))
|
||||
return -ENOSPC;
|
||||
|
||||
/* Zero out the holes. FIXME: How do we zero out non-page-aligned bytes?` */
|
||||
for (int x = 0; x < holes; x++)
|
||||
memset(i->block[__pfn(v->size) + x], 0, blocksize);
|
||||
|
||||
/* Update size and the inode. FIXME: How do we handle non page-aligned size */
|
||||
v->size = (pfn + npages) * blocksize;
|
||||
v->sb->ops->write_vnode(v->sb, v);
|
||||
}
|
||||
|
||||
/* Copy the data from page buffer into inode blocks */
|
||||
|
||||
@@ -135,8 +135,13 @@ int memfs_init_rootdir(struct superblock *sb)
|
||||
if (!(d = vfs_alloc_dentry()))
|
||||
return -ENOMEM;
|
||||
|
||||
/* Initialise it. NOTE: On root, parent is itself */
|
||||
strncpy(d->name, "/", VFS_DNAME_MAX);
|
||||
/*
|
||||
* Initialise it.
|
||||
* NOTE: On root, parent is itself.
|
||||
* NOTE: Root has no name. This helps since splitpath
|
||||
* cuts out the '/' and "" is left for root name search.
|
||||
*/
|
||||
strncpy(d->name, VFS_STR_ROOTDIR, VFS_DNAME_MAX);
|
||||
d->ops = generic_dentry_operations;
|
||||
d->parent = d;
|
||||
d->vnode = v;
|
||||
|
||||
@@ -228,8 +228,6 @@ int memfs_vnode_mknod(struct vnode *v, char *dirname, unsigned int mode)
|
||||
BUG_ON(parent->vref.next != &v->dentries);
|
||||
BUG_ON(!vfs_isdir(v));
|
||||
|
||||
printf("Parent name: %s\n", parent->name);
|
||||
|
||||
/* Populate the children */
|
||||
if ((err = v->ops.readdir(v)) < 0)
|
||||
return err;
|
||||
@@ -263,8 +261,9 @@ int memfs_vnode_mknod(struct vnode *v, char *dirname, unsigned int mode)
|
||||
/* Write the updated directory buffer back to disk block */
|
||||
v->fops.write(v, 0, 1, v->dirbuf.buffer);
|
||||
|
||||
/* Update parent vnode */
|
||||
/* Update parent vnode size */
|
||||
v->size += sizeof(*memfsd);
|
||||
v->sb->ops->write_vnode(v->sb, v);
|
||||
|
||||
/* Allocate a new vfs dentry */
|
||||
if (!(newd = vfs_alloc_dentry()))
|
||||
@@ -382,7 +381,10 @@ int memfs_vnode_readdir(struct vnode *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Copies fs-specific dirent data into user buffer in
|
||||
* generic struct dirent format.
|
||||
*/
|
||||
int memfs_vnode_filldir(void *userbuf, struct vnode *v, int count)
|
||||
{
|
||||
int nbytes;
|
||||
@@ -412,6 +414,7 @@ struct vnode_ops memfs_vnode_operations = {
|
||||
.readdir = memfs_vnode_readdir,
|
||||
.filldir = memfs_vnode_filldir,
|
||||
.mknod = memfs_vnode_mknod,
|
||||
.lookup = generic_vnode_lookup,
|
||||
};
|
||||
|
||||
struct superblock_ops memfs_superblock_operations = {
|
||||
|
||||
Reference in New Issue
Block a user