[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 21/22] lib/vfscore: re-implement stdio and enable new code
Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx> --- lib/vfscore/Config.uk | 1 + lib/vfscore/Makefile.uk | 9 ++++ lib/vfscore/exportsyms.uk | 26 +++++++++++ lib/vfscore/file.c | 61 +------------------------- lib/vfscore/include/vfscore/file.h | 1 - lib/vfscore/stdio.c | 70 ++++++++++++++++++------------ 6 files changed, 80 insertions(+), 88 deletions(-) diff --git a/lib/vfscore/Config.uk b/lib/vfscore/Config.uk index 49d6daa1..6cf6c63a 100644 --- a/lib/vfscore/Config.uk +++ b/lib/vfscore/Config.uk @@ -3,3 +3,4 @@ config LIBVFSCORE default n select LIBNOLIBC if !HAVE_LIBC select LIBUKDEBUG + select LIBUKLOCK diff --git a/lib/vfscore/Makefile.uk b/lib/vfscore/Makefile.uk index 06933d96..1fd35858 100644 --- a/lib/vfscore/Makefile.uk +++ b/lib/vfscore/Makefile.uk @@ -5,5 +5,14 @@ CINCLUDES-y += -I$(LIBVFSCORE_BASE)/include LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/fd.c LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/file.c LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/stdio.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/mount.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/vnode.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/dentry.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/syscalls.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/main.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/task.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/lookup.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/fops.c +LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/subr_uio.c EXTRA_LD_SCRIPT-$(CONFIG_LIBVFSCORE) += $(LIBVFSCORE_BASE)/extra.ld \ No newline at end of file diff --git a/lib/vfscore/exportsyms.uk b/lib/vfscore/exportsyms.uk index 9e229a11..50b62204 100644 --- a/lib/vfscore/exportsyms.uk +++ b/lib/vfscore/exportsyms.uk @@ -5,3 +5,29 @@ vfscore_get_file close write read +sys_mount +vfscore_nullop +vfscore_release_mp_dentries +vfscore_vget +vfscore_uiomove +vfscore_vop_nullop +vfscore_vop_einval +vfscore_vop_eperm +vfscore_vop_erofs +open +write +close +read +mkdir +fsync +fstat +stat +chmod +dup +dup2 +dup3 +vfscore_uiomove +sys_sync +vfscore_mount_dump +sys_umount +sys_umount2 diff --git a/lib/vfscore/file.c b/lib/vfscore/file.c index 0f6dfa93..e56f16dc 100644 --- a/lib/vfscore/file.c +++ b/lib/vfscore/file.c @@ -38,66 +38,7 @@ #include <uk/print.h> #include <vfscore/file.h> #include <uk/assert.h> -#include <uk/arch/atomic.h> - -int close(int fd) -{ - struct vfscore_file *file = vfscore_get_file(fd); - - if (!file) { - uk_pr_warn("no such file descriptor: %d\n", fd); - errno = EBADF; - return -1; - } - - if (!file->fops->close) { - errno = EIO; - return -1; - } - - return file->fops->close(file); -} - -ssize_t write(int fd, const void *buf, size_t count) -{ - struct vfscore_file *file = vfscore_get_file(fd); - - if (!file) { - uk_pr_warn("no such file descriptor: %d\n", fd); - errno = EBADF; - return -1; - } - - if (!file->fops->write) { - uk_pr_warn("file does not have write op: %d\n", fd); - errno = EINVAL; - return -1; - } - - return file->fops->write(file, buf, count); -} - -ssize_t read(int fd, void *buf, size_t count) -{ - struct vfscore_file *file = vfscore_get_file(fd); - - if (!file) { - uk_pr_warn("no such file descriptor: %d\n", fd); - errno = EBADF; - return -1; - } - - if (!file->fops->read) { - uk_pr_warn("file does not have read op: %d\n", fd); - errno = EINVAL; - return -1; - } - - return file->fops->read(file, buf, count); -} - -/* TODO: remove stub */ -#define vfs_close(fp) (0) +#include "vfs.h" int fdrop(struct vfscore_file *fp) { diff --git a/lib/vfscore/include/vfscore/file.h b/lib/vfscore/include/vfscore/file.h index 87d5975c..7f45ca78 100644 --- a/lib/vfscore/include/vfscore/file.h +++ b/lib/vfscore/include/vfscore/file.h @@ -59,7 +59,6 @@ struct vfscore_file { off_t f_offset; /* current position in file */ void *f_data; /* file descriptor specific data */ struct dentry *f_dentry; - const struct vfscore_fops *fops; }; int vfscore_alloc_fd(void); diff --git a/lib/vfscore/stdio.c b/lib/vfscore/stdio.c index 7d749442..5f15ef2a 100644 --- a/lib/vfscore/stdio.c +++ b/lib/vfscore/stdio.c @@ -42,18 +42,29 @@ #include <unistd.h> /* One function for stderr and stdout */ -static ssize_t stdout_write(struct vfscore_file *vfscore_file __unused, - const void *buf, size_t count) +static ssize_t stdio_write(struct vnode *vp __unused, + struct uio *uio, + int ioflag __unused) { - return ukplat_coutk(buf, count); + UK_ASSERT(!uio->uio_offset); + UK_ASSERT(uio->uio_iovcnt == 1); + return ukplat_coutk(uio->uio_iov->iov_base, uio->uio_iov->iov_len); } -static ssize_t stdin_read(struct vfscore_file *vfscore_file __unused, - void *_buf, size_t count) +static ssize_t stdio_read(struct vnode *vp __unused, + struct vfscore_file *file __unused, + struct uio *uio, + int ioflag __unused) { int bytes_read; - size_t bytes_total = 0; - char *buf = (char *)_buf; + size_t bytes_total = 0, count; + char *buf; + + UK_ASSERT(!uio->uio_offset); + UK_ASSERT(uio->uio_iovcnt == 1); + + buf = uio->uio_iov->iov_base; + count = uio->uio_iov->iov_len; do { while ((bytes_read = ukplat_cink(buf, @@ -64,8 +75,8 @@ static ssize_t stdin_read(struct vfscore_file *vfscore_file __unused, *(buf - 1) = *(buf - 1) == '\r' ? '\n' : *(buf - 1); - stdout_write(vfscore_file, (buf - bytes_read), - bytes_read); + /* Echo the input */ + ukplat_coutk(buf - bytes_read, bytes_read); bytes_total += bytes_read; } while (bytes_total < count && *(buf - 1) != '\n' @@ -74,33 +85,38 @@ static ssize_t stdin_read(struct vfscore_file *vfscore_file __unused, return bytes_total; } -static struct vfscore_fops stdin_fops = { - .read = stdin_read, -}; -static struct vfscore_fops stdout_fops = { - .write = stdout_write, +static struct vnops stdio_vnops = { + .vop_write = stdio_write, + .vop_read = stdio_read, }; -static struct vfscore_file stdin_file = { - .fd = 0, - .fops = &stdin_fops, +static struct vnode stdio_vnode = { + .v_ino = 1, + .v_op = &stdio_vnops, + .v_lock = UK_MUTEX_INITIALIZER(stdio_vnode.v_lock), + .v_refcnt = 1, }; -static struct vfscore_file stdout_file = { - .fd = 1, - .fops = &stdout_fops, +static struct dentry stdio_dentry = { + .d_vnode = &stdio_vnode, }; -static struct vfscore_file stderr_file = { - .fd = 2, - .fops = &stdout_fops, +static struct vfscore_file stdio_file = { + .fd = 1, + .f_flags = FWRITE | FREAD, + .f_dentry = &stdio_dentry, + /* reference count is 2 because close(0) is a valid + * operation. However it is not properly handled in the + * current implementation. */ + .f_count = 2, }; - void init_stdio(void) { - vfscore_install_fd(0, &stdin_file); - vfscore_install_fd(1, &stdout_file); - vfscore_install_fd(2, &stderr_file); + vfscore_install_fd(0, &stdio_file); + if (dup2(0, 1) != 1) + uk_pr_err("failed to dup to stdin\n"); + if (dup2(0, 2) != 2) + uk_pr_err("failed to dup to stderr\n"); } -- 2.19.2 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |