[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v5 2/2] lib/vfscore: implement fops for std(out|err)
Normally printf-alike functions are writing to the file 1 or 2. This patch provides necessary file operations for it to work Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx> --- lib/vfscore/Makefile.uk | 1 + lib/vfscore/fd.c | 5 ++-- lib/vfscore/stdio.c | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 lib/vfscore/stdio.c diff --git a/lib/vfscore/Makefile.uk b/lib/vfscore/Makefile.uk index fa56c8e..9ed6b6f 100644 --- a/lib/vfscore/Makefile.uk +++ b/lib/vfscore/Makefile.uk @@ -4,3 +4,4 @@ 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 diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c index 799339a..865a37a 100644 --- a/lib/vfscore/fd.c +++ b/lib/vfscore/fd.c @@ -43,6 +43,8 @@ #define FDTABLE_MAX_FILES (sizeof(uint64_t) * 8) +void init_stdio(void); + struct fdtable { uint64_t bitmap; uint32_t fd_start; @@ -82,7 +84,6 @@ void vfscore_put_fd(int fd) void vfscore_install_fd(int fd, struct vfscore_file *file) { UK_ASSERT(fd < (int) FDTABLE_MAX_FILES); - UK_ASSERT(fd > 2); UK_ASSERT(file); file->fd = fd; @@ -95,7 +96,6 @@ struct vfscore_file *vfscore_get_file(int fd) struct vfscore_file *ret = NULL; UK_ASSERT(fd < (int) FDTABLE_MAX_FILES); - UK_ASSERT(fd > 2); flags = ukplat_lcpu_save_irqf(); if (!(fdtable.bitmap & ((uint64_t) 1 << fd))) @@ -113,4 +113,5 @@ __constructor static void fdtable_init(void) /* reserve stdin, stdout and stderr */ fdtable.bitmap = 7; + init_stdio(); } diff --git a/lib/vfscore/stdio.c b/lib/vfscore/stdio.c new file mode 100644 index 0000000..c631f5f --- /dev/null +++ b/lib/vfscore/stdio.c @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Yuri Volchkov <yuri.volchkov@xxxxxxxxx> + * + * + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#include <vfscore/file.h> +#include <uk/plat/console.h> + +/* One function for stderr and stdout */ +static ssize_t stdout_write(struct vfscore_file *vfscore_file, const void *buf, + size_t count) +{ + (void) vfscore_file; + return ukplat_coutk(buf, count); +} + +static struct vfscore_fops stdout_fops = { + .write = stdout_write, +}; + +static struct vfscore_file stdout_file = { + .fd = 1, + .fops = &stdout_fops, +}; + +static struct vfscore_file stderr_file = { + .fd = 2, + .fops = &stdout_fops, +}; + + +void init_stdio(void) +{ + vfscore_install_fd(1, &stdout_file); + vfscore_install_fd(2, &stderr_file); +} -- 2.17.0 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |