tenox7 / lsblk

lsblk like utility for Windows
Apache License 2.0
29 stars 8 forks source link

PhysicalDrive0 Error: Unable to open \??\PhysicalDrive0, NTSTATUS=0xC0000022 #5

Open asd-a opened 1 year ago

asd-a commented 1 year ago

using it in Windows 11,it reports that

it seems that the winapi used in lsblk.c is out of date, cannot been compiled successfully by the latest winlibs-gcc(this one)

reports:

PS D:\workspace\projects\lsblk> gcc lsblk.c -o lsblk -lntdll -lshlwapi
lsblk.c: In function 'ListDisks':
lsblk.c:95:18: warning: implicit declaration of function 'NtOpenDirectoryObject' [-Wimplicit-function-declaration]
   95 |         status = NtOpenDirectoryObject(&hDir, DIRECTORY_QUERY | DIRECTORY_TRAVERSE, &attr);
      |                  ^~~~~~~~~~~~~~~~~~~~~
lsblk.c:107:26: warning: implicit declaration of function 'NtQueryDirectoryObject' [-Wimplicit-function-declaration]
  107 |                 status = NtQueryDirectoryObject(hDir, DirInfo, sizeof(OBJECT_DIRECTORY_INFORMATION) * nDirInfo, FALSE, first, &index, &bytes);
      |                          ^~~~~~~~~~~~~~~~~~~~~~
lsblk.c: In function 'QueryDisk':
lsblk.c:137:9: error: unknown type name 'GET_DISK_ATTRIBUTES'; did you mean 'SECURITY_ATTRIBUTES'?
  137 |         GET_DISK_ATTRIBUTES DiskAttributes;
      |         ^~~~~~~~~~~~~~~~~~~
      |         SECURITY_ATTRIBUTES
lsblk.c:183:72: error: 'IOCTL_DISK_GET_DISK_ATTRIBUTES' undeclared (first use in this function); did you mean 'IOCTL_VOLUME_GET_GPT_ATTRIBUTES'?
  183 |         status = NtDeviceIoControlFile(hDisk, NULL, NULL, NULL, &iosb, IOCTL_DISK_GET_DISK_ATTRIBUTES, NULL, 0, &DiskAttributes, sizeof(DiskAttributes));
      |                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                        IOCTL_VOLUME_GET_GPT_ATTRIBUTES
lsblk.c:183:72: note: each undeclared identifier is reported only once for each function it appears in
lsblk.c:185:49: error: request for member 'Attributes' in something not a structure or union
  185 |                 wprintf(L" %d ", (DiskAttributes.Attributes) ? 0 : 1);
      |                                                 ^
lsblk.c:223:9: warning: implicit declaration of function 'StrTrimW' [-Wimplicit-function-declaration]
  223 |         StrTrimW(buff, L" ");
      |         ^~~~~~~~
lsblk.c:296:29: warning: implicit declaration of function 'IsEqualPartitionType' [-Wimplicit-function-declaration]
  296 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_BASIC_DATA_GUID)) wprintf(L" [Basic Data]");
      |                             ^~~~~~~~~~~~~~~~~~~~
lsblk.c:297:99: error: 'PARTITION_BSP_GUID' undeclared (first use in this function); did you mean 'PARTITION_SYSTEM_GUID'?
  297 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_BSP_GUID)) wprintf(L" [BSP]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_SYSTEM_GUID
lsblk.c:298:99: error: 'PARTITION_CLUSTER_GUID' undeclared (first use in this function); did you mean 'PARTITION_SYSTEM_GUID'?
  298 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_CLUSTER_GUID)) wprintf(L" [Cluster]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_SYSTEM_GUID
lsblk.c:299:99: error: 'PARTITION_DPP_GUID' undeclared (first use in this function); did you mean 'PARTITION_SYSTEM_GUID'?
  299 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_DPP_GUID)) wprintf(L" [DPP]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_SYSTEM_GUID
lsblk.c:302:99: error: 'PARTITION_LEGACY_BL_GUID' undeclared (first use in this function); did you mean 'PARTITION_LDM_DATA_GUID'?
  302 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_LEGACY_BL_GUID)) wprintf(L" [Legacy Boot]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_LDM_DATA_GUID
lsblk.c:303:99: error: 'PARTITION_LEGACY_BL_GUID_BACKUP' undeclared (first use in this function)
  303 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_LEGACY_BL_GUID_BACKUP)) wprintf(L" [Legacy Boot Backup]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lsblk.c:304:99: error: 'PARTITION_MAIN_OS_GUID' undeclared (first use in this function); did you mean 'PARTITION_BASIC_DATA_GUID'?
  304 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_MAIN_OS_GUID)) wprintf(L" [OS Main]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_BASIC_DATA_GUID
lsblk.c:307:99: error: 'PARTITION_MSFT_SNAPSHOT_GUID' undeclared (first use in this function); did you mean 'PARTITION_MSFT_RECOVERY_GUID'?
  307 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_MSFT_SNAPSHOT_GUID)) wprintf(L" [Snapshot]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_MSFT_RECOVERY_GUID
lsblk.c:308:99: error: 'PARTITION_OS_DATA_GUID' undeclared (first use in this function); did you mean 'PARTITION_LDM_DATA_GUID'?
  308 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_OS_DATA_GUID)) wprintf(L" [OS Data]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_LDM_DATA_GUID
lsblk.c:309:99: error: 'PARTITION_PATCH_GUID' undeclared (first use in this function); did you mean 'PARTITION_SYSTEM_GUID'?
  309 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_PATCH_GUID)) wprintf(L" [Patch]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_SYSTEM_GUID
lsblk.c:310:99: error: 'PARTITION_PRE_INSTALLED_GUID' undeclared (first use in this function); did you mean 'PARTITION_LDM_DATA_GUID'?
  310 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_PRE_INSTALLED_GUID)) wprintf(L" [Preinstall]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_LDM_DATA_GUID
lsblk.c:311:99: error: 'PARTITION_SPACES_GUID' undeclared (first use in this function); did you mean 'PARTITION_SYSTEM_GUID'?
  311 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_SPACES_GUID)) wprintf(L" [Spaces]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_SYSTEM_GUID
lsblk.c:312:99: error: 'PARTITION_SPACES_DATA_GUID' undeclared (first use in this function); did you mean 'PARTITION_BASIC_DATA_GUID'?
  312 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_SPACES_DATA_GUID)) wprintf(L" [Spaces Data]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_BASIC_DATA_GUID
lsblk.c:314:99: error: 'PARTITION_WINDOWS_SYSTEM_GUID' undeclared (first use in this function); did you mean 'PARTITION_SYSTEM_GUID'?
  314 |                         if (IsEqualPartitionType(DiskLayout->PartitionEntry[n].Gpt.PartitionType, PARTITION_WINDOWS_SYSTEM_GUID)) wprintf(L" [Windows System]");
      |                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                   PARTITION_SYSTEM_GUID
tenox7 commented 1 year ago

ok so looks like there are two separate issues

would you mind opening two separate bugs?

thanks

asd-a commented 1 year ago

alright

tenox7 commented 1 year ago

thank you

is this PhysicalDrive0 Error: Unable to open \??\PhysicalDrive0, NTSTATUS=0xC0000022 the error you get when running on windows 11?

tenox7 commented 1 year ago

0xC0000022 is access denied, have you tried it with elevated privileges?

asd-a commented 1 year ago

thanks, it works.

asd-a commented 1 year ago

it might need a user-friendly error reports, thanks for helping me