From 10fa72d4515dc74fe61994e1db7a1733d12b4c8f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 22 Nov 2022 21:01:45 +0100 Subject: [PATCH] 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. --- Kernel/Arch/x86/common/RTC.cpp | 4 ++-- Kernel/Arch/x86/common/RTC.h | 2 +- Kernel/FileSystem/DevPtsFS/Inode.cpp | 2 +- Kernel/FileSystem/Ext2FS/Inode.cpp | 22 +++++++++++----------- Kernel/FileSystem/Ext2FS/Inode.h | 2 +- Kernel/FileSystem/FATFS/Inode.cpp | 8 ++++---- Kernel/FileSystem/FATFS/Inode.h | 2 +- Kernel/FileSystem/ISO9660FS/Inode.cpp | 6 +++--- Kernel/FileSystem/ISO9660FS/Inode.h | 2 +- Kernel/FileSystem/Inode.cpp | 6 +++--- Kernel/FileSystem/Inode.h | 2 +- Kernel/FileSystem/InodeFile.cpp | 4 ++-- Kernel/FileSystem/InodeMetadata.h | 18 ++++++++---------- Kernel/FileSystem/ProcFS/GlobalInode.cpp | 2 +- Kernel/FileSystem/ProcFS/GlobalInode.h | 2 +- Kernel/FileSystem/SysFS/Inode.cpp | 2 +- Kernel/FileSystem/SysFS/Inode.h | 2 +- Kernel/FileSystem/TmpFS/Inode.cpp | 6 +++--- Kernel/FileSystem/TmpFS/Inode.h | 2 +- Kernel/FileSystem/VirtualFileSystem.cpp | 8 ++++---- Kernel/ProcessExposed.h | 2 +- Kernel/Time/TimeManagement.cpp | 6 +++--- Kernel/Time/TimeManagement.h | 2 +- 23 files changed, 56 insertions(+), 58 deletions(-) diff --git a/Kernel/Arch/x86/common/RTC.cpp b/Kernel/Arch/x86/common/RTC.cpp index 7373c62f97..f9816f52e0 100644 --- a/Kernel/Arch/x86/common/RTC.cpp +++ b/Kernel/Arch/x86/common/RTC.cpp @@ -19,9 +19,9 @@ void initialize() 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() diff --git a/Kernel/Arch/x86/common/RTC.h b/Kernel/Arch/x86/common/RTC.h index c57ec79acb..80e49ff1e7 100644 --- a/Kernel/Arch/x86/common/RTC.h +++ b/Kernel/Arch/x86/common/RTC.h @@ -12,6 +12,6 @@ namespace Kernel::RTC { void initialize(); time_t now(); -time_t boot_time(); +Time boot_time(); } diff --git a/Kernel/FileSystem/DevPtsFS/Inode.cpp b/Kernel/FileSystem/DevPtsFS/Inode.cpp index 116a9f3db6..30f7afc038 100644 --- a/Kernel/FileSystem/DevPtsFS/Inode.cpp +++ b/Kernel/FileSystem/DevPtsFS/Inode.cpp @@ -38,7 +38,7 @@ InodeMetadata DevPtsFSInode::metadata() const { if (auto pty = m_pty.strong_ref()) { 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 m_metadata; diff --git a/Kernel/FileSystem/Ext2FS/Inode.cpp b/Kernel/FileSystem/Ext2FS/Inode.cpp index ecf28273d1..a08a35d2d3 100644 --- a/Kernel/FileSystem/Ext2FS/Inode.cpp +++ b/Kernel/FileSystem/Ext2FS/Inode.cpp @@ -477,10 +477,10 @@ InodeMetadata Ext2FSInode::metadata() const metadata.uid = m_raw_inode.i_uid; metadata.gid = m_raw_inode.i_gid; metadata.link_count = m_raw_inode.i_links_count; - metadata.atime = m_raw_inode.i_atime; - metadata.ctime = m_raw_inode.i_ctime; - metadata.mtime = m_raw_inode.i_mtime; - metadata.dtime = m_raw_inode.i_dtime; + metadata.atime = Time::from_timespec({ m_raw_inode.i_atime, 0 }); + metadata.ctime = Time::from_timespec({ m_raw_inode.i_ctime, 0 }); + metadata.mtime = Time::from_timespec({ m_raw_inode.i_mtime, 0 }); + metadata.dtime = Time::from_timespec({ m_raw_inode.i_dtime, 0 }); metadata.block_size = fs().block_size(); metadata.block_count = m_raw_inode.i_blocks; @@ -930,23 +930,23 @@ ErrorOr> Ext2FSInode::lookup(StringView name) return fs().get_inode({ fsid(), inode_index }); } -ErrorOr Ext2FSInode::update_timestamps(Optional atime, Optional ctime, Optional mtime) +ErrorOr Ext2FSInode::update_timestamps(Optional