summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-12-01 00:52:31 +0100
committerCarl Hetherington <cth@carlh.net>2019-12-01 00:52:31 +0100
commit986de5e8c56dfa2edd7025811660a01f319cb96e (patch)
treea42675252c8efbaf21b098396e12bdc439807564
parentce17803bf356f3e796dccde43b4cc3656609e7fc (diff)
Some drive discovery hacks.
-rw-r--r--hacks/drives.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/hacks/drives.cc b/hacks/drives.cc
new file mode 100644
index 000000000..cfe568f36
--- /dev/null
+++ b/hacks/drives.cc
@@ -0,0 +1,38 @@
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+#include <iostream>
+#include <string>
+
+using std::cout;
+using std::cerr;
+using std::string;
+
+int main ()
+{
+ if (!boost::filesystem::exists("/sys/block")) {
+ cerr << "Could not find /sys/block\n";
+ exit (EXIT_FAILURE);
+ }
+
+ for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator("/sys/block"); i != boost::filesystem::directory_iterator(); ++i) {
+ if (boost::starts_with(i->path().filename().string(), "loop")) {
+ continue;
+ }
+
+ string model;
+ boost::filesystem::path device = i->path() / "device" / "model";
+ FILE* f = fopen(device.string().c_str(), "r");
+ if (f) {
+ char buffer[128];
+ fgets (buffer, 128, f);
+ model = buffer;
+ boost::trim (model);
+ fclose (f);
+ }
+
+ cout << i->path() << " " << model << "\n";
+ }
+
+ return 0;
+}
+