From 6bd24f7782d09706eaf987b86eaebdcb67f01722 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周三, 19 5月 2021 14:04:53 +0800 Subject: [PATCH] logging --- src/library/os/windows/os_win.cpp | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/library/os/windows/os_win.cpp b/src/library/os/windows/os_win.cpp index cfa6b0d..06166bd 100644 --- a/src/library/os/windows/os_win.cpp +++ b/src/library/os/windows/os_win.cpp @@ -5,6 +5,7 @@ #include <iphlpapi.h> #include <stdio.h> +#include "../../base/string_utils.h" #include "../../base/logger.h" #include "../os.h" using namespace std; @@ -23,41 +24,40 @@ // http://www.ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.c // http://stackoverflow.com/questions/3098696/same-code-returns-diffrent-result-on-windows7-32-bit-system -#define MAX_UNITS 30 +#define MAX_UNITS 40 // bug check return with diskinfos == null func_ret_ok FUNCTION_RETURN getDiskInfos(std::vector<DiskInfo>& diskInfos) { DWORD fileMaxLen; - size_t ndrives = 0; + size_t ndrives = 0, drives_scanned = 0; DWORD fileFlags; - char volName[MAX_PATH], fileSysName[MAX_PATH]; + char volName[MAX_PATH]; DWORD volSerial = 0; const DWORD dwSize = MAX_PATH; char szLogicalDrives[MAX_PATH] = {0}; - FUNCTION_RETURN return_value = FUNC_RET_NOT_AVAIL; + FUNCTION_RETURN return_value; const DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives); if (dwResult > 0) { return_value = FUNC_RET_OK; char* szSingleDrive = szLogicalDrives; - while (*szSingleDrive && ndrives < MAX_UNITS) { + while (*szSingleDrive && drives_scanned < MAX_UNITS) { // get the next drive UINT driveType = GetDriveType(szSingleDrive); if (driveType == DRIVE_FIXED) { + char fileSysName[MAX_PATH]; BOOL success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH, &volSerial, &fileMaxLen, &fileFlags, fileSysName, MAX_PATH); if (success) { - LOG_INFO("drive : %s", szSingleDrive); - LOG_INFO("Volume Name : %s", volName); - LOG_INFO("Volume Serial : 0x%x", volSerial); - LOG_DEBUG("Max file length : %d", fileMaxLen); - LOG_DEBUG("Filesystem : %s", fileSysName); - DiskInfo diskInfo; + LOG_DEBUG("drive: %s,volume Name: %s, Volume Serial: 0x%x,Filesystem: %s", szSingleDrive, volName, + volSerial, fileSysName); + DiskInfo diskInfo = {}; diskInfo.id = (int)ndrives; - strncpy(diskInfo.device, volName, min(std::size_t{MAX_PATH}, sizeof(volName)) - 1); - strncpy(diskInfo.label, fileSysName, - min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)) - 1); + diskInfo.label_initialized = true; + license::mstrlcpy(diskInfo.device, volName, min(std::size_t{MAX_PATH}, sizeof(volName))); + license::mstrlcpy(diskInfo.label, fileSysName, min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName))); memcpy(diskInfo.disk_sn, &volSerial, sizeof(DWORD)); + diskInfo.sn_initialized = true; diskInfo.preferred = (szSingleDrive[0] == 'C'); diskInfos.push_back(diskInfo); ndrives++; @@ -67,13 +67,15 @@ } else { LOG_DEBUG("This volume is not fixed : %s, type: %d", szSingleDrive); } + szSingleDrive += strlen(szSingleDrive) + 1; + drives_scanned++; } } if (diskInfos.size() > 0) { return_value = FUNC_RET_OK; } else { return_value = FUNC_RET_NOT_AVAIL; - LOG_INFO("No fixed drive were detected"); + LOG_DEBUG("No fixed drive were detected"); } return return_value; -- Gitblit v1.9.1