2014-04-07 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* \brief File system that hosts a single node
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2014-04-07
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-04-07 14:15:40 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2014-04-07 14:15:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__VFS__SINGLE_FILE_SYSTEM_H_
|
|
|
|
#define _INCLUDE__VFS__SINGLE_FILE_SYSTEM_H_
|
|
|
|
|
|
|
|
#include <vfs/file_system.h>
|
2014-08-19 13:38:28 +00:00
|
|
|
#include <vfs/vfs_handle.h>
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
namespace Vfs { class Single_file_system; }
|
|
|
|
|
|
|
|
|
|
|
|
class Vfs::Single_file_system : public File_system
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
Node_type const _type;
|
|
|
|
Node_rwx const _rwx;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2019-01-21 09:48:39 +00:00
|
|
|
typedef String<64> Filename;
|
|
|
|
|
|
|
|
Filename _filename { };
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2016-06-27 08:47:23 +00:00
|
|
|
protected:
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
struct Single_vfs_handle : Vfs_handle
|
|
|
|
{
|
|
|
|
using Vfs_handle::Vfs_handle;
|
|
|
|
|
|
|
|
virtual Read_result read(char *dst, file_size count,
|
|
|
|
file_size &out_count) = 0;
|
|
|
|
|
|
|
|
virtual Write_result write(char const *src, file_size count,
|
|
|
|
file_size &out_count) = 0;
|
|
|
|
|
2018-11-13 12:59:21 +00:00
|
|
|
virtual Sync_result sync()
|
|
|
|
{
|
|
|
|
return SYNC_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
virtual bool read_ready() = 0;
|
2022-02-04 16:34:42 +00:00
|
|
|
|
2022-12-06 18:11:44 +00:00
|
|
|
virtual bool write_ready() const = 0;
|
|
|
|
|
2022-02-04 16:34:42 +00:00
|
|
|
virtual bool notify_read_ready() { return true; }
|
2017-08-15 18:51:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Single_vfs_dir_handle : Single_vfs_handle
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
Node_type const _type;
|
|
|
|
Node_rwx const _rwx;
|
|
|
|
|
|
|
|
Filename const &_filename;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Single_vfs_dir_handle(Single_vfs_dir_handle const &);
|
|
|
|
Single_vfs_dir_handle &operator = (Single_vfs_dir_handle const &);
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
Single_vfs_dir_handle(Directory_service &ds,
|
|
|
|
File_io_service &fs,
|
|
|
|
Genode::Allocator &alloc,
|
2019-09-25 15:13:29 +00:00
|
|
|
Node_type type,
|
|
|
|
Node_rwx rwx,
|
|
|
|
Filename const &filename)
|
2019-01-21 09:48:39 +00:00
|
|
|
:
|
|
|
|
Single_vfs_handle(ds, fs, alloc, 0),
|
2019-09-25 15:13:29 +00:00
|
|
|
_type(type), _rwx(rwx), _filename(filename)
|
2017-08-15 18:51:53 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
Read_result read(char *dst, file_size count,
|
|
|
|
file_size &out_count) override
|
|
|
|
{
|
|
|
|
out_count = 0;
|
|
|
|
|
|
|
|
if (count < sizeof(Dirent))
|
|
|
|
return READ_ERR_INVALID;
|
|
|
|
|
|
|
|
file_size index = seek() / sizeof(Dirent);
|
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
Dirent &out = *(Dirent*)dst;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
auto dirent_type = [&] ()
|
|
|
|
{
|
|
|
|
switch (_type) {
|
|
|
|
case Node_type::DIRECTORY: return Dirent_type::DIRECTORY;
|
|
|
|
case Node_type::SYMLINK: return Dirent_type::SYMLINK;
|
|
|
|
case Node_type::CONTINUOUS_FILE: return Dirent_type::CONTINUOUS_FILE;
|
|
|
|
case Node_type::TRANSACTIONAL_FILE: return Dirent_type::TRANSACTIONAL_FILE;
|
2017-08-15 18:51:53 +00:00
|
|
|
}
|
2019-09-25 15:13:29 +00:00
|
|
|
return Dirent_type::END;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
out = {
|
|
|
|
.fileno = (Genode::addr_t)this,
|
|
|
|
.type = dirent_type(),
|
|
|
|
.rwx = _rwx,
|
|
|
|
.name = { _filename.string() }
|
|
|
|
};
|
2017-08-15 18:51:53 +00:00
|
|
|
} else {
|
2019-09-25 15:13:29 +00:00
|
|
|
out = {
|
|
|
|
.fileno = (Genode::addr_t)this,
|
|
|
|
.type = Dirent_type::END,
|
|
|
|
.rwx = { },
|
|
|
|
.name = { }
|
|
|
|
};
|
2017-08-15 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out_count = sizeof(Dirent);
|
|
|
|
|
|
|
|
return READ_OK;
|
|
|
|
}
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
Write_result write(char const *, file_size, file_size &) override
|
2017-08-15 18:51:53 +00:00
|
|
|
{
|
|
|
|
return WRITE_ERR_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool read_ready() override { return true; }
|
2022-12-06 18:11:44 +00:00
|
|
|
|
|
|
|
bool write_ready() const override { return true; }
|
2017-08-15 18:51:53 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
bool _root(const char *path)
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
return (strcmp(path, "") == 0) || (strcmp(path, "/") == 0);
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
bool _single_file(const char *path)
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2019-01-21 09:48:39 +00:00
|
|
|
return (strlen(path) == (strlen(_filename.string()) + 1)) &&
|
|
|
|
(strcmp(&path[1], _filename.string()) == 0);
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
Single_file_system(Node_type node_type,
|
|
|
|
char const *type_name,
|
|
|
|
Node_rwx rwx,
|
|
|
|
Xml_node config)
|
2014-04-07 14:15:40 +00:00
|
|
|
:
|
2019-09-25 15:13:29 +00:00
|
|
|
_type(node_type), _rwx(rwx),
|
2019-01-21 09:48:39 +00:00
|
|
|
_filename(config.attribute_value("name", Filename(type_name)))
|
|
|
|
{ }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************
|
|
|
|
** Directory-service interface **
|
|
|
|
*********************************/
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
Dataspace_capability dataspace(char const *) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
return Dataspace_capability();
|
|
|
|
}
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
void release(char const *, Dataspace_capability) override { }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
Stat_result stat(char const *path, Stat &out) override
|
|
|
|
{
|
2019-09-25 15:13:29 +00:00
|
|
|
out = Stat { };
|
2016-04-01 14:10:40 +00:00
|
|
|
out.device = (Genode::addr_t)this;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
if (_root(path)) {
|
2019-09-25 15:13:29 +00:00
|
|
|
out.type = Node_type::DIRECTORY;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
} else if (_single_file(path)) {
|
2019-09-25 15:13:29 +00:00
|
|
|
out.type = _type;
|
|
|
|
out.rwx = _rwx;
|
2016-04-01 14:10:40 +00:00
|
|
|
out.inode = 1;
|
2014-04-07 14:15:40 +00:00
|
|
|
} else {
|
|
|
|
return STAT_ERR_NO_ENTRY;
|
|
|
|
}
|
|
|
|
return STAT_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-09 12:32:31 +00:00
|
|
|
file_size num_dirent(char const *path) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2016-05-11 16:21:47 +00:00
|
|
|
if (_root(path))
|
2014-04-07 14:15:40 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
bool directory(char const *path) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2016-05-11 16:21:47 +00:00
|
|
|
if (_root(path))
|
2014-04-07 14:15:40 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *leaf_path(char const *path) override
|
|
|
|
{
|
2016-05-11 16:21:47 +00:00
|
|
|
return _single_file(path) ? path : 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
Opendir_result opendir(char const *path, bool create,
|
|
|
|
Vfs_handle **out_handle,
|
|
|
|
Allocator &alloc) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-08-15 18:51:53 +00:00
|
|
|
if (!_root(path))
|
|
|
|
return OPENDIR_ERR_LOOKUP_FAILED;
|
|
|
|
|
|
|
|
if (create)
|
|
|
|
return OPENDIR_ERR_PERMISSION_DENIED;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2018-01-12 19:47:48 +00:00
|
|
|
try {
|
|
|
|
*out_handle = new (alloc)
|
|
|
|
Single_vfs_dir_handle(*this, *this, alloc,
|
2019-09-25 15:13:29 +00:00
|
|
|
_type, _rwx, _filename);
|
2018-01-12 19:47:48 +00:00
|
|
|
return OPENDIR_OK;
|
|
|
|
}
|
|
|
|
catch (Genode::Out_of_ram) { return OPENDIR_ERR_OUT_OF_RAM; }
|
|
|
|
catch (Genode::Out_of_caps) { return OPENDIR_ERR_OUT_OF_CAPS; }
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
void close(Vfs_handle *handle) override
|
|
|
|
{
|
|
|
|
if (handle && (&handle->ds() == this))
|
|
|
|
destroy(handle->alloc(), handle);
|
|
|
|
}
|
|
|
|
|
2020-03-09 15:21:00 +00:00
|
|
|
Unlink_result unlink(char const *path) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2020-03-09 15:21:00 +00:00
|
|
|
if (_single_file(path))
|
|
|
|
return UNLINK_ERR_NO_PERM;
|
|
|
|
|
|
|
|
return UNLINK_ERR_NO_ENTRY;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 13:32:43 +00:00
|
|
|
Rename_result rename(char const *from, char const *to) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2016-05-11 16:21:47 +00:00
|
|
|
if (_single_file(from) || _single_file(to))
|
2016-03-02 13:32:43 +00:00
|
|
|
return RENAME_ERR_NO_PERM;
|
|
|
|
return RENAME_ERR_NO_ENTRY;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
/********************************
|
|
|
|
** File I/O service interface **
|
|
|
|
********************************/
|
|
|
|
|
|
|
|
Read_result complete_read(Vfs_handle *vfs_handle, char *dst,
|
|
|
|
file_size count,
|
|
|
|
file_size &out_count) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-08-15 18:51:53 +00:00
|
|
|
Single_vfs_handle *handle =
|
|
|
|
static_cast<Single_vfs_handle*>(vfs_handle);
|
|
|
|
|
|
|
|
if (handle)
|
|
|
|
return handle->read(dst, count, out_count);
|
|
|
|
|
|
|
|
return READ_ERR_INVALID;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
Write_result write(Vfs_handle *vfs_handle, char const *src, file_size count,
|
|
|
|
file_size &out_count) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-08-15 18:51:53 +00:00
|
|
|
Single_vfs_handle *handle =
|
|
|
|
static_cast<Single_vfs_handle*>(vfs_handle);
|
|
|
|
|
|
|
|
if (handle)
|
|
|
|
return handle->write(src, count, out_count);
|
|
|
|
|
|
|
|
return WRITE_ERR_INVALID;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
bool read_ready(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
|
|
|
Single_vfs_handle *handle =
|
|
|
|
static_cast<Single_vfs_handle*>(vfs_handle);
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
if (handle)
|
|
|
|
return handle->read_ready();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2022-12-06 18:11:44 +00:00
|
|
|
bool write_ready(Vfs_handle const &vfs_handle) const override
|
|
|
|
{
|
|
|
|
Single_vfs_handle const &handle =
|
|
|
|
static_cast<Single_vfs_handle const &>(vfs_handle);
|
|
|
|
|
|
|
|
return handle.write_ready();
|
|
|
|
}
|
|
|
|
|
2022-02-04 16:34:42 +00:00
|
|
|
bool notify_read_ready(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
|
|
|
Single_vfs_handle *handle =
|
|
|
|
static_cast<Single_vfs_handle*>(vfs_handle);
|
|
|
|
|
|
|
|
if (handle)
|
|
|
|
return handle->notify_read_ready();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
Ftruncate_result ftruncate(Vfs_handle *, file_size) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
return FTRUNCATE_ERR_NO_PERM;
|
|
|
|
}
|
2018-11-13 12:59:21 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Sync_result complete_sync(Vfs_handle *vfs_handle) override
|
2018-11-13 12:59:21 +00:00
|
|
|
{
|
|
|
|
Single_vfs_handle *handle =
|
|
|
|
static_cast<Single_vfs_handle*>(vfs_handle);
|
|
|
|
|
|
|
|
if (handle)
|
|
|
|
return handle->sync();
|
|
|
|
|
|
|
|
return SYNC_ERR_INVALID;
|
|
|
|
}
|
2014-04-07 14:15:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VFS__SINGLE_FILE_SYSTEM_H_ */
|