2014-04-07 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* \brief Directory-service interface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2011-02-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2011-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__DIRECTORY_SERVICE_H_
|
|
|
|
#define _INCLUDE__VFS__DIRECTORY_SERVICE_H_
|
|
|
|
|
|
|
|
#include <vfs/types.h>
|
|
|
|
|
|
|
|
namespace Vfs {
|
|
|
|
class Vfs_handle;
|
2018-03-31 14:50:49 +00:00
|
|
|
class Vfs_watch_handle;
|
2014-04-07 14:15:40 +00:00
|
|
|
struct Directory_service;
|
2016-03-30 13:24:19 +00:00
|
|
|
|
|
|
|
using Genode::Allocator;
|
2014-04-07 14:15:40 +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
|
|
|
struct Vfs::Directory_service : Interface
|
2014-04-07 14:15:40 +00:00
|
|
|
{
|
|
|
|
virtual Dataspace_capability dataspace(char const *path) = 0;
|
|
|
|
virtual void release(char const *path, Dataspace_capability) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
enum General_error { ERR_FD_INVALID, NUM_GENERAL_ERRORS };
|
|
|
|
|
|
|
|
|
|
|
|
/**********
|
|
|
|
** Open **
|
|
|
|
**********/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flags of 'mode' argument of open syscall
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
OPEN_MODE_RDONLY = 0,
|
|
|
|
OPEN_MODE_WRONLY = 1,
|
|
|
|
OPEN_MODE_RDWR = 2,
|
|
|
|
OPEN_MODE_ACCMODE = 3,
|
|
|
|
OPEN_MODE_CREATE = 0x0800, /* libc O_EXCL */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Open_result
|
|
|
|
{
|
|
|
|
OPEN_ERR_UNACCESSIBLE,
|
|
|
|
OPEN_ERR_NO_PERM,
|
|
|
|
OPEN_ERR_EXISTS,
|
2015-10-01 09:53:00 +00:00
|
|
|
OPEN_ERR_NAME_TOO_LONG,
|
|
|
|
OPEN_ERR_NO_SPACE,
|
2017-08-15 18:51:53 +00:00
|
|
|
OPEN_ERR_OUT_OF_RAM,
|
|
|
|
OPEN_ERR_OUT_OF_CAPS,
|
2014-04-07 14:15:40 +00:00
|
|
|
OPEN_OK
|
|
|
|
};
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
virtual Open_result open(char const *path,
|
|
|
|
unsigned mode,
|
|
|
|
Vfs_handle **handle,
|
2016-05-25 13:47:22 +00:00
|
|
|
Allocator &alloc) = 0;
|
2016-03-30 13:24:19 +00:00
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
enum Opendir_result
|
|
|
|
{
|
|
|
|
OPENDIR_ERR_LOOKUP_FAILED,
|
|
|
|
OPENDIR_ERR_NAME_TOO_LONG,
|
|
|
|
OPENDIR_ERR_NODE_ALREADY_EXISTS,
|
|
|
|
OPENDIR_ERR_NO_SPACE,
|
|
|
|
OPENDIR_ERR_OUT_OF_RAM,
|
|
|
|
OPENDIR_ERR_OUT_OF_CAPS,
|
|
|
|
OPENDIR_ERR_PERMISSION_DENIED,
|
|
|
|
OPENDIR_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
|
|
|
virtual Opendir_result opendir(char const * /* path */, bool /* create */,
|
|
|
|
Vfs_handle **, Allocator &)
|
2017-08-15 18:51:53 +00:00
|
|
|
{
|
|
|
|
return OPENDIR_ERR_LOOKUP_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Openlink_result
|
|
|
|
{
|
|
|
|
OPENLINK_ERR_LOOKUP_FAILED,
|
|
|
|
OPENLINK_ERR_NAME_TOO_LONG,
|
|
|
|
OPENLINK_ERR_NODE_ALREADY_EXISTS,
|
|
|
|
OPENLINK_ERR_NO_SPACE,
|
|
|
|
OPENLINK_ERR_OUT_OF_RAM,
|
|
|
|
OPENLINK_ERR_OUT_OF_CAPS,
|
|
|
|
OPENLINK_ERR_PERMISSION_DENIED,
|
|
|
|
OPENLINK_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
|
|
|
virtual Openlink_result openlink(char const * /* path */, bool /* create */,
|
|
|
|
Vfs_handle **, Allocator &)
|
2017-08-15 18:51:53 +00:00
|
|
|
{
|
|
|
|
return OPENLINK_ERR_PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
/**
|
|
|
|
* Close handle resources and deallocate handle
|
2017-08-15 18:51:53 +00:00
|
|
|
*
|
|
|
|
* Note: it might be necessary to call 'sync()' before 'close()'
|
|
|
|
* to ensure that previously written data has been completely
|
|
|
|
* processed.
|
2016-03-30 13:24:19 +00:00
|
|
|
*/
|
|
|
|
virtual void close(Vfs_handle *handle) = 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2018-03-31 14:50:49 +00:00
|
|
|
enum Watch_result
|
|
|
|
{
|
|
|
|
WATCH_ERR_UNACCESSIBLE,
|
|
|
|
WATCH_ERR_STATIC,
|
|
|
|
WATCH_ERR_OUT_OF_RAM,
|
|
|
|
WATCH_ERR_OUT_OF_CAPS,
|
|
|
|
WATCH_OK
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Watch a file-system node for changes.
|
|
|
|
*/
|
|
|
|
virtual Watch_result watch(char const *path,
|
|
|
|
Vfs_watch_handle**,
|
|
|
|
Allocator&)
|
|
|
|
{
|
|
|
|
/* default implementation for static file-systems */
|
2018-04-04 10:33:53 +00:00
|
|
|
return (leaf_path(path)) ? WATCH_ERR_STATIC : WATCH_ERR_UNACCESSIBLE;
|
2018-03-31 14:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void close(Vfs_watch_handle *)
|
|
|
|
{
|
|
|
|
Genode::error("watch handle closed at invalid file-system");
|
|
|
|
throw ~0;
|
|
|
|
};
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/**********
|
|
|
|
** Stat **
|
|
|
|
**********/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These values are the same as in the FreeBSD libc
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
STAT_MODE_SYMLINK = 0120000,
|
|
|
|
STAT_MODE_FILE = 0100000,
|
|
|
|
STAT_MODE_DIRECTORY = 0040000,
|
|
|
|
STAT_MODE_CHARDEV = 0020000,
|
|
|
|
STAT_MODE_BLOCKDEV = 0060000,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Stat
|
|
|
|
{
|
2016-06-22 13:38:42 +00:00
|
|
|
file_size size = 0;
|
|
|
|
unsigned mode = 0;
|
|
|
|
unsigned uid = 0;
|
|
|
|
unsigned gid = 0;
|
|
|
|
unsigned long inode = 0;
|
|
|
|
unsigned long device = 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
};
|
|
|
|
|
2016-04-01 09:42:31 +00:00
|
|
|
enum Stat_result { STAT_ERR_NO_ENTRY = NUM_GENERAL_ERRORS,
|
|
|
|
STAT_ERR_NO_PERM, STAT_OK };
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2017-08-15 18:51:53 +00:00
|
|
|
/*
|
|
|
|
* Note: it might be necessary to call 'sync()' before 'stat()'
|
|
|
|
* to get the correct file size.
|
|
|
|
*/
|
2014-04-07 14:15:40 +00:00
|
|
|
virtual Stat_result stat(char const *path, Stat &) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/************
|
|
|
|
** Dirent **
|
|
|
|
************/
|
|
|
|
|
|
|
|
enum { DIRENT_MAX_NAME_LEN = 128 };
|
|
|
|
|
|
|
|
enum Dirent_type {
|
|
|
|
DIRENT_TYPE_FILE,
|
|
|
|
DIRENT_TYPE_DIRECTORY,
|
|
|
|
DIRENT_TYPE_FIFO,
|
|
|
|
DIRENT_TYPE_CHARDEV,
|
|
|
|
DIRENT_TYPE_BLOCKDEV,
|
|
|
|
DIRENT_TYPE_SYMLINK,
|
|
|
|
DIRENT_TYPE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Dirent
|
|
|
|
{
|
2016-06-22 13:38:42 +00:00
|
|
|
unsigned long fileno = 0;
|
|
|
|
Dirent_type type = DIRENT_TYPE_END;
|
|
|
|
char name[DIRENT_MAX_NAME_LEN] = { 0 };
|
2014-04-07 14:15:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/************
|
|
|
|
** Unlink **
|
|
|
|
************/
|
|
|
|
|
2015-10-30 11:33:26 +00:00
|
|
|
enum Unlink_result { UNLINK_ERR_NO_ENTRY, UNLINK_ERR_NO_PERM,
|
|
|
|
UNLINK_ERR_NOT_EMPTY, UNLINK_OK };
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
virtual Unlink_result unlink(char const *path) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/************
|
|
|
|
** Rename **
|
|
|
|
************/
|
|
|
|
|
|
|
|
enum Rename_result { RENAME_ERR_NO_ENTRY, RENAME_ERR_CROSS_FS,
|
|
|
|
RENAME_ERR_NO_PERM, RENAME_OK };
|
|
|
|
|
|
|
|
virtual Rename_result rename(char const *from, char const *to) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return number of directory entries located at given path
|
|
|
|
*/
|
2014-09-09 12:32:31 +00:00
|
|
|
virtual file_size num_dirent(char const *path) = 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
virtual bool directory(char const *path) = 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
2018-07-09 15:34:50 +00:00
|
|
|
/**
|
|
|
|
* Return leaf path or nullptr if the path does not exist
|
|
|
|
*/
|
2014-04-07 14:15:40 +00:00
|
|
|
virtual char const *leaf_path(char const *path) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VFS__DIRECTORY_SERVICE_H_ */
|