From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 8C3B43858D20; Thu, 7 Dec 2023 10:37:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C3B43858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1701945459; bh=iSpH7ftV+e0Yy8rhaRAIWgVR8MmESIpSXzEH+NmARMg=; h=To:Subject:Date:From:From; b=U80kEaeFJCRpqXP3+HnHq75jz9XBfqydekMM0xsHUuJ8U6psGEYozrfeY+vGXQ5lk iMoanighyzhXTarvNdUPy0sA2F/DJIgEkpzIz0J8Li+BB0FD1FLhhILfFB70/HYbKU vq4z8+BFg7KKXMyKKcMf/4Uk1nHg1990RRTOXejU= To: cygwin-apps-cvs@sourceware.org Subject: [csih - Cygwin service installation helper, a helper script and tools to create service installation scripts] branch master, updated. v0_9_11-7-gd81198e4445e X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 2fef9c6ba08551e49142f3406a68252803195f02 X-Git-Newrev: d81198e4445e514ac842f8649cd5b60ad27e0dba Message-Id: <20231207103739.8C3B43858D20@sourceware.org> Date: Thu, 7 Dec 2023 10:37:39 +0000 (GMT) From: Corinna Vinschen List-Id: https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/csih.git;h=d81198e4445e514ac842f8649cd5b60ad27e0dba commit d81198e4445e514ac842f8649cd5b60ad27e0dba Author: Corinna Vinschen Date: Thu Dec 7 11:37:20 2023 +0100 Bump version to 0.9.14 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/csih.git;h=f563ec33f28f2e9faad534d454d90b1e25ec66de commit f563ec33f28f2e9faad534d454d90b1e25ec66de Author: Corinna Vinschen Date: Thu Dec 7 11:37:00 2023 +0100 getVolInfo: revamp - drop always available Windows definitions - add definitions missing from winternl.h - make locale aware - drop wchar<->char conversions and print wchar strings directly - simplify flag printing - print hex values with leading 0x and leading zeros - add printing of flags from FILE_FS_SECTOR_SIZE_INFORMATION Diff: --- cygwin/getVolInfo.c | 249 +++++++++++++++++++++++++--------------------------- version.h | 2 +- 2 files changed, 122 insertions(+), 129 deletions(-) diff --git a/cygwin/getVolInfo.c b/cygwin/getVolInfo.c index 70e436fd1b25..e96f10f05fba 100644 --- a/cygwin/getVolInfo.c +++ b/cygwin/getVolInfo.c @@ -24,82 +24,89 @@ */ #include #include +#include +#include #include -#define _WIN32_WINNT 0x0600 +#define _WIN32_WINNT 0x0a00 #include #include #include -#include -#ifndef FILE_RETURNS_CLEANUP_RESULT_INFO -#define FILE_RETURNS_CLEANUP_RESULT_INFO 0x00000200 -#endif -#ifndef FILE_SUPPORTS_POSIX_UNLINK_RENAME -#define FILE_SUPPORTS_POSIX_UNLINK_RENAME 0x00000400 -#endif -#ifndef FILE_SUPPORTS_INTEGRITY_STREAMS -#define FILE_SUPPORTS_INTEGRITY_STREAMS 0x04000000 -#endif -#ifndef FILE_SUPPORTS_BLOCK_REFCOUNTING -#define FILE_SUPPORTS_BLOCK_REFCOUNTING 0x08000000 -#endif -#ifndef FILE_SUPPORTS_SPARSE_VDL -#define FILE_SUPPORTS_SPARSE_VDL 0x10000000 -#endif -#ifndef FILE_DAX_VOLUME -#define FILE_DAX_VOLUME 0x20000000 -#endif -#ifndef FILE_SUPPORTS_GHOSTING -#define FILE_SUPPORTS_GHOSTING 0x40000000 -#endif - -int __stdcall -sys_wcstombs (char *tgt, int tlen, const WCHAR *src, int slen) +/* winternl.h is seriously lacking */ +NTSTATUS NTAPI RtlDosPathNameToNtPathName_U_WithStatus (PCWSTR, + PUNICODE_STRING, + PCWSTR *, + VOID *); + +#define FILE_REMOVABLE_MEDIA 0x00000001 +#define FILE_REMOTE_DEVICE 0x00000010 + +#define FileFsSectorSizeInformation (FileFsVolumeFlagsInformation + 1) + +typedef struct _FILE_FS_SECTOR_SIZE_INFORMATION { - int ret; + ULONG LogicalBytesPerSector; + ULONG PhysicalBytesPerSectorForAtomicity; + ULONG PhysicalBytesPerSectorForPerformance; + ULONG FileSystemEffectivePhysicalBytesPerSectorForAtomicity; + ULONG Flags; + ULONG ByteOffsetForSectorAlignment; + ULONG ByteOffsetForPartitionAlignment; +} FILE_FS_SECTOR_SIZE_INFORMATION, *PFILE_FS_SECTOR_SIZE_INFORMATION; + +/* Sector Size Information Flags */ +#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001 +#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002 +#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004 +#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008 +#define SSINFO_FLAGS_BYTE_ADDRESSABLE 0x00000010 - ret = WideCharToMultiByte (GetOEMCP (), 0, src, slen, tgt, tlen, NULL, NULL); - if (ret) - tgt[ret < tlen ? ret : tlen - 1] = '\0'; - return ret; +void +_print_flag (ULONG flags, ULONG val, const char *name) +{ + printf (" %-34s: %s\n", name, (flags & val) ? "TRUE" : "FALSE"); } +#define print_flag(_flags,_val) _print_flag(_flags, _val, #_val) + int main (int argc, char **argv) { - char * winpath; - DWORD flags = 0; - HANDLE h; - UNICODE_STRING wpath; - UNICODE_STRING upath; OBJECT_ATTRIBUTES attr; + UNICODE_STRING upath; IO_STATUS_BLOCK io; NTSTATUS stat; + HANDLE h; + + BOOL remote = FALSE; + wchar_t *winpath; + char buf[4096]; + + setlocale (LC_ALL, ""); if (argc < 2) { fprintf (stderr, "usage: %s path\n", argv[0]); return 1; } - winpath = (char *) cygwin_create_path (CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE, argv[1]); + + winpath = (wchar_t *) cygwin_create_path (CCP_POSIX_TO_WIN_W | CCP_ABSOLUTE, + argv[1]); if (winpath == NULL) { fprintf (stderr, "create_cygwin_path (posix to win32 absolute) failed\n"); return 1; } - if (!RtlCreateUnicodeStringFromAsciiz (&wpath, winpath)) - { - fprintf (stderr, "RtlCreateUnicodeStringFromAsciiz failed\n"); - free (winpath); - return 1; - } - if (!RtlDosPathNameToNtPathName_U (wpath.Buffer, &upath, NULL, NULL)) + + stat = RtlDosPathNameToNtPathName_U_WithStatus (winpath, &upath, NULL, NULL); + if (!NT_SUCCESS (stat)) { - fprintf (stderr, "RtlDosPathNameToNtPathName_U failed\n"); - RtlFreeUnicodeString (&wpath); + fprintf (stderr, "RtlDosPathNameToNtPathName_U_WithStatus(%s) failed, " + "0x%08x\n", winpath, stat); free (winpath); return 1; } + InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL); stat = NtOpenFile (&h, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); @@ -109,123 +116,109 @@ main (int argc, char **argv) if (stat == STATUS_NO_MEDIA_IN_DEVICE) { upath.Length = 6 * sizeof (WCHAR); - stat = NtOpenFile (&h, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, 0); + stat = NtOpenFile (&h, READ_CONTROL, &attr, &io, + FILE_SHARE_VALID_FLAGS, 0); } if (!NT_SUCCESS (stat)) { - char buf[1024]; - wcstombs (buf, upath.Buffer, upath.Length / sizeof (WCHAR)); - buf[upath.Length / sizeof (WCHAR)] = '\0'; - fprintf (stderr, "NtOpenFile(%s) failed, %08x\n", buf, stat); + fprintf (stderr, "NtOpenFile(%.*ls) failed, 0x%08x\n", + upath.Length / sizeof (WCHAR), upath.Buffer, + stat); return 1; } - - char buf[1024]; - char name[256]; - - stat = NtQueryVolumeInformationFile (h, &io, buf, 1024, - FileFsDeviceInformation); + /* FileFsDeviceInformation */ + stat = NtQueryVolumeInformationFile (h, &io, buf, sizeof buf, + FileFsDeviceInformation); if (NT_SUCCESS (stat)) { PFILE_FS_DEVICE_INFORMATION pfi = (PFILE_FS_DEVICE_INFORMATION) buf; - printf ("Device Type : %x\n", pfi->DeviceType); - printf ("Characteristics : %x\n", pfi->Characteristics); + printf ("Device Type : 0x%02x\n", pfi->DeviceType); + printf ("Characteristics : 0x%08x\n", pfi->Characteristics); + print_flag (pfi->Characteristics, FILE_REMOVABLE_MEDIA); + print_flag (pfi->Characteristics, FILE_REMOTE_DEVICE); + + remote = !!(pfi->Characteristics & FILE_REMOTE_DEVICE); } else - fprintf (stderr, "FileFsDeviceInformation failed, %08x\n", stat); - stat = NtQueryVolumeInformationFile (h, &io, buf, 1024, - FileFsVolumeInformation); + fprintf (stderr, "FileFsDeviceInformation failed, 0x%08x\n", stat); + /* FileFsVolumeInformation */ + stat = NtQueryVolumeInformationFile (h, &io, buf, sizeof buf, + FileFsVolumeInformation); if (NT_SUCCESS (stat)) { PFILE_FS_VOLUME_INFORMATION pfi = (PFILE_FS_VOLUME_INFORMATION) buf; if (pfi->VolumeLabelLength) { - sys_wcstombs (name, 256, pfi->VolumeLabel, - pfi->VolumeLabelLength / sizeof (WCHAR)); - printf ("Volume Name : <%s>\n", name); + printf ("Volume Name : <%.*ls>\n", + pfi->VolumeLabelLength / sizeof (WCHAR), pfi->VolumeLabel); } else printf ("Volume Name : <>\n"); printf ("Serial Number : %u\n", pfi->VolumeSerialNumber); } else - fprintf (stderr, "FileFsVolumeInformation failed, %08x\n", stat); - stat = NtQueryVolumeInformationFile (h, &io, buf, 1024, + fprintf (stderr, "FileFsVolumeInformation failed, 0x%08x\n", stat); + /* FileFsAttributeInformation */ + stat = NtQueryVolumeInformationFile (h, &io, buf, sizeof buf, FileFsAttributeInformation); if (NT_SUCCESS (stat)) { PFILE_FS_ATTRIBUTE_INFORMATION pfi = (PFILE_FS_ATTRIBUTE_INFORMATION) buf; printf ("Max Filenamelength : %u\n",pfi->MaximumComponentNameLength); - sys_wcstombs (name, 256, pfi->FileSystemName, - pfi->FileSystemNameLength / sizeof (WCHAR)); - printf ("Filesystemname : <%s>\n", name); - printf ("Flags : %x\n", flags = pfi->FileSystemAttributes); - - printf (" FILE_CASE_SENSITIVE_SEARCH : %s\n", - (flags & FILE_CASE_SENSITIVE_SEARCH) ? "TRUE" : "FALSE"); - printf (" FILE_CASE_PRESERVED_NAMES : %s\n", - (flags & FILE_CASE_PRESERVED_NAMES) ? "TRUE" : "FALSE"); - printf (" FILE_UNICODE_ON_DISK : %s\n", - (flags & FILE_UNICODE_ON_DISK) ? "TRUE" : "FALSE"); - printf (" FILE_PERSISTENT_ACLS : %s\n", - (flags & FILE_PERSISTENT_ACLS) ? "TRUE" : "FALSE"); - printf (" FILE_FILE_COMPRESSION : %s\n", - (flags & FILE_FILE_COMPRESSION) ? "TRUE" : "FALSE"); - printf (" FILE_VOLUME_QUOTAS : %s\n", - (flags & FILE_VOLUME_QUOTAS) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_SPARSE_FILES : %s\n", - (flags & FILE_SUPPORTS_SPARSE_FILES) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_REPARSE_POINTS : %s\n", - (flags & FILE_SUPPORTS_REPARSE_POINTS) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_REMOTE_STORAGE : %s\n", - (flags & FILE_SUPPORTS_REMOTE_STORAGE) ? "TRUE" : "FALSE"); - printf (" FILE_RETURNS_CLEANUP_RESULT_INFO : %s\n", - (flags & FILE_RETURNS_CLEANUP_RESULT_INFO) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_POSIX_UNLINK_RENAME : %s\n", - (flags & FILE_SUPPORTS_POSIX_UNLINK_RENAME) ? "TRUE" : "FALSE"); - printf (" FILE_VOLUME_IS_COMPRESSED : %s\n", - (flags & FILE_VOLUME_IS_COMPRESSED) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_OBJECT_IDS : %s\n", - (flags & FILE_SUPPORTS_OBJECT_IDS) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_ENCRYPTION : %s\n", - (flags & FILE_SUPPORTS_ENCRYPTION) ? "TRUE" : "FALSE"); - printf (" FILE_NAMED_STREAMS : %s\n", - (flags & FILE_NAMED_STREAMS) ? "TRUE" : "FALSE"); - printf (" FILE_READ_ONLY_VOLUME : %s\n", - (flags & FILE_READ_ONLY_VOLUME) ? "TRUE" : "FALSE"); - printf (" FILE_SEQUENTIAL_WRITE_ONCE : %s\n", - (flags & FILE_SEQUENTIAL_WRITE_ONCE) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_TRANSACTIONS : %s\n", - (flags & FILE_SUPPORTS_TRANSACTIONS) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_HARD_LINKS : %s\n", - (flags & FILE_SUPPORTS_HARD_LINKS) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_EXTENDED_ATTRIBUTES : %s\n", - (flags & FILE_SUPPORTS_EXTENDED_ATTRIBUTES) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_OPEN_BY_FILE_ID : %s\n", - (flags & FILE_SUPPORTS_OPEN_BY_FILE_ID) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_USN_JOURNAL : %s\n", - (flags & FILE_SUPPORTS_USN_JOURNAL) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_INTEGRITY_STREAMS : %s\n", - (flags & FILE_SUPPORTS_INTEGRITY_STREAMS) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_BLOCK_REFCOUNTING : %s\n", - (flags & FILE_SUPPORTS_BLOCK_REFCOUNTING) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_SPARSE_VDL : %s\n", - (flags & FILE_SUPPORTS_SPARSE_VDL) ? "TRUE" : "FALSE"); - printf (" FILE_DAX_VOLUME : %s\n", - (flags & FILE_DAX_VOLUME) ? "TRUE" : "FALSE"); - printf (" FILE_SUPPORTS_GHOSTING : %s\n", - (flags & FILE_SUPPORTS_GHOSTING) ? "TRUE" : "FALSE"); + printf ("Filesystemname : <%.*ls>\n", + pfi->FileSystemNameLength / sizeof (WCHAR), pfi->FileSystemName); + printf ("Flags : 0x%08x\n", pfi->FileSystemAttributes); + print_flag (pfi->FileSystemAttributes, FILE_CASE_SENSITIVE_SEARCH); + print_flag (pfi->FileSystemAttributes, FILE_CASE_PRESERVED_NAMES); + print_flag (pfi->FileSystemAttributes, FILE_UNICODE_ON_DISK); + print_flag (pfi->FileSystemAttributes, FILE_PERSISTENT_ACLS); + print_flag (pfi->FileSystemAttributes, FILE_FILE_COMPRESSION); + print_flag (pfi->FileSystemAttributes, FILE_VOLUME_QUOTAS); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_SPARSE_FILES); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_REPARSE_POINTS); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_REMOTE_STORAGE); + print_flag (pfi->FileSystemAttributes, FILE_RETURNS_CLEANUP_RESULT_INFO); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_POSIX_UNLINK_RENAME); + print_flag (pfi->FileSystemAttributes, FILE_VOLUME_IS_COMPRESSED); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_OBJECT_IDS); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_ENCRYPTION); + print_flag (pfi->FileSystemAttributes, FILE_NAMED_STREAMS); + print_flag (pfi->FileSystemAttributes, FILE_READ_ONLY_VOLUME); + print_flag (pfi->FileSystemAttributes, FILE_SEQUENTIAL_WRITE_ONCE); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_TRANSACTIONS); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_HARD_LINKS); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_EXTENDED_ATTRIBUTES); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_OPEN_BY_FILE_ID); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_USN_JOURNAL); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_INTEGRITY_STREAMS); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_BLOCK_REFCOUNTING); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_SPARSE_VDL); + print_flag (pfi->FileSystemAttributes, FILE_DAX_VOLUME); + print_flag (pfi->FileSystemAttributes, FILE_SUPPORTS_GHOSTING); } else - fprintf (stderr, "FileFsAttributeInformation failed, %08x\n", stat); + fprintf (stderr, "FileFsAttributeInformation failed, 0x%08x\n", stat); + /* FileFsSectorSizeInformation */ + stat = NtQueryVolumeInformationFile (h, &io, buf, sizeof buf, + FileFsSectorSizeInformation); + if (NT_SUCCESS (stat)) + { + PFILE_FS_SECTOR_SIZE_INFORMATION pfi = + (PFILE_FS_SECTOR_SIZE_INFORMATION) buf; + printf ("SectorInfoFlags : 0x%02x\n", pfi->Flags); + print_flag (pfi->Flags, SSINFO_FLAGS_NO_SEEK_PENALTY); + print_flag (pfi->Flags, SSINFO_FLAGS_TRIM_ENABLED); + } + /* Do not generate an error message if the FS is remote. */ + else if (!remote) + fprintf (stderr, "FileFsSectorSizeInformation failed, 0x%08x\n", stat); NtClose (h); free (winpath); RtlFreeUnicodeString (&upath); - RtlFreeUnicodeString (&wpath); return 0; } diff --git a/version.h b/version.h index 08b7c5bcb0b1..e0002dc3cfe7 100644 --- a/version.h +++ b/version.h @@ -2,5 +2,5 @@ #define STRINGIFY1(s) #s #define VERSION_MAJOR 0 #define VERSION_MINOR 9 -#define VERSION_MICRO 13 +#define VERSION_MICRO 14 #define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_MICRO)