|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v4 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/{fd.c => stdio.c} | 87 ++++++++---------------------------
3 files changed, 24 insertions(+), 69 deletions(-)
copy lib/vfscore/{fd.c => stdio.c} (55%)
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 5b545c1..309cdcc 100644
--- a/lib/vfscore/fd.c
+++ b/lib/vfscore/fd.c
@@ -42,6 +42,8 @@
#define FDTABLE_MAX_FILES (sizeof(uint64_t) * 8)
+void init_stdio(void);
+
struct fdtable {
uint64_t bitmap;
uint32_t fd_start;
@@ -79,7 +81,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;
@@ -92,7 +93,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)))
@@ -110,4 +110,5 @@ __constructor static void fdtable_init(void)
/* reserve stdin, stdout and stderr */
fdtable.bitmap = 7;
+ init_stdio();
}
diff --git a/lib/vfscore/fd.c b/lib/vfscore/stdio.c
similarity index 55%
copy from lib/vfscore/fd.c
copy to lib/vfscore/stdio.c
index 5b545c1..c631f5f 100644
--- a/lib/vfscore/fd.c
+++ b/lib/vfscore/stdio.c
@@ -33,81 +33,34 @@
* THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
*/
-#include <string.h>
-#include <uk/essentials.h>
-#include <uk/arch/atomic.h>
-#include <uk/assert.h>
#include <vfscore/file.h>
-#include <uk/plat/lcpu.h>
+#include <uk/plat/console.h>
-#define FDTABLE_MAX_FILES (sizeof(uint64_t) * 8)
-
-struct fdtable {
- uint64_t bitmap;
- uint32_t fd_start;
- struct vfscore_file *files[FDTABLE_MAX_FILES];
-};
-struct fdtable fdtable;
-
-int vfscore_alloc_fd(void)
+/* One function for stderr and stdout */
+static ssize_t stdout_write(struct vfscore_file *vfscore_file, const void *buf,
+ size_t count)
{
- unsigned long flags;
- int ret;
-
- flags = ukplat_lcpu_save_irqf();
- ret = ukarch_find_lsbit(~fdtable.bitmap);
-
- if (!ret)
- goto exit;
-
- fdtable.bitmap |= (uint64_t) 1 << ret;
-
-exit:
- ukplat_lcpu_restore_irqf(flags);
- return ret;
-}
-
-void vfscore_put_fd(int fd)
-{
- UK_ASSERT(fd < (int) FDTABLE_MAX_FILES);
- /* Currently it is not allowed to free std(in|out|err) */
- UK_ASSERT(fd > 2);
-
- ukarch_test_and_clr_bit(fd, &fdtable.bitmap);
+ (void) vfscore_file;
+ return ukplat_coutk(buf, count);
}
-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;
- fdtable.files[fd] = file;
-}
-
-struct vfscore_file *vfscore_get_file(int fd)
-{
- unsigned long flags;
- struct vfscore_file *ret = NULL;
+static struct vfscore_fops stdout_fops = {
+ .write = stdout_write,
+};
- UK_ASSERT(fd < (int) FDTABLE_MAX_FILES);
- UK_ASSERT(fd > 2);
+static struct vfscore_file stdout_file = {
+ .fd = 1,
+ .fops = &stdout_fops,
+};
- flags = ukplat_lcpu_save_irqf();
- if (!(fdtable.bitmap & ((uint64_t) 1 << fd)))
- goto exit;
- ret = fdtable.files[fd];
+static struct vfscore_file stderr_file = {
+ .fd = 2,
+ .fops = &stdout_fops,
+};
-exit:
- ukplat_lcpu_restore_irqf(flags);
- return ret;
-}
-__constructor static void fdtable_init(void)
+void init_stdio(void)
{
- memset(&fdtable, 0, sizeof(fdtable));
-
- /* reserve stdin, stdout and stderr */
- fdtable.bitmap = 7;
+ 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 |