From cbb11cd88d985db033c744b59291a2cf03fd16be Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周二, 13 10月 2020 21:53:31 +0800 Subject: [PATCH] #ifdef _DEBUG -> #ifndef NDEBUG for better cmake compatibility --- src/library/os/linux/os_linux.cpp | 38 +++++++++++--------------------------- 1 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp index 57fb028..0f53b9c 100644 --- a/src/library/os/linux/os_linux.cpp +++ b/src/library/os/linux/os_linux.cpp @@ -1,13 +1,15 @@ #include <paths.h> #include <sys/stat.h> #include <stdio.h> +#include <cerrno> +#include <cstring> #include "../os.h" #include "../../base/logger.h" #include <mntent.h> #include <dirent.h> #include <sys/utsname.h> -#ifdef _DEBUG +#ifndef NDEBUG #include <valgrind/memcheck.h> #endif @@ -52,7 +54,7 @@ free(hexuuid); } -#define MAX_UNITS 20 +#define MAX_UNITS 40 FUNCTION_RETURN getDiskInfos(DiskInfo *diskInfos, size_t *disk_info_size) { struct stat mount_stat, sym_stat; /*static char discard[1024]; @@ -89,9 +91,10 @@ } currentDrive = 0; - while (NULL != (ent = getmntent(aFile))) { + while (NULL != (ent = getmntent(aFile)) && currentDrive < maxDrives) { if ((strncmp(ent->mnt_type, "ext", 3) == 0 || strncmp(ent->mnt_type, "xfs", 3) == 0 || - strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0) && + strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0 + || strncmp(ent->mnt_type, "btr", 3) == 0) && ent->mnt_fsname != NULL && strncmp(ent->mnt_fsname, "/dev/", 5) == 0) { if (stat(ent->mnt_fsname, &mount_stat) == 0) { drive_found = -1; @@ -115,6 +118,8 @@ } else { tmpDrives[drive_found].preferred = 0; } + } else { + LOG_DEBUG("Error %s during stat of %s \n", std::strerror(errno), ent->mnt_fsname); } } } @@ -140,7 +145,7 @@ for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { parseUUID(dir->d_name, tmpDrives[i].disk_sn, sizeof(tmpDrives[i].disk_sn)); -#ifdef _DEBUG +#ifndef NDEBUG VALGRIND_CHECK_VALUE_IS_DEFINED(tmpDrives[i].device); LOG_DEBUG("uuid %d %s %02x%02x%02x%02x\n", i, tmpDrives[i].device, tmpDrives[i].disk_sn[0], @@ -161,7 +166,7 @@ for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { strncpy(tmpDrives[i].label, dir->d_name, 255 - 1); - printf("label %d %s %s\n", i, tmpDrives[i].label, tmpDrives[i].device); + LOG_DEBUG("label %d %s %s\n", i, tmpDrives[i].label, tmpDrives[i].device); } } } @@ -174,27 +179,6 @@ free(statDrives); return result; } - -static void _getCpuid(unsigned int *p, unsigned int ax) { - __asm __volatile( - "movl %%ebx, %%esi\n\t" - "cpuid\n\t" - "xchgl %%ebx, %%esi" - : "=a"(p[0]), "=S"(p[1]), "=c"(p[2]), "=d"(p[3]) - : "0"(ax)); -} - -FUNCTION_RETURN getCpuId(unsigned char identifier[6]) { - unsigned int i; - unsigned int cpuinfo[4] = {0, 0, 0, 0}; - _getCpuid(cpuinfo, 0); - for (i = 0; i < 3; i++) { - identifier[i * 2] = cpuinfo[i] & 0xFF; - identifier[i * 2 + 1] = (cpuinfo[i] & 0xFF00) >> 8; - } - return FUNC_RET_OK; -} - FUNCTION_RETURN getMachineName(unsigned char identifier[6]) { -- Gitblit v1.9.1