blob: cfe568f36e915e29ed4cc85458a41edcebd582fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}
|