commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r766773 - in /commons/sandbox/runtime/trunk/src/main/native: include/arch/windows/acr_arch.h include/arch/windows/acr_arch_private.h os/win32/file.c
Date Mon, 20 Apr 2009 17:58:53 GMT
Author: mturk
Date: Mon Apr 20 17:58:53 2009
New Revision: 766773

URL: http://svn.apache.org/viewvc?rev=766773&view=rev
Log:
Implement windows readlink

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=766773&r1=766772&r2=766773&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Mon Apr
20 17:58:53 2009
@@ -52,6 +52,58 @@
 
 /*
  * ---------------------------------------------------------------------
+ * begin of DDK declarations
+ * Copied from <ntifs.h>
+ * ---------------------------------------------------------------------
+ */
+ 
+#if _MSC_VER >= 1200
+#pragma warning(push)
+#endif
+#pragma warning(disable:4201)       // unnamed struct
+
+#define SYMLINK_FLAG_RELATIVE   1
+
+typedef struct _REPARSE_DATA_BUFFER {
+    ULONG  ReparseTag;
+    USHORT ReparseDataLength;
+    USHORT Reserved;
+    union {
+        struct {
+            USHORT SubstituteNameOffset;
+            USHORT SubstituteNameLength;
+            USHORT PrintNameOffset;
+            USHORT PrintNameLength;
+            ULONG Flags;
+            WCHAR PathBuffer[1];
+        } SymbolicLinkReparseBuffer;
+        struct {
+            USHORT SubstituteNameOffset;
+            USHORT SubstituteNameLength;
+            USHORT PrintNameOffset;
+            USHORT PrintNameLength;
+            WCHAR PathBuffer[1];
+        } MountPointReparseBuffer;
+        struct {
+            UCHAR  DataBuffer[1];
+        } GenericReparseBuffer;
+    } DUMMYUNIONNAME;
+} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
+
+#if _MSC_VER >= 1200
+#pragma warning(pop)
+#else
+#pragma warning( default : 4201 )
+#endif
+
+/*
+ * ---------------------------------------------------------------------
+ * end of DDK declarations
+ * ---------------------------------------------------------------------
+ */
+
+/*
+ * ---------------------------------------------------------------------
  * begin of PEB declarations
  * Copied from http://source.winehq.org
  * and renamed RTL with ACR

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=766773&r1=766772&r2=766773&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Mon Apr 20 17:58:53 2009
@@ -27,14 +27,14 @@
 #include <iphlpapi.h>
 #include <userenv.h>
 #include <shellapi.h>
-
+#include <winioctl.h>
 
 #if HAVE_FILEEXTD_H
 #if !defined (NTDDI_VISTA)
 #include <fileextd.h>
 #define HAVE_FILEEXTD_LIB   1
 #endif
-#elif defined (NTDDI_VISTA)
+#elif _WIN32_WINNT >= 0x0600
 #undef HAVE_FILEEXTD_H
 #define HAVE_FILEEXTD_H     1
 #define HAVE_FILEEXTD_LIB   0

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=766773&r1=766772&r2=766773&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Mon Apr 20 17:58:53 2009
@@ -17,6 +17,7 @@
 #include "acr.h"
 #include "acr_private.h"
 #include "acr_error.h"
+#include "acr_memory.h"
 #include "acr_string.h"
 #include "acr_file.h"
 
@@ -117,7 +118,7 @@
         DWORD dwFlags = 0;
         if (J2W(target)[wcslen(J2W(target))] == L'\\')
             dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY;
-        if (CreateSymbolicLinkW(J2W(lnkname), J2W(target), dwFlags)) {
+        if (!CreateSymbolicLinkW(J2W(lnkname), J2W(target), dwFlags)) {
             int err = ACR_GET_OS_ERROR();
             if (ACR_STATUS_IS_EACCES(err))
                 ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
@@ -137,21 +138,48 @@
                                                   jstring lnkname)
 {
     jstring rv = NULL;
-    int slib = 0;
+
     UNREFERENCED_O;
-#if HAVE_FILEEXTD_H
-    if (!ACR_HAVE_LATE_DLL_FUNC(GetFileInformationByHandleEx)) {
-#if HAVE_FILEEXTD_LIB
-        slib = 1;
-#else
+    if (!ACR_HAVE_LATE_DLL_FUNC(CreateSymbolicLinkW)) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTIMPL, 0);
-#endif
+        return JNI_FALSE;
     }
     WITH_WSTR(lnkname) {
+        void *buf = ACR_Calloc(_E, THROW_FMARK, MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
+        if (buf) {
+            HANDLE sh = CreateFileW(J2W(lnkname),
+                                    GENERIC_READ,
+                                    FILE_SHARE_DELETE,
+                                    NULL,
+                                    OPEN_EXISTING,
+                                    FILE_FLAG_OPEN_REPARSE_POINT,
+                                    NULL);    
+            if (sh != INVALID_HANDLE_VALUE) {
+                DWORD dl;
+                PREPARSE_DATA_BUFFER repb;
+                DeviceIoControl(sh,
+                                FSCTL_GET_REPARSE_POINT,
+                                NULL,
+                                0,
+                                buf,
+                                MAXIMUM_REPARSE_DATA_BUFFER_SIZE,
+                                &dl,
+                                NULL);
+                repb = (PREPARSE_DATA_BUFFER)buf;
+                if (repb->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
+                    char *pb = (char *)repb->SymbolicLinkReparseBuffer.PathBuffer;
+                    rv = (*_E)->NewString(_E, (const jchar *)(pb + repb->SymbolicLinkReparseBuffer.PrintNameOffset),
+                                          repb->SymbolicLinkReparseBuffer.PrintNameLength
>> 1);
+                }
+                CloseHandle(sh);
+            }
+            else {
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+                                    ACR_GET_OS_ERROR());
+            }
+            free(buf);
+        }
 
     } END_WITH_WSTR(lnkname);
-#else
-    ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTIMPL, 0);
-#endif
     return rv;
 }



Mime
View raw message