1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

Kernel+LibC+VFS: Implement utimensat(3)

Create POSIX utimensat() library call and corresponding system call to
update file access and modification times.
This commit is contained in:
Ariel Don 2022-05-02 15:26:10 -05:00 committed by Andreas Kling
parent 7550017f97
commit 9a6bd85924
10 changed files with 146 additions and 0 deletions

View file

@ -1545,6 +1545,8 @@ ErrorOr<void> Ext2FSInode::set_atime(time_t t)
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
return EROFS;
if (t > INT32_MAX)
return EINVAL;
m_raw_inode.i_atime = t;
set_metadata_dirty(true);
return {};

View file

@ -196,6 +196,25 @@ ErrorOr<void> VirtualFileSystem::utime(StringView path, Custody& base, time_t at
return {};
}
ErrorOr<void> VirtualFileSystem::utimensat(StringView path, Custody& base, timespec const& atime, timespec const& mtime, int options)
{
auto custody = TRY(resolve_path(path, base, nullptr, options));
auto& inode = custody->inode();
auto& current_process = Process::current();
if (!current_process.is_superuser() && inode.metadata().uid != current_process.euid())
return EACCES;
if (custody->is_readonly())
return EROFS;
// NOTE: A standard ext2 inode cannot store nanosecond timestamps.
if (atime.tv_nsec != UTIME_OMIT)
TRY(inode.set_atime(atime.tv_sec));
if (mtime.tv_nsec != UTIME_OMIT)
TRY(inode.set_mtime(mtime.tv_sec));
return {};
}
ErrorOr<InodeMetadata> VirtualFileSystem::lookup_metadata(StringView path, Custody& base, int options)
{
auto custody = TRY(resolve_path(path, base, nullptr, options));

View file

@ -64,6 +64,7 @@ public:
ErrorOr<void> access(StringView path, int mode, Custody& base);
ErrorOr<InodeMetadata> lookup_metadata(StringView path, Custody& base, int options = 0);
ErrorOr<void> utime(StringView path, Custody& base, time_t atime, time_t mtime);
ErrorOr<void> utimensat(StringView path, Custody& base, timespec const& atime, timespec const& mtime, int options = 0);
ErrorOr<void> rename(StringView oldpath, StringView newpath, Custody& base);
ErrorOr<void> mknod(StringView path, mode_t, dev_t, Custody& base);
ErrorOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base);