$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/isrlib))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/posix-environ))
+$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/posix-fd))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/posix-fdtab))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/posix-fdio))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/posix-eventfd))
--- /dev/null
+config LIBPOSIX_FD
+ bool "posix-fd: Open file descriptions"
+ select LIBUKFILE
+ select LIBUKLOCK
+ select LIBUKLOCK_MUTEX
--- /dev/null
+$(eval $(call addlib_s,libposix_fd,$(CONFIG_LIBPOSIX_FD)))
+
+CINCLUDES-$(CONFIG_LIBPOSIX_FD) += -I$(LIBPOSIX_FD_BASE)/include
+CXXINCLUDES-$(CONFIG_LIBPOSIX_FD) += -I$(LIBPOSIX_FD_BASE)/include
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+
+/* Common definitions pertaining to POSIX open file descriptions */
+
+#ifndef __UK_POSIX_FD_H__
+#define __UK_POSIX_FD_H__
+
+#include <fcntl.h>
+#include <sys/epoll.h>
+
+#include <uk/essentials.h>
+#include <uk/file.h>
+#include <uk/mutex.h>
+#include <uk/refcount.h>
+
+/* Open file description */
+struct uk_ofile {
+ const struct uk_file *file;
+ unsigned int mode;
+ __atomic refcnt;
+ off_t pos; /* Current file read/write offset position */
+ struct uk_mutex lock; /* Lock for modifying open file state */
+};
+
+/**
+ * Initialize an open file description with a refcount of 1.
+ *
+ * @param of Open file description to be initialized
+ * @param f File to reference
+ * @param mode Mode bits of open file description
+ */
+static inline
+void uk_ofile_init(struct uk_ofile *of,
+ const struct uk_file *f, unsigned int mode)
+{
+ uk_refcount_init(&of->refcnt, 1);
+ uk_mutex_init(&of->lock);
+ of->file = f;
+ of->mode = mode;
+ of->pos = 0;
+}
+
+
+/* Mode bits from fcntl.h that open files are interested in */
+#define UKFD_MODE_MASK \
+ (O_WRONLY|O_RDWR|O_NONBLOCK|O_APPEND|O_DIRECT|O_SYNC|O_DSYNC)
+
+/* Unikraft-specific mode bits, chosen to not overlap with any O_* flags */
+/* Open file is not seekable (e.g. for pipes, sockets & FIFOs) */
+#define UKFD_O_NOSEEK 010
+/* File I/O should not use the file locks (e.g. if driver handles them) */
+#define UKFD_O_NOIOLOCK 020
+
+/* Event sets */
+#define UKFD_POLL_ALWAYS (EPOLLERR|EPOLLHUP)
+#define UKFD_POLLIN (EPOLLIN|EPOLLRDNORM|EPOLLRDBAND)
+#define UKFD_POLLOUT (EPOLLOUT|EPOLLWRNORM|EPOLLWRBAND)
+
+#endif /* __UK_POSIX_FD_H__ */
bool "posix-fdio: File I/O and control"
select LIBUKATOMIC
select LIBUKFILE
+ select LIBPOSIX_FD
select LIBPOSIX_TIME
select LIBUKTIMECONV
select LIBPOSIX_FDTAB
+++ /dev/null
-/* SPDX-License-Identifier: BSD-3-Clause */
-/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
- * Licensed under the BSD-3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- */
-
-/* Common definitions pertaining to POSIX open file descriptions */
-
-#ifndef __UK_POSIX_FD_H__
-#define __UK_POSIX_FD_H__
-
-#include <fcntl.h>
-#include <sys/epoll.h>
-
-#include <uk/ofile.h>
-
-/* Mode bits from fcntl.h that open files are interested in */
-#define UKFD_MODE_MASK \
- (O_WRONLY|O_RDWR|O_NONBLOCK|O_APPEND|O_DIRECT|O_SYNC|O_DSYNC)
-
-/* Unikraft-specific mode bits, chosen to not overlap with any O_* flags */
-/* Open file is not seekable (e.g. for pipes, sockets & FIFOs) */
-#define UKFD_O_NOSEEK 010
-/* File I/O should not use the file locks (e.g. if driver handles them) */
-#define UKFD_O_NOIOLOCK 020
-
-/* Event sets */
-#define UKFD_POLL_ALWAYS (EPOLLERR|EPOLLHUP)
-#define UKFD_POLLIN (EPOLLIN|EPOLLRDNORM|EPOLLRDBAND)
-#define UKFD_POLLOUT (EPOLLOUT|EPOLLWRNORM|EPOLLWRBAND)
-
-#endif /* __UK_POSIX_FD_H__ */
bool "posix-fdtab: File descriptor table"
select LIBUKATOMIC
select LIBUKFILE
+ select LIBPOSIX_FD
if LIBPOSIX_FDTAB
config LIBPOSIX_FDTAB_MAXFDS
# Hidden, selected by core components when needed
config LIBPOSIX_FDTAB_LEGACY_SHIM
bool
- default n
endif
}
/* struct uk_ofile allocation & refcounting */
-static inline struct uk_ofile *ofile_new(struct uk_fdtab *tab)
+static inline struct uk_ofile *ofile_new(struct uk_fdtab *tab,
+ const struct uk_file *f,
+ unsigned int mode)
{
struct uk_ofile *of = uk_malloc(tab->alloc, sizeof(*of));
if (of)
- uk_ofile_init(of);
+ uk_ofile_init(of, f, mode);
return of;
}
static inline void ofile_del(struct uk_fdtab *tab, struct uk_ofile *of)
UK_ASSERT(f);
tab = _active_tab();
- of = ofile_new(tab);
+ of = ofile_new(tab, f, mode & ~O_CLOEXEC);
if (!of)
return -ENOMEM;
- /* Take refs on file & ofile */
uk_file_acquire(f);
- ofile_acq(of);
- /* Prepare open file */
- of->file = f;
- of->pos = 0;
- of->mode = mode & ~O_CLOEXEC;
/* Place the file in fdtab */
flags = (mode & O_CLOEXEC) ? UK_FDTAB_CLOEXEC : 0;
entry = fdtab_encode(of, flags);
#define __UK_POSIX_FDTAB_H__
#include <uk/config.h>
-#include <uk/ofile.h>
+#include <uk/posix-fd.h>
#define UK_LIBPOSIX_FDTAB_INIT_PRIO UK_PRIO_EARLIEST
#define UK_FD_MAX INT_MAX
select LIBUKDEBUG
select LIBUKALLOC
select LIBUKFILE
+ select LIBPOSIX_FD
select LIBPOSIX_FDIO
help
This microlibrary allows other microlibraries to register a
bool "ukfile: Common support for files"
select LIBUKATOMIC
select LIBUKLOCK
- select LIBUKLOCK_MUTEX
select LIBUKLOCK_RWLOCK
select LIBUKSCHED
select LIBNOLIBC if !HAVE_LIBC
config LIBUKFILE_FINALIZERS
bool
+ select LIBUKLOCK_MUTEX
+++ /dev/null
-/* SPDX-License-Identifier: BSD-3-Clause */
-/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
- * Licensed under the BSD-3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- */
-
-/* Open file description */
-
-#ifndef __UKFILE_OFILE_H__
-#define __UKFILE_OFILE_H__
-
-#include <uk/essentials.h>
-#include <uk/file.h>
-#include <uk/mutex.h>
-
-struct uk_ofile {
- const struct uk_file *file;
- unsigned int mode;
- __atomic refcnt;
- off_t pos;
- struct uk_mutex lock; /* Lock for modifying open file state */
-};
-
-static inline
-void uk_ofile_init(struct uk_ofile *of)
-{
- uk_refcount_init(&of->refcnt, 0);
- uk_mutex_init(&of->lock);
-}
-
-#endif /* __UKFILE_OFILE_H__ */