OSDN Git Service

* devices.in (dev_storage): Use native NT device name for kmsg mailslot.
authorcorinna <corinna>
Mon, 13 Aug 2007 15:08:25 +0000 (15:08 +0000)
committercorinna <corinna>
Mon, 13 Aug 2007 15:08:25 +0000 (15:08 +0000)
* devices.cc: Regenerate.
* fhandler.cc (fhandler_base::operator =): Use path_conv assignment
operator.
(fhandler_base::set_name): Ditto.
(fhandler_base::open): Use NT native path in debug output.
* fhandler_mailslot.cc: Convert to NT native function calls.
* ntdll.h (struct _FILE_MAILSLOT_SET_INFORMATION): Define.
(NtCreateMailslotFile): Declare.
* path.cc (path_conv::set_normalized_path): Don't set wide_path to NULL.
(path_conv::set_name): Remove unused function.
* path.h (path_conv::set_name): Drop declaration.
(path_conv::operator =): Define.

winsup/cygwin/ChangeLog
winsup/cygwin/devices.cc
winsup/cygwin/devices.in
winsup/cygwin/fhandler.cc
winsup/cygwin/fhandler_mailslot.cc
winsup/cygwin/ntdll.h
winsup/cygwin/path.cc
winsup/cygwin/path.h

index dc82967..ac9b4e0 100644 (file)
@@ -1,3 +1,19 @@
+2007-08-13  Corinna Vinschen  <corinna@vinschen.de>
+
+       * devices.in (dev_storage): Use native NT device name for kmsg mailslot.
+       * devices.cc: Regenerate.
+       * fhandler.cc (fhandler_base::operator =): Use path_conv assignment
+       operator.
+       (fhandler_base::set_name): Ditto.
+       (fhandler_base::open): Use NT native path in debug output.
+       * fhandler_mailslot.cc: Convert to NT native function calls.
+       * ntdll.h (struct _FILE_MAILSLOT_SET_INFORMATION): Define.
+       (NtCreateMailslotFile): Declare.
+       * path.cc (path_conv::set_normalized_path): Don't set wide_path to NULL.
+       (path_conv::set_name): Remove unused function.
+       * path.h (path_conv::set_name): Drop declaration.
+       (path_conv::operator =): Define.
+
 2007-08-12  Corinna Vinschen  <corinna@vinschen.de>
 
        * fhandler.cc (fhandler_base::open): Remove HIDDEN_DOT_FILES code.
index 123b884..1915715 100644 (file)
@@ -104,7 +104,7 @@ static const device dev_storage[] =
   {"/dev/fifo", BRACK(FH_FIFO), "\\dev\\fifo"},
   {"/dev/full", BRACK(FH_FULL), "\\dev\\full"},
   {"/dev/kmem", BRACK(FH_KMEM), "\\dev\\mem"},
-  {"/dev/kmsg", BRACK(FH_KMSG), "\\\\.\\mailslot\\cygwin\\dev\\kmsg"},
+  {"/dev/kmsg", BRACK(FH_KMSG), "\\Device\\MailSlot\\cygwin\\dev\\kmsg"},
   {"/dev/mem", BRACK(FH_MEM), "\\dev\\mem"},
   {"/dev/nst0", BRACK(FHDEV(DEV_TAPE_MAJOR, 128)), "\\Device\\Tape0"},
   {"/dev/nst1", BRACK(FHDEV(DEV_TAPE_MAJOR, 129)), "\\Device\\Tape1"},
index cbafcf2..e72d821 100644 (file)
@@ -97,7 +97,7 @@ const device dev_bad_storage =
 "/dev/sdb%{a-z}s%(1-15)d", BRACK(FH_SDB{uc $1} | {$2}), "\\Device\\Harddisk{52 + ord($1) - ord('a')}\\Partition{$2 % 16}"
 "/dev/sdc%{a-z}s%(1-15)d", BRACK(FH_SDC{uc $1} | {$2}), "\\Device\\Harddisk{78 + ord($1) - ord('a')}\\Partition{$2 % 16}"
 "/dev/sdd%{a-x}s%(1-15)d", BRACK(FH_SDD{uc $1} | {$2}), "\\Device\\Harddisk{104 + ord($1) - ord('a')}\\Partition{$2 % 16}"
-"/dev/kmsg", BRACK(FH_KMSG), "\\\\.\\mailslot\\cygwin\\dev\\kmsg"
+"/dev/kmsg", BRACK(FH_KMSG), "\\Device\\MailSlot\\cygwin\\dev\\kmsg"
 "/dev", BRACK(FH_DEV), "/dev"
 %other {return NULL;}
 %%
