Answer the question
In order to leave comments, you need to log in
How to get a list of physical hard drives in the system and their mount locations?
I am writing a program for testing hardware, and to test hard drives, you need to get a list of hard drives and their correspondence to mount points (if any) and, of course, to a device file like
/dev/sd*
For these purposes, I used the convenient lsblk program , which, when requested, gives all they ask is:
lsblk -io KNAME,TYPE,SIZE,MODEL,MOUNTPOINT
KNAME TYPE SIZE MODEL MOUNTPOINT
sda disk 465.8G WDC WD5000AZRX-0
sda1 part 457.9G /
sda2 part 1K
sda5 part 7.9G [SWAP]
sr0 rom 1024M iHAS124 W
FILE * fp = popen("lsblk -io KNAME,TYPE,SIZE,MODEL,MOUNTPOINT", "r");
...// проверка на ошибки
while(fgets(buf, sizeof(buf) -1,fp)) {
if (strstr(buf, "disk")) {
//пошли тут тестировать
}
Answer the question
In order to leave comments, you need to log in
Running strace lsbkl tells it to read /sys/block and interpret it somehow.
Can you try the same, directly?
Well, or look at the source code, in the end.
blockdev --report
Show block devices
And mount shows what is mounted and where.
lsblk has been shipped with util-linux since version 2.19. finding a deb package should not be difficult.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question