src/java.base/unix/native/libjava/UnixFileSystem_md.c
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47216 71c04702a3d5
child 51105 c6600aba799b
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45178
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4981
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4981
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4981
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4981
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4981
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
42777
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
    26
#include <unistd.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/stat.h>
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    31
#ifdef MACOSX
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    32
#include <sys/param.h>
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    33
#include <sys/mount.h>
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    34
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sys/statvfs.h>
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    36
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <limits.h>
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    41
#include <errno.h>
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    42
#include <fcntl.h>
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    43
#include <dirent.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "io_util.h"
13360
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
    49
#include "io_util_md.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "java_io_FileSystem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include "java_io_UnixFileSystem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    53
#if defined(_AIX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    54
  #if !defined(NAME_MAX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    55
    #define NAME_MAX MAXNAMLEN
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    56
  #endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    57
  #define DIR DIR64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    58
  #define opendir opendir64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    59
  #define closedir closedir64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    60
#endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    61
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    62
#if defined(__solaris__) && !defined(NAME_MAX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    63
  #define NAME_MAX MAXNAMLEN
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    64
#endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    65
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    66
#if defined(_ALLBSD_SOURCE)
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    67
  #define dirent64 dirent
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    68
  #define readdir64_r readdir_r
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    69
  #define stat64 stat
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    70
  #ifndef MACOSX
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    71
    #define statvfs64 statvfs
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    72
  #endif
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    73
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/* -- Field IDs -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    jfieldID path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
} ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
Java_java_io_UnixFileSystem_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    jclass fileClass = (*env)->FindClass(env, "java/io/File");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (!fileClass) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    ids.path = (*env)->GetFieldID(env, fileClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                  "path", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/* -- Path operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
extern int canonicalize(char *path, const char *out, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                          jstring pathname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    jstring rv = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    WITH_PLATFORM_STRING(env, pathname, path) {
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   102
        char canonicalPath[PATH_MAX];
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   103
        if (canonicalize((char *)path,
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   104
                         canonicalPath, PATH_MAX) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } else {
13360
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   107
#ifdef MACOSX
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   108
            rv = newStringPlatform(env, canonicalPath);
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   109
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            rv = JNU_NewStringPlatform(env, canonicalPath);
13360
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   111
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/* -- Attribute accessors -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
statMode(const char *path, int *mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   124
    struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   125
    if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   126
        *mode = sb.st_mode;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   127
        return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
Java_java_io_UnixFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                                  jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    jint rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            int fmt = mode & S_IFMT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            rv = (jint) (java_io_FileSystem_BA_EXISTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                  | ((fmt == S_IFREG) ? java_io_FileSystem_BA_REGULAR : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                  | ((fmt == S_IFDIR) ? java_io_FileSystem_BA_DIRECTORY : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                        jobject file, jint a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    jboolean rv = JNI_FALSE;
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   156
    int mode = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    case java_io_FileSystem_ACCESS_READ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        mode = R_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    case java_io_FileSystem_ACCESS_WRITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        mode = W_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    case java_io_FileSystem_ACCESS_EXECUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        mode = X_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    default: assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (access(path, mode) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                          jobject file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                          jint access,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                          jboolean enable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                          jboolean owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   188
        int amode = 0;
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   189
        int mode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        switch (access) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        case java_io_FileSystem_ACCESS_READ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                amode = S_IRUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                amode = S_IRUSR | S_IRGRP | S_IROTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        case java_io_FileSystem_ACCESS_WRITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                amode = S_IWUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                amode = S_IWUSR | S_IWGRP | S_IWOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        case java_io_FileSystem_ACCESS_EXECUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                amode = S_IXUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                amode = S_IXUSR | S_IXGRP | S_IXOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (enable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                mode |= amode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                mode &= ~amode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (chmod(path, mode) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                                jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    jlong rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   232
        struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   233
        if (stat64(path, &sb) == 0) {
45297
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   234
#if defined(_AIX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   235
            rv =  (jlong)sb.st_mtime * 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   236
            rv += (jlong)sb.st_mtime_n / 1000000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   237
#elif defined(MACOSX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   238
            rv  = (jlong)sb.st_mtimespec.tv_sec * 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   239
            rv += (jlong)sb.st_mtimespec.tv_nsec / 1000000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   240
#else
45178
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   241
            rv  = (jlong)sb.st_mtim.tv_sec * 1000;
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   242
            rv += (jlong)sb.st_mtim.tv_nsec / 1000000;
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   243
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                      jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    jlong rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   257
        struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   258
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   259
            rv = sb.st_size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
/* -- File operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                                  jstring pathname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    WITH_PLATFORM_STRING(env, pathname, path) {
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   276
        FD fd;
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   277
        /* The root directory always exists */
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   278
        if (strcmp (path, "/")) {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   279
            fd = handleOpen(path, O_RDWR | O_CREAT | O_EXCL, 0666);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   280
            if (fd < 0) {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   281
                if (errno != EEXIST)
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   282
                    JNU_ThrowIOExceptionWithLastError(env, path);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   283
            } else {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   284
                if (close(fd) == -1)
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   285
                    JNU_ThrowIOExceptionWithLastError(env, path);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   286
                rv = JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
Java_java_io_UnixFileSystem_delete0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                    jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (remove(path) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                 jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    DIR *dir = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    struct dirent64 *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    struct dirent64 *result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    int len, maxlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    jobjectArray rv, old;
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   318
    jclass str_class;
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   319
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   320
    str_class = JNU_ClassString(env);
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   321
    CHECK_NULL_RETURN(str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        dir = opendir(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (dir == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    if (ptr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /* Allocate an initial String array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    maxlen = 16;
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   338
    rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    if (rv == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /* Scan the directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    while ((readdir64_r(dir, ptr, &result) == 0)  && (result != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        jstring name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (len == maxlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            old = rv;
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   348
            rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            if (rv == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            (*env)->DeleteLocalRef(env, old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
13360
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   353
#ifdef MACOSX
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   354
        name = newStringPlatform(env, ptr->d_name);
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   355
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        name = JNU_NewStringPlatform(env, ptr->d_name);
13360
b62b5e86f92a 7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents: 12047
diff changeset
   357
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (name == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        (*env)->SetObjectArrayElement(env, rv, len++, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        (*env)->DeleteLocalRef(env, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /* Copy the final results into an appropriately-sized array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    old = rv;
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   367
    rv = (*env)->NewObjectArray(env, len, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    if (rv == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    if (JNU_CopyObjectArray(env, rv, old, len) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 error:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
Java_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                            jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (mkdir(path, 0777) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                    jobject from, jobject to)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    WITH_FIELD_PLATFORM_STRING(env, from, ids.path, fromPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        WITH_FIELD_PLATFORM_STRING(env, to, ids.path, toPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (rename(fromPath, toPath) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        } END_PLATFORM_STRING(env, toPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    } END_PLATFORM_STRING(env, fromPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                                                jobject file, jlong time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   421
        struct stat64 sb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   423
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   424
            struct timeval tv[2];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   426
            /* Preserve access time */
45297
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   427
#if defined(_AIX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   428
            tv[0].tv_sec = sb.st_atime;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   429
            tv[0].tv_usec = sb.st_atime_n / 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   430
#elif defined(MACOSX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   431
            tv[0].tv_sec = sb.st_atimespec.tv_sec;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   432
            tv[0].tv_usec = sb.st_atimespec.tv_nsec / 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   433
#else
45178
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   434
            tv[0].tv_sec = sb.st_atim.tv_sec;
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   435
            tv[0].tv_usec = sb.st_atim.tv_nsec / 1000;
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   436
#endif
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   437
            /* Change last-modified time */
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   438
            tv[1].tv_sec = time / 1000;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   439
            tv[1].tv_usec = (time % 1000) * 1000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   441
            if (utimes(path, tv) == 0)
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   442
                rv = JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                        jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                     jobject file, jint t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    jlong rv = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   474
#ifdef MACOSX
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   475
        struct statfs fsstat;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   476
#else
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   477
        struct statvfs64 fsstat;
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   478
#endif
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   479
        memset(&fsstat, 0, sizeof(fsstat));
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   480
#ifdef MACOSX
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   481
        if (statfs(path, &fsstat) == 0) {
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   482
            switch(t) {
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   483
                case java_io_FileSystem_SPACE_TOTAL:
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   484
                    rv = jlong_mul(long_to_jlong(fsstat.f_bsize),
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   485
                                   long_to_jlong(fsstat.f_blocks));
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   486
                    break;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   487
                case java_io_FileSystem_SPACE_FREE:
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   488
                    rv = jlong_mul(long_to_jlong(fsstat.f_bsize),
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   489
                                   long_to_jlong(fsstat.f_bfree));
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   490
                    break;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   491
                case java_io_FileSystem_SPACE_USABLE:
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   492
                    rv = jlong_mul(long_to_jlong(fsstat.f_bsize),
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   493
                                   long_to_jlong(fsstat.f_bavail));
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   494
                    break;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   495
                default:
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   496
                    assert(0);
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   497
            }
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   498
        }
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   499
#else
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   500
        if (statvfs64(path, &fsstat) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            switch(t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            case java_io_FileSystem_SPACE_TOTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                               long_to_jlong(fsstat.f_blocks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            case java_io_FileSystem_SPACE_FREE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                               long_to_jlong(fsstat.f_bfree));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            case java_io_FileSystem_SPACE_USABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                               long_to_jlong(fsstat.f_bavail));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   518
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
}
42777
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   522
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   523
JNIEXPORT jlong JNICALL
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   524
Java_java_io_UnixFileSystem_getNameMax0(JNIEnv *env, jobject this,
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   525
                                        jstring pathname)
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   526
{
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   527
    jlong length = -1;
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   528
    WITH_PLATFORM_STRING(env, pathname, path) {
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   529
        length = (jlong)pathconf(path, _PC_NAME_MAX);
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   530
    } END_PLATFORM_STRING(env, path);
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   531
    return length != -1 ? length : (jlong)NAME_MAX;
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   532
}