mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:32:45 +00:00 
			
		
		
		
	Userland: Implement simple lspci command
This commit is contained in:
		
							parent
							
								
									6fe18a0417
								
							
						
					
					
						commit
						99ed4ce30c
					
				
					 2 changed files with 39 additions and 1 deletions
				
			
		|  | @ -268,7 +268,7 @@ Optional<KBuffer> procfs$pci(InodeIdentifier) | |||
|         obj.set("class", PCI::get_class(address)); | ||||
|         obj.set("subsystem_id", PCI::get_subsystem_id(address)); | ||||
|         obj.set("subsystem_vendor_id", PCI::get_subsystem_vendor_id(address)); | ||||
|         json.append(obj); | ||||
|         json.append(move(obj)); | ||||
|     }); | ||||
|     return json.serialized<KBufferBuilder>(); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										38
									
								
								Userland/lspci.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Userland/lspci.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| #include <AK/AKString.h> | ||||
| #include <AK/JsonArray.h> | ||||
| #include <AK/JsonObject.h> | ||||
| #include <LibCore/CFile.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| int main(int argc, char** argv) | ||||
| { | ||||
|     UNUSED_PARAM(argc); | ||||
|     UNUSED_PARAM(argv); | ||||
| 
 | ||||
|     CFile file("/proc/pci"); | ||||
|     if (!file.open(CIODevice::ReadOnly)) { | ||||
|         fprintf(stderr, "Error: %s\n", file.error_string()); | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|     auto file_contents = file.read_all(); | ||||
|     auto json = JsonValue::from_string(file_contents).as_array(); | ||||
|     json.for_each([](auto& value) { | ||||
|         auto dev = value.as_object(); | ||||
| 
 | ||||
|         auto bus = dev.get("bus").to_u32(); | ||||
|         auto slot = dev.get("slot").to_u32(); | ||||
|         auto function = dev.get("function").to_u32(); | ||||
|         auto vendor_id = dev.get("vendor_id").to_u32(); | ||||
|         auto device_id = dev.get("device_id").to_u32(); | ||||
|         auto revision_id = dev.get("revision_id").to_u32(); | ||||
|         auto class_id = dev.get("class").to_u32(); | ||||
| 
 | ||||
|         printf("%02x:%02x.%d %04x: %04x:%04x (rev %02x)\n", | ||||
|             bus, slot, function, | ||||
|             class_id, vendor_id, device_id, revision_id | ||||
|         ); | ||||
|     }); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Conrad Pankoff
						Conrad Pankoff