Created
April 24, 2018 02:15
-
-
Save sorbits/eeb70cc2f9aa3d73d39b54955096930f to your computer and use it in GitHub Desktop.
Get list of browsable volumes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/param.h> | |
#include <sys/mount.h> | |
#include <sys/ucred.h> | |
#include <string.h> | |
#include <vector> | |
#include <string> | |
std::vector<std::string> volumes () | |
{ | |
std::vector<std::string> res; | |
struct statfs* mnts; | |
int mnt_count = getmntinfo(&mnts, MNT_WAIT); // getfsstat | |
for(int i = 0; i < mnt_count; ++i) | |
{ | |
if(mnts[i].f_flags & MNT_DONTBROWSE) | |
continue; | |
res.push_back(mnts[i].f_mntonname); | |
} | |
return res; | |
} | |
int main (int argc, char const* argv[]) | |
{ | |
for(auto const& volume : volumes()) | |
fprintf(stderr, "%s\n", volume.c_str()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment