proc: hack in special file descriptors

The previos commit broke executions of all program files due to a NULL
memory access when inserting special file descriptors. This will be
replaced when some sort of /dev fs is implemented
This commit is contained in:
Michael Shaw 2024-01-24 18:49:06 -05:00
commit e2ea205129
5 changed files with 28 additions and 11 deletions

View file

@ -16,7 +16,7 @@ typedef struct fs *(*vfs_init_t)(struct block_device *);
ssize_t vfs_write(struct file *file, void *buf, off_t off, size_t count)
{
/* TODO: implement */
if ((file->vnode.flags & VFS_VTYPE_MASK) == VFS_VNO_CHARDEV)
if (file->type == FTYPE_CHARDEV)
return -EBADF;
if ((file->vnode.flags & VFS_VTYPE_MASK) != VFS_VNO_REG)
@ -28,7 +28,7 @@ ssize_t vfs_write(struct file *file, void *buf, off_t off, size_t count)
ssize_t vfs_read(struct file *file, void *buf, off_t off, size_t count)
{
/* TODO: implement */
if ((file->vnode.flags & VFS_VTYPE_MASK) == VFS_VNO_CHARDEV)
if (file->type == FTYPE_CHARDEV)
return -EBADF;
/* TODO: implement */
@ -56,12 +56,16 @@ struct file *vfs_open(const char *pathname, int *err)
/* allocate a file */
struct file *file = slab_alloc(file_slab);
if (!file) {
kprintf(LOG_ERROR "Failed to allocate file descriptor\n");
kprintf(LOG_ERROR "Failed to allocate file struct\n");
return NULL;
}
memset(file, 0, sizeof(struct file));
/* terrible temporary hack */
if (pathname == NULL && (uintptr_t)err == 0x4)
return file;
/* find the file */
int result = rootfs->ops->open(rootfs, &file->vnode, pathname);