Serenity Operating System
at master 49 lines 2.0 kB view raw
1/* 2 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <Kernel/FileSystem/Inode.h> 8#include <Kernel/Memory/PrivateInodeVMObject.h> 9 10namespace Kernel::Memory { 11 12ErrorOr<NonnullLockRefPtr<PrivateInodeVMObject>> PrivateInodeVMObject::try_create_with_inode(Inode& inode) 13{ 14 if (inode.size() == 0) 15 return EINVAL; 16 return try_create_with_inode_and_range(inode, 0, inode.size()); 17} 18 19ErrorOr<NonnullLockRefPtr<PrivateInodeVMObject>> PrivateInodeVMObject::try_create_with_inode_and_range(Inode& inode, u64 offset, size_t range_size) 20{ 21 // Note: To ensure further allocation of a Region with this VMObject will not complain 22 // on "smaller" VMObject than the requested Region, we simply take the max size between both values. 23 auto size = max(inode.size(), (offset + range_size)); 24 VERIFY(size > 0); 25 auto new_physical_pages = TRY(VMObject::try_create_physical_pages(size)); 26 auto dirty_pages = TRY(Bitmap::create(new_physical_pages.size(), false)); 27 return adopt_nonnull_lock_ref_or_enomem(new (nothrow) PrivateInodeVMObject(inode, move(new_physical_pages), move(dirty_pages))); 28} 29 30ErrorOr<NonnullLockRefPtr<VMObject>> PrivateInodeVMObject::try_clone() 31{ 32 auto new_physical_pages = TRY(this->try_clone_physical_pages()); 33 auto dirty_pages = TRY(Bitmap::create(new_physical_pages.size(), false)); 34 return adopt_nonnull_lock_ref_or_enomem<VMObject>(new (nothrow) PrivateInodeVMObject(*this, move(new_physical_pages), move(dirty_pages))); 35} 36 37PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages, Bitmap dirty_pages) 38 : InodeVMObject(inode, move(new_physical_pages), move(dirty_pages)) 39{ 40} 41 42PrivateInodeVMObject::PrivateInodeVMObject(PrivateInodeVMObject const& other, FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages, Bitmap dirty_pages) 43 : InodeVMObject(other, move(new_physical_pages), move(dirty_pages)) 44{ 45} 46 47PrivateInodeVMObject::~PrivateInodeVMObject() = default; 48 49}