CN105138331A - 一种基于linux系统区分本地磁盘与usb移动磁盘的方法 - Google Patents

一种基于linux系统区分本地磁盘与usb移动磁盘的方法 Download PDF

Info

Publication number
CN105138331A
CN105138331A CN201510529432.6A CN201510529432A CN105138331A CN 105138331 A CN105138331 A CN 105138331A CN 201510529432 A CN201510529432 A CN 201510529432A CN 105138331 A CN105138331 A CN 105138331A
Authority
CN
China
Prior art keywords
disk
usb
local disk
linux
sys
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201510529432.6A
Other languages
English (en)
Inventor
焦芬芳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Electronic Information Industry Co Ltd
Original Assignee
Inspur Electronic Information Industry Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN201510529432.6A priority Critical patent/CN105138331A/zh
Publication of CN105138331A publication Critical patent/CN105138331A/zh
Pending legal-status Critical Current

Links

Abstract

本发明提供一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法,操作方法如下:先通过linux的sys虚拟文件系统找到block设备;再找出以sd开头命名的磁盘;然后根据磁盘在pci总线的挂接层次来区分是本地磁盘还是usb移动磁盘。本发明的一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法和现有技术相比,能够区分本地磁盘与usb移动磁盘,具有通用和高效率的特点,因而,具有很好的使用价值。

Description

一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法
技术领域
本发明涉及计算机领域,具体地说是一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法。
背景技术
一般在集群监控软件中都会监控本地磁盘的实时读写速率,在实际监控中发现,集群中的计算节点本地磁盘的名字可能不一样,有的计算节点本地磁盘名字是sda,有的计算节点本地磁盘名字是sdb,造成计算节点名字不同的原因与linux系统扫描磁盘的顺序有关系,例如,在USB接口上插有一个u盘,linux重启后,系统先扫描到USB上的移动磁盘命名为sda,依次扫描到本地磁盘命名为sdb。所以,监控本地磁盘实时读写速率前,需要先确定哪些sd*是本地磁盘。如果,监控软件不能区分本地磁盘还是usb移动磁盘,就需要人为的去改代码,哪些计算节点的本地磁盘是sda、哪些是sdb等,这样的软件不够通用。
发明内容
本发明的目的是克服现有技术中存在的不足,提供一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法。
本发明的技术方案是按以下方式实现的,其操作方法如下:
先通过linux的sys虚拟文件系统找到block设备;再找出以sd开头命名的磁盘;然后根据磁盘在pci总线的挂接层次来区分是本地磁盘还是usb移动磁盘。
上述方法的具体方式如下:
(1)、打开/sys/block/目录;
(2)、读取目录,如果为空,程序结束,否则判断是否以sd开头;
(3)、如果不是sd开头,跳到第2步;
(4)、打开该文件,获取该文件描述符;
(5)、通过/proc/self/fd/该文件描述符,获取该文件的实际路径;
(6)、解析实际路径中sd*的祖父目录是否为usb,例如:
usb的移动硬盘的实际路径:
/sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/1-1:1.0/host6/target6:0:0/6:0:0:0/block/sdb;
本地磁盘的实际路径:
/sys/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda
(7)、是usb,舍弃该sd*;不是usb,则该sd*为本地磁盘
(8)、跳到第(2)步。
本发明提出的通过linux的sys虚拟文件系统,区分本地磁盘与usb移动磁盘,关键是先通过/sys/block获取以sd开头的磁盘文件,然后获取该文件的软链接,即该sd*的实际路径,该sd*实际路径包含了sd*设备驱动层次,如果是usb移动硬盘,它的祖父目录包含usb驱动,否则不包含。
本发明的优点是:
本发明的一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法和现有技术相比,能够区分本地磁盘与usb移动磁盘,具有通用和高效率的特点,因而,具有很好的使用价值。
附图说明
图1为一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法的结构示意图。
实施方式
下面结合附图对本发明的一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法作以下详细说明。
如图1所示,本发明的一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法,操作方法如下:
先通过linux的sys虚拟文件系统找到block设备;再找出以sd开头命名的磁盘;然后根据磁盘在pci总线的挂接层次来区分是本地磁盘还是usb移动磁盘。
具体方式如下:
(1)、打开/sys/block/目录;
(2)、读取目录,如果为空,程序结束,否则判断是否以sd开头;
(3)、如果不是sd开头,跳到第2步;
(4)、打开该文件,获取该文件描述符;
(5)、通过/proc/self/fd/该文件描述符,获取该文件的实际路径;
(6)、解析实际路径中sd*的祖父目录是否为usb,例如:
usb的移动硬盘的实际路径:
/sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/1-1:1.0/host6/target6:0:0/6:0:0:0/block/sdb;
本地磁盘的实际路径:
/sys/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda
(7)、是usb,舍弃该sd*;不是usb,则该sd*为本地磁盘
(8)、跳到第(2)步。
本发明的一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法其加工制作非常简单方便,按照说明书附图所示即可加工。
除说明书所述的技术特征外,均为本专业技术人员的已知技术。

Claims (2)

