summaryrefslogtreecommitdiff
path: root/diskio-unix.cc
diff options
context:
space:
mode:
authorRod Smith <rodsmith@rodsbooks.com>2017-07-26 19:45:51 -0400
committerRod Smith <rodsmith@rodsbooks.com>2017-07-26 19:45:51 -0400
commit7dfc89673419e9c45ec63b517f2b060189592f5f (patch)
treed96065ae16a88667ead506d5001162bf7cf2c7d1 /diskio-unix.cc
parentfc0e014beaa6935576e93cf440f8b3d960b2d3f7 (diff)
downloadsgdisk-7dfc89673419e9c45ec63b517f2b060189592f5f.tar.gz
Added support for showing the disk's model name under Linux.
Diffstat (limited to 'diskio-unix.cc')
-rw-r--r--diskio-unix.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/diskio-unix.cc b/diskio-unix.cc
index a7c4724..d9f8b8d 100644
--- a/diskio-unix.cc
+++ b/diskio-unix.cc
@@ -30,6 +30,8 @@
#endif
#include <iostream>
+#include <fstream>
+#include <sstream>
#include "diskio.h"
@@ -66,6 +68,7 @@ int DiskIO::OpenForRead(void) {
cerr << "The specified file does not exist!\n";
realFilename = "";
userFilename = "";
+ modelName = "";
isOpen = 0;
openForWrite = 0;
} else {
@@ -86,6 +89,16 @@ int DiskIO::OpenForRead(void) {
else
isOpen = 1;
} // if (fstat64()...)
+#if defined(__linux__) && !defined(EFI)
+ if (isOpen && realFilename.substr(0,4) == "/dev") {
+ ostringstream modelNameFilename;
+ modelNameFilename << "/sys/block" << realFilename.substr(4,512) << "/device/model";
+ ifstream modelNameFile(modelNameFilename.str().c_str());
+ if (modelNameFile.is_open()) {
+ getline(modelNameFile, modelName);
+ } // if
+ } // if
+#endif
} // if/else
} // if