rump_fs: add modification time

Issue #1784.
This commit is contained in:
Josef Söntgen 2019-03-20 14:52:13 +01:00 committed by Christian Helmuth
parent 2e5166efd7
commit 400039e1b6
5 changed files with 57 additions and 11 deletions

View File

@ -148,6 +148,17 @@ class Rump_fs::Directory : public Node
return node;
}
void update_modification_time(Timestamp const time) override
{
struct timespec ts[2] = {
{ .tv_sec = 0, .tv_nsec = 0 },
{ .tv_sec = time.value, .tv_nsec = 0 }
};
/* silently igore error */
rump_sys_futimens(_fd, (const timespec*)&ts);
}
size_t read(char *dst, size_t len, seek_off_t seek_offset) override
{
if (len < sizeof(Directory_entry)) {
@ -230,10 +241,15 @@ class Rump_fs::Directory : public Node
Status status() override
{
struct stat st;
if (rump_sys_fstat(_fd, &st) < 0)
st.st_mtime = 0;
Status s;
s.inode = inode();
s.size = num_entries() * sizeof (Directory_entry);
s.mode = File_system::Status::MODE_DIRECTORY;
s.modification_time = { (int64_t)st.st_mtime };
return s;
}

View File

@ -114,6 +114,17 @@ class Rump_fs::File : public Node
virtual ~File() { rump_sys_close(_fd); }
void update_modification_time(Timestamp const time) override
{
struct timespec ts[2] = {
{ .tv_sec = 0, .tv_nsec = 0 },
{ .tv_sec = time.value, .tv_nsec = 0 }
};
/* silently igore error */
rump_sys_futimens(_fd, (const timespec*)&ts);
}
size_t read(char *dst, size_t len, seek_off_t seek_offset) override
{
ssize_t ret;
@ -142,25 +153,22 @@ class Rump_fs::File : public Node
virtual Status status() override
{
struct stat st;
if (rump_sys_fstat(_fd, &st) < 0) {
st.st_size = 0;
st.st_mtime = 0;
}
Status s;
s.inode = inode();
s.size = length();
s.size = st.st_size;
s.mode = File_system::Status::MODE_FILE;
s.modification_time = { (int64_t)st.st_mtime };
return s;
}
file_size_t length() const
{
struct stat s;
if(rump_sys_fstat(_fd, &s) < 0)
return 0;
return s.st_size;
}
void truncate(file_size_t size) override
{
rump_sys_ftruncate(_fd, size);

View File

@ -100,6 +100,15 @@ class Rump_fs::Session_component : public Session_rpc_object
}
break;
case Packet_descriptor::WRITE_TIMESTAMP:
if (tx_sink()->packet_valid(packet) && packet.length() <= packet.size()) {
packet.with_timestamp([&] (File_system::Timestamp const time) {
open_node.node().update_modification_time(time);
succeeded = true;
});
}
break;
case Packet_descriptor::CONTENT_CHANGED:
open_node.register_notify(*tx_sink());
/* notify_listeners may bounce the packet back*/

View File

@ -54,6 +54,8 @@ class Rump_fs::Node : public Node_base
*/
void name(char const *name) { strncpy(_name, name, sizeof(_name)); }
virtual void update_modification_time(Timestamp const) = 0;
virtual size_t read(char *dst, size_t len, seek_off_t) = 0;
virtual size_t write(char const *src, size_t len, seek_off_t) = 0;
virtual Status status() = 0;

View File

@ -47,6 +47,11 @@ class Rump_fs::Symlink : public Node
Node::name(basename(path));
}
void update_modification_time(Timestamp const time) override
{
/* XXX not handled for now: either dirfd or fd to _path is required */
}
size_t write(char const *src, size_t const len, seek_off_t seek_offset) override
{
/* Ideal symlink operations are atomic. */
@ -68,10 +73,16 @@ class Rump_fs::Symlink : public Node
Status status() override
{
struct stat st;
if (rump_sys_lstat(_path.base(), &st) < 0) {
st.st_mtime = 0;
}
Status s;
s.inode = inode();
s.size = length();
s.mode = File_system::Status::MODE_SYMLINK;
s.modification_time = { (int64_t)st.st_mtime };
return s;
}