I need a way to get the name and size (in megabytes if possible) of all disks in C++ on Linux (Arch to be specific).
>Solution :
You can simply read files from /sys filesystem.
For example on my machine:
chus@kagi:~$ cat /sys/block/nvme0n1/size
2000409264
Just open the file, read the number in, multiply by 512 — and you have size in bytes. If disk is present in the system — it’s there under /sys/block.
PS: The name of disk is obviously /dev/nvme0n1.