c++ - Detecting mounted drives on Linux and Mac OS X -


i’m using qdir::drives() list of drives. works great on windows, on linux , mac returns single item “/”, i. e. root. expected behavior, how can list of drives on mac , linux?

non-qt, native api solutions welcome.

clarification on "drive" definition: i'd list of mount points visble "drives" in finder or linux built-in file manager.

as far filesystem concerned, there no concept of drives in unix/linux (i can't vouch macosx i'd it's same). closest thing mount points, normal application shouldn't bother them since available under filesystem root / (hence behaviour of qdir::drives() observe).

if want see mount points in use, parse output of mount command (without arguments) or, @ least on linux, contents of /etc/mtab file. beware though, mount points can pretty hairy real quick (loop devices, fuse filesystems, network shares, ...) so, again, wouldn't recommend making use of them unless application designed administer them.

keep in mind on unix-y oses, mount points matter system administrators, not end-users, unless we're speaking of removable media or transient network shares.


edit: following clarifications in comments, on linux should use getmntent or getmntent_r parse contents of /etc/mtab file , list of mount points , corresponding devices.

the trick after determine ones want display (removable? network share?). know /sys/block/... can that, don't know details you'll have dig bit more.

for example, check whether /dev/sdd1 (a usb key) mounted on /media/usb0/ removable device, (note how use device name sdd, not partition name sdd1):

$ cat /sys/block/sdd/removable 1 

as opposed main hard drive:

$ cat /sys/block/sda/removable 0 

hope puts on right track.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -