mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:32:45 +00:00 
			
		
		
		
	 6a1c85aa61
			
		
	
	
		6a1c85aa61
		
	
	
	
	
		
			
			Previously, PartitionTable was constructed using a Kernel::StorageDevice making it only usable in the kernel. This commit adds a new constructor that takes a Core::File instead, making it usable in userland as well. This also adds the m_block_size field which stores the block size of the underlying device obtained by calling StorageDevice::block_size() in the kernel or by using the STORAGE_DEVICE_GET_BLOCK_SIZE ioctl in userland. This avoids the need for an #ifdef every time block size is needed.
		
			
				
	
	
		
			36 lines
		
	
	
	
		
			762 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
	
		
			762 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 {
 | |
| 
 | |
| #ifdef KERNEL
 | |
| PartitionTable::PartitionTable(Kernel::StorageDevice const& device)
 | |
|     : m_device(device)
 | |
|     , m_block_size(device.block_size())
 | |
| {
 | |
| }
 | |
| #else
 | |
| PartitionTable::PartitionTable(NonnullRefPtr<Core::File> device_file)
 | |
|     : m_device_file(device_file)
 | |
| {
 | |
|     VERIFY(ioctl(m_device_file->leak_fd(), STORAGE_DEVICE_GET_BLOCK_SIZE, &m_block_size) >= 0);
 | |
| }
 | |
| #endif
 | |
| 
 | |
| Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index) const
 | |
| {
 | |
|     if (index > partitions_count())
 | |
|         return {};
 | |
|     return m_partitions[index];
 | |
| }
 | |
| 
 | |
| }
 |