update main #1

Merged
Sinipelto merged 240 commits from Bananymous/banan-os:main into main 2023-11-20 13:20:51 +02:00
2 changed files with 13 additions and 0 deletions
Showing only changes of commit 2191ca46bb - Show all commits

View File

@ -145,6 +145,7 @@ namespace Kernel
(PAGE_SIZE / sizeof(TmpInodeInfo)); (PAGE_SIZE / sizeof(TmpInodeInfo));
const size_t m_max_pages; const size_t m_max_pages;
size_t m_used_pages { 0 };
}; };
template<TmpFuncs::with_block_buffer_callback F> template<TmpFuncs::with_block_buffer_callback F>

View File

@ -6,6 +6,9 @@ namespace Kernel
BAN::ErrorOr<TmpFileSystem*> TmpFileSystem::create(size_t max_pages, mode_t mode, uid_t uid, gid_t gid) BAN::ErrorOr<TmpFileSystem*> TmpFileSystem::create(size_t max_pages, mode_t mode, uid_t uid, gid_t gid)
{ {
if (max_pages < 2)
return BAN::Error::from_errno(ENOSPC);
auto* result = new TmpFileSystem(max_pages); auto* result = new TmpFileSystem(max_pages);
if (result == nullptr) if (result == nullptr)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
@ -22,6 +25,8 @@ namespace Kernel
paddr_t data_paddr = Heap::get().take_free_page(); paddr_t data_paddr = Heap::get().take_free_page();
if (data_paddr == 0) if (data_paddr == 0)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
m_used_pages++;
m_data_pages.set_paddr(data_paddr); m_data_pages.set_paddr(data_paddr);
m_data_pages.set_flags(PageInfo::Flags::Present); m_data_pages.set_flags(PageInfo::Flags::Present);
PageTable::with_fast_page(data_paddr, [&] { PageTable::with_fast_page(data_paddr, [&] {
@ -31,6 +36,8 @@ namespace Kernel
paddr_t inodes_paddr = Heap::get().take_free_page(); paddr_t inodes_paddr = Heap::get().take_free_page();
if (inodes_paddr == 0) if (inodes_paddr == 0)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
m_used_pages++;
m_inode_pages.set_paddr(inodes_paddr); m_inode_pages.set_paddr(inodes_paddr);
m_inode_pages.set_flags(PageInfo::Flags::Present); m_inode_pages.set_flags(PageInfo::Flags::Present);
PageTable::with_fast_page(inodes_paddr, [&] { PageTable::with_fast_page(inodes_paddr, [&] {
@ -178,6 +185,8 @@ namespace Kernel
auto& page_info = PageTable::fast_page_as_sized<PageInfo>(index_in_page); auto& page_info = PageTable::fast_page_as_sized<PageInfo>(index_in_page);
ASSERT(page_info.flags() & PageInfo::Flags::Present); ASSERT(page_info.flags() & PageInfo::Flags::Present);
Heap::get().release_page(page_info.paddr()); Heap::get().release_page(page_info.paddr());
m_used_pages--;
page_info.set_paddr(0); page_info.set_paddr(0);
page_info.set_flags(0); page_info.set_flags(0);
}); });
@ -256,9 +265,12 @@ namespace Kernel
if (!(next_info.flags() & PageInfo::Flags::Present)) if (!(next_info.flags() & PageInfo::Flags::Present))
{ {
if (m_used_pages >= m_max_pages)
return BAN::Error::from_errno(ENOSPC);
paddr_t new_paddr = Heap::get().take_free_page(); paddr_t new_paddr = Heap::get().take_free_page();
if (new_paddr == 0) if (new_paddr == 0)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
m_used_pages++;
PageTable::with_fast_page(new_paddr, [&] { PageTable::with_fast_page(new_paddr, [&] {
memset(PageTable::fast_page_as_ptr(), 0x00, PAGE_SIZE); memset(PageTable::fast_page_as_ptr(), 0x00, PAGE_SIZE);