From 8641d850f9c03bf633d7e8198b267890ce3fac4a Mon Sep 17 00:00:00 2001 From: A1ive <10670106+a1ive@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:52:32 +0800 Subject: [PATCH] specify disk path (#34) --- libnw/disk.c | 7 +++++-- libnw/libnw.c | 1 + libnw/libnw.h | 1 + libnw/version.h | 4 ++-- nwinfo.c | 33 ++++++++++++++++++++++++--------- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/libnw/disk.c b/libnw/disk.c index 8baca09b..c09499cd 100644 --- a/libnw/disk.c +++ b/libnw/disk.c @@ -558,14 +558,17 @@ PrintDiskInfo(BOOL cdrom, PNODE node, CDI_SMART* smart) { PHY_DRIVE_INFO* PhyDriveList = NULL; DWORD PhyDriveCount = 0, i = 0; + CHAR DiskPath[64]; PhyDriveCount = GetDriveInfoList(cdrom, &PhyDriveList); if (PhyDriveCount == 0) goto out; for (i = 0; i < PhyDriveCount; i++) { + snprintf(DiskPath, sizeof(DiskPath), cdrom ? "\\\\.\\CdRom%u" : "\\\\.\\PhysicalDrive%u", i); + if (NWLC->DiskPath && _stricmp(NWLC->DiskPath, DiskPath) != 0) + continue; PNODE nd = NWL_NodeAppendNew(node, "Disk", NFLG_TABLE_ROW); - NWL_NodeAttrSetf(nd, "Path", 0, - cdrom ? "\\\\.\\CdRom%u" : "\\\\.\\PhysicalDrive%u", i); + NWL_NodeAttrSet(nd, "Path",DiskPath, 0); if (PhyDriveList[i].HwID) { WCHAR* hwName = NULL; diff --git a/libnw/libnw.c b/libnw/libnw.c index 41b4724e..8cdb0d97 100644 --- a/libnw/libnw.c +++ b/libnw/libnw.c @@ -26,6 +26,7 @@ VOID NW_Init(PNWLIB_CONTEXT pContext) NWLC->NwFile = stdout; NWLC->AcpiTable = 0; NWLC->SmbiosType = 127; + NWLC->DiskPath = NULL; NWL_NtGetVersion(&NWLC->NwOsInfo); GetNativeSystemInfo(&NWLC->NwSi); NWLC->NwRoot = NWL_NodeAlloc("NWinfo", 0); diff --git a/libnw/libnw.h b/libnw/libnw.h index 6c0a0ed6..a1f7f296 100644 --- a/libnw/libnw.h +++ b/libnw/libnw.h @@ -50,6 +50,7 @@ typedef struct _NWLIB_CONTEXT BOOL SkipVirtualNet; UINT8 SmbiosType; LPCSTR PciClass; + LPCSTR DiskPath; BOOL DisableSmart; VOID (*SpdProgress) (LPCSTR lpszText); diff --git a/libnw/version.h b/libnw/version.h index 9a852ba9..0a5fe63d 100644 --- a/libnw/version.h +++ b/libnw/version.h @@ -7,8 +7,8 @@ #define NWINFO_MAJOR_VERSION 0 #define NWINFO_MINOR_VERSION 9 -#define NWINFO_MICRO_VERSION 4 -#define NWINFO_BUILD_VERSION 1 +#define NWINFO_MICRO_VERSION 5 +#define NWINFO_BUILD_VERSION 0 #define NWINFO_VERSION NWINFO_MAJOR_VERSION,NWINFO_MINOR_VERSION,NWINFO_MICRO_VERSION,NWINFO_BUILD_VERSION #define NWINFO_VERSION_STR QUOTE(NWINFO_MAJOR_VERSION.NWINFO_MINOR_VERSION.NWINFO_MICRO_VERSION.NWINFO_BUILD_VERSION) diff --git a/nwinfo.c b/nwinfo.c index 946b9eb6..dc8f527c 100644 --- a/nwinfo.c +++ b/nwinfo.c @@ -12,23 +12,34 @@ static void nwinfo_help(void) NWINFO_COPYRIGHT "\n" "Usage: nwinfo OPTIONS\n" "OPTIONS:\n" - " --format=XXX Specify output format. [YAML|JSON|LUA]\n" + " --format=FMT Specify output format.\n" + " FMT can be 'YAML' (default), 'JSON' and 'LUA'.\n" " --output=FILE Write to FILE instead of printing to screen.\n" - " --cp=XXXX Set the code page of output text. [ANSI|UTF8]\n" + " --cp=CODEPAGE Set the code page of output text.\n" + " CODEPAGE can be 'ANSI' and 'UTF8'.\n" " --human Display numbers in human readable format.\n" " --debug Print debug info to stdout.\n" " --hide-sensitive Hide sensitive data (MAC & S/N).\n" " --sys Print system info.\n" " --cpu Print CPUID info.\n" - " --net[=active] Print [active] network info\n" - " --acpi[=XXXX] Print ACPI [table=XXXX] info.\n" - " --smbios[=XX] Print SMBIOS [type=XX] info.\n" - " --disk Print disk info.\n" + " --net[=FLAG] Print network info\n" + " FLAG can be 'ACTIVE' (print only the active network).\n" + " --acpi[=SGN] Print ACPI info.\n" + " SGN specifies the signature of the ACPI table,\n" + " e.g. 'FACP' (Fixed ACPI Description Table).\n" + " --smbios[=TYPE] Print SMBIOS info.\n" + " TYPE specifies the type of the SMBIOS table,\n" + " e.g. '2' (Base Board Information).\n" + " --disk[=PATH] Print disk info.\n" + " PATH specifies the path of the disk,\n" + " e.g. '\\\\.\\PhysicalDrive0', '\\\\.\\CdRom0'.\n" " --no-smart Don't print disk S.M.A.R.T. info.\n" " --display Print EDID info.\n" - " --pci[=XX] Print PCI [class=XX] info.\n" + " --pci[=CLASS] Print PCI info.\n" + " CLASS specifies the class code of pci devices,\n" + " e.g. '0C05' (SMBus).\n" " --usb Print USB info.\n" - " --spd Print SPD info\n" + " --spd Print SPD info.\n" " --battery Print battery info.\n" " --uefi Print UEFI info.\n" " --shares Print network mapped drives.\n" @@ -100,8 +111,12 @@ int main(int argc, char* argv[]) nwContext.SmbiosType = (UINT8)strtoul(&argv[i][9], NULL, 0); nwContext.DmiInfo = TRUE; } - else if (_stricmp(argv[i], "--disk") == 0) + else if (_strnicmp(argv[i], "--disk", 6) == 0) + { + if (argv[i][6] == '=' && argv[i][7]) + nwContext.DiskPath = &argv[i][7]; nwContext.DiskInfo = TRUE; + } else if (_stricmp(argv[i], "--no-smart") == 0) nwContext.DisableSmart = TRUE; else if (_stricmp(argv[i], "--display") == 0)