diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index c1c8d5d93db..b2f90f85ac1 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1537,34 +1537,23 @@ ErrorOr> Ext2FSInode::lookup(StringView name) return fs().get_inode({ fsid(), inode_index }); } -ErrorOr Ext2FSInode::set_atime(time_t t) +ErrorOr Ext2FSInode::update_timestamps(Optional atime, Optional ctime, Optional mtime) { MutexLocker locker(m_inode_lock); if (fs().is_readonly()) return EROFS; - if (t > INT32_MAX) + if (atime.value_or(0) > INT32_MAX) return EINVAL; - m_raw_inode.i_atime = t; - set_metadata_dirty(true); - return {}; -} - -ErrorOr Ext2FSInode::set_ctime(time_t t) -{ - MutexLocker locker(m_inode_lock); - if (fs().is_readonly()) - return EROFS; - m_raw_inode.i_ctime = t; - set_metadata_dirty(true); - return {}; -} - -ErrorOr Ext2FSInode::set_mtime(time_t t) -{ - MutexLocker locker(m_inode_lock); - if (fs().is_readonly()) - return EROFS; - m_raw_inode.i_mtime = t; + if (ctime.value_or(0) > INT32_MAX) + return EINVAL; + if (mtime.value_or(0) > INT32_MAX) + return EINVAL; + if (atime.has_value()) + m_raw_inode.i_atime = atime.value(); + if (ctime.has_value()) + m_raw_inode.i_ctime = ctime.value(); + if (mtime.has_value()) + m_raw_inode.i_mtime = mtime.value(); set_metadata_dirty(true); return {}; } diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index 35b6805e028..e9b7de9fbdb 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -44,9 +44,7 @@ private: virtual ErrorOr> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual ErrorOr add_child(Inode& child, StringView name, mode_t) override; virtual ErrorOr remove_child(StringView name) override; - virtual ErrorOr set_atime(time_t) override; - virtual ErrorOr set_ctime(time_t) override; - virtual ErrorOr set_mtime(time_t) override; + virtual ErrorOr update_timestamps(Optional atime, Optional ctime, Optional mtime) override; virtual ErrorOr increment_link_count() override; virtual ErrorOr decrement_link_count() override; virtual ErrorOr chmod(mode_t) override; diff --git a/Kernel/FileSystem/ISO9660FileSystem.cpp b/Kernel/FileSystem/ISO9660FileSystem.cpp index 670d5964b6b..528cebc5bbb 100644 --- a/Kernel/FileSystem/ISO9660FileSystem.cpp +++ b/Kernel/FileSystem/ISO9660FileSystem.cpp @@ -528,17 +528,7 @@ ErrorOr ISO9660Inode::truncate(u64) return EROFS; } -ErrorOr ISO9660Inode::set_atime(time_t) -{ - return EROFS; -} - -ErrorOr ISO9660Inode::set_ctime(time_t) -{ - return EROFS; -} - -ErrorOr ISO9660Inode::set_mtime(time_t) +ErrorOr ISO9660Inode::update_timestamps(Optional, Optional, Optional) { return EROFS; } diff --git a/Kernel/FileSystem/ISO9660FileSystem.h b/Kernel/FileSystem/ISO9660FileSystem.h index 62f76912e17..9480f2d40db 100644 --- a/Kernel/FileSystem/ISO9660FileSystem.h +++ b/Kernel/FileSystem/ISO9660FileSystem.h @@ -359,9 +359,7 @@ public: virtual ErrorOr chmod(mode_t) override; virtual ErrorOr chown(UserID, GroupID) override; virtual ErrorOr truncate(u64) override; - virtual ErrorOr set_atime(time_t) override; - virtual ErrorOr set_ctime(time_t) override; - virtual ErrorOr set_mtime(time_t) override; + virtual ErrorOr update_timestamps(Optional atime, Optional ctime, Optional mtime) override; private: // HACK: The base ISO 9660 standard says the maximum filename length is 37 diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index f7e9b04b228..faa5050f86e 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -106,17 +106,7 @@ void Inode::will_be_destroyed() (void)flush_metadata(); } -ErrorOr Inode::set_atime(time_t) -{ - return ENOTIMPL; -} - -ErrorOr Inode::set_ctime(time_t) -{ - return ENOTIMPL; -} - -ErrorOr Inode::set_mtime(time_t) +ErrorOr Inode::update_timestamps([[maybe_unused]] Optional atime, [[maybe_unused]] Optional ctime, [[maybe_unused]] Optional mtime) { return ENOTIMPL; } @@ -236,8 +226,7 @@ void Inode::did_modify_contents() // FIXME: What happens if this fails? // ENOTIMPL would be a meaningless error to return here auto time = kgettimeofday().to_truncated_seconds(); - (void)set_mtime(time); - (void)set_ctime(time); + (void)update_timestamps({}, time, time); m_watchers.for_each([&](auto& watcher) { watcher->notify_inode_event({}, identifier(), InodeWatcherEvent::Type::ContentModified); diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index 2d8660ec98d..a01df472466 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -80,9 +80,7 @@ public: bool is_metadata_dirty() const { return m_metadata_dirty; } - virtual ErrorOr set_atime(time_t); - virtual ErrorOr set_ctime(time_t); - virtual ErrorOr set_mtime(time_t); + virtual ErrorOr update_timestamps(Optional atime, Optional ctime, Optional mtime); virtual ErrorOr increment_link_count(); virtual ErrorOr decrement_link_count(); diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 08058d866c3..9a805774bf5 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -49,7 +49,7 @@ ErrorOr InodeFile::write(OpenFileDescription& description, u64 offset, U nwritten = TRY(m_inode->write_bytes(offset, count, data, &description)); } if (nwritten > 0) { - auto mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); + auto mtime_result = m_inode->update_timestamps({}, {}, kgettimeofday().to_truncated_seconds()); Thread::current()->did_file_write(nwritten); evaluate_block_conditions(); if (mtime_result.is_error()) @@ -106,7 +106,7 @@ ErrorOr> InodeFile::pseudo_path(OpenFileDescription const ErrorOr InodeFile::truncate(u64 size) { TRY(m_inode->truncate(size)); - TRY(m_inode->set_mtime(kgettimeofday().to_truncated_seconds())); + TRY(m_inode->update_timestamps({}, {}, kgettimeofday().to_truncated_seconds())); return {}; } diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 4d6cb263b85..ee5cbf149fc 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -145,11 +145,6 @@ ErrorOr ProcFSGlobalInode::truncate(u64 size) return m_associated_component->truncate(size); } -ErrorOr ProcFSGlobalInode::set_mtime(time_t time) -{ - return m_associated_component->set_mtime(time); -} - InodeMetadata ProcFSGlobalInode::metadata() const { MutexLocker locker(m_inode_lock); diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h index 1601ba9e2c4..b9a878aaadc 100644 --- a/Kernel/FileSystem/ProcFS.h +++ b/Kernel/FileSystem/ProcFS.h @@ -84,7 +84,6 @@ protected: virtual ErrorOr traverse_as_directory(Function(FileSystem::DirectoryEntryView const&)>) const override; virtual ErrorOr> lookup(StringView) override; virtual ErrorOr truncate(u64) override final; - virtual ErrorOr set_mtime(time_t) override final; NonnullLockRefPtr m_associated_component; }; diff --git a/Kernel/FileSystem/SysFS.cpp b/Kernel/FileSystem/SysFS.cpp index 00783245b6f..33ae1bff947 100644 --- a/Kernel/FileSystem/SysFS.cpp +++ b/Kernel/FileSystem/SysFS.cpp @@ -121,11 +121,6 @@ ErrorOr SysFSInode::chown(UserID, GroupID) return EPERM; } -ErrorOr SysFSInode::set_mtime(time_t time) -{ - return m_associated_component->set_mtime(time); -} - ErrorOr SysFSInode::truncate(u64 size) { return m_associated_component->truncate(size); diff --git a/Kernel/FileSystem/SysFS.h b/Kernel/FileSystem/SysFS.h index 0afd4b22d04..303585ecf6e 100644 --- a/Kernel/FileSystem/SysFS.h +++ b/Kernel/FileSystem/SysFS.h @@ -54,7 +54,6 @@ protected: virtual ErrorOr chmod(mode_t) override; virtual ErrorOr chown(UserID, GroupID) override; virtual ErrorOr truncate(u64) override; - virtual ErrorOr set_mtime(time_t) override; virtual ErrorOr attach(OpenFileDescription& description) override final; virtual void did_seek(OpenFileDescription&, off_t) override final; diff --git a/Kernel/FileSystem/SysFS/Component.h b/Kernel/FileSystem/SysFS/Component.h index 6ea0ee48153..4b18eeaf885 100644 --- a/Kernel/FileSystem/SysFS/Component.h +++ b/Kernel/FileSystem/SysFS/Component.h @@ -35,7 +35,6 @@ public: virtual mode_t permissions() const; virtual ErrorOr truncate(u64) { return EPERM; } virtual size_t size() const { return 0; } - virtual ErrorOr set_mtime(time_t) { return ENOTIMPL; } virtual ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; } virtual ErrorOr refresh_data(OpenFileDescription&) const { return {}; } diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h b/Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h index c7a79eaef55..ba2f979d280 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h +++ b/Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h @@ -27,7 +27,6 @@ public: virtual mode_t permissions() const override; virtual ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override; virtual ErrorOr truncate(u64) override; - virtual ErrorOr set_mtime(time_t) override { return {}; } private: PowerStateSwitchNode(FirmwareSysFSDirectory&); diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index bbdd340a651..9dc3bf211b0 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -301,29 +301,16 @@ ErrorOr TmpFSInode::truncate(u64 size) return {}; } -ErrorOr TmpFSInode::set_atime(time_t time) +ErrorOr TmpFSInode::update_timestamps(Optional atime, Optional ctime, Optional mtime) { MutexLocker locker(m_inode_lock); - m_metadata.atime = time; - set_metadata_dirty(true); - return {}; -} - -ErrorOr TmpFSInode::set_ctime(time_t time) -{ - MutexLocker locker(m_inode_lock); - - m_metadata.ctime = time; - set_metadata_dirty(true); - return {}; -} - -ErrorOr TmpFSInode::set_mtime(time_t t) -{ - MutexLocker locker(m_inode_lock); - - m_metadata.mtime = t; + if (atime.has_value()) + m_metadata.atime = atime.value(); + if (ctime.has_value()) + m_metadata.ctime = ctime.value(); + if (mtime.has_value()) + m_metadata.ctime = mtime.value(); set_metadata_dirty(true); return {}; } diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h index 5ec0e632dc3..92cf7146179 100644 --- a/Kernel/FileSystem/TmpFS.h +++ b/Kernel/FileSystem/TmpFS.h @@ -59,9 +59,7 @@ public: virtual ErrorOr chmod(mode_t) override; virtual ErrorOr chown(UserID, GroupID) override; virtual ErrorOr truncate(u64) override; - virtual ErrorOr set_atime(time_t) override; - virtual ErrorOr set_ctime(time_t) override; - virtual ErrorOr set_mtime(time_t) override; + virtual ErrorOr update_timestamps(Optional atime, Optional ctime, Optional mtime) override; private: TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr parent); diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index bdb4f0858a8..2a1c183a431 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -213,8 +213,7 @@ ErrorOr VirtualFileSystem::utime(Credentials const& credentials, StringVie if (custody->is_readonly()) return EROFS; - TRY(inode.set_atime(atime)); - TRY(inode.set_mtime(mtime)); + TRY(inode.update_timestamps(atime, {}, mtime)); return {}; } @@ -228,10 +227,10 @@ ErrorOr VirtualFileSystem::utimensat(Credentials const& credentials, Strin 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)); + TRY(inode.update_timestamps( + (atime.tv_nsec != UTIME_OMIT) ? atime.tv_nsec : Optional {}, + {}, + (mtime.tv_nsec != UTIME_OMIT) ? mtime.tv_nsec : Optional {})); return {}; } @@ -321,7 +320,7 @@ ErrorOr> VirtualFileSystem::open(Credenti if (should_truncate_file) { TRY(inode.truncate(0)); - TRY(inode.set_mtime(kgettimeofday().to_truncated_seconds())); + TRY(inode.update_timestamps({}, {}, kgettimeofday().to_truncated_seconds())); } auto description = TRY(OpenFileDescription::try_create(custody)); description->set_rw_mode(options); diff --git a/Kernel/ProcessExposed.cpp b/Kernel/ProcessExposed.cpp index e79abb1ca5a..990f9bd7471 100644 --- a/Kernel/ProcessExposed.cpp +++ b/Kernel/ProcessExposed.cpp @@ -184,11 +184,6 @@ ErrorOr ProcFSSystemBoolean::truncate(u64 size) return {}; } -ErrorOr ProcFSSystemBoolean::set_mtime(time_t) -{ - return {}; -} - ErrorOr ProcFSExposedLink::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const { VERIFY(offset == 0); diff --git a/Kernel/ProcessExposed.h b/Kernel/ProcessExposed.h index 76604ae48a2..5658088d338 100644 --- a/Kernel/ProcessExposed.h +++ b/Kernel/ProcessExposed.h @@ -74,7 +74,6 @@ public: virtual ErrorOr> lookup(StringView) { VERIFY_NOT_REACHED(); }; virtual ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; } virtual ErrorOr truncate(u64) { return EPERM; } - virtual ErrorOr set_mtime(time_t) { return ENOTIMPL; } virtual mode_t required_mode() const { return 0444; } virtual UserID owner_user() const { return 0; } @@ -201,7 +200,6 @@ private: virtual ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override final; virtual mode_t required_mode() const override final { return 0644; } virtual ErrorOr truncate(u64) override final; - virtual ErrorOr set_mtime(time_t) override final; }; }