mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 09:20:36 +00:00
Kernel: Track time-of-last-write in SlavePTY and report it as mtime
This commit is contained in:
parent
ae9c5bf216
commit
4527d9852a
Notes:
sideshowbarker
2024-07-19 02:52:57 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4527d9852aa
4 changed files with 17 additions and 5 deletions
|
@ -50,7 +50,7 @@ static AK::Singleton<HashTable<unsigned>> s_ptys;
|
|||
|
||||
bool DevPtsFS::initialize()
|
||||
{
|
||||
m_root_inode = adopt(*new DevPtsFSInode(*this, 1));
|
||||
m_root_inode = adopt(*new DevPtsFSInode(*this, 1, nullptr));
|
||||
m_root_inode->m_metadata.inode = { fsid(), 1 };
|
||||
m_root_inode->m_metadata.mode = 0040555;
|
||||
m_root_inode->m_metadata.uid = 0;
|
||||
|
@ -86,7 +86,7 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
|
|||
auto* device = Device::get_device(201, pty_index);
|
||||
ASSERT(device);
|
||||
|
||||
auto inode = adopt(*new DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index()));
|
||||
auto inode = adopt(*new DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index(), static_cast<SlavePTY*>(device)));
|
||||
inode->m_metadata.inode = inode_id;
|
||||
inode->m_metadata.size = 0;
|
||||
inode->m_metadata.uid = device->uid();
|
||||
|
@ -109,9 +109,11 @@ void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
|
|||
s_ptys->remove(slave_pty.index());
|
||||
}
|
||||
|
||||
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index)
|
||||
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index, SlavePTY* pty)
|
||||
: Inode(fs, index)
|
||||
{
|
||||
if (pty)
|
||||
m_pty = pty->make_weak_ptr();
|
||||
}
|
||||
|
||||
DevPtsFSInode::~DevPtsFSInode()
|
||||
|
@ -130,6 +132,11 @@ ssize_t DevPtsFSInode::write_bytes(off_t, ssize_t, const u8*, FileDescription*)
|
|||
|
||||
InodeMetadata DevPtsFSInode::metadata() const
|
||||
{
|
||||
if (m_pty) {
|
||||
auto metadata = m_metadata;
|
||||
metadata.mtime = m_pty->time_of_last_write();
|
||||
return metadata;
|
||||
}
|
||||
return m_metadata;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
virtual ~DevPtsFSInode() override;
|
||||
|
||||
private:
|
||||
DevPtsFSInode(DevPtsFS&, unsigned index);
|
||||
DevPtsFSInode(DevPtsFS&, unsigned index, SlavePTY*);
|
||||
|
||||
// ^Inode
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const override;
|
||||
|
@ -80,6 +80,7 @@ private:
|
|||
virtual KResult chmod(mode_t) override;
|
||||
virtual KResult chown(uid_t, gid_t) override;
|
||||
|
||||
WeakPtr<SlavePTY> m_pty;
|
||||
InodeMetadata m_metadata;
|
||||
};
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ void SlavePTY::on_master_write(const u8* buffer, ssize_t size)
|
|||
|
||||
ssize_t SlavePTY::on_tty_write(const u8* data, ssize_t size)
|
||||
{
|
||||
m_time_of_last_write = kgettimeofday().tv_sec;
|
||||
return m_master->on_slave_write(data, size);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
void on_master_write(const u8*, ssize_t);
|
||||
unsigned index() const { return m_index; }
|
||||
|
||||
time_t time_of_last_write() const { return m_time_of_last_write; }
|
||||
|
||||
private:
|
||||
// ^TTY
|
||||
virtual String tty_name() const override;
|
||||
|
@ -57,7 +59,8 @@ private:
|
|||
SlavePTY(MasterPTY&, unsigned index);
|
||||
|
||||
RefPtr<MasterPTY> m_master;
|
||||
unsigned m_index;
|
||||
time_t m_time_of_last_write { 0 };
|
||||
unsigned m_index { 0 };
|
||||
char m_tty_name[32];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue