mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Kernel: Use AK::Time for InodeMetadata timestamps instead of time_t
Before this change, we were truncating the nanosecond part of file timestamps in many different places.
This commit is contained in:
parent
f8290e1ad4
commit
10fa72d451
Notes:
sideshowbarker
2024-07-17 04:10:17 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/10fa72d451 Pull-request: https://github.com/SerenityOS/serenity/pull/16147 Reviewed-by: https://github.com/Hendiadyoin1
23 changed files with 56 additions and 58 deletions
|
@ -19,9 +19,9 @@ void initialize()
|
||||||
s_boot_time = now();
|
s_boot_time = now();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t boot_time()
|
Time boot_time()
|
||||||
{
|
{
|
||||||
return s_boot_time;
|
return Time::from_timespec({ s_boot_time, 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool update_in_progress()
|
static bool update_in_progress()
|
||||||
|
|
|
@ -12,6 +12,6 @@ namespace Kernel::RTC {
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
time_t now();
|
time_t now();
|
||||||
time_t boot_time();
|
Time boot_time();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ InodeMetadata DevPtsFSInode::metadata() const
|
||||||
{
|
{
|
||||||
if (auto pty = m_pty.strong_ref()) {
|
if (auto pty = m_pty.strong_ref()) {
|
||||||
auto metadata = m_metadata;
|
auto metadata = m_metadata;
|
||||||
metadata.mtime = pty->time_of_last_write();
|
metadata.mtime = Time::from_timespec({ pty->time_of_last_write(), 0 });
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
return m_metadata;
|
return m_metadata;
|
||||||
|
|
|
@ -477,10 +477,10 @@ InodeMetadata Ext2FSInode::metadata() const
|
||||||
metadata.uid = m_raw_inode.i_uid;
|
metadata.uid = m_raw_inode.i_uid;
|
||||||
metadata.gid = m_raw_inode.i_gid;
|
metadata.gid = m_raw_inode.i_gid;
|
||||||
metadata.link_count = m_raw_inode.i_links_count;
|
metadata.link_count = m_raw_inode.i_links_count;
|
||||||
metadata.atime = m_raw_inode.i_atime;
|
metadata.atime = Time::from_timespec({ m_raw_inode.i_atime, 0 });
|
||||||
metadata.ctime = m_raw_inode.i_ctime;
|
metadata.ctime = Time::from_timespec({ m_raw_inode.i_ctime, 0 });
|
||||||
metadata.mtime = m_raw_inode.i_mtime;
|
metadata.mtime = Time::from_timespec({ m_raw_inode.i_mtime, 0 });
|
||||||
metadata.dtime = m_raw_inode.i_dtime;
|
metadata.dtime = Time::from_timespec({ m_raw_inode.i_dtime, 0 });
|
||||||
metadata.block_size = fs().block_size();
|
metadata.block_size = fs().block_size();
|
||||||
metadata.block_count = m_raw_inode.i_blocks;
|
metadata.block_count = m_raw_inode.i_blocks;
|
||||||
|
|
||||||
|
@ -930,23 +930,23 @@ ErrorOr<NonnullLockRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
|
||||||
return fs().get_inode({ fsid(), inode_index });
|
return fs().get_inode({ fsid(), inode_index });
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> Ext2FSInode::update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime)
|
ErrorOr<void> Ext2FSInode::update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime)
|
||||||
{
|
{
|
||||||
MutexLocker locker(m_inode_lock);
|
MutexLocker locker(m_inode_lock);
|
||||||
if (fs().is_readonly())
|
if (fs().is_readonly())
|
||||||
return EROFS;
|
return EROFS;
|
||||||
if (atime.value_or(0) > INT32_MAX)
|
if (atime.value_or({}).to_timespec().tv_sec > INT32_MAX)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (ctime.value_or(0) > INT32_MAX)
|
if (ctime.value_or({}).to_timespec().tv_sec > INT32_MAX)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (mtime.value_or(0) > INT32_MAX)
|
if (mtime.value_or({}).to_timespec().tv_sec > INT32_MAX)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (atime.has_value())
|
if (atime.has_value())
|
||||||
m_raw_inode.i_atime = atime.value();
|
m_raw_inode.i_atime = atime.value().to_timespec().tv_sec;
|
||||||
if (ctime.has_value())
|
if (ctime.has_value())
|
||||||
m_raw_inode.i_ctime = ctime.value();
|
m_raw_inode.i_ctime = ctime.value().to_timespec().tv_sec;
|
||||||
if (mtime.has_value())
|
if (mtime.has_value())
|
||||||
m_raw_inode.i_mtime = mtime.value();
|
m_raw_inode.i_mtime = mtime.value().to_timespec().tv_sec;
|
||||||
set_metadata_dirty(true);
|
set_metadata_dirty(true);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
virtual ErrorOr<NonnullLockRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
|
virtual ErrorOr<NonnullLockRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
|
||||||
virtual ErrorOr<void> add_child(Inode& child, StringView name, mode_t) override;
|
virtual ErrorOr<void> add_child(Inode& child, StringView name, mode_t) override;
|
||||||
virtual ErrorOr<void> remove_child(StringView name) override;
|
virtual ErrorOr<void> remove_child(StringView name) override;
|
||||||
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime) override;
|
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||||
virtual ErrorOr<void> increment_link_count() override;
|
virtual ErrorOr<void> increment_link_count() override;
|
||||||
virtual ErrorOr<void> decrement_link_count() override;
|
virtual ErrorOr<void> decrement_link_count() override;
|
||||||
virtual ErrorOr<void> chmod(mode_t) override;
|
virtual ErrorOr<void> chmod(mode_t) override;
|
||||||
|
|
|
@ -34,7 +34,7 @@ FATInode::FATInode(FATFS& fs, FATEntry entry, NonnullOwnPtr<KString> filename)
|
||||||
.atime = fat_date_time(m_entry.last_accessed_date, { 0 }),
|
.atime = fat_date_time(m_entry.last_accessed_date, { 0 }),
|
||||||
.ctime = fat_date_time(m_entry.creation_date, m_entry.creation_time),
|
.ctime = fat_date_time(m_entry.creation_date, m_entry.creation_time),
|
||||||
.mtime = fat_date_time(m_entry.modification_date, m_entry.modification_time),
|
.mtime = fat_date_time(m_entry.modification_date, m_entry.modification_time),
|
||||||
.dtime = 0,
|
.dtime = {},
|
||||||
.block_count = 0,
|
.block_count = 0,
|
||||||
.block_size = 0,
|
.block_size = 0,
|
||||||
.major_device = 0,
|
.major_device = 0,
|
||||||
|
@ -167,12 +167,12 @@ ErrorOr<NonnullOwnPtr<KString>> FATInode::compute_filename(FATEntry& entry, Vect
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t FATInode::fat_date_time(FATPackedDate date, FATPackedTime time)
|
Time FATInode::fat_date_time(FATPackedDate date, FATPackedTime time)
|
||||||
{
|
{
|
||||||
if (date.value == 0)
|
if (date.value == 0)
|
||||||
return 0;
|
return Time();
|
||||||
|
|
||||||
return Time::from_timestamp(first_fat_year + date.year, date.month, date.day, time.hour, time.minute, time.second * 2, 0).to_seconds();
|
return Time::from_timestamp(first_fat_year + date.year, date.month, date.day, time.hour, time.minute, time.second * 2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView FATInode::byte_terminated_string(StringView string, u8 fill_byte)
|
StringView FATInode::byte_terminated_string(StringView string, u8 fill_byte)
|
||||||
|
|
|
@ -45,7 +45,7 @@ private:
|
||||||
|
|
||||||
static ErrorOr<NonnullOwnPtr<KString>> compute_filename(FATEntry&, Vector<FATLongFileNameEntry> const& = {});
|
static ErrorOr<NonnullOwnPtr<KString>> compute_filename(FATEntry&, Vector<FATLongFileNameEntry> const& = {});
|
||||||
static StringView byte_terminated_string(StringView, u8);
|
static StringView byte_terminated_string(StringView, u8);
|
||||||
static time_t fat_date_time(FATPackedDate date, FATPackedTime time);
|
static Time fat_date_time(FATPackedDate, FATPackedTime);
|
||||||
|
|
||||||
ErrorOr<Vector<BlockBasedFileSystem::BlockIndex>> compute_block_list();
|
ErrorOr<Vector<BlockBasedFileSystem::BlockIndex>> compute_block_list();
|
||||||
ErrorOr<NonnullOwnPtr<KBuffer>> read_block_list();
|
ErrorOr<NonnullOwnPtr<KBuffer>> read_block_list();
|
||||||
|
|
|
@ -140,7 +140,7 @@ ErrorOr<void> ISO9660Inode::truncate(u64)
|
||||||
return EROFS;
|
return EROFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> ISO9660Inode::update_timestamps(Optional<time_t>, Optional<time_t>, Optional<time_t>)
|
ErrorOr<void> ISO9660Inode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
|
||||||
{
|
{
|
||||||
return EROFS;
|
return EROFS;
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ void ISO9660Inode::create_metadata()
|
||||||
{
|
{
|
||||||
u32 data_length = LittleEndian { m_record.data_length.little };
|
u32 data_length = LittleEndian { m_record.data_length.little };
|
||||||
bool is_directory = has_flag(m_record.file_flags, ISO::FileFlags::Directory);
|
bool is_directory = has_flag(m_record.file_flags, ISO::FileFlags::Directory);
|
||||||
time_t recorded_at = parse_numerical_date_time(m_record.recording_date_and_time);
|
auto recorded_at = Time::from_timespec({ parse_numerical_date_time(m_record.recording_date_and_time), 0 });
|
||||||
|
|
||||||
m_metadata = {
|
m_metadata = {
|
||||||
.inode = identifier(),
|
.inode = identifier(),
|
||||||
|
@ -176,7 +176,7 @@ void ISO9660Inode::create_metadata()
|
||||||
.atime = recorded_at,
|
.atime = recorded_at,
|
||||||
.ctime = recorded_at,
|
.ctime = recorded_at,
|
||||||
.mtime = recorded_at,
|
.mtime = recorded_at,
|
||||||
.dtime = 0,
|
.dtime = {},
|
||||||
.block_count = 0,
|
.block_count = 0,
|
||||||
.block_size = 0,
|
.block_size = 0,
|
||||||
.major_device = 0,
|
.major_device = 0,
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
virtual ErrorOr<void> chmod(mode_t) override;
|
virtual ErrorOr<void> chmod(mode_t) override;
|
||||||
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
||||||
virtual ErrorOr<void> truncate(u64) override;
|
virtual ErrorOr<void> truncate(u64) override;
|
||||||
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime) override;
|
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// HACK: The base ISO 9660 standard says the maximum filename length is 37
|
// HACK: The base ISO 9660 standard says the maximum filename length is 37
|
||||||
|
|
|
@ -119,7 +119,7 @@ ErrorOr<size_t> Inode::read_bytes(off_t offset, size_t length, UserOrKernelBuffe
|
||||||
return read_bytes_locked(offset, length, buffer, open_description);
|
return read_bytes_locked(offset, length, buffer, open_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<time_t> atime, [[maybe_unused]] Optional<time_t> ctime, [[maybe_unused]] Optional<time_t> mtime)
|
ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<Time> atime, [[maybe_unused]] Optional<Time> ctime, [[maybe_unused]] Optional<Time> mtime)
|
||||||
{
|
{
|
||||||
return ENOTIMPL;
|
return ENOTIMPL;
|
||||||
}
|
}
|
||||||
|
@ -238,8 +238,8 @@ void Inode::did_modify_contents()
|
||||||
{
|
{
|
||||||
// FIXME: What happens if this fails?
|
// FIXME: What happens if this fails?
|
||||||
// ENOTIMPL would be a meaningless error to return here
|
// ENOTIMPL would be a meaningless error to return here
|
||||||
auto time = kgettimeofday().to_truncated_seconds();
|
auto now = kgettimeofday();
|
||||||
(void)update_timestamps({}, time, time);
|
(void)update_timestamps({}, now, now);
|
||||||
|
|
||||||
m_watchers.for_each([&](auto& watcher) {
|
m_watchers.for_each([&](auto& watcher) {
|
||||||
watcher->notify_inode_event({}, identifier(), InodeWatcherEvent::Type::ContentModified);
|
watcher->notify_inode_event({}, identifier(), InodeWatcherEvent::Type::ContentModified);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
|
|
||||||
bool is_metadata_dirty() const { return m_metadata_dirty; }
|
bool is_metadata_dirty() const { return m_metadata_dirty; }
|
||||||
|
|
||||||
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime);
|
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime);
|
||||||
virtual ErrorOr<void> increment_link_count();
|
virtual ErrorOr<void> increment_link_count();
|
||||||
virtual ErrorOr<void> decrement_link_count();
|
virtual ErrorOr<void> decrement_link_count();
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ ErrorOr<size_t> InodeFile::write(OpenFileDescription& description, u64 offset, U
|
||||||
|
|
||||||
size_t nwritten = TRY(m_inode->write_bytes(offset, count, data, &description));
|
size_t nwritten = TRY(m_inode->write_bytes(offset, count, data, &description));
|
||||||
if (nwritten > 0) {
|
if (nwritten > 0) {
|
||||||
auto mtime_result = m_inode->update_timestamps({}, {}, kgettimeofday().to_truncated_seconds());
|
auto mtime_result = m_inode->update_timestamps({}, {}, kgettimeofday());
|
||||||
Thread::current()->did_file_write(nwritten);
|
Thread::current()->did_file_write(nwritten);
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
if (mtime_result.is_error())
|
if (mtime_result.is_error())
|
||||||
|
@ -96,7 +96,7 @@ ErrorOr<NonnullOwnPtr<KString>> InodeFile::pseudo_path(OpenFileDescription const
|
||||||
ErrorOr<void> InodeFile::truncate(u64 size)
|
ErrorOr<void> InodeFile::truncate(u64 size)
|
||||||
{
|
{
|
||||||
TRY(m_inode->truncate(size));
|
TRY(m_inode->truncate(size));
|
||||||
TRY(m_inode->update_timestamps({}, {}, kgettimeofday().to_truncated_seconds()));
|
TRY(m_inode->update_timestamps({}, {}, kgettimeofday()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
|
#include <AK/Time.h>
|
||||||
#include <Kernel/FileSystem/DeviceFileTypes.h>
|
#include <Kernel/FileSystem/DeviceFileTypes.h>
|
||||||
#include <Kernel/FileSystem/InodeIdentifier.h>
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
||||||
#include <Kernel/Forward.h>
|
#include <Kernel/Forward.h>
|
||||||
|
@ -106,12 +107,9 @@ struct InodeMetadata {
|
||||||
buffer.st_size = size;
|
buffer.st_size = size;
|
||||||
buffer.st_blksize = block_size;
|
buffer.st_blksize = block_size;
|
||||||
buffer.st_blocks = block_count;
|
buffer.st_blocks = block_count;
|
||||||
buffer.st_atim.tv_sec = atime;
|
buffer.st_atim = atime.to_timespec();
|
||||||
buffer.st_atim.tv_nsec = 0;
|
buffer.st_mtim = mtime.to_timespec();
|
||||||
buffer.st_mtim.tv_sec = mtime;
|
buffer.st_ctim = ctime.to_timespec();
|
||||||
buffer.st_mtim.tv_nsec = 0;
|
|
||||||
buffer.st_ctim.tv_sec = ctime;
|
|
||||||
buffer.st_ctim.tv_nsec = 0;
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +119,10 @@ struct InodeMetadata {
|
||||||
UserID uid { 0 };
|
UserID uid { 0 };
|
||||||
GroupID gid { 0 };
|
GroupID gid { 0 };
|
||||||
nlink_t link_count { 0 };
|
nlink_t link_count { 0 };
|
||||||
time_t atime { 0 };
|
Time atime {};
|
||||||
time_t ctime { 0 };
|
Time ctime {};
|
||||||
time_t mtime { 0 };
|
Time mtime {};
|
||||||
time_t dtime { 0 };
|
Time dtime {};
|
||||||
blkcnt_t block_count { 0 };
|
blkcnt_t block_count { 0 };
|
||||||
blksize_t block_size { 0 };
|
blksize_t block_size { 0 };
|
||||||
MajorNumber major_device { 0 };
|
MajorNumber major_device { 0 };
|
||||||
|
|
|
@ -62,7 +62,7 @@ ErrorOr<void> ProcFSGlobalInode::truncate(u64 size)
|
||||||
return m_associated_component->truncate(size);
|
return m_associated_component->truncate(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> ProcFSGlobalInode::update_timestamps(Optional<time_t>, Optional<time_t>, Optional<time_t>)
|
ErrorOr<void> ProcFSGlobalInode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ protected:
|
||||||
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||||
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView) override;
|
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView) override;
|
||||||
virtual ErrorOr<void> truncate(u64) override final;
|
virtual ErrorOr<void> truncate(u64) override final;
|
||||||
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime) override;
|
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||||
|
|
||||||
NonnullLockRefPtr<ProcFSExposedComponent> m_associated_component;
|
NonnullLockRefPtr<ProcFSExposedComponent> m_associated_component;
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,7 @@ ErrorOr<void> SysFSInode::truncate(u64 size)
|
||||||
return m_associated_component->truncate(size);
|
return m_associated_component->truncate(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> SysFSInode::update_timestamps(Optional<time_t>, Optional<time_t>, Optional<time_t>)
|
ErrorOr<void> SysFSInode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ protected:
|
||||||
virtual ErrorOr<void> chmod(mode_t) override;
|
virtual ErrorOr<void> chmod(mode_t) override;
|
||||||
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
||||||
virtual ErrorOr<void> truncate(u64) override;
|
virtual ErrorOr<void> truncate(u64) override;
|
||||||
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime) override;
|
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||||
|
|
||||||
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
|
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
|
||||||
virtual void did_seek(OpenFileDescription&, off_t) override final;
|
virtual void did_seek(OpenFileDescription&, off_t) override final;
|
||||||
|
|
|
@ -28,7 +28,7 @@ ErrorOr<NonnullLockRefPtr<TmpFSInode>> TmpFSInode::try_create(TmpFS& fs, InodeMe
|
||||||
ErrorOr<NonnullLockRefPtr<TmpFSInode>> TmpFSInode::try_create_root(TmpFS& fs)
|
ErrorOr<NonnullLockRefPtr<TmpFSInode>> TmpFSInode::try_create_root(TmpFS& fs)
|
||||||
{
|
{
|
||||||
InodeMetadata metadata;
|
InodeMetadata metadata;
|
||||||
auto now = kgettimeofday().to_truncated_seconds();
|
auto now = kgettimeofday();
|
||||||
metadata.atime = now;
|
metadata.atime = now;
|
||||||
metadata.ctime = now;
|
metadata.ctime = now;
|
||||||
metadata.mtime = now;
|
metadata.mtime = now;
|
||||||
|
@ -266,7 +266,7 @@ ErrorOr<void> TmpFSInode::chown(UserID uid, GroupID gid)
|
||||||
ErrorOr<NonnullLockRefPtr<Inode>> TmpFSInode::create_child(StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
|
ErrorOr<NonnullLockRefPtr<Inode>> TmpFSInode::create_child(StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
|
||||||
{
|
{
|
||||||
MutexLocker locker(m_inode_lock);
|
MutexLocker locker(m_inode_lock);
|
||||||
time_t now = kgettimeofday().to_truncated_seconds();
|
auto now = kgettimeofday();
|
||||||
|
|
||||||
InodeMetadata metadata;
|
InodeMetadata metadata;
|
||||||
metadata.mode = mode;
|
metadata.mode = mode;
|
||||||
|
@ -352,7 +352,7 @@ ErrorOr<void> TmpFSInode::truncate(u64 size)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> TmpFSInode::update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime)
|
ErrorOr<void> TmpFSInode::update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime)
|
||||||
{
|
{
|
||||||
MutexLocker locker(m_inode_lock);
|
MutexLocker locker(m_inode_lock);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
virtual ErrorOr<void> chmod(mode_t) override;
|
virtual ErrorOr<void> chmod(mode_t) override;
|
||||||
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
||||||
virtual ErrorOr<void> truncate(u64) override;
|
virtual ErrorOr<void> truncate(u64) override;
|
||||||
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime) override;
|
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr<TmpFSInode> parent);
|
TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr<TmpFSInode> parent);
|
||||||
|
|
|
@ -281,7 +281,7 @@ ErrorOr<void> VirtualFileSystem::utime(Credentials const& credentials, StringVie
|
||||||
if (custody->is_readonly())
|
if (custody->is_readonly())
|
||||||
return EROFS;
|
return EROFS;
|
||||||
|
|
||||||
TRY(inode.update_timestamps(atime, {}, mtime));
|
TRY(inode.update_timestamps(Time::from_timespec({ atime, 0 }), {}, Time::from_timespec({ mtime, 0 })));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,9 +296,9 @@ ErrorOr<void> VirtualFileSystem::utimensat(Credentials const& credentials, Strin
|
||||||
|
|
||||||
// NOTE: A standard ext2 inode cannot store nanosecond timestamps.
|
// NOTE: A standard ext2 inode cannot store nanosecond timestamps.
|
||||||
TRY(inode.update_timestamps(
|
TRY(inode.update_timestamps(
|
||||||
(atime.tv_nsec != UTIME_OMIT) ? atime.tv_sec : Optional<time_t> {},
|
(atime.tv_nsec != UTIME_OMIT) ? Time::from_timespec(atime) : Optional<Time> {},
|
||||||
{},
|
{},
|
||||||
(mtime.tv_nsec != UTIME_OMIT) ? mtime.tv_sec : Optional<time_t> {}));
|
(mtime.tv_nsec != UTIME_OMIT) ? Time::from_timespec(mtime) : Optional<Time> {}));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::open(Credenti
|
||||||
|
|
||||||
if (should_truncate_file) {
|
if (should_truncate_file) {
|
||||||
TRY(inode.truncate(0));
|
TRY(inode.truncate(0));
|
||||||
TRY(inode.update_timestamps({}, {}, kgettimeofday().to_truncated_seconds()));
|
TRY(inode.update_timestamps({}, {}, kgettimeofday()));
|
||||||
}
|
}
|
||||||
auto description = TRY(OpenFileDescription::try_create(custody));
|
auto description = TRY(OpenFileDescription::try_create(custody));
|
||||||
description->set_rw_mode(options);
|
description->set_rw_mode(options);
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
virtual mode_t required_mode() const { return 0444; }
|
virtual mode_t required_mode() const { return 0444; }
|
||||||
virtual UserID owner_user() const { return 0; }
|
virtual UserID owner_user() const { return 0; }
|
||||||
virtual GroupID owner_group() const { return 0; }
|
virtual GroupID owner_group() const { return 0; }
|
||||||
static time_t modified_time() { return TimeManagement::now().to_timeval().tv_sec; }
|
static Time modified_time() { return TimeManagement::now(); }
|
||||||
|
|
||||||
virtual void prepare_for_deletion() { }
|
virtual void prepare_for_deletion() { }
|
||||||
virtual ErrorOr<void> refresh_data(OpenFileDescription&) const
|
virtual ErrorOr<void> refresh_data(OpenFileDescription&) const
|
||||||
|
|
|
@ -227,7 +227,7 @@ time_t TimeManagement::ticks_per_second() const
|
||||||
return m_time_keeper_timer->ticks_per_second();
|
return m_time_keeper_timer->ticks_per_second();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t TimeManagement::boot_time()
|
Time TimeManagement::boot_time()
|
||||||
{
|
{
|
||||||
#if ARCH(I386) || ARCH(X86_64)
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
return RTC::boot_time();
|
return RTC::boot_time();
|
||||||
|
@ -246,14 +246,14 @@ UNMAP_AFTER_INIT TimeManagement::TimeManagement()
|
||||||
if (ACPI::is_enabled()) {
|
if (ACPI::is_enabled()) {
|
||||||
if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
||||||
RTC::initialize();
|
RTC::initialize();
|
||||||
m_epoch_time.tv_sec += boot_time();
|
m_epoch_time.tv_sec += boot_time().to_timespec().tv_sec;
|
||||||
} else {
|
} else {
|
||||||
dmesgln("ACPI: RTC CMOS Not present");
|
dmesgln("ACPI: RTC CMOS Not present");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We just assume that we can access RTC CMOS, if ACPI isn't usable.
|
// We just assume that we can access RTC CMOS, if ACPI isn't usable.
|
||||||
RTC::initialize();
|
RTC::initialize();
|
||||||
m_epoch_time.tv_sec += boot_time();
|
m_epoch_time.tv_sec += boot_time().to_timespec().tv_sec;
|
||||||
}
|
}
|
||||||
if (probe_non_legacy_hardware_timers) {
|
if (probe_non_legacy_hardware_timers) {
|
||||||
if (!probe_and_set_x86_non_legacy_hardware_timers())
|
if (!probe_and_set_x86_non_legacy_hardware_timers())
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
Time epoch_time(TimePrecision = TimePrecision::Precise) const;
|
Time epoch_time(TimePrecision = TimePrecision::Precise) const;
|
||||||
void set_epoch_time(Time);
|
void set_epoch_time(Time);
|
||||||
time_t ticks_per_second() const;
|
time_t ticks_per_second() const;
|
||||||
static time_t boot_time();
|
static Time boot_time();
|
||||||
|
|
||||||
bool is_system_timer(HardwareTimerBase const&) const;
|
bool is_system_timer(HardwareTimerBase const&) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue