kernel: Implement st_dev and st_rdev
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1a6ad11462
commit
1094042a7d
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <bits/makedev.h>
|
||||||
#include <luna/SharedPtr.h>
|
#include <luna/SharedPtr.h>
|
||||||
#include <luna/StaticString.h>
|
#include <luna/StaticString.h>
|
||||||
#include <luna/StringView.h>
|
#include <luna/StringView.h>
|
||||||
@ -48,6 +49,8 @@ namespace VFS
|
|||||||
m_handles--;
|
m_handles--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual dev_t host_device_id() const = 0;
|
||||||
|
|
||||||
virtual ~FileSystem() = default;
|
virtual ~FileSystem() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -101,6 +104,11 @@ namespace VFS
|
|||||||
return StringView {};
|
return StringView {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual dev_t device_id() const
|
||||||
|
{
|
||||||
|
return luna_dev_makedev(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Metadata accessors
|
// Metadata accessors
|
||||||
virtual usize size() const = 0;
|
virtual usize size() const = 0;
|
||||||
|
|
||||||
|
@ -74,4 +74,10 @@ namespace DeviceRegistry
|
|||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dev_t next_null_device_id()
|
||||||
|
{
|
||||||
|
static u32 next_minor = 0;
|
||||||
|
return luna_dev_makedev(0, next_minor++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,7 @@ namespace DeviceRegistry
|
|||||||
mode_t mode = 0666);
|
mode_t mode = 0666);
|
||||||
|
|
||||||
Result<void> init();
|
Result<void> init();
|
||||||
|
|
||||||
|
// Used for file systems (like tmpfs) that do not have a host device.
|
||||||
|
dev_t next_null_device_id();
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,18 @@ 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->set_device(device, {});
|
inode->set_device(device, {});
|
||||||
|
// FIXME: This should be queried from Device directly, but Device doesn't have an API to store and retrieve its
|
||||||
|
// device ID atm.
|
||||||
|
inode->set_device_id(luna_dev_makedev(major, minor), {});
|
||||||
|
|
||||||
return (SharedPtr<VFS::Inode>)inode;
|
return (SharedPtr<VFS::Inode>)inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileSystem::FileSystem()
|
||||||
|
{
|
||||||
|
m_host_device_id = DeviceRegistry::next_null_device_id();
|
||||||
|
}
|
||||||
|
|
||||||
Result<void> FileSystem::set_mount_dir(SharedPtr<VFS::Inode> parent)
|
Result<void> FileSystem::set_mount_dir(SharedPtr<VFS::Inode> parent)
|
||||||
{
|
{
|
||||||
return m_root_inode->replace_entry(parent, "..");
|
return m_root_inode->replace_entry(parent, "..");
|
||||||
|
@ -27,16 +27,23 @@ namespace TmpFS
|
|||||||
|
|
||||||
static Result<SharedPtr<VFS::FileSystem>> create();
|
static Result<SharedPtr<VFS::FileSystem>> create();
|
||||||
|
|
||||||
|
dev_t host_device_id() const override
|
||||||
|
{
|
||||||
|
return m_host_device_id;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~FileSystem() = default;
|
virtual ~FileSystem() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileSystem() = default;
|
FileSystem();
|
||||||
|
|
||||||
void set_root(SharedPtr<VFS::Inode> root);
|
void set_root(SharedPtr<VFS::Inode> root);
|
||||||
|
|
||||||
SharedPtr<VFS::Inode> m_root_inode;
|
SharedPtr<VFS::Inode> m_root_inode;
|
||||||
|
|
||||||
Atomic<usize> m_next_inode_number { 2 };
|
Atomic<usize> m_next_inode_number { 2 };
|
||||||
|
|
||||||
|
dev_t m_host_device_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileInode : public VFS::FileInode
|
class FileInode : public VFS::FileInode
|
||||||
@ -251,11 +258,21 @@ namespace TmpFS
|
|||||||
m_device = device;
|
m_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_device_id(dev_t id, Badge<FileSystem>)
|
||||||
|
{
|
||||||
|
m_device_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
VFS::FileSystem* fs() const override
|
VFS::FileSystem* fs() const override
|
||||||
{
|
{
|
||||||
return m_fs;
|
return m_fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dev_t device_id() const override
|
||||||
|
{
|
||||||
|
return m_device_id;
|
||||||
|
}
|
||||||
|
|
||||||
usize inode_number() const override
|
usize inode_number() const override
|
||||||
{
|
{
|
||||||
return m_inode_number;
|
return m_inode_number;
|
||||||
@ -340,6 +357,7 @@ namespace TmpFS
|
|||||||
u32 m_uid { 0 };
|
u32 m_uid { 0 };
|
||||||
u32 m_gid { 0 };
|
u32 m_gid { 0 };
|
||||||
u32 m_nlinks { 0 };
|
u32 m_nlinks { 0 };
|
||||||
|
dev_t m_device_id { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirInode : public VFS::Inode
|
class DirInode : public VFS::Inode
|
||||||
|
@ -40,6 +40,8 @@ Result<u64> sys_fstatat(Registers*, SyscallArgs args)
|
|||||||
kstat.st_uid = inode->uid();
|
kstat.st_uid = inode->uid();
|
||||||
kstat.st_gid = inode->gid();
|
kstat.st_gid = inode->gid();
|
||||||
kstat.st_size = inode->size();
|
kstat.st_size = inode->size();
|
||||||
|
kstat.st_dev = inode->fs()->host_device_id();
|
||||||
|
kstat.st_rdev = inode->device_id();
|
||||||
|
|
||||||
if (!MemoryManager::copy_to_user_typed(st, &kstat)) return err(EFAULT);
|
if (!MemoryManager::copy_to_user_typed(st, &kstat)) return err(EFAULT);
|
||||||
|
|
||||||
|
@ -10,9 +10,11 @@ struct stat
|
|||||||
ino_t st_ino;
|
ino_t st_ino;
|
||||||
mode_t st_mode;
|
mode_t st_mode;
|
||||||
nlink_t st_nlink;
|
nlink_t st_nlink;
|
||||||
|
dev_t st_dev;
|
||||||
uid_t st_uid;
|
uid_t st_uid;
|
||||||
gid_t st_gid;
|
gid_t st_gid;
|
||||||
off_t st_size;
|
off_t st_size;
|
||||||
|
dev_t st_rdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user