Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=a7bad7258d081638aa8bd8e5c58e6fa2ce3f5149
commit a7bad7258d081638aa8bd8e5c58e6fa2ce3f5149 Author: James Buren <[email protected]> Date: Mon Aug 27 01:50:07 2012 -0500 fix probeAll() in device diff --git a/Device.cc b/Device.cc index da204bc..83c68a7 100644 --- a/Device.cc +++ b/Device.cc @@ -4,6 +4,7 @@ #include <fcntl.h> #include <unistd.h> #include <string.h> +#include <glob.h> #include <linux/major.h> #include "Utility.hh" #include "DosPartitionTable.hh" @@ -83,34 +84,33 @@ Device::~Device() delete _table; } -vector <Device> Device::probeAll() +vector <Device *> Device::probeAll() { - blkid_cache cache = 0; - blkid_dev_iterate iter = 0; - blkid_dev dev = 0; - Device device; - vector <Device> devices; + glob_t gl; + Device *device = 0; + vector <Device *> devices; - if(blkid_get_cache(&cache,"/dev/null") != 0) - goto bail; - - if(blkid_probe_all(cache) != 0) - goto bail; + memset(&gl,0,sizeof(glob_t)); - if((iter = blkid_dev_iterate_begin(cache)) == 0) - goto bail; + if(glob("/dev/[hsv]d[a-z]",0,0,&gl) != 0) + { + globfree(&gl); + return devices; + } - while(blkid_dev_next(iter,&dev) == 0) - if(device.read(blkid_dev_devname(dev))) + for( size_t i = 0 ; i < gl.gl_pathc ; ++i ) + { + const char *path = gl.gl_pathv[i]; + + device = new Device(); + + if(device->read(path)) devices.push_back(device); + else + delete device; + } -bail: - - if(iter != 0) - blkid_dev_iterate_end(iter); - - if(cache != 0) - blkid_put_cache(cache); + globfree(&gl); return devices; } diff --git a/Device.hh b/Device.hh index e12ce37..9282bdd 100644 --- a/Device.hh +++ b/Device.hh @@ -13,9 +13,10 @@ class Device public: Device(); ~Device(); - static vector <Device> probeAll(); + static vector <Device *> probeAll(); bool read(const string &path); bool write(); + string getPath() { return _path; } string getLabelType() { return (_table != 0) ? _table->getLabelType() : "unknown"; } size_t getTableSize() { return (_table != 0) ? _table->getTableSize() : 0; } Partition *getPartition(size_t n) { return (_table != 0) ? _table->getPartition(n) : 0; } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
