You can simply read list of all files like /dev/sd*
(in C, you would need to use opendir
/readdir
/closedir
) and filter it by sdX
(where X is one or two letters).
Also, you can get list of all partitions by reading single file /proc/partitions
, and then filter 4th field by sdX
:
$ cat /proc/partitions
major minor #blocks name
8 0 52428799 sda
8 1 265041 sda1
8 2 1 sda2
8 5 2096451 sda5
8 6 50066541 sda6
which would give you list of all physical disks together with their capacity (3rd field).