Kernel: Inode::create_file() now takes uid and gid as parameters

This commit is contained in:
Bananymous 2023-07-10 13:32:10 +03:00
parent f1089e2b8a
commit 3b5bc63d1b
6 changed files with 12 additions and 8 deletions

View File

@ -146,7 +146,7 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override; virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t) override; virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t, uid_t, gid_t) override;
private: private:
BAN::ErrorOr<uint32_t> data_block_index(uint32_t); BAN::ErrorOr<uint32_t> data_block_index(uint32_t);

View File

@ -88,7 +88,7 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); } virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); }
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); } virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); }
virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t) { if (!mode().ifdir()) return BAN::Error::from_errno(ENOTDIR); ASSERT_NOT_REACHED(); } virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t, uid_t, gid_t) { if (!mode().ifdir()) return BAN::Error::from_errno(ENOTDIR); ASSERT_NOT_REACHED(); }
}; };
} }

View File

@ -70,7 +70,7 @@ namespace Kernel
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> directory_find_inode(BAN::StringView) override; virtual BAN::ErrorOr<BAN::RefPtr<Inode>> directory_find_inode(BAN::StringView) override;
virtual BAN::ErrorOr<void> directory_read_next_entries(off_t, DirectoryEntryList*, size_t) override; virtual BAN::ErrorOr<void> directory_read_next_entries(off_t, DirectoryEntryList*, size_t) override;
virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t) override; virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t, uid_t, gid_t) override;
private: private:
RamDirectoryInode(RamFileSystem&, ino_t parent, mode_t, uid_t, gid_t); RamDirectoryInode(RamFileSystem&, ino_t parent, mode_t, uid_t, gid_t);

View File

@ -356,7 +356,7 @@ namespace Kernel
return {}; return {};
} }
BAN::ErrorOr<void> Ext2Inode::create_file(BAN::StringView name, mode_t mode) BAN::ErrorOr<void> Ext2Inode::create_file(BAN::StringView name, mode_t mode, uid_t uid, gid_t gid)
{ {
if (!this->mode().ifdir()) if (!this->mode().ifdir())
return BAN::Error::from_errno(ENOTDIR); return BAN::Error::from_errno(ENOTDIR);
@ -378,13 +378,13 @@ namespace Kernel
Ext2::Inode ext2_inode; Ext2::Inode ext2_inode;
ext2_inode.mode = mode; ext2_inode.mode = mode;
ext2_inode.uid = 0; ext2_inode.uid = uid;
ext2_inode.size = 0; ext2_inode.size = 0;
ext2_inode.atime = current_time; ext2_inode.atime = current_time;
ext2_inode.ctime = current_time; ext2_inode.ctime = current_time;
ext2_inode.mtime = current_time; ext2_inode.mtime = current_time;
ext2_inode.dtime = current_time; ext2_inode.dtime = current_time;
ext2_inode.gid = 0; ext2_inode.gid = gid;
ext2_inode.links_count = 1; ext2_inode.links_count = 1;
ext2_inode.blocks = 0; ext2_inode.blocks = 0;
ext2_inode.flags = 0; ext2_inode.flags = 0;

View File

@ -153,8 +153,12 @@ namespace Kernel
return {}; return {};
} }
BAN::ErrorOr<void> RamDirectoryInode::create_file(BAN::StringView, mode_t) BAN::ErrorOr<void> RamDirectoryInode::create_file(BAN::StringView name, mode_t mode, uid_t uid, gid_t gid)
{ {
(void)name;
(void)mode;
(void)uid;
(void)gid;
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }

View File

@ -567,7 +567,7 @@ namespace Kernel
auto file_name = absolute_path.sv().substring(index); auto file_name = absolute_path.sv().substring(index);
auto parent_file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, directory, O_WRONLY)); auto parent_file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, directory, O_WRONLY));
TRY(parent_file.inode->create_file(file_name, mode)); TRY(parent_file.inode->create_file(file_name, mode, m_credentials.euid(), m_credentials.egid()));
return 0; return 0;
} }