genode/repos/os/src/lib/vfs/zero_file_system.h
Norman Feske 5ab1505d43 file system: enhanced file status info
This patch extends the 'File_system::Status',
'File_system::Directory_entry', and the related 'Vfs' types with
the following additional information:

- Distinction between continuous and transactional files (Node_type)
  (issue #3507)
- Readable, writeable, and executable attributes (Node_rwx),
  replacing the former 'mode' bits
  (issue #3030)

The types 'Node_rwx', 'Node_type' are defined twice,
once for the VFS (vfs/types.h) and once for the 'File_system'
session (file_system_session/file_system_session.h).
Similarly, there is a direct correspondance between
'Vfs::Directory_service::Dirent' and 'File_system::Directory_entry'.

This duplication of types follows the existing pattern of keeping the
VFS and file-system session independent from each other.
2019-11-19 14:23:56 +01:00

83 lines
1.9 KiB
C++

/*
* \brief zero filesystem
* \author Josef Soentgen
* \author Norman Feske
* \date 2012-07-31
*/
/*
* Copyright (C) 2012-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__VFS__ZERO_FILE_SYSTEM_H_
#define _INCLUDE__VFS__ZERO_FILE_SYSTEM_H_
#include <vfs/file_system.h>
namespace Vfs { class Zero_file_system; }
struct Vfs::Zero_file_system : Single_file_system
{
Zero_file_system(Vfs::Env&, Genode::Xml_node config)
:
Single_file_system(Node_type::CONTINUOUS_FILE, name(),
Node_rwx::rw(), config)
{ }
static char const *name() { return "zero"; }
char const *type() override { return "zero"; }
struct Zero_vfs_handle : Single_vfs_handle
{
Zero_vfs_handle(Directory_service &ds,
File_io_service &fs,
Genode::Allocator &alloc)
: Single_vfs_handle(ds, fs, alloc, 0) { }
Read_result read(char *dst, file_size count,
file_size &out_count) override
{
memset(dst, 0, count);
out_count = count;
return READ_OK;
}
Write_result write(char const *, file_size count,
file_size &out_count) override
{
out_count = count;
return WRITE_OK;
}
bool read_ready() override { return true; }
};
/*********************************
** Directory service interface **
*********************************/
Open_result open(char const *path, unsigned,
Vfs_handle **out_handle,
Allocator &alloc) override
{
if (!_single_file(path))
return OPEN_ERR_UNACCESSIBLE;
try {
*out_handle = new (alloc) Zero_vfs_handle(*this, *this, alloc);
return OPEN_OK;
}
catch (Genode::Out_of_ram) { return OPEN_ERR_OUT_OF_RAM; }
catch (Genode::Out_of_caps) { return OPEN_ERR_OUT_OF_CAPS; }
}
};
#endif /* _INCLUDE__VFS__ZERO_FILE_SYSTEM_H_ */