mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:12:44 +00:00 
			
		
		
		
	 3d6b838df3
			
		
	
	
		3d6b838df3
		
	
	
	
	
		
			
			The implemented cloning mechanism should be sound: - If a PartitionTable is passed a File with ShouldCloseFileDescriptor::Yes, then it will keep it alive until the PartitionTable is destroyed. - If a PartitionTable is passed a File with ShouldCloseFileDescriptor::No, then the caller has to ensure that the file descriptor remains alive. If the caller is EBRPartitionTable, the same consideration holds. If the caller is PartitionEditor::PartitionModel, this is satisfied by keeping an OwnPtr<Core::File> around which is the originally opened file. Therefore, we never leak any fds, and never access a Core::File or fd after destroying it.
		
			
				
	
	
		
			27 lines
		
	
	
	
		
			491 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
	
		
			491 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibPartition/PartitionTable.h>
 | |
| 
 | |
| #ifndef KERNEL
 | |
| #    include <sys/ioctl.h>
 | |
| #endif
 | |
| 
 | |
| namespace Partition {
 | |
| 
 | |
| PartitionTable::PartitionTable(PartitionableDevice&& device)
 | |
|     : m_device(move(device))
 | |
| {
 | |
| }
 | |
| 
 | |
| Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index) const
 | |
| {
 | |
|     if (index > partitions_count())
 | |
|         return {};
 | |
|     return m_partitions[index];
 | |
| }
 | |
| 
 | |
| }
 |