From: Carl Hetherington Date: Sat, 30 Nov 2019 23:52:31 +0000 (+0100) Subject: Some drive discovery hacks. X-Git-Tag: v2.15.37~10 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=986de5e8c56dfa2edd7025811660a01f319cb96e Some drive discovery hacks. --- 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 +#include +#include +#include + +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; +} +