1.一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法,其特征在于操作方法如下:
先通过linux的sys虚拟文件系统找到block设备;再找出以sd开头命名的磁盘;然后根据磁盘在pci总线的挂接层次来区分是本地磁盘还是usb移动磁盘。
2.根据权利要求1所述的一种基于LINUX系统区分本地磁盘与USB移动磁盘的方法,其特征在于具体方式如下:
(1)、打开/sys/block/目录;
(2)、读取目录,如果为空,程序结束,否则判断是否以sd开头;
(3)、如果不是sd开头,跳到第2步;
(4)、打开该文件,获取该文件描述符;
(5)、通过/proc/self/fd/该文件描述符,获取该文件的实际路径;
(6)、解析实际路径中sd*的祖父目录是否为usb,例如:
usb的移动硬盘的实际路径:
/sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/1-1:1.0/host6/target6:0:0/6:0:0:0/block/sdb;
本地磁盘的实际路径:
/sys/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda
(7)、是usb,舍弃该sd*;不是usb,则该sd*为本地磁盘
(8)、跳到第(2)步。
CN201510529432.6A 2015-08-26 2015-08-26 一种基于linux系统区分本地磁盘与usb移动磁盘的方法 Pending CN105138331A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510529432.6A CN105138331A (zh) 2015-08-26 2015-08-26 一种基于linux系统区分本地磁盘与usb移动磁盘的方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510529432.6A CN105138331A (zh) 2015-08-26 2015-08-26 一种基于linux系统区分本地磁盘与usb移动磁盘的方法

Publications (1)

Publication Number Publication Date
CN105138331A true CN105138331A (zh) 2015-12-09

Family

ID=54723689

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510529432.6A Pending CN105138331A (zh) 2015-08-26 2015-08-26 一种基于linux系统区分本地磁盘与usb移动磁盘的方法

Country Status (1)

Country Link
CN (1) CN105138331A (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107016104A (zh) * 2017-04-12 2017-08-04 广东浪潮大数据研究有限公司 一种在Linux系统中自动识别所有逻辑硬盘设备名称的方法及系统

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103942088A (zh) * 2014-04-01 2014-07-23 国云科技股份有限公司 一种获取虚拟机usb存储设备使用情况的方法
US20140321858A1 (en) * 2003-01-31 2014-10-30 Centurylink Intellectual Property Llc Optical Network Termination Systems and Methods
CN104536902A (zh) * 2015-01-28 2015-04-22 浪潮电子信息产业股份有限公司 一种测试服务器io子系统的性能调优方法

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140321858A1 (en) * 2003-01-31 2014-10-30 Centurylink Intellectual Property Llc Optical Network Termination Systems and Methods
CN103942088A (zh) * 2014-04-01 2014-07-23 国云科技股份有限公司 一种获取虚拟机usb存储设备使用情况的方法
CN104536902A (zh) * 2015-01-28 2015-04-22 浪潮电子信息产业股份有限公司 一种测试服务器io子系统的性能调优方法

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
CRUCIFIX: "《学步网https://www.xuebuyuan.com/2175797.html》", 2 October 2014 *
SHMTU2005: "《chinaunix:http://bbs.chinaunix.net/thread-1712952-1-1.html》", 31 May 2010 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107016104A (zh) * 2017-04-12 2017-08-04 广东浪潮大数据研究有限公司 一种在Linux系统中自动识别所有逻辑硬盘设备名称的方法及系统

Similar Documents

Publication Publication Date Title
US10923119B2 (en) Speech data processing method and apparatus, device and storage medium
TWI628542B (zh) 快閃記憶體的垃圾回收斷電回復方法以及使用該方法的裝置
US20150066878A1 (en) Efficient Context Save/Restore During Hardware Decompression of DEFLATE Encoded Data
JP2006202076A (ja) トレース情報収集システム、トレース情報収集方法、及びトレース情報収集プログラム
US9298592B2 (en) Testing a software interface for a streaming hardware device
US8930761B2 (en) Test case result processing
CN106326171A (zh) 硬盘背板的硬盘类型识别方法和装置
US9996349B2 (en) Clearing specified blocks of main storage
CN106598796A (zh) 一种测试reboot时硬件信息稳定性的方法
CN112115047B (zh) 一种硬实时操作系统延时测试方法及系统
CN104598355A (zh) 一种路由器usb性能自动化测试系统及其测试方法
KR20160016744A (ko) 플래시 메모리 장치에 데이터를 기록하는 방법, 플래시 메모리 장치, 및 저장 시스템
TWI439925B (zh) 內嵌式系統及其執行緒與緩衝區管理方法
CN108231132B (zh) 一种nand闪存验证装置和验证系统
CN112256551A (zh) 一种远程日志抓取方法、装置、电子设备和存储介质
CN103019977A (zh) 嵌入式系统应用设备实现版本自动识别的方法及启动方法
CN105161132A (zh) 一种基于FPGA的NVMe SSD只读保护方法
CN105138331A (zh) 一种基于linux系统区分本地磁盘与usb移动磁盘的方法
US9396145B1 (en) In-chip bus tracer
WO2015155846A1 (ja) データベースのハッシュ結合処理をストレージ装置が実行するシステム
KR101735590B1 (ko) 트랜잭션 추출 장치 및 방법
JP7063445B2 (ja) 障害情報処理プログラム、コンピュータ、障害通知方法、コンピュータシステム
CN103092710A (zh) 云计算操作系统中一种高可用虚拟机运行方法
CN105446658A (zh) 一种风扇震动对raid性能影响的分析方法
US20070101034A1 (en) Monitor method for computer system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20151209

RJ01 Rejection of invention patent application after publication