2014-04-07 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* \brief Directory file system
|
|
|
|
* \author Norman Feske
|
2017-02-01 10:28:15 +00:00
|
|
|
* \author Emery Hemingway
|
|
|
|
* \author Christian Helmuth
|
2014-04-07 14:15:40 +00:00
|
|
|
* \date 2012-04-23
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-03-25 14:41:43 +00:00
|
|
|
* Copyright (C) 2011-2019 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__DIR_FILE_SYSTEM_H_
|
|
|
|
#define _INCLUDE__VFS__DIR_FILE_SYSTEM_H_
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
#include <base/registry.h>
|
2014-04-07 14:15:40 +00:00
|
|
|
#include <vfs/file_system_factory.h>
|
|
|
|
#include <vfs/vfs_handle.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Vfs { class Dir_file_system; }
|
|
|
|
|
|
|
|
|
|
|
|
class Vfs::Dir_file_system : public File_system
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum { MAX_NAME_LEN = 128 };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
Dir_file_system(Dir_file_system const &);
|
|
|
|
Dir_file_system &operator = (Dir_file_system const &);
|
|
|
|
|
2018-04-03 13:59:35 +00:00
|
|
|
Vfs::Env &_env;
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
/**
|
|
|
|
* This instance is the root of VFS
|
|
|
|
*
|
|
|
|
* Additionally, the root has an empty _name.
|
|
|
|
*/
|
2018-04-23 06:55:49 +00:00
|
|
|
bool const _vfs_root;
|
2017-11-20 09:21:38 +00:00
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
struct Dir_vfs_handle : Vfs_handle
|
|
|
|
{
|
2017-11-08 03:41:56 +00:00
|
|
|
struct Subdir_handle_element;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
typedef Genode::Registry<Subdir_handle_element> Subdir_handle_registry;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
struct Subdir_handle_element : Subdir_handle_registry::Element
|
2017-08-15 18:51:53 +00:00
|
|
|
{
|
2018-01-10 12:27:31 +00:00
|
|
|
bool synced { false };
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
Vfs_handle &vfs_handle;
|
2017-11-08 03:41:56 +00:00
|
|
|
Subdir_handle_element(Subdir_handle_registry ®istry,
|
|
|
|
Vfs_handle &vfs_handle)
|
|
|
|
: Subdir_handle_registry::Element(registry, *this),
|
2017-08-15 18:51:53 +00:00
|
|
|
vfs_handle(vfs_handle) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
Absolute_path path;
|
2017-11-08 03:41:56 +00:00
|
|
|
Vfs_handle *queued_read_handle { nullptr };
|
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
|
|
|
Subdir_handle_registry subdir_handle_registry { };
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
Dir_vfs_handle(Directory_service &ds,
|
|
|
|
File_io_service &fs,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
char const *path)
|
|
|
|
: Vfs_handle(ds, fs, alloc, 0),
|
|
|
|
path(path) { }
|
2017-11-08 03:41:56 +00:00
|
|
|
|
|
|
|
~Dir_vfs_handle()
|
|
|
|
{
|
|
|
|
/* close all sub-handles */
|
|
|
|
auto f = [&] (Subdir_handle_element &e) {
|
2018-04-23 07:25:51 +00:00
|
|
|
e.vfs_handle.close();
|
2017-11-08 03:41:56 +00:00
|
|
|
destroy(alloc(), &e);
|
|
|
|
};
|
|
|
|
subdir_handle_registry.for_each(f);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Dir_vfs_handle(Dir_vfs_handle const &);
|
|
|
|
Dir_vfs_handle &operator = (Dir_vfs_handle const &);
|
2017-08-15 18:51:53 +00:00
|
|
|
};
|
|
|
|
|
2018-03-31 14:50:49 +00:00
|
|
|
struct Dir_watch_handle : Vfs_watch_handle
|
|
|
|
{
|
|
|
|
struct Watch_handle_element;
|
|
|
|
|
|
|
|
typedef Genode::Registry<Watch_handle_element> Watch_handle_registry;
|
|
|
|
|
|
|
|
struct Watch_handle_element : Watch_handle_registry::Element
|
|
|
|
{
|
|
|
|
Vfs_watch_handle &watch_handle;
|
|
|
|
Watch_handle_element(Watch_handle_registry ®istry,
|
|
|
|
Vfs_watch_handle &handle)
|
|
|
|
: Watch_handle_registry::Element(registry, *this),
|
|
|
|
watch_handle(handle) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
Watch_handle_registry handle_registry { };
|
|
|
|
|
|
|
|
Dir_watch_handle(File_system &fs, Genode::Allocator &alloc)
|
|
|
|
: Vfs_watch_handle(fs, alloc) { }
|
|
|
|
|
|
|
|
~Dir_watch_handle()
|
|
|
|
{
|
|
|
|
/* close all sub-handles */
|
|
|
|
auto f = [&] (Watch_handle_element &e) {
|
2018-04-23 07:25:51 +00:00
|
|
|
e.watch_handle.close();
|
2018-03-31 14:50:49 +00:00
|
|
|
destroy(alloc(), &e);
|
|
|
|
};
|
|
|
|
handle_registry.for_each(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-25 14:41:43 +00:00
|
|
|
* Propagate the response handler to each sub-handle
|
2018-03-31 14:50:49 +00:00
|
|
|
*/
|
2019-03-25 14:41:43 +00:00
|
|
|
void handler(Watch_response_handler *h) override
|
2018-03-31 14:50:49 +00:00
|
|
|
{
|
|
|
|
handle_registry.for_each( [&] (Watch_handle_element &elem) {
|
2019-03-25 14:41:43 +00:00
|
|
|
elem.watch_handle.handler(h); } );
|
2018-03-31 14:50:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
/* pointer to first child file system */
|
2018-03-02 12:30:10 +00:00
|
|
|
File_system *_first_file_system = nullptr;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/* add new file system to the list of children */
|
|
|
|
void _append_file_system(File_system *fs)
|
|
|
|
{
|
|
|
|
if (!_first_file_system) {
|
|
|
|
_first_file_system = fs;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
File_system *curr = _first_file_system;
|
|
|
|
while (curr->next)
|
|
|
|
curr = curr->next;
|
|
|
|
|
|
|
|
curr->next = fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Directory name
|
|
|
|
*/
|
2019-01-21 09:48:39 +00:00
|
|
|
typedef String<MAX_NAME_LEN> Name;
|
|
|
|
Name const _name;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
/**
|
|
|
|
* Returns if path corresponds to top directory of file system
|
|
|
|
*/
|
|
|
|
bool _top_dir(char const *path) const { return strcmp(path, "/") == 0; }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform operation on a file system
|
|
|
|
*
|
|
|
|
* \param fn functor that takes a file-system reference and
|
|
|
|
* the path as arguments
|
|
|
|
*/
|
|
|
|
template <typename RES, typename FN>
|
|
|
|
RES _dir_op(RES const no_entry, RES const no_perm, RES const ok,
|
|
|
|
char const *path, FN const &fn)
|
|
|
|
{
|
|
|
|
path = _sub_path(path);
|
|
|
|
|
|
|
|
/* path does not match directory name */
|
|
|
|
if (!path)
|
|
|
|
return no_entry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent operation if path equals directory name defined
|
|
|
|
* via the static VFS configuration.
|
|
|
|
*/
|
|
|
|
if (strlen(path) == 0)
|
|
|
|
return no_perm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If any of the sub file systems returns a permission error and
|
|
|
|
* there exists no sub file system that takes the request, we
|
|
|
|
* return the permission error.
|
|
|
|
*/
|
|
|
|
bool permission_denied = false;
|
|
|
|
|
2015-02-04 18:23:01 +00:00
|
|
|
/*
|
|
|
|
* Keep the most meaningful error code. When using stacked file
|
|
|
|
* systems, most child file systems will eventually return no
|
|
|
|
* entry (or leave the error code unchanged). If any of those
|
|
|
|
* file systems has anything more interesting to tell, return
|
|
|
|
* this information after all file systems have been tried and
|
|
|
|
* none could handle the request.
|
|
|
|
*/
|
|
|
|
RES error = ok;
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* The given path refers to at least one of our sub directories.
|
|
|
|
* Propagate the request into all of our file systems. If at least
|
|
|
|
* one operation succeeds, we return success.
|
|
|
|
*/
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
|
|
|
|
RES const err = fn(*fs, path);
|
|
|
|
|
|
|
|
if (err == ok)
|
|
|
|
return err;
|
|
|
|
|
2015-02-04 18:23:01 +00:00
|
|
|
if (err != no_entry && err != no_perm) {
|
|
|
|
error = err;
|
|
|
|
}
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
if (err == no_perm)
|
|
|
|
permission_denied = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* none of our file systems could successfully operate on the path */
|
2015-02-04 18:23:01 +00:00
|
|
|
return error != ok ? error : permission_denied ? no_perm : no_entry;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return portion of the path after the element corresponding to
|
|
|
|
* the current directory.
|
|
|
|
*/
|
|
|
|
char const *_sub_path(char const *path) const
|
|
|
|
{
|
|
|
|
/* do not strip anything from the path when we are root */
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_vfs_root)
|
2014-04-07 14:15:40 +00:00
|
|
|
return path;
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_top_dir(path))
|
2017-08-15 18:51:53 +00:00
|
|
|
return path;
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
/* skip heading slash in path if present */
|
|
|
|
if (path[0] == '/')
|
|
|
|
path++;
|
|
|
|
|
2019-01-21 09:48:39 +00:00
|
|
|
Genode::size_t const name_len = strlen(_name.string());
|
|
|
|
if (strcmp(path, _name.string(), name_len) != 0)
|
2014-04-07 14:15:40 +00:00
|
|
|
return 0;
|
|
|
|
path += name_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first characters of the first path element are equal to
|
|
|
|
* the current directory name. Let's check if the length of the
|
|
|
|
* first path element matches the name length.
|
|
|
|
*/
|
|
|
|
if (*path != 0 && *path != '/')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
/*
|
|
|
|
* Accumulate number of directory entries that match in any of
|
|
|
|
* our sub file systems.
|
2014-04-07 14:15:40 +00:00
|
|
|
*/
|
2017-08-15 18:51:53 +00:00
|
|
|
file_size _sum_dirents_of_file_systems(char const *path)
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-08-15 18:51:53 +00:00
|
|
|
file_size cnt = 0;
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
cnt += fs->num_dirent(path);
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _queue_read_of_file_systems(Dir_vfs_handle *dir_vfs_handle)
|
|
|
|
{
|
2017-11-08 03:41:56 +00:00
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
dir_vfs_handle->queued_read_handle = nullptr;
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
file_offset index = dir_vfs_handle->seek() / sizeof(Dirent);
|
|
|
|
|
|
|
|
char const *sub_path = _sub_path(dir_vfs_handle->path.base());
|
|
|
|
|
|
|
|
if (strlen(sub_path) == 0)
|
|
|
|
sub_path = "/";
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
/* base of composite directory index */
|
2014-04-07 14:15:40 +00:00
|
|
|
int base = 0;
|
2017-11-08 03:41:56 +00:00
|
|
|
|
|
|
|
auto f = [&] (Dir_vfs_handle::Subdir_handle_element &handle_element) {
|
|
|
|
if (dir_vfs_handle->queued_read_handle) return; /* skip through */
|
|
|
|
|
|
|
|
Vfs_handle &vfs_handle = handle_element.vfs_handle;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine number of matching directory entries within
|
|
|
|
* the current file system.
|
|
|
|
*/
|
2017-11-08 03:41:56 +00:00
|
|
|
int const fs_num_dirent = vfs_handle.ds().num_dirent(sub_path);
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Query directory entry if index lies with the file
|
|
|
|
* system.
|
|
|
|
*/
|
|
|
|
if (index - base < fs_num_dirent) {
|
2017-11-08 03:41:56 +00:00
|
|
|
/* set this handle to be used for read completion */
|
|
|
|
dir_vfs_handle->queued_read_handle = &vfs_handle;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
/* seek to file-system local index */
|
2014-04-07 14:15:40 +00:00
|
|
|
index = index - base;
|
2017-11-08 03:41:56 +00:00
|
|
|
vfs_handle.seek(index * sizeof(Dirent));
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2019-03-25 14:41:43 +00:00
|
|
|
/* forward the response handler */
|
|
|
|
dir_vfs_handle->apply_handler([&] (Vfs::Io_response_handler &h) {
|
|
|
|
vfs_handle.handler(&h); });
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
result = vfs_handle.fs().queue_read(&vfs_handle, sizeof(Dirent));
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
2017-11-20 09:21:38 +00:00
|
|
|
|
|
|
|
/* adjust base index for next file system */
|
|
|
|
base += fs_num_dirent;
|
2017-11-08 03:41:56 +00:00
|
|
|
};
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
dir_vfs_handle->subdir_handle_registry.for_each(f);
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
return result;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
Read_result _complete_read_of_file_systems(Dir_vfs_handle *dir_vfs_handle,
|
|
|
|
char *dst, file_size count,
|
|
|
|
file_size &out_count)
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-11-08 03:41:56 +00:00
|
|
|
if (!dir_vfs_handle->queued_read_handle) {
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
/*
|
|
|
|
* no fs was found for the given index or
|
|
|
|
* fs->opendir() failed
|
|
|
|
*/
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
if (count < sizeof(Dirent))
|
|
|
|
return READ_ERR_INVALID;
|
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
Dirent &dirent = *(Dirent*)dst;
|
|
|
|
dirent = Dirent { };
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
out_count = sizeof(Dirent);
|
|
|
|
|
|
|
|
return READ_OK;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
Read_result result = dir_vfs_handle->queued_read_handle->fs().
|
|
|
|
complete_read(dir_vfs_handle->queued_read_handle,
|
2017-08-15 18:51:53 +00:00
|
|
|
dst, count, out_count);
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
if (result == READ_QUEUED)
|
2017-08-15 18:51:53 +00:00
|
|
|
return result;
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
dir_vfs_handle->queued_read_handle = nullptr;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
return result;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-04-03 13:59:35 +00:00
|
|
|
Dir_file_system(Vfs::Env &env,
|
2016-05-25 13:47:22 +00:00
|
|
|
Genode::Xml_node node,
|
2018-04-03 13:59:35 +00:00
|
|
|
File_system_factory &fs_factory)
|
2014-04-07 14:15:40 +00:00
|
|
|
:
|
2019-01-21 09:48:39 +00:00
|
|
|
_env(env),
|
|
|
|
_vfs_root(!node.has_type("dir")),
|
|
|
|
_name(_vfs_root ? Name() : node.attribute_value("name", Name()))
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2015-11-23 12:39:29 +00:00
|
|
|
using namespace Genode;
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
for (unsigned i = 0; i < node.num_sub_nodes(); i++) {
|
|
|
|
|
|
|
|
Xml_node sub_node = node.sub_node(i);
|
|
|
|
|
|
|
|
/* traverse into <dir> nodes */
|
|
|
|
if (sub_node.has_type("dir")) {
|
2018-04-03 13:59:35 +00:00
|
|
|
_append_file_system(new (_env.alloc())
|
|
|
|
Dir_file_system(_env, sub_node, fs_factory));
|
2014-04-07 14:15:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-03-02 12:30:10 +00:00
|
|
|
File_system * const fs =
|
2018-04-03 13:59:35 +00:00
|
|
|
fs_factory.create(_env, sub_node);
|
2018-03-02 12:30:10 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
if (fs) {
|
|
|
|
_append_file_system(fs);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("failed to create <", sub_node.type(), "> VFS node");
|
2015-11-23 12:39:29 +00:00
|
|
|
try {
|
|
|
|
for (unsigned i = 0; i < 16; ++i) {
|
2019-01-21 09:48:39 +00:00
|
|
|
|
|
|
|
Xml_attribute const attr = sub_node.attribute(i);
|
|
|
|
|
|
|
|
String<64> value { };
|
|
|
|
attr.value(value);
|
2015-11-23 12:39:29 +00:00
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("\t", attr.name(), "=\"", value, "\"");
|
2015-11-23 12:39:29 +00:00
|
|
|
}
|
|
|
|
} catch (Xml_node::Nonexistent_attribute) { }
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************
|
|
|
|
** Directory-service interface **
|
|
|
|
*********************************/
|
|
|
|
|
|
|
|
Dataspace_capability dataspace(char const *path) override
|
|
|
|
{
|
|
|
|
path = _sub_path(path);
|
|
|
|
if (!path)
|
|
|
|
return Dataspace_capability();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query sub file systems for dataspace using the path local to
|
|
|
|
* the respective file system
|
|
|
|
*/
|
|
|
|
File_system *fs = _first_file_system;
|
|
|
|
for (; fs; fs = fs->next) {
|
|
|
|
Dataspace_capability ds = fs->dataspace(path);
|
|
|
|
if (ds.valid())
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Dataspace_capability();
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(char const *path, Dataspace_capability ds_cap) override
|
|
|
|
{
|
|
|
|
path = _sub_path(path);
|
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next)
|
|
|
|
fs->release(path, ds_cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stat_result stat(char const *path, Stat &out) override
|
|
|
|
{
|
|
|
|
path = _sub_path(path);
|
|
|
|
|
|
|
|
/* path does not match directory name */
|
|
|
|
if (!path)
|
|
|
|
return STAT_ERR_NO_ENTRY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If path equals directory name, return information about the
|
|
|
|
* current directory.
|
|
|
|
*/
|
2017-11-20 09:21:38 +00:00
|
|
|
if (strlen(path) == 0 || _top_dir(path)) {
|
2019-09-25 15:13:29 +00:00
|
|
|
out = {
|
|
|
|
.size = 0,
|
|
|
|
.type = Node_type::DIRECTORY,
|
|
|
|
.rwx = Node_rwx::rwx(),
|
|
|
|
.inode = 1,
|
|
|
|
.device = (Genode::addr_t)this,
|
|
|
|
.modification_time = { Vfs::Timestamp::INVALID },
|
|
|
|
};
|
2014-04-07 14:15:40 +00:00
|
|
|
return STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The given path refers to one of our sub directories.
|
|
|
|
* Propagate the request into our file systems.
|
|
|
|
*/
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
|
|
|
|
Stat_result const err = fs->stat(path, out);
|
|
|
|
|
|
|
|
if (err == STAT_OK)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (err != STAT_ERR_NO_ENTRY)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* none of our file systems felt responsible for the path */
|
|
|
|
return STAT_ERR_NO_ENTRY;
|
|
|
|
}
|
|
|
|
|
2014-09-09 12:32:31 +00:00
|
|
|
file_size num_dirent(char const *path) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_vfs_root) {
|
2014-04-07 14:15:40 +00:00
|
|
|
return _sum_dirents_of_file_systems(path);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_top_dir(path))
|
2014-04-07 14:15:40 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The path contains at least one element. Remove current
|
|
|
|
* element from path.
|
|
|
|
*/
|
|
|
|
path = _sub_path(path);
|
|
|
|
|
|
|
|
/*
|
2015-03-20 16:50:41 +00:00
|
|
|
* If the resulting 'path' is non-null, the path lies
|
2014-04-07 14:15:40 +00:00
|
|
|
* within our tree. In this case, determine the sum of
|
|
|
|
* matching dirents of all our file systems. Otherwise,
|
|
|
|
* the specified path lies outside our directory node.
|
|
|
|
*/
|
2016-03-31 14:42:28 +00:00
|
|
|
return path ? _sum_dirents_of_file_systems(*path ? path : "/") : 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
/**
|
|
|
|
* Return true if specified path is a directory
|
|
|
|
*/
|
|
|
|
bool directory(char const *path) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_top_dir(path))
|
2017-08-15 18:51:53 +00:00
|
|
|
return true;
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
path = _sub_path(path);
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
if (!path)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (strlen(path) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next)
|
2016-05-11 16:21:47 +00:00
|
|
|
if (fs->directory(path))
|
2014-04-07 14:15:40 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *leaf_path(char const *path) override
|
|
|
|
{
|
|
|
|
path = _sub_path(path);
|
|
|
|
if (!path)
|
2018-12-11 17:40:34 +00:00
|
|
|
return nullptr;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
if (strlen(path) == 0)
|
|
|
|
return path;
|
|
|
|
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
char const *leaf_path = fs->leaf_path(path);
|
|
|
|
if (leaf_path)
|
|
|
|
return leaf_path;
|
|
|
|
}
|
|
|
|
|
2018-12-11 17:40:34 +00:00
|
|
|
return nullptr;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
Open_result open(char const *path,
|
2017-02-01 20:07:14 +00:00
|
|
|
unsigned mode,
|
|
|
|
Vfs_handle **out_handle,
|
|
|
|
Allocator &alloc) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If 'path' is a directory, we create a 'Vfs_handle'
|
|
|
|
* for the root directory so that subsequent 'dirent' calls
|
|
|
|
* are subjected to the stacked file-system layout.
|
|
|
|
*/
|
2016-05-11 16:21:47 +00:00
|
|
|
if (directory(path)) {
|
2018-01-12 19:47:48 +00:00
|
|
|
try {
|
2018-02-13 16:57:00 +00:00
|
|
|
*out_handle = new (alloc) Dir_vfs_handle(*this, *this, alloc, path);
|
2018-01-12 19:47:48 +00:00
|
|
|
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; }
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If 'path' refers to a non-directory node, create a
|
|
|
|
* 'Vfs_handle' local to the file system that provides the
|
|
|
|
* file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
path = _sub_path(path);
|
|
|
|
|
|
|
|
/* check if path does not match directory name */
|
|
|
|
if (!path)
|
|
|
|
return OPEN_ERR_UNACCESSIBLE;
|
|
|
|
|
|
|
|
/* path equals directory name */
|
|
|
|
if (strlen(path) == 0) {
|
2018-01-12 19:47:48 +00:00
|
|
|
try {
|
|
|
|
*out_handle = new (alloc) Vfs_handle(*this, *this, alloc, 0);
|
|
|
|
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; }
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* path refers to any of our sub file systems */
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
Open_result const err = fs->open(path, mode, out_handle, alloc);
|
|
|
|
switch (err) {
|
|
|
|
case OPEN_ERR_UNACCESSIBLE:
|
|
|
|
continue;
|
|
|
|
default:
|
2014-04-07 14:15:40 +00:00
|
|
|
return err;
|
2016-03-30 13:24:19 +00:00
|
|
|
}
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* path does not match any existing file or directory */
|
|
|
|
return OPEN_ERR_UNACCESSIBLE;
|
|
|
|
}
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
/**
|
|
|
|
* Call 'opendir()' on each file system and store handles in
|
|
|
|
* a registry.
|
|
|
|
*/
|
|
|
|
Opendir_result open_composite_dirs(char const *sub_path,
|
|
|
|
Dir_vfs_handle &dir_vfs_handle)
|
|
|
|
{
|
2018-04-04 09:57:50 +00:00
|
|
|
Opendir_result res = OPENDIR_ERR_LOOKUP_FAILED;
|
2017-11-08 03:41:56 +00:00
|
|
|
try {
|
2017-11-20 09:21:38 +00:00
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
2017-11-08 03:41:56 +00:00
|
|
|
Vfs_handle *sub_dir_handle = nullptr;
|
|
|
|
|
|
|
|
Opendir_result r = fs->opendir(
|
|
|
|
sub_path, false, &sub_dir_handle, dir_vfs_handle.alloc());
|
|
|
|
|
|
|
|
switch (r) {
|
|
|
|
case OPENDIR_OK:
|
|
|
|
break;
|
2018-09-07 13:34:27 +00:00
|
|
|
case OPENDIR_ERR_OUT_OF_RAM:
|
|
|
|
case OPENDIR_ERR_OUT_OF_CAPS:
|
2018-01-12 19:47:48 +00:00
|
|
|
return r;
|
2017-11-08 03:41:56 +00:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
new (dir_vfs_handle.alloc())
|
|
|
|
Dir_vfs_handle::Subdir_handle_element(
|
|
|
|
dir_vfs_handle.subdir_handle_registry, *sub_dir_handle);
|
2018-04-04 09:57:50 +00:00
|
|
|
/* return OK because at least one directory has been opened */
|
|
|
|
res = OPENDIR_OK;
|
2017-11-08 03:41:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-04 09:57:50 +00:00
|
|
|
catch (Genode::Out_of_ram) { res = OPENDIR_ERR_OUT_OF_RAM; }
|
|
|
|
catch (Genode::Out_of_caps) { res = OPENDIR_ERR_OUT_OF_CAPS; }
|
2017-11-20 09:21:38 +00:00
|
|
|
|
2018-04-04 09:57:50 +00:00
|
|
|
return res;
|
2017-11-08 03:41:56 +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
|
|
|
|
{
|
2017-11-08 03:41:56 +00:00
|
|
|
Opendir_result result = OPENDIR_OK;
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_top_dir(path)) {
|
2017-08-15 18:51:53 +00:00
|
|
|
if (create)
|
|
|
|
return OPENDIR_ERR_PERMISSION_DENIED;
|
2017-11-20 09:21:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* opendir with '/' (called from 'open_composite_dirs' returns handle
|
|
|
|
* only, VFS root additionally calls 'open_composite_dirs' in order to
|
|
|
|
* open its file systems
|
|
|
|
*/
|
2018-01-12 19:47:48 +00:00
|
|
|
Dir_vfs_handle *root_handle;
|
|
|
|
try {
|
|
|
|
root_handle = new (alloc)
|
|
|
|
Dir_vfs_handle(*this, *this, alloc, path);
|
|
|
|
}
|
|
|
|
catch (Genode::Out_of_ram) { return OPENDIR_ERR_OUT_OF_RAM; }
|
|
|
|
catch (Genode::Out_of_caps) { return OPENDIR_ERR_OUT_OF_CAPS; }
|
2017-11-20 09:21:38 +00:00
|
|
|
|
|
|
|
/* the VFS root may contain more file systems */
|
|
|
|
if (_vfs_root)
|
|
|
|
result = open_composite_dirs("/", *root_handle);
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
if (result == OPENDIR_OK) {
|
|
|
|
*out_handle = root_handle;
|
|
|
|
} else {
|
|
|
|
/* close the root handle and the rest will follow */
|
|
|
|
close(root_handle);
|
|
|
|
}
|
|
|
|
return result;
|
2017-08-15 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const *sub_path = _sub_path(path);
|
|
|
|
|
|
|
|
if (!sub_path)
|
|
|
|
return OPENDIR_ERR_LOOKUP_FAILED;
|
|
|
|
|
|
|
|
if (create) {
|
2018-12-11 17:40:34 +00:00
|
|
|
if (leaf_path(path) != nullptr)
|
|
|
|
return OPENDIR_ERR_NODE_ALREADY_EXISTS;
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
auto opendir_fn = [&] (File_system &fs, char const *path)
|
|
|
|
{
|
|
|
|
Vfs_handle *tmp_handle;
|
|
|
|
Opendir_result opendir_result =
|
|
|
|
fs.opendir(path, true, &tmp_handle, alloc);
|
2018-04-23 07:25:51 +00:00
|
|
|
if (opendir_result == OPENDIR_OK) {
|
|
|
|
tmp_handle->close();
|
|
|
|
}
|
2017-11-08 03:41:56 +00:00
|
|
|
return opendir_result; /* return from lambda */
|
2017-08-15 18:51:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Opendir_result opendir_result =
|
|
|
|
_dir_op(OPENDIR_ERR_LOOKUP_FAILED,
|
|
|
|
OPENDIR_ERR_PERMISSION_DENIED,
|
|
|
|
OPENDIR_OK,
|
|
|
|
path, opendir_fn);
|
|
|
|
|
|
|
|
if (opendir_result != OPENDIR_OK)
|
|
|
|
return opendir_result;
|
|
|
|
}
|
|
|
|
|
2018-01-12 19:47:48 +00:00
|
|
|
Dir_vfs_handle *dir_vfs_handle;
|
|
|
|
try {
|
|
|
|
dir_vfs_handle = new (alloc)
|
|
|
|
Dir_vfs_handle(*this, *this, alloc, path);
|
|
|
|
}
|
|
|
|
catch (Genode::Out_of_ram) { return OPENDIR_ERR_OUT_OF_RAM; }
|
|
|
|
catch (Genode::Out_of_caps) { return OPENDIR_ERR_OUT_OF_CAPS; }
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
/* path equals "/" (for reading the name of this directory) */
|
|
|
|
if (strlen(sub_path) == 0)
|
|
|
|
sub_path = "/";
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
result = open_composite_dirs(sub_path, *dir_vfs_handle);
|
|
|
|
if (result == OPENDIR_OK) {
|
|
|
|
*out_handle = dir_vfs_handle;
|
|
|
|
} else {
|
|
|
|
/* close the master handle and the rest will follow */
|
|
|
|
close(dir_vfs_handle);
|
|
|
|
}
|
|
|
|
return result;
|
2017-08-15 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Openlink_result openlink(char const *path, bool create,
|
|
|
|
Vfs_handle **out_handle,
|
|
|
|
Allocator &alloc) override
|
|
|
|
{
|
|
|
|
auto openlink_fn = [&] (File_system &fs, char const *path)
|
|
|
|
{
|
|
|
|
return fs.openlink(path, create, out_handle, alloc);
|
|
|
|
};
|
|
|
|
|
|
|
|
return _dir_op(OPENLINK_ERR_LOOKUP_FAILED,
|
|
|
|
OPENLINK_ERR_PERMISSION_DENIED,
|
|
|
|
OPENLINK_OK,
|
|
|
|
path, openlink_fn);
|
|
|
|
}
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
void close(Vfs_handle *handle) override
|
|
|
|
{
|
|
|
|
if (handle && (&handle->ds() == this))
|
|
|
|
destroy(handle->alloc(), handle);
|
|
|
|
}
|
|
|
|
|
2018-03-31 14:50:49 +00:00
|
|
|
Watch_result watch(char const *path,
|
|
|
|
Vfs_watch_handle **handle,
|
|
|
|
Allocator &alloc) override
|
|
|
|
{
|
2018-04-04 10:33:53 +00:00
|
|
|
Watch_result res = WATCH_ERR_UNACCESSIBLE;
|
2018-03-31 14:50:49 +00:00
|
|
|
Dir_watch_handle *meta_handle = nullptr;
|
|
|
|
|
2018-04-04 10:33:53 +00:00
|
|
|
char const *sub_path = _sub_path(path);
|
|
|
|
if (!sub_path) return res;
|
|
|
|
|
2018-03-31 14:50:49 +00:00
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
Vfs_watch_handle *sub_handle;
|
|
|
|
|
2018-04-04 10:33:53 +00:00
|
|
|
if (fs->watch(sub_path, &sub_handle, alloc) == WATCH_OK) {
|
2018-03-31 14:50:49 +00:00
|
|
|
if (meta_handle == nullptr) {
|
|
|
|
/* at least one non-static FS, allocate handle */
|
|
|
|
meta_handle = new (alloc) Dir_watch_handle(*this, alloc);
|
|
|
|
*handle = meta_handle;
|
2018-04-04 10:33:53 +00:00
|
|
|
res = WATCH_OK;
|
2018-03-31 14:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attach child FS handle to returned handle */
|
|
|
|
new (alloc)
|
|
|
|
Dir_watch_handle::Watch_handle_element(
|
|
|
|
meta_handle->handle_registry, *sub_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 10:33:53 +00:00
|
|
|
return res;
|
2018-03-31 14:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void close(Vfs_watch_handle *handle) override
|
|
|
|
{
|
|
|
|
if (handle && (&handle->fs() == this))
|
|
|
|
destroy(handle->alloc(), handle);
|
|
|
|
}
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
Unlink_result unlink(char const *path) override
|
|
|
|
{
|
|
|
|
auto unlink_fn = [] (File_system &fs, char const *path)
|
|
|
|
{
|
|
|
|
return fs.unlink(path);
|
|
|
|
};
|
|
|
|
|
|
|
|
return _dir_op(UNLINK_ERR_NO_ENTRY, UNLINK_ERR_NO_PERM, UNLINK_OK,
|
|
|
|
path, unlink_fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rename_result rename(char const *from_path, char const *to_path) override
|
|
|
|
{
|
2016-03-09 07:56:49 +00:00
|
|
|
from_path = _sub_path(from_path);
|
|
|
|
to_path = _sub_path(to_path);
|
|
|
|
|
|
|
|
/* path does not match directory name */
|
|
|
|
if (!from_path)
|
|
|
|
return RENAME_ERR_NO_ENTRY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cannot rename a path in the static VFS configuration.
|
|
|
|
*/
|
|
|
|
if (strlen(from_path) == 0)
|
|
|
|
return RENAME_ERR_NO_PERM;
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* Check if destination path resides within the same file
|
|
|
|
* system instance as the source path.
|
|
|
|
*/
|
|
|
|
if (!to_path)
|
|
|
|
return RENAME_ERR_CROSS_FS;
|
|
|
|
|
2016-03-09 07:56:49 +00:00
|
|
|
Rename_result final = RENAME_ERR_NO_ENTRY;
|
|
|
|
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
|
|
|
|
switch (fs->rename(from_path, to_path)) {
|
|
|
|
case RENAME_OK: return RENAME_OK;
|
|
|
|
case RENAME_ERR_NO_ENTRY: continue;
|
|
|
|
case RENAME_ERR_NO_PERM: return RENAME_ERR_NO_PERM;
|
|
|
|
case RENAME_ERR_CROSS_FS: final = RENAME_ERR_CROSS_FS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return final;
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
** File_system interface **
|
|
|
|
***************************/
|
|
|
|
|
2017-02-07 18:03:23 +00:00
|
|
|
char const *name() const { return "dir"; }
|
|
|
|
char const *type() override { return "dir"; }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-02-07 18:03:23 +00:00
|
|
|
void apply_config(Genode::Xml_node const &node) override
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
File_system *curr = _first_file_system;
|
|
|
|
for (unsigned i = 0; i < node.num_sub_nodes(); i++, curr = curr->next) {
|
|
|
|
Xml_node const &sub_node = node.sub_node(i);
|
|
|
|
|
|
|
|
/* check if type of XML node matches current file-system type */
|
|
|
|
if (sub_node.has_type(curr->type()) == false) {
|
|
|
|
Genode::error("VFS config update failed (node type '",
|
|
|
|
sub_node.type(), "' != fs type '", curr->type(),"')");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr->apply_config(node.sub_node(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/********************************
|
|
|
|
** File I/O 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
|
|
|
Write_result write(Vfs_handle *, char const *, file_size, file_size &) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
return WRITE_ERR_INVALID;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
bool queue_read(Vfs_handle *vfs_handle, file_size) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
2017-08-15 18:51:53 +00:00
|
|
|
Dir_vfs_handle *dir_vfs_handle =
|
|
|
|
static_cast<Dir_vfs_handle*>(vfs_handle);
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_vfs_root)
|
2017-08-15 18:51:53 +00:00
|
|
|
return _queue_read_of_file_systems(dir_vfs_handle);
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_top_dir(dir_vfs_handle->path.base()))
|
2017-08-15 18:51:53 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return _queue_read_of_file_systems(dir_vfs_handle);
|
2014-04-07 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
Read_result complete_read(Vfs_handle *vfs_handle,
|
2017-11-20 09:21:38 +00:00
|
|
|
char *dst, file_size count,
|
|
|
|
file_size &out_count) override
|
|
|
|
{
|
2017-08-15 18:51:53 +00:00
|
|
|
out_count = 0;
|
|
|
|
|
|
|
|
if (count < sizeof(Dirent))
|
|
|
|
return READ_ERR_INVALID;
|
|
|
|
|
|
|
|
Dir_vfs_handle *dir_vfs_handle =
|
|
|
|
static_cast<Dir_vfs_handle*>(vfs_handle);
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_vfs_root)
|
2017-08-15 18:51:53 +00:00
|
|
|
return _complete_read_of_file_systems(dir_vfs_handle, dst, count, out_count);
|
|
|
|
|
2017-11-20 09:21:38 +00:00
|
|
|
if (_top_dir(dir_vfs_handle->path.base())) {
|
2019-09-25 15:13:29 +00:00
|
|
|
|
|
|
|
Dirent &dirent = *(Dirent*)dst;
|
|
|
|
|
|
|
|
file_offset const index = vfs_handle->seek() / sizeof(Dirent);
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
2019-09-25 15:13:29 +00:00
|
|
|
dirent = {
|
|
|
|
.fileno = 1,
|
|
|
|
.type = Dirent_type::DIRECTORY,
|
|
|
|
.rwx = Node_rwx::rwx(),
|
|
|
|
.name = { _name.string() }
|
|
|
|
};
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
} else {
|
2019-09-25 15:13:29 +00:00
|
|
|
|
|
|
|
dirent = {
|
|
|
|
.fileno = 0,
|
|
|
|
.type = Dirent_type::END,
|
|
|
|
.rwx = { },
|
|
|
|
.name = { }
|
|
|
|
};
|
2017-08-15 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out_count = sizeof(Dirent);
|
|
|
|
|
|
|
|
return READ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _complete_read_of_file_systems(dir_vfs_handle, dst, count, out_count);
|
2017-11-20 09:21:38 +00:00
|
|
|
}
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2014-09-09 12:32:31 +00:00
|
|
|
Ftruncate_result ftruncate(Vfs_handle *, file_size) override
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
return FTRUNCATE_ERR_NO_PERM;
|
|
|
|
}
|
2017-02-01 10:28:15 +00:00
|
|
|
|
|
|
|
bool read_ready(Vfs_handle *handle) override
|
|
|
|
{
|
|
|
|
if (&handle->fs() == this)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return handle->fs().read_ready(handle);
|
|
|
|
}
|
2017-02-01 20:07:14 +00:00
|
|
|
|
|
|
|
bool notify_read_ready(Vfs_handle *handle) override
|
|
|
|
{
|
|
|
|
if (&handle->fs() == this)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return handle->fs().notify_read_ready(handle);
|
|
|
|
}
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
bool queue_sync(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
2017-11-08 03:41:56 +00:00
|
|
|
bool result = true;
|
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
Dir_vfs_handle *dir_vfs_handle =
|
|
|
|
static_cast<Dir_vfs_handle*>(vfs_handle);
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
auto f = [&result, dir_vfs_handle] (Dir_vfs_handle::Subdir_handle_element &e) {
|
2019-03-25 14:41:43 +00:00
|
|
|
/* forward the response handler */
|
|
|
|
dir_vfs_handle->apply_handler([&] (Io_response_handler &h) {
|
|
|
|
e.vfs_handle.handler(&h); });
|
2018-01-10 12:27:31 +00:00
|
|
|
e.synced = false;
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
if (!e.vfs_handle.fs().queue_sync(&e.vfs_handle)) {
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
};
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
dir_vfs_handle->subdir_handle_registry.for_each(f);
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
return result;
|
2017-08-15 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sync_result complete_sync(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
|
|
|
Sync_result result = SYNC_OK;
|
|
|
|
|
|
|
|
Dir_vfs_handle *dir_vfs_handle =
|
|
|
|
static_cast<Dir_vfs_handle*>(vfs_handle);
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
auto f = [&result, dir_vfs_handle] (Dir_vfs_handle::Subdir_handle_element &e) {
|
2018-01-10 12:27:31 +00:00
|
|
|
if (e.synced)
|
|
|
|
return;
|
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
Sync_result r = e.vfs_handle.fs().complete_sync(&e.vfs_handle);
|
|
|
|
if (r != SYNC_OK)
|
|
|
|
result = r;
|
2018-01-10 12:27:31 +00:00
|
|
|
else
|
|
|
|
e.synced = true;
|
2017-11-08 03:41:56 +00:00
|
|
|
};
|
2017-08-15 18:51:53 +00:00
|
|
|
|
2017-11-08 03:41:56 +00:00
|
|
|
dir_vfs_handle->subdir_handle_registry.for_each(f);
|
2017-08-15 18:51:53 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2014-04-07 14:15:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VFS__DIR_FILE_SYSTEM_H_ */
|