|
@@ -1,5 +1,11 @@
|
|
|
#include "comm.h"
|
|
|
#include <cstdarg>
|
|
|
+#ifndef _WIN32
|
|
|
+#include <sys/ioctl.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+#include <linux/hdreg.h>
|
|
|
+#include <sys/fcntl.h>
|
|
|
+#endif //NOT _WIN32
|
|
|
#define MAX_PATH_SIZE 256
|
|
|
void GetNewForm(const char* form, char* newForm) {
|
|
|
int indexNum = 0;
|
|
@@ -448,27 +454,44 @@ char* Str2Hex(const char* src, int srcLen)
|
|
|
ifs.close();
|
|
|
}
|
|
|
|
|
|
- bool get_disk_serial_by_system(std::vector<string>& serial_no,const string save_path)
|
|
|
- {
|
|
|
- if (save_path.size() + strlen("/.lshw_result.txt") > MAX_PATH_SIZE) return false;
|
|
|
- char lshw_result[MAX_PATH_SIZE] = { 0 };
|
|
|
- strcpy(lshw_result, save_path.c_str());
|
|
|
- strcat(lshw_result, "/.lshw_result.txt");
|
|
|
-
|
|
|
- char command[512] = { 0 };
|
|
|
- snprintf(command, sizeof(command), "lshw -class disk | grep serial > %s", lshw_result);
|
|
|
-
|
|
|
- if (0 == system(command))
|
|
|
- {
|
|
|
- get_disk_serial(lshw_result, "serial:", serial_no);
|
|
|
- }
|
|
|
- else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- unlink(lshw_result);
|
|
|
-
|
|
|
- return(true);
|
|
|
- }
|
|
|
+ bool isSpace(char x) { return x == ' '; }
|
|
|
+ bool get_disk_serial_by_system(std::vector<string>& serial_no, int& errCode, const string save_path)
|
|
|
+ {
|
|
|
+ //if (save_path.size() + strlen("/.lshw_result.txt") > MAX_PATH_SIZE) return false;
|
|
|
+ //char lshw_result[MAX_PATH_SIZE] = { 0 };
|
|
|
+ //strcpy(lshw_result, save_path.c_str());
|
|
|
+ //strcat(lshw_result, "/.lshw_result.txt");
|
|
|
+
|
|
|
+ //char command[512] = { 0 };
|
|
|
+ //snprintf(command, sizeof(command), "lshw -class disk | grep serial > %s", lshw_result);
|
|
|
+
|
|
|
+ //if (0 == system(command))
|
|
|
+ //{
|
|
|
+ // get_disk_serial(lshw_result, "serial:", serial_no);
|
|
|
+ //}
|
|
|
+ //else {
|
|
|
+ // return false;
|
|
|
+ //}
|
|
|
+ errCode = 0;
|
|
|
+ struct hd_driveid id;
|
|
|
+ int fd = open("/dev/hda", O_RDONLY | O_NONBLOCK);
|
|
|
+ if (fd < 0) {
|
|
|
+ fd = open("/dev/sda", O_RDONLY | O_NONBLOCK);
|
|
|
+ if (fd < 0) {
|
|
|
+ perror("read failed:");
|
|
|
+ errCode = errno;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) {
|
|
|
+ string xx((const char*)(id.serial_no));
|
|
|
+ xx.erase(remove_if(xx.begin(), xx.end(), isSpace), xx.end());
|
|
|
+ serial_no.push_back(xx);
|
|
|
+ }
|
|
|
+ //unlink(lshw_result);
|
|
|
+
|
|
|
+ return(true);
|
|
|
+ }
|
|
|
|
|
|
#include <unistd.h>
|
|
|
bool file_is_exist(string filePath) {
|