index 59ee6a4..8b180b1 100644 (file)
@@ -45,7 +45,7 @@ inline fhandler_base&
 fhandler_base::operator =(fhandler_base& x)
 {
   memcpy (this, &x, sizeof *this);
-  pc.set_normalized_path (x.pc.normalized_path, false);
+  pc = x.pc;
   rabuf = NULL;
   ralen = 0;
   raixget = 0;
@@ -154,8 +154,7 @@ fhandler_base::get_readahead_into_buffer (char *buf, size_t buflen)
 void
 fhandler_base::set_name (path_conv &in_pc)
 {
-  memcpy (&pc, &in_pc, in_pc.size ());
-  pc.set_normalized_path (in_pc.normalized_path, false);
+  pc = in_pc;
 }
 
 char *fhandler_base::get_proc_fd_name (char *buf)
@@ -469,7 +468,7 @@ fhandler_base::open (int flags, mode_t mode)
   IO_STATUS_BLOCK io;
   NTSTATUS status;
 
-  syscall_printf ("(%s, %p)", get_win32_name (), flags);
+  syscall_printf ("(%S, %p)", pc.get_nt_native_path (), flags);
 
   pc.get_object_attr (attr, sa);
 
@@ -577,12 +576,12 @@ fhandler_base::open (int flags, mode_t mode)
   set_open_status ();
 done:
   debug_printf ("%x = NtCreateFile "
-               "(%p, %x, %s, io, NULL, %x, %x, %x, %x, NULL, 0)",
-               status, x, access, get_win32_name (), file_attributes, shared,
-               create_disposition, create_options);
+               "(%p, %x, %S, io, NULL, %x, %x, %x, %x, NULL, 0)",
+               status, x, access, pc.get_nt_native_path (), file_attributes,
+               shared, create_disposition, create_options);
 
-  syscall_printf ("%d = fhandler_base::open (%s, %p)", res, get_win32_name (),
-                 flags);
+  syscall_printf ("%d = fhandler_base::open (%s, %p)",
+                 res, pc.get_nt_native_path (), flags);
   return res;
 }
 
