genode/repos/os/src/server/fs_log/log_file.h
Christian Helmuth 24b1f269be Remove Packet_ref from File_system::Packet_descriptor
The intention of Packet_ref was to allow clients to place opaque
references into the packet descriptor itself, which could be observed on
packet completion. Currently no component in our sources uses this
feature and beyond that it is questionable if it should be used at all:
If the server tampers with the ref the client may easily be confused
into observing an incorrect or invalid context. It seems better to
remove the opaque context from the descriptor and leave the actual
implementation to the client and its needs.
2015-09-30 12:20:37 +02:00

91 lines
2.0 KiB
C++

/*
* \brief File object shared between log sessions
* \author Emery Hemingway
* \date 2015-06-09
*/
/*
* Copyright (C) 2015 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 _FS_LOG__LOG_FILE_H_
#define _FS_LOG__LOG_FILE_H_
/* Genode includes */
#include <log_session/log_session.h>
#include <file_system_session/file_system_session.h>
namespace Fs_log {
using namespace Genode;
using namespace File_system;
class Log_file;
}
class Fs_log::Log_file : public List<Log_file>::Element
{
private:
char _dir_path[ MAX_PATH_LEN];
char _file_name[MAX_NAME_LEN];
File_system::Session &_fs;
File_handle _handle;
seek_off_t _offset;
public:
/**
* Constructor
*/
Log_file(File_system::Session &fs, File_handle handle,
char const *dir_path, char const *file_name,
seek_off_t offset)
:
_fs(fs), _handle(handle), _offset(offset)
{
strncpy(_dir_path, dir_path, sizeof(_dir_path));
strncpy(_file_name, file_name, sizeof(_file_name));
}
bool match(char const *dir, char const *filename) const
{
return
(strcmp(_dir_path, dir, MAX_PATH_LEN) == 0) &&
(strcmp(_file_name, filename, MAX_NAME_LEN) == 0);
}
/**
* Write a log message to the packet buffer.
*/
size_t write(char const *msg, size_t msg_len)
{
File_system::Session::Tx::Source &source = *_fs.tx();
File_system::Packet_descriptor raw_packet;
if (!source.ready_to_submit())
raw_packet = source.get_acked_packet();
else
raw_packet = source.alloc_packet(Log_session::String::MAX_SIZE);
File_system::Packet_descriptor
packet(raw_packet,
_handle, File_system::Packet_descriptor::WRITE,
msg_len, _offset);
_offset += msg_len;
char *buf = source.packet_content(packet);
memcpy(buf, msg, msg_len);
source.submit_packet(packet);
return msg_len;
}
};
#endif