Kernel: Make Inode::set_{a,c,m}time return KResult

This exposed some missing error propagation, which this patch also
takes care of.
This commit is contained in:
Andreas Kling 2021-04-30 15:51:06 +02:00
parent a5f385f052
commit cd9be1733c
Notes: sideshowbarker 2024-07-18 18:52:22 +09:00
8 changed files with 42 additions and 44 deletions

View File

@ -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()

View File

@ -47,9 +47,9 @@ private:
virtual KResultOr<NonnullRefPtr<Inode>> 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<size_t> directory_entry_count() const override;

View File

@ -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()

View File

@ -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();

View File

@ -48,9 +48,11 @@ KResultOr<size_t> 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;
}

View File

@ -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;
}

View File

@ -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:

View File

@ -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<NonnullRefPtr<FileDescription>> 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()) {