2013-12-05 15:45:14 +01:00
|
|
|
/**
|
|
|
|
* \brief Rump symlink node
|
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2014-01-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2013-12-05 15:45:14 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-12-05 15:45:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYMLINK_H_
|
|
|
|
#define _SYMLINK_H_
|
|
|
|
|
2015-04-23 21:26:54 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <file_system/util.h>
|
2013-12-05 15:45:14 +01:00
|
|
|
#include <os/path.h>
|
|
|
|
|
|
|
|
#include "node.h"
|
|
|
|
|
2017-06-20 14:23:22 +02:00
|
|
|
namespace Rump_fs {
|
2013-12-05 15:45:14 +01:00
|
|
|
class Symlink;
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:23:22 +02:00
|
|
|
class Rump_fs::Symlink : public Node
|
2013-12-05 15:45:14 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
typedef Genode::Path<MAX_PATH_LEN> Path;
|
|
|
|
|
|
|
|
Path _path;
|
|
|
|
bool _create;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Symlink(char const *dir, char const *name, bool create)
|
|
|
|
: Node(0), _path(name, dir), _create(create)
|
|
|
|
{
|
|
|
|
Node::name(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Symlink(char const *path)
|
|
|
|
: Node(0), _path(path), _create(false)
|
|
|
|
{
|
|
|
|
Node::name(basename(path));
|
|
|
|
}
|
|
|
|
|
2019-03-20 14:52:13 +01:00
|
|
|
void update_modification_time(Timestamp const time) override
|
|
|
|
{
|
|
|
|
/* XXX not handled for now: either dirfd or fd to _path is required */
|
|
|
|
}
|
|
|
|
|
2018-02-13 15:13:06 +01:00
|
|
|
size_t write(char const *src, size_t const len, seek_off_t seek_offset) override
|
2013-12-05 15:45:14 +01:00
|
|
|
{
|
2015-06-27 22:50:49 +02:00
|
|
|
/* Ideal symlink operations are atomic. */
|
|
|
|
if (!_create || seek_offset)
|
2013-12-05 15:45:14 +01:00
|
|
|
return 0;
|
|
|
|
|
2016-07-15 14:38:08 +02:00
|
|
|
/* src may not be null-terminated */
|
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 19:07:09 +02:00
|
|
|
Genode::String<MAX_PATH_LEN> target(Genode::Cstring(src, len));
|
2016-07-15 14:38:08 +02:00
|
|
|
|
|
|
|
int ret = rump_sys_symlink(target.string(), _path.base());
|
2018-02-13 15:13:06 +01:00
|
|
|
return ret == -1 ? 0 : len;
|
2013-12-05 15:45:14 +01:00
|
|
|
}
|
|
|
|
|
2017-06-20 14:23:22 +02:00
|
|
|
size_t read(char *dst, size_t len, seek_off_t seek_offset) override
|
2013-12-05 15:45:14 +01:00
|
|
|
{
|
|
|
|
int ret = rump_sys_readlink(_path.base(), dst, len);
|
|
|
|
return ret == -1 ? 0 : ret;
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:23:22 +02:00
|
|
|
Status status() override
|
|
|
|
{
|
2019-03-20 14:52:13 +01:00
|
|
|
struct stat st;
|
|
|
|
if (rump_sys_lstat(_path.base(), &st) < 0) {
|
|
|
|
st.st_mtime = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:23:22 +02:00
|
|
|
Status s;
|
|
|
|
s.inode = inode();
|
|
|
|
s.size = length();
|
|
|
|
s.mode = File_system::Status::MODE_SYMLINK;
|
2019-03-20 14:52:13 +01:00
|
|
|
s.modification_time = { (int64_t)st.st_mtime };
|
2017-06-20 14:23:22 +02:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-12-05 15:45:14 +01:00
|
|
|
file_size_t length()
|
|
|
|
{
|
|
|
|
char link_to[MAX_PATH_LEN];
|
|
|
|
return read(link_to, MAX_PATH_LEN, 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _SYMLINK_H_ */
|