Kernel: cast between inheritance with static_cast
using reinterpret_cast is not a good idea. preferably we would use dynamic_cast, but that is not possible since kernel is compiled with -fno-rtti.
This commit is contained in:
		
							parent
							
								
									327b330338
								
							
						
					
					
						commit
						fdb6dc94ba
					
				|  | @ -43,7 +43,7 @@ namespace Kernel | |||
| 						[](BAN::RefPtr<TmpInode> inode) | ||||
| 						{ | ||||
| 							if (inode->is_device()) | ||||
| 								reinterpret_cast<Device*>(inode.ptr())->update(); | ||||
| 								static_cast<Device*>(inode.ptr())->update(); | ||||
| 							return BAN::Iteration::Continue; | ||||
| 						} | ||||
| 					); | ||||
|  | @ -77,7 +77,7 @@ namespace Kernel | |||
| 						{ | ||||
| 							if (inode->is_device()) | ||||
| 								if (((Device*)inode.ptr())->is_storage_device()) | ||||
| 									if (auto ret = reinterpret_cast<StorageDevice*>(inode.ptr())->sync_disk_cache(); ret.is_error()) | ||||
| 									if (auto ret = static_cast<StorageDevice*>(inode.ptr())->sync_disk_cache(); ret.is_error()) | ||||
| 										dwarnln("disk sync: {}", ret.error()); | ||||
| 							return BAN::Iteration::Continue; | ||||
| 						} | ||||
|  | @ -119,13 +119,13 @@ namespace Kernel | |||
| 	void DevFileSystem::add_device(BAN::RefPtr<Device> device) | ||||
| 	{ | ||||
| 		ASSERT(!device->name().contains('/')); | ||||
| 		MUST(reinterpret_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*device, device->name())); | ||||
| 		MUST(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*device, device->name())); | ||||
| 	} | ||||
| 
 | ||||
| 	void DevFileSystem::add_inode(BAN::StringView path, BAN::RefPtr<TmpInode> inode) | ||||
| 	{ | ||||
| 		ASSERT(!path.contains('/')); | ||||
| 		MUST(reinterpret_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path)); | ||||
| 		MUST(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path)); | ||||
| 	} | ||||
| 
 | ||||
| 	void DevFileSystem::for_each_device(const BAN::Function<BAN::Iteration(Device*)>& callback) | ||||
|  | @ -136,7 +136,7 @@ namespace Kernel | |||
| 			{ | ||||
| 				if (!inode->is_device()) | ||||
| 					return BAN::Iteration::Continue; | ||||
| 				return callback(reinterpret_cast<Device*>(inode.ptr())); | ||||
| 				return callback(static_cast<Device*>(inode.ptr())); | ||||
| 			} | ||||
| 		); | ||||
| 	} | ||||
|  |  | |||
|  | @ -31,7 +31,7 @@ namespace Kernel | |||
| 	{ | ||||
| 		auto path = BAN::String::formatted("{}", process.pid()); | ||||
| 		auto inode = TRY(ProcPidInode::create_new(process, *this, 0555, process.credentials().ruid(), process.credentials().rgid())); | ||||
| 		TRY(reinterpret_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path)); | ||||
| 		TRY(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path)); | ||||
| 		return {}; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -40,7 +40,7 @@ namespace Kernel | |||
| 		auto path = BAN::String::formatted("{}", process.pid()); | ||||
| 
 | ||||
| 		auto inode = MUST(root_inode()->find_inode(path)); | ||||
| 		reinterpret_cast<ProcPidInode*>(inode.ptr())->cleanup(); | ||||
| 		static_cast<ProcPidInode*>(inode.ptr())->cleanup(); | ||||
| 
 | ||||
| 		if (auto ret = root_inode()->unlink(path); ret.is_error()) | ||||
| 			dwarnln("{}", ret.error()); | ||||
|  |  | |||
|  | @ -23,9 +23,9 @@ namespace Kernel | |||
| 		root = root.substring(5); | ||||
| 
 | ||||
| 		auto partition_inode = MUST(DevFileSystem::get().root_inode()->find_inode(root)); | ||||
| 		if (!partition_inode->is_device() || !reinterpret_cast<Device*>(partition_inode.ptr())->is_partition()) | ||||
| 		if (!partition_inode->is_device() || !static_cast<Device*>(partition_inode.ptr())->is_partition()) | ||||
| 			Kernel::panic("Specified root '/dev/{}' does not name a partition", root); | ||||
| 		s_instance->m_root_fs = MUST(Ext2FS::create(reinterpret_cast<BlockDevice*>(partition_inode.ptr()))); | ||||
| 		s_instance->m_root_fs = MUST(Ext2FS::create(static_cast<BlockDevice*>(partition_inode.ptr()))); | ||||
| 
 | ||||
| 		Credentials root_creds { 0, 0, 0, 0 }; | ||||
| 		MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"sv)); | ||||
|  | @ -48,11 +48,11 @@ namespace Kernel | |||
| 		if (!block_device_file.inode->is_device()) | ||||
| 			return BAN::Error::from_errno(ENOTBLK); | ||||
| 
 | ||||
| 		auto* device = reinterpret_cast<Device*>(block_device_file.inode.ptr()); | ||||
| 		auto* device = static_cast<Device*>(block_device_file.inode.ptr()); | ||||
| 		if (!device->mode().ifblk()) | ||||
| 			return BAN::Error::from_errno(ENOTBLK); | ||||
| 
 | ||||
| 		auto* block_device = reinterpret_cast<BlockDevice*>(device); | ||||
| 		auto* block_device = static_cast<BlockDevice*>(device); | ||||
| 		auto* file_system = TRY(Ext2FS::create(block_device)); | ||||
| 		return mount(credentials, file_system, target); | ||||
| 	} | ||||
|  |  | |||
|  | @ -41,7 +41,7 @@ namespace Kernel | |||
| 
 | ||||
| 		auto inode = inode_or_error.release_value(); | ||||
| 		if (inode->mode().iflnk()) | ||||
| 			MUST(reinterpret_cast<TmpSymlinkInode*>(inode.ptr())->set_link_target(name())); | ||||
| 			MUST(static_cast<TmpSymlinkInode&>(*inode.ptr()).set_link_target(name())); | ||||
| 	} | ||||
| 
 | ||||
| 	BAN::ErrorOr<void> TTY::tty_ctrl(int command, int flags) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue