Compare commits

...

2 Commits

Author SHA1 Message Date
5188def9e5
stat: Recognize sockets properly
Some checks failed
continuous-integration/drone/push Build is failing
2023-12-04 20:42:31 +01:00
9b01b5a5db
kernel: Correctly register file times for more file systems and file types 2023-12-04 20:42:17 +01:00
11 changed files with 39 additions and 21 deletions

View File

@ -14,6 +14,7 @@ static const char* file_type(mode_t mode)
case S_IFBLK: return "block special device"; case S_IFBLK: return "block special device";
case S_IFLNK: return "symbolic link"; case S_IFLNK: return "symbolic link";
case S_IFIFO: return "pipe"; case S_IFIFO: return "pipe";
case S_IFSOCK: return "socket";
default: return "unknown file type"; default: return "unknown file type";
} }
} }

View File

@ -35,6 +35,19 @@ namespace VFS
struct timespec atime; struct timespec atime;
struct timespec mtime; struct timespec mtime;
struct timespec ctime; struct timespec ctime;
void initialize_times()
{
g_realtime_clock.get_time(atime);
g_realtime_clock.get_time(ctime);
g_realtime_clock.get_time(mtime);
}
void update_mtime()
{
g_realtime_clock.get_time(mtime);
g_realtime_clock.get_time(ctime);
}
}; };
class Inode; class Inode;

View File

@ -27,12 +27,14 @@ Result<SharedPtr<VFS::Inode>> MasterPTY::create_pair(int index)
master->m_settings.c_cc[VQUIT] = '\x1c'; master->m_settings.c_cc[VQUIT] = '\x1c';
master->m_window.ws_col = 80; master->m_window.ws_col = 80;
master->m_window.ws_row = 25; master->m_window.ws_row = 25;
master->m_metadata.initialize_times();
slave->m_master = master.ptr(); slave->m_master = master.ptr();
slave->m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, index + 2); slave->m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, index + 2);
slave->m_metadata.uid = Scheduler::current()->auth.euid; slave->m_metadata.uid = Scheduler::current()->auth.euid;
slave->m_metadata.gid = Scheduler::current()->auth.egid; slave->m_metadata.gid = Scheduler::current()->auth.egid;
slave->m_metadata.mode = 0620; slave->m_metadata.mode = 0620;
slave->m_metadata.initialize_times();
return (SharedPtr<VFS::Inode>)master; return (SharedPtr<VFS::Inode>)master;
} }
@ -193,6 +195,8 @@ Result<usize> MasterPTY::write(const u8* buf, usize, usize length)
{ {
for (usize i = 0; i < length; i++) { TRY(handle_input(buf[i])); } for (usize i = 0; i < length; i++) { TRY(handle_input(buf[i])); }
m_metadata.update_mtime();
return length; return length;
} }

View File

@ -6,6 +6,7 @@ PTYMultiplexer::PTYMultiplexer()
{ {
m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, 0); m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, 0);
m_metadata.mode = 0666; m_metadata.mode = 0666;
m_metadata.initialize_times();
} }
Result<SharedPtr<VFS::Inode>> PTYMultiplexer::open() Result<SharedPtr<VFS::Inode>> PTYMultiplexer::open()

View File

@ -31,6 +31,8 @@ Result<usize> SlavePTY::write(const u8* buf, usize, usize length)
TRY(m_master->m_buffer.append_data(buf, length)); TRY(m_master->m_buffer.append_data(buf, length));
m_metadata.update_mtime();
return length; return length;
} }

View File

@ -5,6 +5,7 @@ TTYLink::TTYLink()
{ {
m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, 1); m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, 1);
m_metadata.mode = 0666; m_metadata.mode = 0666;
m_metadata.initialize_times();
} }
Result<SharedPtr<VFS::Inode>> TTYLink::open() Result<SharedPtr<VFS::Inode>> TTYLink::open()

View File

@ -21,9 +21,7 @@ namespace DevPTS
root->set_fs(*fs, {}); root->set_fs(*fs, {});
root->set_inode_number(); root->set_inode_number();
root->m_metadata.mode = 0755; root->m_metadata.mode = 0755;
g_realtime_clock.get_time(root->m_metadata.ctime); root->m_metadata.initialize_times();
g_realtime_clock.get_time(root->m_metadata.atime);
g_realtime_clock.get_time(root->m_metadata.mtime);
fs->set_root(root); fs->set_root(root);
TRY(g_devpts_instances.try_append(fs.ptr())); TRY(g_devpts_instances.try_append(fs.ptr()));

View File

@ -43,7 +43,7 @@ namespace DevPTS
inode->did_link(); inode->did_link();
g_realtime_clock.get_time(m_metadata.mtime); m_metadata.update_mtime();
return {}; return {};
} }
@ -61,7 +61,7 @@ namespace DevPTS
inode->did_unlink(); inode->did_unlink();
g_realtime_clock.get_time(m_metadata.mtime); m_metadata.update_mtime();
return {}; return {};
} }

