genode/os/include/file_system_session/client.h
Norman Feske ae1d0c04ae 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-05-17 20:33:53 +02:00

107 lines
2.3 KiB
C++

/*
* \brief Client-side file-system session interface
* \author Norman Feske
* \date 2012-04-05
*/
/*
* Copyright (C) 2012 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__FILE_SYSTEM_SESSION__CLIENT_H_
#define _INCLUDE__FILE_SYSTEM_SESSION__CLIENT_H_
#include <base/rpc_client.h>
#include <file_system_session/capability.h>
#include <packet_stream_tx/client.h>
namespace File_system {
class Session_client : public Rpc_client<Session>
{
private:
Packet_stream_tx::Client<Tx> _tx;
public:
/**
* Constructor
*
* \param session session capability
* \param tx_buffer_alloc allocator used for managing the
* transmission buffer
*/
Session_client(Session_capability session,
Range_allocator &tx_buffer_alloc)
:
Rpc_client<Session>(session),
_tx(call<Rpc_tx_cap>(), &tx_buffer_alloc)
{ }
/***********************************
** File-system session interface **
***********************************/
Tx::Source *tx() { return _tx.source(); }
File_handle file(Dir_handle dir, Name const &name, Mode mode, bool create)
{
return call<Rpc_file>(dir, name, mode, create);
}
Symlink_handle symlink(Dir_handle dir, Name const &name, bool create)
{
return call<Rpc_symlink>(dir, name, create);
}
Dir_handle dir(Path const &path, bool create)
{
return call<Rpc_dir>(path, create);
}
Node_handle node(Path const &path)
{
return call<Rpc_node>(path);
}
void close(Node_handle node)
{
call<Rpc_close>(node);
}
Status status(Node_handle node)
{
return call<Rpc_status>(node);
}
void control(Node_handle node, Control control)
{
call<Rpc_control>(node, control);
}
void unlink(Dir_handle dir, Name const &name)
{
call<Rpc_unlink>(dir, name);
}
void truncate(File_handle file, file_size_t size)
{
call<Rpc_truncate>(file, size);
}
void move(Dir_handle from_dir, Name const &from_name,
Dir_handle to_dir, Name const &to_name)
{
call<Rpc_move>(from_dir, from_name, to_dir, to_name);
}
};
}
#endif /* _INCLUDE__FILE_SYSTEM_SESSION__CLIENT_H_ */