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, &sectsize)
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源码用到一下几点

  1. linux内核文件系统
  2. 系统接口如ioctlstat
  3. 操作系统概念,比如文件系统结构、网络、总线
  4. 工程上抽象出统一的设备结构
    以上只是对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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/64681.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

k8s总结

1、k8s是部署、拓展、管理容器的容器编排引擎。可根据负载的变化动态增加或缩减节点保证系统的高可用。 2、ks8s核心组件&#xff1a;node是节点&#xff08;可以是物理机也可以是虚拟机&#xff09;、pod最小的调度单位&#xff0c;是容器的抽象&#xff0c;有svc管理容器网络…

白嫖内网穿透之神卓互联Linux安装教程(树莓派)

最近家里有一个树莓派&#xff0c;捣鼓来去不知道干嘛&#xff0c;于是打算作为内网穿透盒子用&#xff0c;于是百度了一下&#xff0c;发现神卓互联还不错&#xff0c;可以让外网请求通过各种复杂的路由和防火墙访问到内网的服务。 以下是在Linux树莓派系统上安装神卓互联客户…

【测试面试篇1】测试开发与开发|selenium实现自动化测试|设计测试用例|常见的测试方法|开发不认可提测试的bug该怎么办

目录 1.选择走测试为什么还要学这么多的开发知识&#xff1f; 2.为什么选择软件测试开发岗位而不是软件开发岗位&#xff1f; 3.个人的职业规划是什么&#xff1f; 4.测试中遇到的问题如何进行解决&#xff1f; 5.对自己的项目做过哪些测试工作&#xff1f; 6.描述selenium…

Ansible 批量管理华为 CE 交换机

注&#xff1a;本文为 “Ansible 管理华为 CE 交换机” 相关文章合辑。 使用 CloudEngine - Ansible 批量管理华为 CE 交换机 wsf535 IP 属地&#xff1a;贵州 2018.02.05 15:26:05 总体介绍 Ansible 是一个开源的自动化运维工具&#xff0c;AnsibleWorks 成立于 2012 年&a…

防火墙(RHCE)

1、什么是防火墙 防火墙&#xff1a;防火墙是位于内部网和外部网之间的屏障&#xff0c;它按照系统管理员预先定义好的规则来控制数据包 的进出。 防火墙又可以分为硬件防火墙与软件防火墙。硬件防火墙是由厂商设计好的主机硬件&#xff0c;这台硬件防火墙 的操作系统主要以提…

线性代数基础与应用:基底 (Basis) 与现金流及单期贷款模型(中英双语)

具体请参考&#xff1a;https://web.stanford.edu/~boyd/vmls/ 下面的例子来源于这本书。 线性代数基础与应用&#xff1a;基底 (Basis) 与现金流及单期贷款模型 在线性代数中&#xff0c;基底&#xff08;Basis&#xff09;是一个重要的概念&#xff0c;广泛应用于信号处理、…

【安当产品应用案例100集】032-重塑企业SaaS平台的PostgreSQL凭据管理体系

一、案例背景 在本次案例分享中&#xff0c;一家为旅行社提供SaaS服务的技术服务商&#xff0c;其依赖PostgreSQL作为其核心数据存储解决方案&#xff0c;并且在阿里云和内网环境中均部署了相关服务与数据库实例。随着业务的发展和技术团队规模的扩大&#xff0c;当前的数据库…

路径规划之启发式算法之二十:麻雀搜索算法(Sparrow Search Algorithm,SSA)

麻雀搜索算法(Sparrow Search Algorithm,SSA)是一种受麻雀觅食和反捕食行为启发的新型的群智能优化算法,它模拟了麻雀种群的觅食行为和反捕食行为的生物学群体特征。该算法由薛建凯在2020年首次提出,旨在解决全局优化问题,具有求解精度高、效率高等特点。 一、算法原理 S…

Vue 404页面增加宝贝回家公益广告

关于404公益 https://www.dnpw.org/cn/pa-notfound.html 404公益项目主要以寻找走失的孩子为题材&#xff08;官方demo: https://cdn.dnpw.org/404/v1/demo.html&#xff09; 只需在网页中插入如下代码&#xff0c;即可加入404公益&#xff0c;为寻找走失的孩子出一份力&…

threejs——无人机概念切割效果

