diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-02-28 02:18:48 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-02 08:36:08 +0100 |
commit | 336303bda47177aba0ee0ca4d81148ab15a916eb (patch) | |
tree | 7a023b37b117ada2dd524d68f7316a12b2ba65ce /Kernel | |
parent | 05d5e3fad90c5e45b7d65b74251e2c7b8907936e (diff) | |
download | serenity-336303bda47177aba0ee0ca4d81148ab15a916eb.zip |
Kernel: Make kgettimeofday use AK::Time
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 10 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeFile.cpp | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/TmpFS.cpp | 16 | ||||
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 3 | ||||
-rw-r--r-- | Kernel/Net/TCPSocket.cpp | 3 | ||||
-rw-r--r-- | Kernel/Process.cpp | 4 | ||||
-rw-r--r-- | Kernel/Process.h | 3 | ||||
-rw-r--r-- | Kernel/Syscalls/clock.cpp | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/utime.cpp | 5 | ||||
-rw-r--r-- | Kernel/TTY/SlavePTY.cpp | 2 |
11 files changed, 28 insertions, 26 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 284ef795d8..d6befa6882 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -572,7 +572,7 @@ void Ext2FS::free_inode(Ext2FSInode& inode) // NOTE: After this point, the inode metadata is wiped. memset(&inode.m_raw_inode, 0, sizeof(ext2_inode)); - inode.m_raw_inode.i_dtime = kgettimeofday().tv_sec; + inode.m_raw_inode.i_dtime = kgettimeofday().to_truncated_seconds(); write_ext2_inode(inode.index(), inode.m_raw_inode); // Mark the inode as free. @@ -1429,14 +1429,14 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode, return ENOENT; ext2_inode e2inode {}; - auto now = kgettimeofday(); + auto now = kgettimeofday().to_truncated_seconds(); e2inode.i_mode = mode; e2inode.i_uid = uid; e2inode.i_gid = gid; e2inode.i_size = 0; - e2inode.i_atime = now.tv_sec; - e2inode.i_ctime = now.tv_sec; - e2inode.i_mtime = now.tv_sec; + e2inode.i_atime = now; + e2inode.i_ctime = now; + e2inode.i_mtime = now; e2inode.i_dtime = 0; e2inode.i_flags = 0; diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index bd07315735..0dd4fa87c2 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -68,7 +68,7 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, size_t offset, ssize_t nwritten = m_inode->write_bytes(offset, count, data, &description); if (nwritten > 0) { - m_inode->set_mtime(kgettimeofday().tv_sec); + m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); Thread::current()->did_file_write(nwritten); evaluate_block_conditions(); } @@ -132,7 +132,7 @@ 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().tv_sec); + int mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); if (mtime_result < 0) return KResult((ErrnoCode)-mtime_result); return KSuccess; diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index 5ac084baa5..7fc7c4efbf 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -114,10 +114,10 @@ NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs) { InodeMetadata metadata; - auto now = kgettimeofday(); - metadata.atime = now.tv_sec; - metadata.ctime = now.tv_sec; - metadata.mtime = now.tv_sec; + auto now = kgettimeofday().to_truncated_seconds(); + metadata.atime = now; + metadata.ctime = now; + metadata.mtime = now; metadata.mode = S_IFDIR | S_ISVTX | 0777; return create(fs, metadata, { fs.fsid(), 1 }); } @@ -280,15 +280,15 @@ KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(const String& name, mod if (dev != 0) return ENOTSUP; - struct timeval now = kgettimeofday(); + time_t now = kgettimeofday().to_truncated_seconds(); InodeMetadata metadata; metadata.mode = mode; metadata.uid = uid; metadata.gid = gid; - metadata.atime = now.tv_sec; - metadata.ctime = now.tv_sec; - metadata.mtime = now.tv_sec; + metadata.atime = now; + metadata.ctime = now; + metadata.mtime = now; auto child = TmpFSInode::create(fs(), metadata, identifier()); auto result = add_child(child, name, mode); diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 55b0da3ba0..e436604288 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -346,7 +346,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options KResult result = inode.truncate(0); if (result.is_error()) return result; - inode.set_mtime(kgettimeofday().tv_sec); + inode.set_mtime(kgettimeofday().to_truncated_seconds()); } auto description = FileDescription::create(custody); if (!description.is_error()) { diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index e28793009e..b430bccf57 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -193,7 +193,8 @@ void NetworkAdapter::did_receive(ReadonlyBytes payload) } } - m_packet_queue.append({ buffer.value(), kgettimeofday() }); + // FIXME: Should use AK::Time internally + m_packet_queue.append({ buffer.value(), kgettimeofday().to_timeval() }); if (on_receive) on_receive(); diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 703abb7072..2722bcaee2 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -238,7 +238,8 @@ void TCPSocket::send_outgoing_packets() auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); VERIFY(!routing_decision.is_zero()); - auto now = kgettimeofday(); + // FIXME: Should use AK::Time internally + auto now = kgettimeofday().to_timeval(); LOCKER(m_not_acked_lock, Lock::Mode::Shared); for (auto& packet : m_not_acked) { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index a7adc179df..45037536ea 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -381,9 +381,9 @@ int Process::alloc_fd(int first_candidate_fd) return -EMFILE; } -timeval kgettimeofday() +Time kgettimeofday() { - return TimeManagement::now().to_timeval(); + return TimeManagement::now(); } siginfo_t Process::wait_info() diff --git a/Kernel/Process.h b/Kernel/Process.h index cbba6cbf1e..0a64d40209 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -54,8 +54,7 @@ namespace Kernel { -// FIXME: Should use AK::Time internally -timeval kgettimeofday(); +Time kgettimeofday(); #define ENUMERATE_PLEDGE_PROMISES \ __ENUMERATE_PLEDGE_PROMISE(stdio) \ diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp index 5296644141..2966a4f70b 100644 --- a/Kernel/Syscalls/clock.cpp +++ b/Kernel/Syscalls/clock.cpp @@ -135,7 +135,7 @@ KResultOr<int> Process::sys$adjtime(Userspace<const timeval*> user_delta, Usersp KResultOr<int> Process::sys$gettimeofday(Userspace<timeval*> user_tv) { REQUIRE_PROMISE(stdio); - auto tv = kgettimeofday(); + auto tv = kgettimeofday().to_timeval(); if (!copy_to_user(user_tv, &tv)) return EFAULT; return 0; diff --git a/Kernel/Syscalls/utime.cpp b/Kernel/Syscalls/utime.cpp index 31b0509f36..f7a78a5e8d 100644 --- a/Kernel/Syscalls/utime.cpp +++ b/Kernel/Syscalls/utime.cpp @@ -41,8 +41,9 @@ KResultOr<int> Process::sys$utime(Userspace<const char*> user_path, size_t path_ if (!copy_from_user(&buf, user_buf)) return EFAULT; } else { - auto now = kgettimeofday(); - buf = { now.tv_sec, now.tv_sec }; + auto now = kgettimeofday().to_truncated_seconds(); + // Not a bug! + buf = { now, now }; } return VFS::the().utime(path.value(), current_directory(), buf.actime, buf.modtime); } diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index cb5c707d31..5c7b93d2eb 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -77,7 +77,7 @@ void SlavePTY::on_master_write(const UserOrKernelBuffer& buffer, ssize_t size) ssize_t SlavePTY::on_tty_write(const UserOrKernelBuffer& data, ssize_t size) { - m_time_of_last_write = kgettimeofday().tv_sec; + m_time_of_last_write = kgettimeofday().to_truncated_seconds(); return m_master->on_slave_write(data, size); } |