index 543c7f8..d829def 100644 (file)
@@ -53,39 +53,45 @@ int
 fhandler_mailslot::open (int flags, mode_t mode)
 {
   int res = 0;
+  NTSTATUS status;
+  IO_STATUS_BLOCK io;
+  OBJECT_ATTRIBUTES attr;
   HANDLE x;
+  LARGE_INTEGER timeout;
 
   switch (flags & O_ACCMODE)
     {
     case O_RDONLY:     /* Server */
-      x = CreateMailslot (get_win32_name (),
-                         0, /* Any message size */
-                         (flags & O_NONBLOCK) ? 0 : MAILSLOT_WAIT_FOREVER,
-                         &sec_none);
-      if (x == INVALID_HANDLE_VALUE)
+      timeout.QuadPart = (flags & O_NONBLOCK) ? 0LL : 0x8000000000000000LL;
+      status = NtCreateMailslotFile (&x, GENERIC_READ | SYNCHRONIZE,
+                                    pc.get_object_attr (attr, sec_none),
+                                    &io, FILE_SYNCHRONOUS_IO_NONALERT,
+                                    0, 0, &timeout);
+      if (!NT_SUCCESS (status))
        {
          /* FIXME: It's not possible to open the read side of an existing
-            mailslot using CreateFile.  You'll get a handle, but using it
-            in ReadFile returns ERROR_INVALID_PARAMETER.  On the other
-            hand, CreateMailslot returns with ERROR_ALREADY_EXISTS if the
-            mailslot has been created already.
+            mailslot again.  You'll get a handle, but using it in ReadFile
+            returns ERROR_INVALID_PARAMETER.  On the other hand,
+            NtCreateMailslotFile returns with STATUS_OBJECT_NAME_EXISTS if
+            the mailslot has been created already.
             So this is an exclusive open for now.  *Duplicating* read side
             handles works, though, so it might be an option to duplicate
             the handle from the first process to the current process for
             opening the mailslot. */
 #if 0
-         if (GetLastError () != ERROR_ALREADY_EXISTS)
+         if (status != STATUS_OBJECT_NAME_COLLISION)
            {
-             __seterrno ();
+             __seterrno_from_nt_status (status);
              break;
            }
-         x = CreateFile (get_win32_name (), GENERIC_READ,
-                         FILE_SHARE_VALID_FLAGS,
-                         &sec_none, OPEN_EXISTING, 0, 0);
+         status = NtOpenFile (&x, GENERIC_READ | SYNCHRONIZE,
+                              pc.get_object_attr (attr, sec_none), &io,
+                              FILE_SHARE_VALID_FLAGS,
+                              FILE_SYNCHRONOUS_IO_NONALERT);
 #endif
-         if (x == INVALID_HANDLE_VALUE)
+         if (!NT_SUCCESS (status))
            {
-             __seterrno ();
+             __seterrno_from_nt_status (status);
              break;
            }
        }
@@ -103,11 +109,13 @@ fhandler_mailslot::open (int flags, mode_t mode)
          set_errno (EPERM);    /* As on Linux. */
          break;
        }
-      x = CreateFile (get_win32_name (), GENERIC_WRITE, FILE_SHARE_VALID_FLAGS,
-                     &sec_none, OPEN_EXISTING, 0, 0);
-      if (x == INVALID_HANDLE_VALUE)
+      status = NtOpenFile (&x, GENERIC_WRITE | SYNCHRONIZE,
+                          pc.get_object_attr (attr, sec_none), &io,
+                          FILE_SHARE_VALID_FLAGS,
+                          FILE_SYNCHRONOUS_IO_NONALERT);
+      if (!NT_SUCCESS (status))
        {
-         __seterrno ();
+         __seterrno_from_nt_status (status);
          break;
        }
       set_io_handle (x);
@@ -140,15 +148,22 @@ int
 fhandler_mailslot::ioctl (unsigned int cmd, void *buf)
 {
   int res = -1;
+  NTSTATUS status;
+  IO_STATUS_BLOCK io;
 
   switch (cmd)
     {
     case FIONBIO:
       {
-       DWORD timeout = buf ? 0 : MAILSLOT_WAIT_FOREVER;
-       if (!SetMailslotInfo (get_handle (), timeout))
+       FILE_MAILSLOT_SET_INFORMATION fmsi;
+       fmsi.ReadTimeout.QuadPart = buf ? 0LL : 0x8000000000000000LL;
+       status = NtSetInformationFile (get_handle (), &io, &fmsi, sizeof fmsi,
+                                      FileMailslotSetInformation);
+       if (!NT_SUCCESS (status))
          {
-           debug_printf ("SetMailslotInfo (%u): %E", timeout);
+           debug_printf ("NtSetInformationFile (%X): %08x",
+                         fmsi.ReadTimeout.QuadPart, status);
+           __seterrno_from_nt_status (status);
            break;
          }
       }
index 3c94010..ea4b3a6 100644 (file)
@@ -745,6 +745,11 @@ typedef struct _FILE_FULL_EA_INFORMATION
   CHAR EaName[1];
 } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
 
+typedef struct _FILE_MAILSLOT_SET_INFORMATION
+{
+  LARGE_INTEGER ReadTimeout;
+} FILE_MAILSLOT_SET_INFORMATION, *PFILE_MAILSLOT_SET_INFORMATION;
+
 typedef VOID NTAPI (*PIO_APC_ROUTINE)(PVOID, PIO_STATUS_BLOCK, ULONG);
 
 /* Function declarations for ntdll.dll.  These don't appear in any
@@ -757,6 +762,9 @@ extern "C"
   NTSTATUS NTAPI NtCreateFile (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES,
                             PIO_STATUS_BLOCK, PLARGE_INTEGER, ULONG, ULONG,
                             ULONG, ULONG, PVOID, ULONG);
+  NTSTATUS NTAPI NtCreateMailslotFile(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES,
+                                     PIO_STATUS_BLOCK, ULONG, ULONG, ULONG,
+                                     PLARGE_INTEGER);
   NTSTATUS NTAPI NtCreateSection (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES,
                                  PLARGE_INTEGER, ULONG, ULONG, HANDLE);
   NTSTATUS NTAPI NtCreateToken (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES,
index 6620b02..4efc457 100644 (file)
@@ -536,7 +536,6 @@ path_conv::set_normalized_path (const char *path_copy, bool strip_tail)
     }
 
   memcpy (normalized_path, path_copy, n);
-  wide_path = NULL;
 }
 
 PUNICODE_STRING
@@ -1178,15 +1177,6 @@ out:
 #endif
 }
 
-void
-path_conv::set_name (const char *win32, const char *posix)
-{
-  if (!normalized_path_size && normalized_path)
-    cfree (normalized_path);
-  strcpy (path, win32);
-  set_normalized_path (posix, false);
-}
-
 path_conv::~path_conv ()
 {
   if (!normalized_path_size && normalized_path)
index e911f41..194a564 100644 (file)
@@ -245,7 +245,6 @@ class path_conv
     {path[0] = '\0';}
 
   ~path_conv ();
-  void set_name (const char *win32, const char *posix);
   inline char *get_win32 () { return path; }
   PUNICODE_STRING get_nt_native_path ();
   POBJECT_ATTRIBUTES get_object_attr (OBJECT_ATTRIBUTES &attr,
@@ -256,6 +255,13 @@ class path_conv
   operator DWORD &() {return fileattr;}
   operator int () {return fileattr; }
   char operator [](int i) const {return path[i];}
+  path_conv &operator =(path_conv &pc)
+  {
+    memcpy (this, &pc, pc.size ());
+    set_normalized_path (pc.normalized_path, false);
+    wide_path = NULL;
+    return *this;
+  }
   DWORD get_devn () const {return dev.devn;}
   short get_unitn () const {return dev.minor;}
   DWORD file_attributes () const {return fileattr;}