主要技术采用着色器的切割渲染,和之前写的风车可视化的文章不同,这次的切割效果是在着色器的基础上实现的,并新增了很多可调节的变量,兄弟们,走曲儿~ 线上演示地址,点击体验 源码下载地址,点击下载 正文 从图中大概可以看出以下信息,一个由线组成的无人机模型,一个由…

python实现Word转PDF(comtypes、win32com、docx2pdf)

目录 使用 comtypes 或 win32com 使用docx2pdf 使用 comtypes 或 win32com 支持docx和doc格式的文档转PDF&#xff0c;comtypes与win32com底层调用一样&#xff0c;使用方法也一样。保存文件时相当于调用了office中的另存为。只需要修改SaveAs中的FileFormat参数值即可转为对…

双指针---和为s的两个数字

这里写自定义目录标题 题目链接问题分析代码解决执行用时 题目链接 购物车内的商品价格按照升序记录于数组 price。请在购物车中找到两个商品的价格总和刚好是 target。若存在多种情况&#xff0c;返回任一结果即可。 问题分析 暴⼒解法&#xff0c;会超时 &#xff08;两层…

整合 Knife4j 于 Spring Cloud 网关:实现跨服务的 API 文档统一展示

&#x1f3af;导读&#xff1a;本文档概述了构建和配置基于JDK 17、Spring Boot 3.0.7及Spring Cloud 2022.0.3的微服务系统&#xff0c;特别聚焦于集成Knife4j以增强API文档管理和接口测试功能。文中详细介绍了如何在Spring Boot应用中添加Knife4j依赖、配置Swagger UI路径和A…

如何从0构建一个flask项目,直接上实操!!!

项目结构 首先&#xff0c;创建一个项目目录&#xff0c;结构如下&#xff1a; flask_app/ │ ├── app.py # Flask 应用代码 ├── static/ # 存放静态文件&#xff08;如CSS、JS、图片等&#xff09; │ └── style.css # 示例…

WildCard虚拟卡绑定openAI付款方式

绑定流程 官网&#xff1a;WildCard | 一分钟注册&#xff0c;轻松订阅海外软件服务 1、使用手机号验证码注册、可以使用zfb快捷认证 2、填写身份信息后&#xff0c;然后根据流程验证即可。 3、选择卡片使用期限&#xff0c;填入邀请码【FQBZFT91】可立减$2。 4、打开openAI开…

Ubuntu下C语言操作kafka示例

目录 安装kafka&#xff1a; 安装librdkafka consumer Producer 测试运行 安装kafka&#xff1a; Ubuntu下Kafka安装及使用_ubuntu安装kafka-CSDN博客 安装librdkafka github地址&#xff1a;GitHub - confluentinc/librdkafka: The Apache Kafka C/C library $ apt in…

小红书关键词搜索采集 | AI改写 | 无水印下载 | 多维表格 | 采集同步飞书

小红书关键词搜索采集 | AI改写 | 无水印下载 | 多维表格 | 采集同步飞书 一、下载影刀&#xff1a; https://www.winrobot360.com/share/activity?inviteUserUuid595634970300317698 二、加入应用市场 https://www.yingdao.com/share/accede/?inviteKeyb2d3f22a-fd6c-4a…

WatchAlert - 开源多数据源告警引擎

概述 在现代 IT 环境中&#xff0c;监控和告警是确保系统稳定性和可靠性的关键环节。然而&#xff0c;随着业务规模的扩大和数据源的多样化&#xff0c;传统的单一数据源告警系统已经无法满足复杂的需求。为了解决这一问题&#xff0c;我开发了一个开源的多数据源告警引擎——…

单片机:实现HC-SR04超声波测距(附带源码)

使用单片机实现 HC-SR04 超声波测距模块 的功能&#xff0c;通常用于测量物体与超声波传感器之间的距离。HC-SR04 模块通过发射超声波信号并测量其返回时间来计算距离。单片机&#xff08;如 STM32、51 系列、Arduino 等&#xff09;可用来控制该模块的工作&#xff0c;并处理返…

Python langchain ReAct 使用范例

0. 介绍 ReAct: Reasoning Acting &#xff0c;ReAct Prompt 由 few-shot task-solving trajectories 组成&#xff0c;包括人工编写的文本推理过程和动作&#xff0c;以及对动作的环境观察。 1. 范例 langchain version 0.3.7 $ pip show langchain Name: langchain Ver…