public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
* [csih - Cygwin service installation helper, a helper script and tools to create service installation scripts] branch master, updated. v0_9_11-7-gd81198e4445e
@ 2023-12-07 10:37 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-12-07 10:37 UTC (permalink / raw)
  To: cygwin-apps-cvs




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/csih.git;h=d81198e4445e514ac842f8649cd5b60ad27e0dba

commit d81198e4445e514ac842f8649cd5b60ad27e0dba
Author: Corinna Vinschen <vinschen@redhat.com>
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 <vinschen@redhat.com>
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 <stdio.h>
 #include <string.h>
+#include <wchar.h>
+#include <locale.h>
 #include <sys/cygwin.h>
-#define _WIN32_WINNT 0x0600
+#define _WIN32_WINNT 0x0a00
 #include <windows.h>
 #include <winternl.h>
 #include <ntstatus.h>
-#include <wchar.h>
 
-#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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-07 10:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 10:37 [csih - Cygwin service installation helper, a helper script and tools to create service installation scripts] branch master, updated. v0_9_11-7-gd81198e4445e Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).