Kernel: Make kgettimeofday use AK::Time

This commit is contained in:
Ben Wiederhake 2021-02-28 02:18:48 +01:00 committed by Andreas Kling
parent 05d5e3fad9
commit 336303bda4
11 changed files with 28 additions and 26 deletions

View file

@ -572,7 +572,7 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
// NOTE: After this point, the inode metadata is wiped. // NOTE: After this point, the inode metadata is wiped.
memset(&inode.m_raw_inode, 0, sizeof(ext2_inode)); 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); write_ext2_inode(inode.index(), inode.m_raw_inode);
// Mark the inode as free. // Mark the inode as free.
@ -1429,14 +1429,14 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode,
return ENOENT; return ENOENT;
ext2_inode e2inode {}; ext2_inode e2inode {};
auto now = kgettimeofday(); auto now = kgettimeofday().to_truncated_seconds();
e2inode.i_mode = mode; e2inode.i_mode = mode;
e2inode.i_uid = uid; e2inode.i_uid = uid;
e2inode.i_gid = gid; e2inode.i_gid = gid;
e2inode.i_size = 0; e2inode.i_size = 0;
e2inode.i_atime = now.tv_sec; e2inode.i_atime = now;
e2inode.i_ctime = now.tv_sec; e2inode.i_ctime = now;
e2inode.i_mtime = now.tv_sec; e2inode.i_mtime = now;
e2inode.i_dtime = 0; e2inode.i_dtime = 0;
e2inode.i_flags = 0; e2inode.i_flags = 0;

View file

@ -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); ssize_t nwritten = m_inode->write_bytes(offset, count, data, &description);
if (nwritten > 0) { if (nwritten > 0) {
m_inode->set_mtime(kgettimeofday().tv_sec); 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();
} }
@ -132,7 +132,7 @@ KResult InodeFile::truncate(u64 size)
auto truncate_result = m_inode->truncate(size); auto truncate_result = m_inode->truncate(size);
if (truncate_result.is_error()) if (truncate_result.is_error())
return truncate_result; 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) if (mtime_result < 0)
return KResult((ErrnoCode)-mtime_result); return KResult((ErrnoCode)-mtime_result);
return KSuccess; return KSuccess;

View file

@ -114,10 +114,10 @@ NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata,
NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs) NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs)
{ {
InodeMetadata metadata; InodeMetadata metadata;
auto now = kgettimeofday(); auto now = kgettimeofday().to_truncated_seconds();
metadata.atime = now.tv_sec; metadata.atime = now;
metadata.ctime = now.tv_sec; metadata.ctime = now;
metadata.mtime = now.tv_sec; metadata.mtime = now;
metadata.mode = S_IFDIR | S_ISVTX | 0777; metadata.mode = S_IFDIR | S_ISVTX | 0777;
return create(fs, metadata, { fs.fsid(), 1 }); return create(fs, metadata, { fs.fsid(), 1 });
} }
@ -280,15 +280,15 @@ KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(const String& name, mod
if (dev != 0) if (dev != 0)
return ENOTSUP; return ENOTSUP;
struct timeval now = kgettimeofday(); time_t now = kgettimeofday().to_truncated_seconds();
InodeMetadata metadata; InodeMetadata metadata;
metadata.mode = mode; metadata.mode = mode;
metadata.uid = uid; metadata.uid = uid;
metadata.gid = gid; metadata.gid = gid;
metadata.atime = now.tv_sec; metadata.atime = now;
metadata.ctime = now.tv_sec; metadata.ctime = now;
metadata.mtime = now.tv_sec; metadata.mtime = now;
auto child = TmpFSInode::create(fs(), metadata, identifier()); auto child = TmpFSInode::create(fs(), metadata, identifier());
auto result = add_child(child, name, mode); auto result = add_child(child, name, mode);

View file

@ -346,7 +346,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
KResult result = inode.truncate(0); KResult result = inode.truncate(0);
if (result.is_error()) if (result.is_error())
return result; return result;
inode.set_mtime(kgettimeofday().tv_sec); 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()) {

View file

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

View file

@ -238,7 +238,8 @@ void TCPSocket::send_outgoing_packets()
auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); auto routing_decision = route_to(peer_address(), local_address(), bound_interface());
VERIFY(!routing_decision.is_zero()); 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); LOCKER(m_not_acked_lock, Lock::Mode::Shared);
for (auto& packet : m_not_acked) { for (auto& packet : m_not_acked) {

View file

@ -381,9 +381,9 @@ int Process::alloc_fd(int first_candidate_fd)
return -EMFILE; return -EMFILE;
} }
timeval kgettimeofday() Time kgettimeofday()
{ {
return TimeManagement::now().to_timeval(); return TimeManagement::now();
} }
siginfo_t Process::wait_info() siginfo_t Process::wait_info()

View file

@ -54,8 +54,7 @@
namespace Kernel { namespace Kernel {
// FIXME: Should use AK::Time internally Time kgettimeofday();
timeval kgettimeofday();
#define ENUMERATE_PLEDGE_PROMISES \ #define ENUMERATE_PLEDGE_PROMISES \
__ENUMERATE_PLEDGE_PROMISE(stdio) \ __ENUMERATE_PLEDGE_PROMISE(stdio) \

View file

@ -135,7 +135,7 @@ KResultOr<int> Process::sys$adjtime(Userspace<const timeval*> user_delta, Usersp
KResultOr<int> Process::sys$gettimeofday(Userspace<timeval*> user_tv) KResultOr<int> Process::sys$gettimeofday(Userspace<timeval*> user_tv)
{ {
REQUIRE_PROMISE(stdio); REQUIRE_PROMISE(stdio);
auto tv = kgettimeofday(); auto tv = kgettimeofday().to_timeval();
if (!copy_to_user(user_tv, &tv)) if (!copy_to_user(user_tv, &tv))
return EFAULT; return EFAULT;
return 0; return 0;

View file

@ -41,8 +41,9 @@ KResultOr<int> Process::sys$utime(Userspace<const char*> user_path, size_t path_
if (!copy_from_user(&buf, user_buf)) if (!copy_from_user(&buf, user_buf))
return EFAULT; return EFAULT;
} else { } else {
auto now = kgettimeofday(); auto now = kgettimeofday().to_truncated_seconds();
buf = { now.tv_sec, now.tv_sec }; // Not a bug!
buf = { now, now };
} }
return VFS::the().utime(path.value(), current_directory(), buf.actime, buf.modtime); return VFS::the().utime(path.value(), current_directory(), buf.actime, buf.modtime);
} }

View file

@ -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) 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); return m_master->on_slave_write(data, size);
} }