2016-05-25 15:47:22 +02:00
|
|
|
/*
|
2017-02-01 11:28:15 +01:00
|
|
|
* \brief Libc plugin for using a process-local virtual file system
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Emery Hemingway
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2014-04-09
|
2016-05-25 15:47:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-03-25 15:41:43 +01:00
|
|
|
* Copyright (C) 2014-2019 Genode Labs GmbH
|
2016-05-25 15:47:22 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2016-05-25 15:47:22 +02:00
|
|
|
*/
|
|
|
|
|
libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.
The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.
The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.
There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.
Issue #3497
2019-09-18 20:19:10 +02:00
|
|
|
#ifndef _LIBC__INTERNAL__VFS_PLUGIN_H_
|
|
|
|
#define _LIBC__INTERNAL__VFS_PLUGIN_H_
|
2016-05-25 15:47:22 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
2017-01-03 14:33:55 +01:00
|
|
|
#include <libc/component.h>
|
libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.
The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.
The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.
There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.
Issue #3497
2019-09-18 20:19:10 +02:00
|
|
|
#include <vfs/file_system.h>
|
2016-05-25 15:47:22 +02:00
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* libc plugin interface */
|
|
|
|
#include <libc-plugin/plugin.h>
|
|
|
|
#include <libc-plugin/fd_alloc.h>
|
|
|
|
|
libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.
The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.
The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.
There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.
Issue #3497
2019-09-18 20:19:10 +02:00
|
|
|
/* libc-internal includes */
|
|
|
|
#include <internal/errno.h>
|
2017-12-13 00:32:49 +01:00
|
|
|
|
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
namespace Libc { class Vfs_plugin; }
|
|
|
|
|
|
|
|
|
|
|
|
class Libc::Vfs_plugin : public Libc::Plugin
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-03-25 15:41:43 +01:00
|
|
|
Genode::Allocator &_alloc;
|
|
|
|
Vfs::File_system &_root_dir;
|
|
|
|
Vfs::Io_response_handler &_response_handler;
|
2016-05-25 15:47:22 +02:00
|
|
|
|
2017-12-13 00:32:49 +01:00
|
|
|
/**
|
|
|
|
* Sync a handle and propagate errors
|
|
|
|
*/
|
2019-06-06 12:27:46 +02:00
|
|
|
int _vfs_sync(Vfs::Vfs_handle&);
|
2017-08-15 20:51:53 +02:00
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
public:
|
|
|
|
|
2019-03-25 15:41:43 +01:00
|
|
|
Vfs_plugin(Libc::Env &env,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
Vfs::Io_response_handler &handler)
|
2016-05-25 15:47:22 +02:00
|
|
|
:
|
2019-03-25 15:41:43 +01:00
|
|
|
_alloc(alloc), _root_dir(env.vfs()), _response_handler(handler)
|
2019-08-16 19:04:04 +02:00
|
|
|
{ }
|
2016-05-25 15:47:22 +02:00
|
|
|
|
2017-02-01 11:28:15 +01:00
|
|
|
~Vfs_plugin() final { }
|
2016-05-25 15:47:22 +02:00
|
|
|
|
2019-08-16 19:04:04 +02:00
|
|
|
bool root_dir_has_dirents() const { return _root_dir.num_dirent("/") > 0; }
|
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
bool supports_access(const char *, int) override { return true; }
|
|
|
|
bool supports_mkdir(const char *, mode_t) override { return true; }
|
|
|
|
bool supports_open(const char *, int) override { return true; }
|
2019-04-26 12:47:33 +02:00
|
|
|
bool supports_poll() override { return true; }
|
2016-05-25 15:47:22 +02:00
|
|
|
bool supports_readlink(const char *, char *, ::size_t) override { return true; }
|
|
|
|
bool supports_rename(const char *, const char *) override { return true; }
|
|
|
|
bool supports_rmdir(const char *) override { return true; }
|
|
|
|
bool supports_stat(const char *) override { return true; }
|
|
|
|
bool supports_symlink(const char *, const char *) override { return true; }
|
|
|
|
bool supports_unlink(const char *) override { return true; }
|
|
|
|
bool supports_mmap() override { return true; }
|
|
|
|
|
2017-02-01 11:28:15 +01:00
|
|
|
bool supports_select(int nfds,
|
|
|
|
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
|
|
|
struct timeval *timeout) override;
|
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
Libc::File_descriptor *open(const char *, int, int libc_fd);
|
|
|
|
|
|
|
|
Libc::File_descriptor *open(const char *path, int flags) override
|
|
|
|
{
|
|
|
|
return open(path, flags, Libc::ANY_FD);
|
|
|
|
}
|
|
|
|
|
|
|
|
int access(char const *, int) override;
|
|
|
|
int close(Libc::File_descriptor *) override;
|
|
|
|
int dup2(Libc::File_descriptor *, Libc::File_descriptor *) override;
|
|
|
|
int fcntl(Libc::File_descriptor *, int, long) override;
|
|
|
|
int fstat(Libc::File_descriptor *, struct stat *) override;
|
|
|
|
int fstatfs(Libc::File_descriptor *, struct statfs *) override;
|
|
|
|
int fsync(Libc::File_descriptor *fd) override;
|
|
|
|
int ftruncate(Libc::File_descriptor *, ::off_t) override;
|
|
|
|
ssize_t getdirentries(Libc::File_descriptor *, char *, ::size_t , ::off_t *) override;
|
|
|
|
int ioctl(Libc::File_descriptor *, int , char *) override;
|
|
|
|
::off_t lseek(Libc::File_descriptor *fd, ::off_t offset, int whence) override;
|
|
|
|
int mkdir(const char *, mode_t) override;
|
2019-04-26 12:47:33 +02:00
|
|
|
bool poll(File_descriptor &fdo, struct pollfd &pfd) override;
|
2016-05-25 15:47:22 +02:00
|
|
|
ssize_t read(Libc::File_descriptor *, void *, ::size_t) override;
|
|
|
|
ssize_t readlink(const char *, char *, ::size_t) override;
|
|
|
|
int rename(const char *, const char *) override;
|
|
|
|
int rmdir(const char *) override;
|
|
|
|
int stat(const char *, struct stat *) override;
|
|
|
|
int symlink(const char *, const char *) override;
|
|
|
|
int unlink(const char *) override;
|
|
|
|
ssize_t write(Libc::File_descriptor *, const void *, ::size_t ) override;
|
|
|
|
void *mmap(void *, ::size_t, int, int, Libc::File_descriptor *, ::off_t) override;
|
|
|
|
int munmap(void *, ::size_t) override;
|
2017-02-01 11:28:15 +01:00
|
|
|
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) override;
|
2016-05-25 15:47:22 +02:00
|
|
|
};
|
|
|
|
|
libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.
The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.
The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.
There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.
Issue #3497
2019-09-18 20:19:10 +02:00
|
|
|
#endif /* _LIBC__INTERNAL__VFS_PLUGIN_H_ */
|