Skip to content

Instantly share code, notes, and snippets.

@sorbits
Created April 24, 2018 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorbits/eeb70cc2f9aa3d73d39b54955096930f to your computer and use it in GitHub Desktop.
Save sorbits/eeb70cc2f9aa3d73d39b54955096930f to your computer and use it in GitHub Desktop.
Get list of browsable volumes
#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