View File

@ -27,9 +27,7 @@ namespace TmpFS
inode->set_fs(*this, {}); inode->set_fs(*this, {});
inode->set_inode_number(m_next_inode_number++, {}); inode->set_inode_number(m_next_inode_number++, {});
inode->m_metadata.mode = mode; inode->m_metadata.mode = mode;
g_realtime_clock.get_time(inode->m_metadata.mtime); inode->m_metadata.initialize_times();
g_realtime_clock.get_time(inode->m_metadata.atime);
g_realtime_clock.get_time(inode->m_metadata.ctime);
return (SharedPtr<VFS::Inode>)inode; return (SharedPtr<VFS::Inode>)inode;
} }
@ -39,9 +37,7 @@ namespace TmpFS
inode->set_fs(*this, {}); inode->set_fs(*this, {});
TRY(inode->set_link(link, {})); TRY(inode->set_link(link, {}));
inode->set_inode_number(m_next_inode_number++, {}); inode->set_inode_number(m_next_inode_number++, {});
g_realtime_clock.get_time(inode->m_metadata.mtime); inode->m_metadata.initialize_times();
g_realtime_clock.get_time(inode->m_metadata.atime);
g_realtime_clock.get_time(inode->m_metadata.ctime);
return (SharedPtr<VFS::Inode>)inode; return (SharedPtr<VFS::Inode>)inode;
} }
@ -56,9 +52,7 @@ namespace TmpFS
inode->set_fs(*this, {}); inode->set_fs(*this, {});
inode->set_inode_number(m_next_inode_number++, {}); inode->set_inode_number(m_next_inode_number++, {});
inode->m_metadata.mode = mode; inode->m_metadata.mode = mode;
g_realtime_clock.get_time(inode->m_metadata.mtime); inode->m_metadata.initialize_times();
g_realtime_clock.get_time(inode->m_metadata.atime);
g_realtime_clock.get_time(inode->m_metadata.ctime);
return (SharedPtr<VFS::Inode>)inode; return (SharedPtr<VFS::Inode>)inode;
} }
@ -75,9 +69,7 @@ namespace TmpFS
// device ID atm. // device ID atm.
inode->set_device_id(luna_dev_makedev(major, minor), {}); inode->set_device_id(luna_dev_makedev(major, minor), {});
inode->m_metadata.mode = mode; inode->m_metadata.mode = mode;
g_realtime_clock.get_time(inode->m_metadata.mtime); inode->m_metadata.initialize_times();
g_realtime_clock.get_time(inode->m_metadata.atime);
g_realtime_clock.get_time(inode->m_metadata.ctime);
inode->m_metadata.size = device->size(); inode->m_metadata.size = device->size();
return (SharedPtr<VFS::Inode>)inode; return (SharedPtr<VFS::Inode>)inode;

View File

@ -45,7 +45,7 @@ namespace TmpFS
inode->did_link(); inode->did_link();
g_realtime_clock.get_time(m_metadata.mtime); m_metadata.update_mtime();
return {}; return {};
} }
@ -63,7 +63,7 @@ namespace TmpFS
inode->did_unlink(); inode->did_unlink();
g_realtime_clock.get_time(m_metadata.mtime); m_metadata.update_mtime();
return {}; return {};
} }
@ -118,7 +118,7 @@ namespace TmpFS
m_metadata.size = m_data_buffer.size(); m_metadata.size = m_data_buffer.size();
g_realtime_clock.get_time(m_metadata.mtime); m_metadata.update_mtime();
return length; return length;
} }
@ -133,7 +133,7 @@ namespace TmpFS
m_metadata.size = m_data_buffer.size(); m_metadata.size = m_data_buffer.size();
g_realtime_clock.get_time(m_metadata.mtime); m_metadata.update_mtime();
return {}; return {};
} }

View File

@ -5,10 +5,12 @@
UnixSocket::UnixSocket() UnixSocket::UnixSocket()
{ {
m_metadata.initialize_times();
} }
UnixSocket::UnixSocket(UnixSocket* peer) : m_state(State::Connected), m_peer(peer) UnixSocket::UnixSocket(UnixSocket* peer) : m_state(State::Connected), m_peer(peer)
{ {
m_metadata.initialize_times();
} }
UnixSocket::~UnixSocket() UnixSocket::~UnixSocket()
@ -41,6 +43,8 @@ Result<usize> UnixSocket::send(const u8* buf, usize length, int)
TRY(m_peer->m_data.append_data(buf, length)); TRY(m_peer->m_data.append_data(buf, length));
m_peer->m_metadata.update_mtime();
return length; return length;
} }
@ -209,5 +213,7 @@ Result<SharedPtr<OpenFileDescription>> UnixSocket::accept(Registers* regs, int f
*addr = (struct sockaddr*)&peer->m_addr; *addr = (struct sockaddr*)&peer->m_addr;
*addrlen = peer->m_addrlen; *addrlen = peer->m_addrlen;
m_metadata.update_mtime();
return description; return description;
} }