lshw学习——简单介绍
文章目录
- 简介
 - 核心结构
 - 扫描设备原理
 - scan_abi
 - scan_burner
 - scan_cdrom
 - scan_cpufreq
 - scan_cpuid
 - scan_cpuinfo
 - scan_device_tree
 - scan_disk
 - scan_display
 - scan_dmi
 - scan_fat
 - scan_fb
 - scan_graphics
 - scan_ide
 - scan_ideraid
 - scan_input
 - scan_isapnp
 - scan_lvm
 - scan_memory
 - scan_mmc
 - scan_mounts
 - scan_network
 - scan_nvme
 - scan_parisc
 - scan_partitions
 - scan_pci、scan_pci_legacy
 - scan_pcmcialegacy
 - scan_pcmcia
 - scan_pnp
 - scan_s390_devices
 - scan_scsi
 - scan_smp
 - scan_sound
 - scan_spd
 - scan_sysfs
 - scan_usb
 - scan_vio
 - scan_virtio
 - scan_volume
 
- 总结
 - 参考
 
简介
lshw: HardWare LiSter for Linux 一般用来查看linux设备的硬件信息,包括内存、cpu、主板等信息。
$ lshw --help
Hardware Lister (lshw) - 
usage: lshw [-format] [-options ...]lshw -version-version        print program version ()format can be-html           output hardware tree as HTML-xml            output hardware tree as XML-json           output hardware tree as a JSON object-short          output hardware paths-businfo        output bus informationoptions can be-class CLASS    only show a certain class of hardware-C CLASS        same as '-class CLASS'-c CLASS        same as '-class CLASS'-disable TEST   disable a test (like pci, isapnp, cpuid, etc. )-enable TEST    enable a test (like pci, isapnp, cpuid, etc. )-quiet          don't display status-sanitize       sanitize output (remove sensitive information like serial numbers, etc.)-numeric        output numeric IDs (for PCI, USB, etc.)-notime         exclude volatile attributes (timestamps) from output
 
代码:https://ezix.org/src/pkg/lshw.git
核心结构
class hwNode
{public:hwNode(const string & id,hw::hwClass c = hw::generic,const string & vendor = "",const string & product = "",const string & version = "");hwNode(const hwNode & o);~hwNode();hwNode & operator =(const hwNode & o);string getId() const;void setHandle(const string & handle);string getHandle() const;bool enabled() const;bool disabled() const;void enable();void disable();bool claimed() const;void claim(bool claimchildren=false);void unclaim();hw::hwClass getClass() const;const char * getClassName() const;void setClass(hw::hwClass c);string getDescription() const;void setDescription(const string & description);string getVendor() const;void setVendor(const string & vendor);string getSubVendor() const;void setSubVendor(const string & subvendor);string getProduct() const;void setProduct(const string & product);string getSubProduct() const;void setSubProduct(const string & subproduct);string getVersion() const;void setVersion(const string & version);string getDate() const;void setDate(const string &);string getSerial() const;void setSerial(const string & serial);unsigned long long getStart() const;void setStart(unsigned long long start);unsigned long long getSize() const;void setSize(unsigned long long size);unsigned long long getCapacity() const;void setCapacity(unsigned long long capacity);unsigned long long getClock() const;void setClock(unsigned long long clock);unsigned int getWidth() const;void setWidth(unsigned int width);string getSlot() const;void setSlot(const string & slot);string getModalias() const;void setModalias(const string & modalias);unsigned int countChildren(hw::hwClass c = hw::generic) const;hwNode * getChild(unsigned int);hwNode * getChildByPhysId(long);hwNode * getChildByPhysId(const string &);hwNode * getChild(const string & id);hwNode * findChildByHandle(const string & handle);hwNode * findChildByLogicalName(const string & handle);hwNode * findChildByBusInfo(const string & businfo);hwNode * findChildByResource(const hw::resource &);hwNode * findChild(bool(*matchfunction)(const hwNode &));hwNode * addChild(const hwNode & node);bool isBus() const{return countChildren()>0;}bool isCapable(const string & feature) const;void addCapability(const string & feature, const string & description = "");void describeCapability(const string & feature, const string & description);string getCapabilities() const;vector<string> getCapabilitiesList() const;string getCapabilityDescription(const string & feature) const;void attractHandle(const string & handle);void setConfig(const string & key, const string & value);void setConfig(const string & key, unsigned long long value);string getConfig(const string & key) const;vector<string> getConfigKeys() const;vector<string> getConfigValues(const string & separator = "") const;vector<string> getLogicalNames() const;string getLogicalName() const;void setLogicalName(const string &);string getDev() const;void setDev(const string &);string getBusInfo() const;void setBusInfo(const string &);string getPhysId() const;void setPhysId(long);void setPhysId(unsigned, unsigned);void setPhysId(unsigned, unsigned, unsigned);void setPhysId(const string &);void assignPhysIds();void addResource(const hw::resource &);bool usesResource(const hw::resource &) const;vector<string> getResources(const string & separator = "") const;void addHint(const string &, const hw::value &);hw::value getHint(const string &) const;vector<string> getHints() const;void merge(const hwNode & node);void fixInconsistencies();string asXML(unsigned level = 0);string asJSON(unsigned level = 0);string asString();bool dump(const string & filename, bool recurse = true);private:void setId(const string & id);bool attractsHandle(const string & handle) const;bool attractsNode(const hwNode & node) const;struct hwNode_i * This;
};
 
