mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03:00
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:
parent
a5f385f052
commit
cd9be1733c
Notes:
sideshowbarker
2024-07-18 18:52:22 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/cd9be1733cf
@ -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.
|
// 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);
|
Locker locker(m_lock);
|
||||||
if (fs().is_readonly())
|
if (fs().is_readonly())
|
||||||
return -EROFS;
|
return EROFS;
|
||||||
m_raw_inode.i_atime = t;
|
m_raw_inode.i_atime = t;
|
||||||
set_metadata_dirty(true);
|
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);
|
Locker locker(m_lock);
|
||||||
if (fs().is_readonly())
|
if (fs().is_readonly())
|
||||||
return -EROFS;
|
return EROFS;
|
||||||
m_raw_inode.i_ctime = t;
|
m_raw_inode.i_ctime = t;
|
||||||
set_metadata_dirty(true);
|
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);
|
Locker locker(m_lock);
|
||||||
if (fs().is_readonly())
|
if (fs().is_readonly())
|
||||||
return -EROFS;
|
return EROFS;
|
||||||
m_raw_inode.i_mtime = t;
|
m_raw_inode.i_mtime = t;
|
||||||
set_metadata_dirty(true);
|
set_metadata_dirty(true);
|
||||||
return 0;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult Ext2FSInode::increment_link_count()
|
KResult Ext2FSInode::increment_link_count()
|
||||||
|
@ -47,9 +47,9 @@ private:
|
|||||||
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
|
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 add_child(Inode& child, const StringView& name, mode_t) override;
|
||||||
virtual KResult remove_child(const StringView& name) override;
|
virtual KResult remove_child(const StringView& name) override;
|
||||||
virtual int set_atime(time_t) override;
|
virtual KResult set_atime(time_t) override;
|
||||||
virtual int set_ctime(time_t) override;
|
virtual KResult set_ctime(time_t) override;
|
||||||
virtual int set_mtime(time_t) override;
|
virtual KResult set_mtime(time_t) override;
|
||||||
virtual KResult increment_link_count() override;
|
virtual KResult increment_link_count() override;
|
||||||
virtual KResult decrement_link_count() override;
|
virtual KResult decrement_link_count() override;
|
||||||
virtual KResultOr<size_t> directory_entry_count() const override;
|
virtual KResultOr<size_t> directory_entry_count() const override;
|
||||||
|
@ -117,19 +117,19 @@ void Inode::will_be_destroyed()
|
|||||||
flush_metadata();
|
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()
|
KResult Inode::increment_link_count()
|
||||||
|
@ -76,9 +76,9 @@ public:
|
|||||||
|
|
||||||
bool is_metadata_dirty() const { return m_metadata_dirty; }
|
bool is_metadata_dirty() const { return m_metadata_dirty; }
|
||||||
|
|
||||||
virtual int set_atime(time_t);
|
virtual KResult set_atime(time_t);
|
||||||
virtual int set_ctime(time_t);
|
virtual KResult set_ctime(time_t);
|
||||||
virtual int set_mtime(time_t);
|
virtual KResult set_mtime(time_t);
|
||||||
virtual KResult increment_link_count();
|
virtual KResult increment_link_count();
|
||||||
virtual KResult decrement_link_count();
|
virtual KResult decrement_link_count();
|
||||||
|
|
||||||
|
@ -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);
|
ssize_t nwritten = m_inode->write_bytes(offset, count, data, &description);
|
||||||
if (nwritten > 0) {
|
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);
|
Thread::current()->did_file_write(nwritten);
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
|
if (mtime_result.is_error())
|
||||||
|
return mtime_result;
|
||||||
}
|
}
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
return KResult((ErrnoCode)-nwritten);
|
return KResult((ErrnoCode)-nwritten);
|
||||||
@ -109,12 +111,10 @@ String InodeFile::absolute_path(const FileDescription& description) const
|
|||||||
|
|
||||||
KResult InodeFile::truncate(u64 size)
|
KResult InodeFile::truncate(u64 size)
|
||||||
{
|
{
|
||||||
auto truncate_result = m_inode->truncate(size);
|
if (auto result = m_inode->truncate(size); result.is_error())
|
||||||
if (truncate_result.is_error())
|
return result;
|
||||||
return truncate_result;
|
if (auto result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); result.is_error())
|
||||||
int mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds());
|
return result;
|
||||||
if (mtime_result < 0)
|
|
||||||
return KResult((ErrnoCode)-mtime_result);
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ KResult TmpFSInode::truncate(u64 size)
|
|||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TmpFSInode::set_atime(time_t time)
|
KResult TmpFSInode::set_atime(time_t time)
|
||||||
{
|
{
|
||||||
Locker locker(m_lock);
|
Locker locker(m_lock);
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ int TmpFSInode::set_atime(time_t time)
|
|||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TmpFSInode::set_ctime(time_t time)
|
KResult TmpFSInode::set_ctime(time_t time)
|
||||||
{
|
{
|
||||||
Locker locker(m_lock);
|
Locker locker(m_lock);
|
||||||
|
|
||||||
@ -354,11 +354,11 @@ int TmpFSInode::set_ctime(time_t time)
|
|||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TmpFSInode::set_mtime(time_t time)
|
KResult TmpFSInode::set_mtime(time_t t)
|
||||||
{
|
{
|
||||||
Locker locker(m_lock);
|
Locker locker(m_lock);
|
||||||
|
|
||||||
m_metadata.mtime = time;
|
m_metadata.mtime = t;
|
||||||
notify_watchers();
|
notify_watchers();
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
@ -67,9 +67,9 @@ public:
|
|||||||
virtual KResult chmod(mode_t) override;
|
virtual KResult chmod(mode_t) override;
|
||||||
virtual KResult chown(uid_t, gid_t) override;
|
virtual KResult chown(uid_t, gid_t) override;
|
||||||
virtual KResult truncate(u64) override;
|
virtual KResult truncate(u64) override;
|
||||||
virtual int set_atime(time_t) override;
|
virtual KResult set_atime(time_t) override;
|
||||||
virtual int set_ctime(time_t) override;
|
virtual KResult set_ctime(time_t) override;
|
||||||
virtual int set_mtime(time_t) override;
|
virtual KResult set_mtime(time_t) override;
|
||||||
virtual void one_ref_left() override;
|
virtual void one_ref_left() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -209,12 +209,10 @@ KResult VFS::utime(StringView path, Custody& base, time_t atime, time_t mtime)
|
|||||||
if (custody.is_readonly())
|
if (custody.is_readonly())
|
||||||
return EROFS;
|
return EROFS;
|
||||||
|
|
||||||
int error = inode.set_atime(atime);
|
if (auto result = inode.set_atime(atime); result.is_error())
|
||||||
if (error < 0)
|
return result;
|
||||||
return KResult((ErrnoCode)-error);
|
if (auto result = inode.set_mtime(mtime); result.is_error())
|
||||||
error = inode.set_mtime(mtime);
|
return result;
|
||||||
if (error < 0)
|
|
||||||
return KResult((ErrnoCode)-error);
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,10 +317,10 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
|
|||||||
return EROFS;
|
return EROFS;
|
||||||
|
|
||||||
if (should_truncate_file) {
|
if (should_truncate_file) {
|
||||||
KResult result = inode.truncate(0);
|
if (auto result = inode.truncate(0); result.is_error())
|
||||||
if (result.is_error())
|
return result;
|
||||||
|
if (auto result = inode.set_mtime(kgettimeofday().to_truncated_seconds()); result.is_error())
|
||||||
return result;
|
return result;
|
||||||
inode.set_mtime(kgettimeofday().to_truncated_seconds());
|
|
||||||
}
|
}
|
||||||
auto description = FileDescription::create(custody);
|
auto description = FileDescription::create(custody);
|
||||||
if (!description.is_error()) {
|
if (!description.is_error()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user