commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r819525 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.msc.in os/win32/fsysio.c os/win32/temps.c os/win32/wusec.c
Date Mon, 28 Sep 2009 13:16:48 GMT
Author: mturk
Date: Mon Sep 28 13:16:47 2009
New Revision: 819525

URL: http://svn.apache.org/viewvc?rev=819525&view=rev
Log:
Implement win32 file sys io

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=819525&r1=819524&r2=819525&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon Sep 28 13:16:47 2009
@@ -110,6 +110,7 @@
 	$(SRCDIR)/os/win32/env.$(OBJ) \
 	$(SRCDIR)/os/win32/execmem.$(OBJ) \
 	$(SRCDIR)/os/win32/file.$(OBJ) \
+	$(SRCDIR)/os/win32/fsysio.$(OBJ) \
 	$(SRCDIR)/os/win32/main.$(OBJ) \
 	$(SRCDIR)/os/win32/platform.$(OBJ) \
 	$(SRCDIR)/os/win32/os.$(OBJ) \

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=819525&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Mon Sep 28 13:16:47 2009
@@ -0,0 +1,226 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_port.h"
+#include "acr_error.h"
+#include "acr_string.h"
+#include "acr_memory.h"
+#include "acr_descriptor.h"
+#include "acr_pointer.h"
+#include "acr_file.h"
+#include "acr_fileio.h"
+#include "acr_port.h"
+
+static int file_cleanup(void *file, int type, unsigned int flags)
+{
+    int rc = ACR_EBADF;
+    acr_file_t *fp = (acr_file_t *)file;
+
+    if (type != ACR_DT_FILE) {
+        return ACR_EBADF;
+    }
+    if (IS_VALID_HANDLE(fp->fd)) {
+        if (!CloseHandle(fp->fd))
+            rc = ACR_GET_OS_ERROR();
+        else
+            rc = ACR_SUCCESS;
+    }
+    x_free(fp->name);
+    x_free(fp);
+    return rc;
+}
+
+static int descriptor_cleanup(ACR_JNISTDARGS,
+                              acr_descriptor_cb_type_e cm,
+                              acr_descriptor_cb_t *dp)
+{
+    int rc = ACR_SUCCESS;
+    switch (cm) {
+        case ACR_DESC_CLOSE:
+            if (dp->di > 0) {
+                acr_file_t *fp = ACR_IOH_FDATA(dp->di);
+                if (fp->flags & ACR_FOPEN_NOCLEANUP) {
+                    rc = file_cleanup(fp, ACR_DT_FILE, 0);
+                    ACR_IOH_FDATA(dp->di) = NULL;
+                }
+                rc == 0 ? rc = acr_ioh_close(dp->di) : acr_ioh_close(dp->di);
+            }
+            else
+                rc = ACR_EBADF;
+        break;
+        case ACR_DESC_SYNC:
+            if (dp->di > 0) {
+                acr_file_t *fp = ACR_IOH_FDATA(dp->di);
+                if (!FlushFileBuffers(fp->fd))
+                    rc = ACR_GET_OS_ERROR();
+            }
+            else
+                rc = ACR_EBADF;
+        break;
+        default:
+            rc = ACR_ENOTIMPL;
+        break;
+    }
+    return rc;
+}
+
+static int do_fopen(ACR_JNISTDARGS, wchar_t *fname, int flags, int prot,
+                    jobject *fdo)
+{
+    int    rc = 0;
+    int    fo = -1;
+    HANDLE fh = INVALID_HANDLE_VALUE;
+    DWORD aflags = 0;
+    DWORD oflags = 0;
+    DWORD cflags = 0;
+    DWORD sflags = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+    SECURITY_ATTRIBUTES sa;
+    acr_file_t *fp = NULL;
+
+    if ((flags & ACR_FOPEN_READ) && (flags &ACR_FOPEN_WRITE))
+        oflags = GENERIC_READ | GENERIC_WRITE;
+    else if (flags & ACR_FOPEN_READ)
+        oflags = GENERIC_READ;
+    else if (flags & ACR_FOPEN_WRITE)
+        oflags = GENERIC_WRITE;
+    else {
+        /* Neither READ nor WRITE was specified.
+         * We don't know how to open the file.
+         */
+        return ACR_EINVAL;
+    }
+    if (flags & ACR_FOPEN_CREATE) {
+        oflags |= O_CREAT;
+        if (flags & ACR_FOPEN_EXCL)
+            cflags = CREATE_NEW;
+        else if (flags & ACR_FOPEN_TRUNCATE)
+            cflags = CREATE_ALWAYS;
+        else
+            cflags = OPEN_ALWAYS;
+    }
+    if ((flags & ACR_FOPEN_EXCL) && !(flags & ACR_FOPEN_CREATE)) {
+        return ACR_EINVAL;
+    }
+    if (flags & ACR_FOPEN_DELONCLOSE)
+        aflags |= FILE_FLAG_DELETE_ON_CLOSE;
+    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+    sa.bInheritHandle = FALSE;
+    if (prot == ACR_FPROT_OS_DEFAULT) {
+        /* Allow access only to owner and Administrators Group */
+        sa.lpSecurityDescriptor = ACR_StdSecurityDescriptor(INVALID_HANDLE_VALUE,
+                                                            ACR_DT_FILE,
+                                                            ACR_FPROT_URWX |
+                                                            ACR_FPROT_GRWX);
+    }
+    else {
+        /* Use provided protection flags */
+        sa.lpSecurityDescriptor = ACR_StdSecurityDescriptor(INVALID_HANDLE_VALUE,
+                                                            ACR_DT_FILE,
+                                                            prot);
+    }
+    fh = CreateFileW(fname,
+                     oflags,
+                     sflags,
+                     &sa,
+                     cflags,
+                     aflags,
+                     NULL);
+    if (IS_INVALID_HANDLE(fh)) {
+        return ACR_GET_OS_ERROR();
+    }
+    fp = ACR_CALLOC(acr_file_t, 1);
+    if (!fp) {
+        rc = ACR_ENOMEM;
+        goto finally;;
+    }
+    fp->fd    = fh;
+    fp->name  = ACR_StrdupW(_E, THROW_NMARK, fname);
+    fp->flags = flags;
+    fp->type  = ACR_FT_REG; /* Presume it's a regular file */
+    if (flags & ACR_FOPEN_NOCLEANUP)
+        fo = acr_ioh_open(fp, ACR_DT_FILE, 0, NULL);
+    else
+        fo = acr_ioh_open(fp, ACR_DT_FILE, 0, file_cleanup);
+    if (fo < 0) {
+        rc = ACR_GET_OS_ERROR();
+        goto finally;
+    }
+    /* Create File Descriptor Object */
+    *fdo = ACR_DescriptorCreate(_E, ACR_DT_FILE, fo, NULL,
+                                descriptor_cleanup);
+    if (!*fdo) {
+        rc = ACR_GET_OS_ERROR();
+        goto finally;
+    }
+    if (flags & ACR_FOPEN_APPEND) {
+        /* Position to the file end
+         */
+        SetFilePointer(fh, 0, NULL, FILE_END);
+    }
+finally:
+    if (rc) {
+        if (IS_VALID_HANDLE(fh))
+            CloseHandle(fh);
+        if (fp) {
+            x_free(fp->name);
+            x_free(fp);
+        }
+    }
+
+    return rc;
+}
+
+ACR_IO_EXPORT_DECLARE(jobject, FileSystemProvider, open0)(ACR_JNISTDARGS,
+                                                          jstring fname,
+                                                          jint flags)
+{
+    int rc = 0;
+    jobject fdo = NULL;
+
+    WITH_WSTR(fname) {
+        rc = do_fopen(_E, _O, J2W(fname), flags, ACR_FPROT_OS_DEFAULT, &fdo);
+    } END_WITH_WSTR(fname);
+
+    if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
+        /* Don't Throw in case of EXCL and EEXIST
+         */
+        ACR_THROW_IO_IF_ERR(rc);
+    }
+    return fdo;
+}
+
+ACR_IO_EXPORT_DECLARE(jobject, FileSystemProvider, open1)(ACR_JNISTDARGS,
+                                                          jstring fname,
+                                                          jint flags,
+                                                          jint prot)
+{
+    int rc = 0;
+    jobject fdo = NULL;
+
+    WITH_WSTR(fname) {
+        rc = do_fopen(_E, _O, J2W(fname), flags, prot, &fdo);
+    } END_WITH_WSTR(fname);
+
+    if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
+        /* Don't Throw in case of EXCL and EEXIST
+         */
+        ACR_THROW_IO_IF_ERR(rc);
+    }
+    return fdo;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c?rev=819525&r1=819524&r2=819525&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c Mon Sep 28 13:16:47 2009
@@ -47,20 +47,21 @@
 
 static int tmp_file_cleanup(void *file, int type, unsigned int flags)
 {
+    int rc = ACR_EBADF;
     acr_file_t *fp = (acr_file_t *)file;
 
     if (type != ACR_DT_FILE) {
         return ACR_EBADF;
     }
-    x_free(fp->name);
     if (IS_VALID_HANDLE(fp->fd)) {
         if (!CloseHandle(fp->fd))
-            return ACR_GET_OS_ERROR();
+            rc = ACR_GET_OS_ERROR();
         else
-            return ACR_SUCCESS;
+            rc = ACR_SUCCESS;
     }
-    else
-        return ACR_EBADF;
+    x_free(fp->name);
+    x_free(fp);
+    return rc;
 }
 
 static HANDLE getftemp(wchar_t *path, DWORD flags)

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c?rev=819525&r1=819524&r2=819525&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c Mon Sep 28 13:16:47 2009
@@ -527,11 +527,14 @@
         /* Return the error from GetSecurityDescriptor */
         return ACR_GET_OS_ERROR();
     }
-    if (uid) {
+    if (IS_VALID_HANDLE(uid))
         sinf |= OWNER_SECURITY_INFORMATION;
-    }
-    if (gid)
+    else
+        uid = NULL;
+    if (IS_VALID_HANDLE(gid))
         sinf |= GROUP_SECURITY_INFORMATION;
+    else
+        gid = NULL;
     if (psd) {
         BOOL hasdacl;
         BOOL defdacl;



Mime
View raw message