Kernel: Implement Socket inodes for tmpfs

This commit is contained in:
Bananymous 2024-02-07 15:33:48 +02:00
parent 454bee3f02
commit 132286895f
3 changed files with 57 additions and 2 deletions

View File

@ -80,6 +80,24 @@ namespace Kernel
friend class TmpInode; friend class TmpInode;
}; };
class TmpSocketInode : public TmpInode
{
public:
static BAN::ErrorOr<BAN::RefPtr<TmpSocketInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t);
~TmpSocketInode();
protected:
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return BAN::Error::from_errno(ENODEV); }
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override { return BAN::Error::from_errno(ENODEV); }
virtual BAN::ErrorOr<void> truncate_impl(size_t) override { return BAN::Error::from_errno(ENODEV); }
virtual bool has_data_impl() const override { return true; }
private:
TmpSocketInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
friend class TmpInode;
};
class TmpSymlinkInode : public TmpInode class TmpSymlinkInode : public TmpInode
{ {
public: public:

View File

@ -215,6 +215,30 @@ namespace Kernel
return {}; return {};
} }
/* SOCKET INODE */
BAN::ErrorOr<BAN::RefPtr<TmpSocketInode>> TmpSocketInode::create_new(TmpFileSystem& fs, mode_t mode, uid_t uid, gid_t gid)
{
auto info = create_inode_info(Mode::IFSOCK | mode, uid, gid);
ino_t ino = TRY(fs.allocate_inode(info));
auto* inode_ptr = new TmpSocketInode(fs, ino, info);
if (inode_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM);
return BAN::RefPtr<TmpSocketInode>::adopt(inode_ptr);
}
TmpSocketInode::TmpSocketInode(TmpFileSystem& fs, ino_t ino, const TmpInodeInfo& info)
: TmpInode(fs, ino, info)
{
ASSERT(mode().ifsock());
}
TmpSocketInode::~TmpSocketInode()
{
}
/* SYMLINK INODE */ /* SYMLINK INODE */
BAN::ErrorOr<BAN::RefPtr<TmpSymlinkInode>> TmpSymlinkInode::create_new(TmpFileSystem& fs, mode_t mode, uid_t uid, gid_t gid, BAN::StringView target) BAN::ErrorOr<BAN::RefPtr<TmpSymlinkInode>> TmpSymlinkInode::create_new(TmpFileSystem& fs, mode_t mode, uid_t uid, gid_t gid, BAN::StringView target)
@ -446,7 +470,19 @@ namespace Kernel
BAN::ErrorOr<void> TmpDirectoryInode::create_file_impl(BAN::StringView name, mode_t mode, uid_t uid, gid_t gid) BAN::ErrorOr<void> TmpDirectoryInode::create_file_impl(BAN::StringView name, mode_t mode, uid_t uid, gid_t gid)
{ {
auto new_inode = TRY(TmpFileInode::create_new(m_fs, mode, uid, gid)); BAN::RefPtr<TmpInode> new_inode;
switch (mode & Mode::TYPE_MASK)
{
case Mode::IFREG:
new_inode = TRY(TmpFileInode::create_new(m_fs, mode, uid, gid));
break;
case Mode::IFSOCK:
new_inode = TRY(TmpSocketInode::create_new(m_fs, mode, uid, gid));
break;
default:
dprintln("Creating with mode {o} is not supported", mode);
return BAN::Error::from_errno(ENOTSUP);
}
TRY(link_inode(*new_inode, name)); TRY(link_inode(*new_inode, name));
return {}; return {};
} }

View File

@ -649,8 +649,9 @@ namespace Kernel
case Inode::Mode::IFREG: break; case Inode::Mode::IFREG: break;
case Inode::Mode::IFDIR: break; case Inode::Mode::IFDIR: break;
case Inode::Mode::IFIFO: break; case Inode::Mode::IFIFO: break;
case Inode::Mode::IFSOCK: break;
default: default:
return BAN::Error::from_errno(EINVAL); return BAN::Error::from_errno(ENOTSUP);
} }
LockGuard _(m_lock); LockGuard _(m_lock);