Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=0567169e2d019743c8bd6084dba4148beefdbeb9
commit 0567169e2d019743c8bd6084dba4148beefdbeb9 Author: James Buren <[email protected]> Date: Wed Aug 22 00:45:44 2012 -0500 add probeAll static function to Device class diff --git a/Device.cc b/Device.cc index 22773fa..4ab72a1 100644 --- a/Device.cc +++ b/Device.cc @@ -77,6 +77,38 @@ Device::~Device() { } +vector <Device> Device::probeAll() +{ + blkid_cache cache = 0; + blkid_dev_iterate iter = 0; + blkid_dev dev = 0; + Device device; + vector <Device> devices; + + if(blkid_get_cache(&cache,"/dev/null") != 0) + goto bail; + + if(blkid_probe_all(cache) != 0) + goto bail; + + if((iter = blkid_dev_iterate_begin(cache)) == 0) + goto bail; + + while(blkid_dev_next(iter,&dev) == 0) + if(device.read(blkid_dev_devname(dev))) + devices.push_back(device); + +bail: + + if(iter != 0) + blkid_dev_iterate_end(iter); + + if(cache != 0) + blkid_put_cache(cache); + + return devices; +} + bool Device::read(const string &path) { int fd = -1; diff --git a/Device.hh b/Device.hh index 36fa6ac..e81a1e6 100644 --- a/Device.hh +++ b/Device.hh @@ -1,8 +1,10 @@ #pragma once #include <string> +#include <vector> using std::string; +using std::vector; class Device { @@ -10,6 +12,7 @@ class Device public: Device(); ~Device(); + static vector <Device> probeAll(); bool read(const string &path); unsigned long long sizeToSectors(unsigned long long size) { return size / _lsectorsize; } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
