genode/repos/os/src/server/ram_fs/symlink.h
Emery Hemingway 2f1db06deb rump_fs/fuse_fs/lx_fs/ram_fs: symlink fixup
Allow symlinks to be passed to the read and write file system utilities.

Disallow writes to symlinks with offsets in file system servers, this is
to ensure that writing the target of a symlink is an atomic operation.

Fixes #1604
2015-07-21 09:40:19 +02:00

47 lines
887 B
C++

/*
* \brief Symlink file-system node
* \author Norman Feske
* \date 2012-04-11
*/
#ifndef _SYMLINK_H_
#define _SYMLINK_H_
/* local includes */
#include <node.h>
namespace File_system {
class Symlink : public Node
{
private:
char _link_to[MAX_PATH_LEN];
public:
Symlink(char const *name) { Node::name(name); }
size_t read(char *dst, size_t len, seek_off_t seek_offset)
{
size_t count = min(len, sizeof(_link_to) + 1);
Genode::strncpy(dst, _link_to, count);
return count;
}
size_t write(char const *src, size_t len, seek_off_t seek_offset)
{
/* Ideal symlink operations are atomic. */
if (seek_offset) return 0;
size_t count = min(len, sizeof(_link_to) + 1);
Genode::strncpy(_link_to, src, count);
return count;
}
file_size_t length() const { return strlen(_link_to) + 1; }
};
}
#endif /* _SYMLINK_H_ */