genode/repos/os/src/lib/vfs/log_file_system.h

98 lines
2.3 KiB
C
Raw Normal View History

2014-04-12 00:05:57 +02:00
/*
* \brief LOG file system
* \author Norman Feske
* \date 2014-04-11
*/
/*
* Copyright (C) 2014-2016 Genode Labs GmbH
2014-04-12 00:05:57 +02:00
*
* 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__VFS__LOG_FILE_SYSTEM_H_
#define _INCLUDE__VFS__LOG_FILE_SYSTEM_H_
#include <log_session/connection.h>
#include <vfs/single_file_system.h>
#include <util/reconstructible.h>
2014-04-12 00:05:57 +02:00
namespace Vfs { class Log_file_system; }
class Vfs::Log_file_system : public Single_file_system
{
private:
typedef Genode::String<64> Label;
Label _label;
Genode::Constructible<Genode::Log_connection> _log_connection;
Genode::Constructible<Genode::Log_session_client> _log_client;
Genode::Log_session & _log_session(Genode::Env &env)
{
if (_label.valid()) {
_log_connection.construct(env, _label);
return *_log_connection;
} else {
_log_client.construct(
Genode::reinterpret_cap_cast<Genode::Log_session>
(env.parent().session_cap(Genode::Parent::Env::log())));
return *_log_client;
}
}
Genode::Log_session &_log;
2014-04-12 00:05:57 +02:00
public:
Log_file_system(Genode::Env &env,
Genode::Allocator&,
Genode::Xml_node config,
Io_response_handler &)
2014-04-12 00:05:57 +02:00
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_label(config.attribute_value("label", Label())),
_log(_log_session(env))
2014-04-12 00:05:57 +02:00
{ }
static const char *name() { return "log"; }
/********************************
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *src, file_size count,
file_size &out_count) override
2014-04-12 00:05:57 +02:00
{
out_count = count;
/* count does not include the trailing '\0' */
while (count > 0) {
char tmp[Genode::Log_session::MAX_STRING_LEN];
2014-04-12 00:05:57 +02:00
int const curr_count = min(count, sizeof(tmp) - 1);
memcpy(tmp, src, curr_count);
2014-04-12 00:05:57 +02:00
tmp[curr_count > 0 ? curr_count : 0] = 0;
_log.write(tmp);
count -= curr_count;
src += curr_count;
}
return WRITE_OK;
}
Read_result read(Vfs_handle *, char *, file_size,
file_size &out_count) override
2014-04-12 00:05:57 +02:00
{
out_count = 0;
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return false; }
2014-04-12 00:05:57 +02:00
};
#endif /* _INCLUDE__VFS__LOG_FILE_SYSTEM_H_ */