People, I need get the list of hard disk connected in C language on Linux system:
Example, running a program on a computer with 2 IDE disks and 1 SATA disk connected.
./a.out Out required:
/dev/hda /dev/hdb /dev/sda help?
People, I need get the list of hard disk connected in C language on Linux system:
Example, running a program on a computer with 2 IDE disks and 1 SATA disk connected.
./a.out Out required:
/dev/hda /dev/hdb /dev/sda help?
Use libsysfs, the recommended way to query the kernel about attached devices of all kinds.
FILE *fp = popen("fdisk -l | grep \"Disk /\" | awk '{print $2};' | sed 's/://'", "r"); while(fgets(path, sizeof(path) -1,fp) != NULL) //your code pclose(fp); sudo before fdisk if user is present in sudoers list.The simplest way would be simply read and parse /proc/partitions.
Maybe you can reference fdisk's source code. Follow this website: ftp://ftp.gnu.org/gnu/fdisk