diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 6e03f441517..094f7212736 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1584,34 +1584,34 @@ void Ext2FSInode::one_ref_left() // FIXME: I would like to not live forever, but uncached Ext2FS is fucking painful right now. } -int Ext2FSInode::set_atime(time_t t) +KResult Ext2FSInode::set_atime(time_t t) { Locker locker(m_lock); if (fs().is_readonly()) - return -EROFS; + return EROFS; m_raw_inode.i_atime = t; set_metadata_dirty(true); - return 0; + return KSuccess; } -int Ext2FSInode::set_ctime(time_t t) +KResult Ext2FSInode::set_ctime(time_t t) { Locker locker(m_lock); if (fs().is_readonly()) - return -EROFS; + return EROFS; m_raw_inode.i_ctime = t; set_metadata_dirty(true); - return 0; + return KSuccess; } -int Ext2FSInode::set_mtime(time_t t) +KResult Ext2FSInode::set_mtime(time_t t) { Locker locker(m_lock); if (fs().is_readonly()) - return -EROFS; + return EROFS; m_raw_inode.i_mtime = t; set_metadata_dirty(true); - return 0; + return KSuccess; } KResult Ext2FSInode::increment_link_count() diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index 29ddeff0465..25b55c9f875 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -47,9 +47,9 @@ private: virtual KResultOr> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override; virtual KResult add_child(Inode& child, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; - virtual int set_atime(time_t) override; - virtual int set_ctime(time_t) override; - virtual int set_mtime(time_t) override; + virtual KResult set_atime(time_t) override; + virtual KResult set_ctime(time_t) override; + virtual KResult set_mtime(time_t) override; virtual KResult increment_link_count() override; virtual KResult decrement_link_count() override; virtual KResultOr directory_entry_count() const override; diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 56cb560bc77..5872d2d9192 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -117,19 +117,19 @@ void Inode::will_be_destroyed() flush_metadata(); } -int Inode::set_atime(time_t) +KResult Inode::set_atime(time_t) { - return -ENOTIMPL; + return ENOTIMPL; } -int Inode::set_ctime(time_t) +KResult Inode::set_ctime(time_t) { - return -ENOTIMPL; + return ENOTIMPL; } -int Inode::set_mtime(time_t) +KResult Inode::set_mtime(time_t) { - return -ENOTIMPL; + return ENOTIMPL; } KResult Inode::increment_link_count() diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index 1a42e01fbdc..8b64922c60c 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -76,9 +76,9 @@ public: bool is_metadata_dirty() const { return m_metadata_dirty; } - virtual int set_atime(time_t); - virtual int set_ctime(time_t); - virtual int set_mtime(time_t); + virtual KResult set_atime(time_t); + virtual KResult set_ctime(time_t); + virtual KResult set_mtime(time_t); virtual KResult increment_link_count(); virtual KResult decrement_link_count(); diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 76bd3880f9b..235cc0a1c91 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -48,9 +48,11 @@ KResultOr InodeFile::write(FileDescription& description, u64 offset, con ssize_t nwritten = m_inode->write_bytes(offset, count, data, &description); if (nwritten > 0) { - m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); + auto mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); Thread::current()->did_file_write(nwritten); evaluate_block_conditions(); + if (mtime_result.is_error()) + return mtime_result; } if (nwritten < 0) return KResult((ErrnoCode)-nwritten); @@ -109,12 +111,10 @@ String InodeFile::absolute_path(const FileDescription& description) const KResult InodeFile::truncate(u64 size) { - auto truncate_result = m_inode->truncate(size); - if (truncate_result.is_error()) - return truncate_result; - int mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); - if (mtime_result < 0) - return KResult((ErrnoCode)-mtime_result); + if (auto result = m_inode->truncate(size); result.is_error()) + return result; + if (auto result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); result.is_error()) + return result; return KSuccess; } diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index 9428940e96c..a0ac7c3b22b 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -335,7 +335,7 @@ KResult TmpFSInode::truncate(u64 size) return KSuccess; } -int TmpFSInode::set_atime(time_t time) +KResult TmpFSInode::set_atime(time_t time) { Locker locker(m_lock); @@ -345,7 +345,7 @@ int TmpFSInode::set_atime(time_t time) return KSuccess; } -int TmpFSInode::set_ctime(time_t time) +KResult TmpFSInode::set_ctime(time_t time) { Locker locker(m_lock); @@ -354,11 +354,11 @@ int TmpFSInode::set_ctime(time_t time) return KSuccess; } -int TmpFSInode::set_mtime(time_t time) +KResult TmpFSInode::set_mtime(time_t t) { Locker locker(m_lock); - m_metadata.mtime = time; + m_metadata.mtime = t; notify_watchers(); return KSuccess; } diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h index 5a3be0d3579..ed6eefb29ae 100644 --- a/Kernel/FileSystem/TmpFS.h +++ b/Kernel/FileSystem/TmpFS.h @@ -67,9 +67,9 @@ public: virtual KResult chmod(mode_t) override; virtual KResult chown(uid_t, gid_t) override; virtual KResult truncate(u64) override; - virtual int set_atime(time_t) override; - virtual int set_ctime(time_t) override; - virtual int set_mtime(time_t) override; + virtual KResult set_atime(time_t) override; + virtual KResult set_ctime(time_t) override; + virtual KResult set_mtime(time_t) override; virtual void one_ref_left() override; private: diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 4753c1d6dee..7955e8c25c6 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -209,12 +209,10 @@ KResult VFS::utime(StringView path, Custody& base, time_t atime, time_t mtime) if (custody.is_readonly()) return EROFS; - int error = inode.set_atime(atime); - if (error < 0) - return KResult((ErrnoCode)-error); - error = inode.set_mtime(mtime); - if (error < 0) - return KResult((ErrnoCode)-error); + if (auto result = inode.set_atime(atime); result.is_error()) + return result; + if (auto result = inode.set_mtime(mtime); result.is_error()) + return result; return KSuccess; } @@ -319,10 +317,10 @@ KResultOr> VFS::open(StringView path, int options return EROFS; if (should_truncate_file) { - KResult result = inode.truncate(0); - if (result.is_error()) + if (auto result = inode.truncate(0); result.is_error()) + return result; + if (auto result = inode.set_mtime(kgettimeofday().to_truncated_seconds()); result.is_error()) return result; - inode.set_mtime(kgettimeofday().to_truncated_seconds()); } auto description = FileDescription::create(custody); if (!description.is_error()) {