File-system interface, ram_fs, libc-fs
This patch introduces the file-system-session interface, provides an
implementation of this interface in the form of an in-memory file
system, and enables the libc to use the new file-system facility.
The new interface resides in 'os/include/file_system_session/'. It
uses synchronous RPC calls for functions referring to directory
and meta-data handling. For transferring payload from/to files, the
packet-stream interface is used. I envision that the asynchronous design
of the packet-stream interface fits well will the block-session
interface. Compared to Unix-like file-system APIs, Genode's file-system
session interface is much simpler. In particular, it does not support
per-file permissions. On Genode, we facilitate binding policy (such as
write-permission) is sessions rather than individual file objects.
As a reference implementation of the new interface, there is the
new 'ram_fs' service at 'os/src/server/ram_fs'. It stores sparse
files in memory. At the startup, 'ram_fs' is able to populate the
file-system content with directories and ROM modules as specified
in its configuration.
To enable libc-using programs to access the new file-system interface,
there is the new libc plugin at 'libports/src/lib/libc-fs'. Using this
plugin, files stored on a native Genode file system can be accessed
using the traditional POSIX file API.
To see how the three parts described above fit together, the test
case at 'libports/run/libc_fs' can be taken as reference. It reuses
the original 'libc_ffat' test to exercise several file operations
on a RAM file-system using the libc API.
:Known limitations:
The current state should be regarded as work in progress. In particular
the error handling is not complete yet. Not all of the session functions
return the proper exceptions in the event of an error. I plan to
successively refine the interface while advancing the file-system
implementations. Also the support for truncating files and symlink
handling are not yet implemented.
Furthermore, there is much room for optimization, in particular for the
handling of directory entries. Currently, we communicate only one dir
entry at a time, which is bad when traversing large trees. However, I
decided to focus on functionality first and defer optimizations (such as
batching dir entries) to a later stage.
The current implementation does not handle file modification times at
all, which may be a severe limitation for tools that depend on this
information such as GNU make. Support for time will be added after we
have revisited Genode's timer-session interface (issue #1).
Fixes #54
Fixes #171
2012-04-11 13:46:33 +00:00
|
|
|
/*
|
|
|
|
* \brief Connection to file-system service
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2012-04-05
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-02-12 12:12:27 +00:00
|
|
|
* Copyright (C) 2012-2018 Genode Labs GmbH
|
File-system interface, ram_fs, libc-fs
This patch introduces the file-system-session interface, provides an
implementation of this interface in the form of an in-memory file
system, and enables the libc to use the new file-system facility.
The new interface resides in 'os/include/file_system_session/'. It
uses synchronous RPC calls for functions referring to directory
and meta-data handling. For transferring payload from/to files, the
packet-stream interface is used. I envision that the asynchronous design
of the packet-stream interface fits well will the block-session
interface. Compared to Unix-like file-system APIs, Genode's file-system
session interface is much simpler. In particular, it does not support
per-file permissions. On Genode, we facilitate binding policy (such as
write-permission) is sessions rather than individual file objects.
As a reference implementation of the new interface, there is the
new 'ram_fs' service at 'os/src/server/ram_fs'. It stores sparse
files in memory. At the startup, 'ram_fs' is able to populate the
file-system content with directories and ROM modules as specified
in its configuration.
To enable libc-using programs to access the new file-system interface,
there is the new libc plugin at 'libports/src/lib/libc-fs'. Using this
plugin, files stored on a native Genode file system can be accessed
using the traditional POSIX file API.
To see how the three parts described above fit together, the test
case at 'libports/run/libc_fs' can be taken as reference. It reuses
the original 'libc_ffat' test to exercise several file operations
on a RAM file-system using the libc API.
:Known limitations:
The current state should be regarded as work in progress. In particular
the error handling is not complete yet. Not all of the session functions
return the proper exceptions in the event of an error. I plan to
successively refine the interface while advancing the file-system
implementations. Also the support for truncating files and symlink
handling are not yet implemented.
Furthermore, there is much room for optimization, in particular for the
handling of directory entries. Currently, we communicate only one dir
entry at a time, which is bad when traversing large trees. However, I
decided to focus on functionality first and defer optimizations (such as
batching dir entries) to a later stage.
The current implementation does not handle file modification times at
all, which may be a severe limitation for tools that depend on this
information such as GNU make. Support for time will be added after we
have revisited Genode's timer-session interface (issue #1).
Fixes #54
Fixes #171
2012-04-11 13:46:33 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
File-system interface, ram_fs, libc-fs
This patch introduces the file-system-session interface, provides an
implementation of this interface in the form of an in-memory file
system, and enables the libc to use the new file-system facility.
The new interface resides in 'os/include/file_system_session/'. It
uses synchronous RPC calls for functions referring to directory
and meta-data handling. For transferring payload from/to files, the
packet-stream interface is used. I envision that the asynchronous design
of the packet-stream interface fits well will the block-session
interface. Compared to Unix-like file-system APIs, Genode's file-system
session interface is much simpler. In particular, it does not support
per-file permissions. On Genode, we facilitate binding policy (such as
write-permission) is sessions rather than individual file objects.
As a reference implementation of the new interface, there is the
new 'ram_fs' service at 'os/src/server/ram_fs'. It stores sparse
files in memory. At the startup, 'ram_fs' is able to populate the
file-system content with directories and ROM modules as specified
in its configuration.
To enable libc-using programs to access the new file-system interface,
there is the new libc plugin at 'libports/src/lib/libc-fs'. Using this
plugin, files stored on a native Genode file system can be accessed
using the traditional POSIX file API.
To see how the three parts described above fit together, the test
case at 'libports/run/libc_fs' can be taken as reference. It reuses
the original 'libc_ffat' test to exercise several file operations
on a RAM file-system using the libc API.
:Known limitations:
The current state should be regarded as work in progress. In particular
the error handling is not complete yet. Not all of the session functions
return the proper exceptions in the event of an error. I plan to
successively refine the interface while advancing the file-system
implementations. Also the support for truncating files and symlink
handling are not yet implemented.
Furthermore, there is much room for optimization, in particular for the
handling of directory entries. Currently, we communicate only one dir
entry at a time, which is bad when traversing large trees. However, I
decided to focus on functionality first and defer optimizations (such as
batching dir entries) to a later stage.
The current implementation does not handle file modification times at
all, which may be a severe limitation for tools that depend on this
information such as GNU make. Support for time will be added after we
have revisited Genode's timer-session interface (issue #1).
Fixes #54
Fixes #171
2012-04-11 13:46:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__FILE_SYSTEM_SESSION__CONNECTION_H_
|
|
|
|
#define _INCLUDE__FILE_SYSTEM_SESSION__CONNECTION_H_
|
|
|
|
|
|
|
|
#include <file_system_session/client.h>
|
|
|
|
#include <base/connection.h>
|
|
|
|
#include <base/allocator.h>
|
2016-03-17 15:29:27 +00:00
|
|
|
#include <util/retry.h>
|
File-system interface, ram_fs, libc-fs
This patch introduces the file-system-session interface, provides an
implementation of this interface in the form of an in-memory file
system, and enables the libc to use the new file-system facility.
The new interface resides in 'os/include/file_system_session/'. It
uses synchronous RPC calls for functions referring to directory
and meta-data handling. For transferring payload from/to files, the
packet-stream interface is used. I envision that the asynchronous design
of the packet-stream interface fits well will the block-session
interface. Compared to Unix-like file-system APIs, Genode's file-system
session interface is much simpler. In particular, it does not support
per-file permissions. On Genode, we facilitate binding policy (such as
write-permission) is sessions rather than individual file objects.
As a reference implementation of the new interface, there is the
new 'ram_fs' service at 'os/src/server/ram_fs'. It stores sparse
files in memory. At the startup, 'ram_fs' is able to populate the
file-system content with directories and ROM modules as specified
in its configuration.
To enable libc-using programs to access the new file-system interface,
there is the new libc plugin at 'libports/src/lib/libc-fs'. Using this
plugin, files stored on a native Genode file system can be accessed
using the traditional POSIX file API.
To see how the three parts described above fit together, the test
case at 'libports/run/libc_fs' can be taken as reference. It reuses
the original 'libc_ffat' test to exercise several file operations
on a RAM file-system using the libc API.
:Known limitations:
The current state should be regarded as work in progress. In particular
the error handling is not complete yet. Not all of the session functions
return the proper exceptions in the event of an error. I plan to
successively refine the interface while advancing the file-system
implementations. Also the support for truncating files and symlink
handling are not yet implemented.
Furthermore, there is much room for optimization, in particular for the
handling of directory entries. Currently, we communicate only one dir
entry at a time, which is bad when traversing large trees. However, I
decided to focus on functionality first and defer optimizations (such as
batching dir entries) to a later stage.
The current implementation does not handle file modification times at
all, which may be a severe limitation for tools that depend on this
information such as GNU make. Support for time will be added after we
have revisited Genode's timer-session interface (issue #1).
Fixes #54
Fixes #171
2012-04-11 13:46:33 +00:00
|
|
|
|
2015-10-07 16:31:52 +00:00
|
|
|
namespace File_system {
|
|
|
|
|
2016-03-17 15:29:27 +00:00
|
|
|
struct Connection_base;
|
2015-10-07 16:31:52 +00:00
|
|
|
struct Connection;
|
|
|
|
|
|
|
|
/* recommended packet transmission buffer size */
|
|
|
|
enum { DEFAULT_TX_BUF_SIZE = 128*1024 };
|
|
|
|
}
|
File-system interface, ram_fs, libc-fs
This patch introduces the file-system-session interface, provides an
implementation of this interface in the form of an in-memory file
system, and enables the libc to use the new file-system facility.
The new interface resides in 'os/include/file_system_session/'. It
uses synchronous RPC calls for functions referring to directory
and meta-data handling. For transferring payload from/to files, the
packet-stream interface is used. I envision that the asynchronous design
of the packet-stream interface fits well will the block-session
interface. Compared to Unix-like file-system APIs, Genode's file-system
session interface is much simpler. In particular, it does not support
per-file permissions. On Genode, we facilitate binding policy (such as
write-permission) is sessions rather than individual file objects.
As a reference implementation of the new interface, there is the
new 'ram_fs' service at 'os/src/server/ram_fs'. It stores sparse
files in memory. At the startup, 'ram_fs' is able to populate the
file-system content with directories and ROM modules as specified
in its configuration.
To enable libc-using programs to access the new file-system interface,
there is the new libc plugin at 'libports/src/lib/libc-fs'. Using this
plugin, files stored on a native Genode file system can be accessed
using the traditional POSIX file API.
To see how the three parts described above fit together, the test
case at 'libports/run/libc_fs' can be taken as reference. It reuses
the original 'libc_ffat' test to exercise several file operations
on a RAM file-system using the libc API.
:Known limitations:
The current state should be regarded as work in progress. In particular
the error handling is not complete yet. Not all of the session functions
return the proper exceptions in the event of an error. I plan to
successively refine the interface while advancing the file-system
implementations. Also the support for truncating files and symlink
handling are not yet implemented.
Furthermore, there is much room for optimization, in particular for the
handling of directory entries. Currently, we communicate only one dir
entry at a time, which is bad when traversing large trees. However, I
decided to focus on functionality first and defer optimizations (such as
batching dir entries) to a later stage.
The current implementation does not handle file modification times at
all, which may be a severe limitation for tools that depend on this
information such as GNU make. Support for time will be added after we
have revisited Genode's timer-session interface (issue #1).
Fixes #54
Fixes #171
2012-04-11 13:46:33 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2016-03-17 15:29:27 +00:00
|
|
|
/**
|
|
|
|
* The base implementation of a File_system connection
|
|
|
|
*/
|
2019-01-30 16:27:46 +00:00
|
|
|
struct File_system::Connection : Genode::Connection<Session>, Session_client
|
2015-03-04 20:12:14 +00:00
|
|
|
{
|
2016-05-20 09:00:53 +00:00
|
|
|
/**
|
2019-01-30 16:27:46 +00:00
|
|
|
* Extend session quota on demand while calling an RPC function
|
2016-05-20 09:00:53 +00:00
|
|
|
*
|
|
|
|
* \noapi
|
|
|
|
*/
|
2019-01-30 16:27:46 +00:00
|
|
|
template <typename FUNC>
|
|
|
|
auto _retry(FUNC func) -> decltype(func())
|
2016-05-10 15:24:51 +00:00
|
|
|
{
|
2019-01-30 16:27:46 +00:00
|
|
|
enum { UPGRADE_ATTEMPTS = ~0U };
|
|
|
|
return Genode::retry<Out_of_ram>(
|
|
|
|
[&] () {
|
|
|
|
return Genode::retry<Out_of_caps>(
|
|
|
|
[&] () { return func(); },
|
|
|
|
[&] () { File_system::Connection::upgrade_caps(2); },
|
|
|
|
UPGRADE_ATTEMPTS);
|
|
|
|
},
|
|
|
|
[&] () { File_system::Connection::upgrade_ram(8*1024); },
|
|
|
|
UPGRADE_ATTEMPTS);
|
2016-05-10 15:24:51 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param tx_buffer_alloc allocator used for managing the
|
|
|
|
* transmission buffer
|
2016-03-17 15:29:27 +00:00
|
|
|
* \param label session label
|
|
|
|
* \param root root directory of session
|
2022-02-11 14:11:03 +00:00
|
|
|
* \param writeable session is writeable
|
2016-05-10 15:24:51 +00:00
|
|
|
* \param tx_buf_size size of transmission buffer in bytes
|
|
|
|
*/
|
2019-01-30 16:27:46 +00:00
|
|
|
Connection(Genode::Env &env,
|
|
|
|
Genode::Range_allocator &tx_block_alloc,
|
|
|
|
char const *label = "",
|
|
|
|
char const *root = "/",
|
|
|
|
bool writeable = true,
|
|
|
|
size_t tx_buf_size = DEFAULT_TX_BUF_SIZE)
|
2016-05-10 15:24:51 +00:00
|
|
|
:
|
2019-01-30 16:27:46 +00:00
|
|
|
Genode::Connection<Session>(env,
|
|
|
|
session(env.parent(),
|
|
|
|
"ram_quota=%ld, "
|
|
|
|
"cap_quota=%ld, "
|
|
|
|
"tx_buf_size=%ld, "
|
|
|
|
"label=\"%s\", "
|
|
|
|
"root=\"%s\", "
|
|
|
|
"writeable=%d",
|
|
|
|
8*1024*sizeof(long) + tx_buf_size,
|
|
|
|
CAP_QUOTA,
|
|
|
|
tx_buf_size,
|
|
|
|
label, root, writeable)),
|
2016-07-22 08:05:52 +00:00
|
|
|
Session_client(cap(), tx_block_alloc, env.rm())
|
2016-05-10 15:24:51 +00:00
|
|
|
{ }
|
|
|
|
|
2016-03-17 15:29:27 +00:00
|
|
|
Dir_handle dir(Path const &path, bool create) override
|
|
|
|
{
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 20:03:22 +00:00
|
|
|
return _retry([&] () {
|
|
|
|
return Session_client::dir(path, create); });
|
2016-03-17 15:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
File_handle file(Dir_handle dir, Name const &name, Mode mode, bool create) override
|
|
|
|
{
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 20:03:22 +00:00
|
|
|
return _retry([&] () {
|
|
|
|
return Session_client::file(dir, name, mode, create); });
|
2016-03-17 15:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Symlink_handle symlink(Dir_handle dir, Name const &name, bool create) override
|
|
|
|
{
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 20:03:22 +00:00
|
|
|
return _retry([&] () {
|
|
|
|
return Session_client::symlink(dir, name, create); });
|
2016-03-17 15:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node_handle node(Path const &path) override
|
|
|
|
{
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 20:03:22 +00:00
|
|
|
return _retry([&] () {
|
|
|
|
return Session_client::node(path); });
|
2016-03-17 15:29:27 +00:00
|
|
|
}
|
2018-02-12 12:12:27 +00:00
|
|
|
|
|
|
|
Watch_handle watch(Path const &path) override
|
|
|
|
{
|
|
|
|
return _retry([&] () {
|
|
|
|
return Session_client::watch(path); });
|
|
|
|
}
|
2016-03-17 15:29:27 +00:00
|
|
|
};
|
|
|
|
|
File-system interface, ram_fs, libc-fs
This patch introduces the file-system-session interface, provides an
implementation of this interface in the form of an in-memory file
system, and enables the libc to use the new file-system facility.
The new interface resides in 'os/include/file_system_session/'. It
uses synchronous RPC calls for functions referring to directory
and meta-data handling. For transferring payload from/to files, the
packet-stream interface is used. I envision that the asynchronous design
of the packet-stream interface fits well will the block-session
interface. Compared to Unix-like file-system APIs, Genode's file-system
session interface is much simpler. In particular, it does not support
per-file permissions. On Genode, we facilitate binding policy (such as
write-permission) is sessions rather than individual file objects.
As a reference implementation of the new interface, there is the
new 'ram_fs' service at 'os/src/server/ram_fs'. It stores sparse
files in memory. At the startup, 'ram_fs' is able to populate the
file-system content with directories and ROM modules as specified
in its configuration.
To enable libc-using programs to access the new file-system interface,
there is the new libc plugin at 'libports/src/lib/libc-fs'. Using this
plugin, files stored on a native Genode file system can be accessed
using the traditional POSIX file API.
To see how the three parts described above fit together, the test
case at 'libports/run/libc_fs' can be taken as reference. It reuses
the original 'libc_ffat' test to exercise several file operations
on a RAM file-system using the libc API.
:Known limitations:
The current state should be regarded as work in progress. In particular
the error handling is not complete yet. Not all of the session functions
return the proper exceptions in the event of an error. I plan to
successively refine the interface while advancing the file-system
implementations. Also the support for truncating files and symlink
handling are not yet implemented.
Furthermore, there is much room for optimization, in particular for the
handling of directory entries. Currently, we communicate only one dir
entry at a time, which is bad when traversing large trees. However, I
decided to focus on functionality first and defer optimizations (such as
batching dir entries) to a later stage.
The current implementation does not handle file modification times at
all, which may be a severe limitation for tools that depend on this
information such as GNU make. Support for time will be added after we
have revisited Genode's timer-session interface (issue #1).
Fixes #54
Fixes #171
2012-04-11 13:46:33 +00:00
|
|
|
#endif /* _INCLUDE__FILE_SYSTEM_SESSION__CONNECTION_H_ */
|