fs: make buf on write const
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
debd580784
commit
171ea49050
5 changed files with 49 additions and 9 deletions
|
|
@ -6,24 +6,64 @@
|
|||
#include <lib/errno.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
static struct file *check_fd(int fd)
|
||||
{
|
||||
struct proc *proc = get_cur_proc();
|
||||
|
||||
if (fd >= proc->fd_array_size)
|
||||
return NULL;
|
||||
|
||||
struct file *f = proc->fdt + fd;
|
||||
if (!f->dirent)
|
||||
return NULL;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static ssize_t do_read(dirent_t *dirent, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return vfs_read(dirent->inode, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
static ssize_t do_write(dirent_t *dirent, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return vfs_write(dirent->inode, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
static ssize_t sys_pread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return -ENOSYS;
|
||||
struct file *f = check_fd(fd);
|
||||
if (!f)
|
||||
return -EBADF;
|
||||
|
||||
return do_read(f->dirent, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
static ssize_t sys_read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
return -ENOSYS;
|
||||
struct file *f = check_fd(fd);
|
||||
if (!f)
|
||||
return -EBADF;
|
||||
|
||||
return do_read(f->dirent, buf, nbyte, f->offset);
|
||||
}
|
||||
|
||||
static ssize_t sys_pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return -ENOSYS;
|
||||
struct file *f = check_fd(fd);
|
||||
if (!f)
|
||||
return -EBADF;
|
||||
|
||||
return do_write(f->dirent, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
static ssize_t sys_write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
return -ENOSYS;
|
||||
struct file *f = check_fd(fd);
|
||||
if (!f)
|
||||
return -EBADF;
|
||||
|
||||
return do_write(f->dirent, buf, nbyte, f->offset);
|
||||
}
|
||||
|
||||
static int sys_open(const char *path, int flags)
|
||||
|
|
|
|||
Loading…
Reference in a new issue