libc: add modification time

Issue #1784.
This commit is contained in:
Josef Söntgen 2019-03-20 15:16:07 +01:00 committed by Christian Helmuth
parent 9a82bbb54d
commit d0bf6d2b52
2 changed files with 43 additions and 0 deletions

View File

@ -48,6 +48,11 @@ class Libc::Vfs_plugin : public Plugin
*/
int _vfs_sync(Vfs::Vfs_handle&);
/**
* Update modification time
*/
void _vfs_write_mtime(Vfs::Vfs_handle&);
public:
Vfs_plugin(Libc::Env &env,

View File

@ -108,6 +108,8 @@ static void vfs_stat_to_libc_stat_struct(Vfs::Directory_service::Stat const &src
dst->st_blocks = (dst->st_size + FS_BLOCK_SIZE - 1) / FS_BLOCK_SIZE;
dst->st_ino = src.inode;
dst->st_dev = src.device;
long long mtime = src.modification_time.value;
dst->st_mtime = mtime != Vfs::Timestamp::INVALID ? mtime : 0;
}
@ -343,8 +345,44 @@ Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags,
}
void Libc::Vfs_plugin::_vfs_write_mtime(Vfs::Vfs_handle &handle)
{
struct timespec ts;
/* XXX using clock_gettime directly is probably not the best idea */
if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
ts.tv_sec = 0;
}
Vfs::Timestamp time { .value = (long long)ts.tv_sec };
struct Check : Libc::Suspend_functor
{
bool retry { false };
Vfs::Vfs_handle &vfs_handle;
Vfs::Timestamp &time;
Check(Vfs::Vfs_handle &vfs_handle, Vfs::Timestamp &time)
: vfs_handle(vfs_handle), time(time) { }
bool suspend() override
{
retry = !vfs_handle.fs().update_modification_timestamp(&vfs_handle, time);
return retry;
}
} check(handle, time);
do {
_suspend_ptr->suspend(check);
} while (check.retry);
}
int Libc::Vfs_plugin::_vfs_sync(Vfs::Vfs_handle &vfs_handle)
{
_vfs_write_mtime(vfs_handle);
typedef Vfs::File_io_service::Sync_result Result;
Result result = Result::SYNC_QUEUED;