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
This commit is contained in:
Emery Hemingway 2015-06-27 15:50:49 -05:00 committed by Norman Feske
parent b60f28bee9
commit 2f1db06deb
5 changed files with 15 additions and 5 deletions

View File

@ -49,7 +49,8 @@ class File_system::Symlink : public Node
size_t write(char const *src, size_t len, seek_off_t seek_offset) size_t write(char const *src, size_t len, seek_off_t seek_offset)
{ {
if (!_create) /* Ideal symlink operations are atomic. */
if (!_create || seek_offset)
return 0; return 0;
int ret = rump_sys_symlink(src, _path.base()); int ret = rump_sys_symlink(src, _path.base());

View File

@ -70,6 +70,9 @@ class File_system::Symlink : public Node
size_t write(char const *src, size_t len, seek_off_t seek_offset) size_t write(char const *src, size_t len, seek_off_t seek_offset)
{ {
/* Ideal symlink operations are atomic. */
if (seek_offset) return 0;
int res = Fuse::fuse()->op.symlink(src, _path.base()); int res = Fuse::fuse()->op.symlink(src, _path.base());
if (res != 0) if (res != 0)
return 0; return 0;

View File

@ -103,7 +103,7 @@ namespace File_system {
/** /**
* Read file content * Read file content
*/ */
static inline size_t read(Session &fs, File_handle const &file_handle, static inline size_t read(Session &fs, Node_handle const &node_handle,
void *dst, size_t count, seek_off_t seek_offset = 0) void *dst, size_t count, seek_off_t seek_offset = 0)
{ {
bool success = true; bool success = true;
@ -122,7 +122,7 @@ namespace File_system {
Packet_descriptor Packet_descriptor
packet(source.alloc_packet(curr_packet_size), packet(source.alloc_packet(curr_packet_size),
0, 0,
file_handle, node_handle,
File_system::Packet_descriptor::READ, File_system::Packet_descriptor::READ,
curr_packet_size, curr_packet_size,
seek_offset); seek_offset);
@ -160,7 +160,7 @@ namespace File_system {
/** /**
* Write file content * Write file content
*/ */
static inline size_t write(Session &fs, File_handle const &file_handle, static inline size_t write(Session &fs, Node_handle const &node_handle,
void const *src, size_t count, seek_off_t seek_offset = 0) void const *src, size_t count, seek_off_t seek_offset = 0)
{ {
bool success = true; bool success = true;
@ -179,7 +179,7 @@ namespace File_system {
Packet_descriptor Packet_descriptor
packet(source.alloc_packet(curr_packet_size), packet(source.alloc_packet(curr_packet_size),
0, 0,
file_handle, node_handle,
File_system::Packet_descriptor::WRITE, File_system::Packet_descriptor::WRITE,
curr_packet_size, curr_packet_size,
seek_offset); seek_offset);

View File

@ -39,6 +39,9 @@ class File_system::Symlink : public Node
size_t write(char const *src, size_t len, seek_off_t seek_offset) 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); size_t count = min(len, sizeof(_link_to) + 1);
Genode::strncpy(_link_to, src, count); Genode::strncpy(_link_to, src, count);
return count; return count;

View File

@ -31,6 +31,9 @@ namespace File_system {
size_t write(char const *src, size_t len, seek_off_t seek_offset) 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); size_t count = min(len, sizeof(_link_to) + 1);
Genode::strncpy(_link_to, src, count); Genode::strncpy(_link_to, src, count);
return count; return count;