2012-10-04 13:46:09 +00:00
|
|
|
/*
|
|
|
|
* \brief Stdio filesystem
|
|
|
|
* \author Josef Soentgen
|
|
|
|
* \date 2012-08-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
2012-10-04 13:46:09 +00: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 _NOUX__STDIO_FILE_SYSTEM_H_
|
|
|
|
#define _NOUX__STDIO_FILE_SYSTEM_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <util/string.h>
|
2014-04-07 14:15:40 +00:00
|
|
|
#include <vfs/single_file_system.h>
|
2012-10-04 13:46:09 +00:00
|
|
|
|
|
|
|
/* Noux includes */
|
|
|
|
#include <noux_session/sysio.h>
|
|
|
|
#include "terminal_connection.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Noux {
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
class Stdio_file_system : public Vfs::Single_file_system
|
2012-10-04 13:46:09 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Terminal::Session_client *_terminal;
|
|
|
|
bool _echo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
Stdio_file_system(Xml_node config)
|
2012-10-04 13:46:09 +00:00
|
|
|
:
|
2014-04-07 14:15:40 +00:00
|
|
|
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
|
|
|
|
_terminal(terminal()),
|
2012-10-04 13:46:09 +00:00
|
|
|
_echo(true)
|
2014-04-07 14:15:40 +00:00
|
|
|
{ }
|
2012-10-04 13:46:09 +00:00
|
|
|
|
2014-04-07 10:34:41 +00:00
|
|
|
static char const *name() { return "stdio"; }
|
2012-10-04 13:46:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/********************************
|
|
|
|
** File I/O service interface **
|
|
|
|
********************************/
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
Write_result write(Vfs::Vfs_handle *, char const *buf, size_t buf_size,
|
|
|
|
size_t &out_count) override
|
2012-10-04 13:46:09 +00:00
|
|
|
{
|
2014-04-07 14:15:40 +00:00
|
|
|
out_count = _terminal->write(buf, buf_size);
|
2012-10-04 13:46:09 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
return WRITE_OK;
|
2012-10-04 13:46:09 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
Read_result read(Vfs::Vfs_handle *, char *dst, size_t count, size_t &out_count) override
|
2012-10-04 13:46:09 +00:00
|
|
|
{
|
2014-04-07 14:15:40 +00:00
|
|
|
out_count = _terminal->read(dst, count);
|
2012-10-04 13:46:09 +00:00
|
|
|
|
|
|
|
if (_echo)
|
2014-04-07 14:15:40 +00:00
|
|
|
_terminal->write(dst, count);
|
2012-10-04 13:46:09 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
return READ_OK;
|
2012-10-04 13:46:09 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
Ftruncate_result ftruncate(Vfs::Vfs_handle *, size_t) override
|
|
|
|
{
|
|
|
|
return FTRUNCATE_OK;
|
|
|
|
}
|
2012-10-04 13:46:09 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
Ioctl_result ioctl(Vfs::Vfs_handle *vfs_handle, Ioctl_opcode opcode,
|
|
|
|
Ioctl_arg arg, Ioctl_out &out) override
|
2012-10-04 13:46:09 +00:00
|
|
|
{
|
2014-04-07 14:15:40 +00:00
|
|
|
switch (opcode) {
|
2012-10-04 13:46:09 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
case Vfs::File_io_service::IOCTL_OP_TIOCSETAF:
|
2012-10-04 13:46:09 +00:00
|
|
|
{
|
2014-04-07 14:15:40 +00:00
|
|
|
_echo = (arg & (Vfs::File_io_service::IOCTL_VAL_ECHO));
|
|
|
|
return IOCTL_OK;
|
2012-10-04 13:46:09 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
case Vfs::File_io_service::IOCTL_OP_TIOCSETAW:
|
2012-10-04 13:46:09 +00:00
|
|
|
{
|
|
|
|
PDBG("OP_TIOCSETAW not implemented");
|
2014-04-07 14:15:40 +00:00
|
|
|
return IOCTL_ERR_INVALID;
|
2012-10-04 13:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
PDBG("invalid ioctl(request=0x%x)", opcode);
|
2012-10-04 13:46:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
return IOCTL_ERR_INVALID;
|
2012-10-04 13:46:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _NOUX__STDIO_FILE_SYSTEM_H_ */
|