扫描设备原理
大部分都是通过读取/proc、/sys、/dev虚拟文件系统下面的文件内容获取系统运行状态和设备信息。
 下面就依次分析lshw源码中core文件夹下面提供的函数:
scan_abi
/proc/sys/abi,含义参考https://www.kernel.org/doc/Documentation/admin-guide/sysctl/abi.rst
scan_burner
ioctl执行scsi命令
scan_cdrom
核心代码:
ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
ioctl(fd, CDROM_GET_CAPABILITY);
ioctl(fd, CDROM_DRIVE_STATUS, 0)
 
scan_cpufreq
/sys/devices/system/cpu/cpu%d/cpufreq/,下面有cpu频率信息
ls /sys/devices/system/cpu/cpu0/cpufreq/
affected_cpus     cpuinfo_min_freq                          energy_performance_preference  scaling_cur_freq  scaling_max_freq
base_frequency    cpuinfo_transition_latency                related_cpus                   scaling_driver    scaling_min_freq
cpuinfo_max_freq  energy_performance_available_preferences  scaling_available_governors    scaling_governor  scaling_setspeed
 
scan_cpuid
scan_cpuinfo
/proc/cpuinfo,从该文件获取cpu信息。
scan_device_tree
/proc/device-tree,从该路径下获取信息
scan_disk
核心代码:
long size = 0;
unsigned long long bytes = 0;
int sectsize = 0;
int physsectsize = 0;
int fd = open(disk_path, O_RDONLY | O_NONBLOCK);
ioctl(fd, BLKPBSZGET, &physsectsize)
ioctl(fd, BLKSSZGET, §size)
ioctl(fd, BLKGETSIZE64, &bytes)
(ioctl(fd, BLKGETSIZE, &size)
 
scan_display
scan_dmi
/sys/firmware/dmi/tables,扫描该路径下面信息。
$ ls /sys/firmware/dmi/tables
DMI  smbios_entry_point
 
还会尝试结合/dev/mem、/sys/firmware/efi/systab和/proc/efi/systab的内容分析。
scan_fat
读取裸设备块数据,随后解析FAT文件系统格式。
scan_fb
从/proc/devices中获取fb设备号,随后获取到framebuffer设备文件描述符fb,核心代码:
#define FBIOGET_VSCREENINFO     0x4600
#define FBIOGET_FSCREENINFO     0x4602
ioctl(fd[i], FBIOGET_FSCREENINFO, &fbi);
ioctl(fd[i], FBIOGET_VSCREENINFO, &fbconfig);
 
scan_graphics
/sys/class/graphics,扫描该路径下面的设备信息。
ls /sys/class/graphics/fb0/
bits_per_pixel  bl_curve  cursor  device  modes  pan    rotate  stride     uevent
blank           console   dev     mode    name   power  state   subsystem  virtual_size
 
scan_ide
/proc/ide,扫描该路径下设备的信息。
scan_ideraid
扫描ideraid设备,核心还是通过ioctl来直接获取设备信息。
scan_input
/sys/class/input,扫描该路径下面设备信息。
$ ls /sys/class/input/
event0  event2  event4  input0  input3  input5  js0   mouse0  mouse2
event1  event3  event5  input1  input4  input6  mice  mouse1
 
scan_isapnp
scan_lvm
通过读取裸设备文件,通过解析LVM2 structures获取lvm信息。
scan_memory
核心代码
pagesize = sysconf(_SC_PAGESIZE);
physpages = sysconf(_SC_PHYS_PAGES);
stat("/proc/kcore", &buf)
 
读取/sys/bus/memory、/sys/devices/system/memory/
$ ls /sys/bus/memory/
devices  drivers  drivers_autoprobe  drivers_probe  uevent
$ ls /sys/devices/system/memory/
auto_online_blocks  memory1   memory13  memory3   memory35  memory39  memory42  memory46  memory7  probe
block_size_bytes    memory10  memory14  memory32  memory36  memory4   memory43  memory47  memory8  soft_offline_page
hard_offline_page   memory11  memory15  memory33  memory37  memory40  memory44  memory5   memory9  uevent
memory0             memory12  memory2   memory34  memory38  memory41  memory45  memory6   power
 
scan_mmc
/sys/class/mmc_host/
scan_mounts
/proc/mounts读取挂载信息。
scan_network
通过扫描/proc/net/dev、/sys/class/net获取网络设备,之后通过ioctl获取设备信息。
scan_nvme
扫描/sys/class/nvme获取nvme设备,之后再扫描磁盘。
scan_parisc
/sys/devices/parisc
scan_partitions
扫描磁盘分区
scan_pci、scan_pci_legacy
扫描/proc/bus/pci、/sys/bus/pci获取pci设备,随后读取设备裸数据来获取信息。
scan_pcmcialegacy
scan_pcmcia
scan_pnp
/sys/bus/pnp
scan_s390_devices
scan_scsi
扫描scsi设备,/proc/scsi、/sys/class/scsi_*。
scan_smp
/sys/devices/system/cpu/online
scan_sound
/sys/class/sound
scan_spd
/proc/sys/dev/sensors、
scan_sysfs
scan_usb
/proc/bus/usb/devices、/sys/kernel/debug/usb/devices
scan_vio
/sys/bus/vio
scan_virtio
/sys/bus/virtio
scan_volume
总结
lshw源码用到一下几点
- linux内核文件系统
 - 系统接口如
ioctl、stat等 - 操作系统概念,比如文件系统结构、网络、总线
 - 工程上抽象出统一的设备结构
以上只是对lshw的初步分析,进一步的理解还是需要直接阅读代码。 
参考
Hardware Lister (lshw)
 linux内核文件系统:proc、tmpfs、devfs、sysfs简要介绍
 linux下 /proc 和 /sys 详解
 Linux kernel简介
 proc/sys目录介绍
 Documentation for /proc/sys/abi/
 The Linux Kernel documentation
相关文章:
lshw学习——简单介绍
文章目录 简介核心结构扫描设备原理scan_abiscan_burnerscan_cdromscan_cpufreqscan_cpuidscan_cpuinfoscan_device_treescan_diskscan_displayscan_dmiscan_fatscan_fbscan_graphicsscan_idescan_ideraidscan_inputscan_isapnpscan_lvmscan_memoryscan_mmcscan_mountsscan_net…...
深入理解Kafka:核心设计与实践原理读书笔记
目录 初识Kafka基本概念安装与配置ZooKeeper安装与配置Kafka的安装与配置 生产与消费服务端参数配置 生产者客户端开发消息对象 ProducerRecord必要的参数配置发送消息序列化分区器生产者拦截器 原理分析整体架构元数据的更新 重要的生产者参数acksmax.request.sizeretries和re…...
OnOn-WebSsh (昂~昂~轻量级WebSSH) 可实现 网页 中的 ssh 客户端操作,支持多用户多线程操作 ssh 持久化
OnOn-WebSsh springBoot 服务器 开源技术栏 OnOn-WebSsh (昂昂轻量级WebSSH) 可实现 网页 中的 ssh 客户端操作,支持多用户多线程操作 支持指定ssh 连接, 支持sftp 以及 ssh 持久化. OnOn-WebSSH (OnOn Lightweight WebSSH) enables SSH client operations withi…...
LDP+LBP代码解析及应用场景分析
代码整体结构与功能概述 这段 C 代码主要实现了两个图像特征提取算法,分别是局部方向模式(Local Directional Pattern,LDP)和多分块局部二值模式(Multi-Block Local Binary Pattern,Multi-Block LBP&#…...
51c视觉~合集33
我自己的原文哦~ https://blog.51cto.com/whaosoft/12163849 #Robin3D 3D场景的大语言模型:在鲁棒数据训练下的3DLLM新SOTA! 论文地址:https://arxiv.org/abs/2410.00255代码将开源:https://github.com/WeitaiKang/Robin3D 介绍 多模态…...
element plus的table组件,点击table的数据是,会出现一个黑色边框
在使用 Element Plus 的 Table 组件时,如果你点击表格数据后出现了一个黑色边框,这通常是因为浏览器默认的焦点样式(outline)被触发了。如图: 你可以通过自定义 CSS 来隐藏这个黑色边框,代码如下࿱…...
springmvc的拦截器,全局异常处理和文件上传
拦截器: 拦截不符合规则的,放行符合规则的。 等价于过滤器。 拦截器只拦截controller层API接口。 如何定义拦截器。 定义一个类并实现拦截器接口 public class MyInterceptor implements HandlerInterceptor {public boolean preHandle(HttpServletRequest reque…...
【coredump】笔记
coredump 是什么?最标准的解释是什么? Core dump(也称为 core 文件或 core dump 文件)是计算机程序在运行时崩溃时生成的文件,它捕获了程序在崩溃时的内存状态。这些文件通常用于调试目的,以帮助开发人员分…...
【Linux】磁盘空间莫名消失,找不到具体原因的思路
磁盘空间莫名消失,找不到具体原因的思路 先说下常见的几种原因: 1、删除的文件未释放空间 2、日志或过期文件未及时清理 3、inode导致 4、隐藏文件夹或者目录 6、磁盘碎片 最后一种单独介绍。 环境:情况是根分区(/…...
智能体实战(需求分析助手)一、需求概述及迭代规划
需求分析助手开发迭代规划 功能概述 需求分析助手是一款基于大模型的智能系统,旨在帮助用户高效完成需求获取、需求分析、需求文档编写及需求验证的全流程工作。通过对用户输入的智能处理和分析,需求分析助手能够简化需求管理流程,并根据不同业务场景提供定制化支持。 核心…...
idea | maven项目标红解决方案 | 强制刷新所有依赖
场景:父pom多模块,新增时,依赖正常,但是application.yml看起来没被springboot识别,试过rebuild、重开idea清除缓存,重新maven面板reload all maven projects, 试过pom文件的依赖先移除再重新粘贴导入进来&a…...
*【每日一题 基础题】 [蓝桥杯 2023 省 B] 飞机降落
题目描述 N 架飞机准备降落到某个只有一条跑道的机场。其中第 i 架飞机在 Ti 时刻到达机场上空,到达时它的剩余油料还可以继续盘旋 Di 个单位时间,即它最早可以于 Ti 时刻开始降落,最晚可以于 Ti Di 时刻开始降落。降落过程需要 Li个单位时间…...
在Windows本地用网页查看编辑服务器上的 jupyter notebook
 Motivation: jupyter notebook 可以存中间变量,方便我调整代码,但是怎么用服务器的GPU并在网页上查看编辑呢? 参考 https://zhuanlan.zhihu.com/p/440080687 服务端(Ubuntu): 激活环境 source activate my_env安装notebook …...
OpenCV圆形标定板检测算法findGrid原理详解
OpenCV的findGrid函数检测圆形标定板的流程如下: class CirclesGridClusterFinder {CirclesGridClusterFinder(const CirclesGridClusterFinder&); public:CirclesGridClusterFinder...
自动图像标注可体验
✨✨ 欢迎大家来访Srlua的博文(づ ̄3 ̄)づ╭❤~✨✨ 🌟🌟 欢迎各位亲爱的读者,感谢你们抽出宝贵的时间来阅读我的文章。 我是Srlua小谢,在这里我会分享我的知识和经验。&am…...
武汉市电子信息与通信工程职称公示了
2024年武汉市电子信息与通信工程专业职称公示了,本次公示通过人员有109人。 基本这已经是今年武汉市工程相关职称最后公示了,等待出证即可。 为什么有人好奇,一样的资料,都是业绩、论文等,有的人可以过,有的…...
Ansible基本用法
Ansible 1 Ansible概念 Ansible是一个基于Python开发的配置管理和应用部署工具,现在也在自动化管理领域大放异彩。它融合了众多老牌运维工具的优点,Pubbet和Saltstack能实现的功能,Ansible基本上都可以实现。 Ansible能批量配置、部署、管理…...
MFC 应用程序语言切换
在开发多语言支持的 MFC 应用程序时,如何实现动态语言切换是一个常见的问题。在本文中,我们将介绍两种实现语言切换的方式,并讨论其优缺点。同时,我们还会介绍如何通过保存配置文件来记住用户的语言选择,以及如何在程序…...
Swift 的动态性
Swift 的动态性指的是 Swift 编程语言支持运行时操作的一些特性,使得代码的行为能够在运行时作出一定的调整或决策。这些特性通常可以让程序在运行时动态地添加、删除或修改对象的属性、方法等,而不是在编译时完全确定。 Swift 的动态性主要体现在以下几…...
用.Net Core框架创建一个Web API接口服务器
我们选择一个Web Api类型的项目创建一个解决方案为解决方案取一个名称我们这里选择的是。Net 8.0框架 注意,需要勾选的项。 我们找到appsetting.json配置文件 appsettings.json配置文件内容如下 {"Logging": {"LogLevel": {"Default&quo…...
未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?
编辑:陈萍萍的公主一点人工一点智能 未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战,在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...
Linux链表操作全解析
Linux C语言链表深度解析与实战技巧 一、链表基础概念与内核链表优势1.1 为什么使用链表?1.2 Linux 内核链表与用户态链表的区别 二、内核链表结构与宏解析常用宏/函数 三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势5.1 插入效率5.2 安全…...
论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(二)
HoST框架核心实现方法详解 - 论文深度解读(第二部分) 《Learning Humanoid Standing-up Control across Diverse Postures》 系列文章: 论文深度解读 + 算法与代码分析(二) 作者机构: 上海AI Lab, 上海交通大学, 香港大学, 浙江大学, 香港中文大学 论文主题: 人形机器人…...
【HarmonyOS 5.0】DevEco Testing:鸿蒙应用质量保障的终极武器
——全方位测试解决方案与代码实战 一、工具定位与核心能力 DevEco Testing是HarmonyOS官方推出的一体化测试平台,覆盖应用全生命周期测试需求,主要提供五大核心能力: 测试类型检测目标关键指标功能体验基…...
macOS多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用
文章目录 问题现象问题原因解决办法 问题现象 macOS启动台(Launchpad)多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用。 问题原因 很明显,都是Google家的办公全家桶。这些应用并不是通过独立安装的…...
Python实现prophet 理论及参数优化
文章目录 Prophet理论及模型参数介绍Python代码完整实现prophet 添加外部数据进行模型优化 之前初步学习prophet的时候,写过一篇简单实现,后期随着对该模型的深入研究,本次记录涉及到prophet 的公式以及参数调优,从公式可以更直观…...
GitHub 趋势日报 (2025年06月08日)
📊 由 TrendForge 系统生成 | 🌐 https://trendforge.devlive.org/ 🌐 本日报中的项目描述已自动翻译为中文 📈 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...
微信小程序云开发平台MySQL的连接方式
注:微信小程序云开发平台指的是腾讯云开发 先给结论:微信小程序云开发平台的MySQL,无法通过获取数据库连接信息的方式进行连接,连接只能通过云开发的SDK连接,具体要参考官方文档: 为什么? 因为…...
SAP学习笔记 - 开发26 - 前端Fiori开发 OData V2 和 V4 的差异 (Deepseek整理)
上一章用到了V2 的概念,其实 Fiori当中还有 V4,咱们这一章来总结一下 V2 和 V4。 SAP学习笔记 - 开发25 - 前端Fiori开发 Remote OData Service(使用远端Odata服务),代理中间件(ui5-middleware-simpleproxy)-CSDN博客…...
html css js网页制作成品——HTML+CSS榴莲商城网页设计(4页)附源码
目录 一、👨🎓网站题目 二、✍️网站描述 三、📚网站介绍 四、🌐网站效果 五、🪓 代码实现 🧱HTML 六、🥇 如何让学习不再盲目 七、🎁更多干货 一、👨…...
