jdk/src/java.base/unix/native/libjava/UnixFileSystem_md.c
author stuefe
Thu, 01 Jun 2017 08:59:24 +0200
changeset 45297 df90da0c10aa
parent 45178 9ff621041842
permissions -rw-r--r--
8181207: 8177809 breaks AIX 5.3, 6.1 builds Reviewed-by: vtewari, simonis, clanger
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#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
    47
#include "io_util_md.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "java_io_FileSystem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "java_io_UnixFileSystem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    51
#if defined(_AIX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    52
  #if !defined(NAME_MAX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    53
    #define NAME_MAX MAXNAMLEN
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    54
  #endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    55
  #define DIR DIR64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    56
  #define opendir opendir64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    57
  #define closedir closedir64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    58
#endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    59
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    60
#if defined(__solaris__) && !defined(NAME_MAX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    61
  #define NAME_MAX MAXNAMLEN
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    62
#endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    63
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    64
#if defined(_ALLBSD_SOURCE)
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    65
  #define dirent64 dirent
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    66
  #define readdir64_r readdir_r
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    67
  #define stat64 stat
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    68
  #ifndef MACOSX
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    69
    #define statvfs64 statvfs
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 42777
diff changeset
    70
  #endif
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
    71
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/* -- Field IDs -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jfieldID path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
} ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
Java_java_io_UnixFileSystem_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    jclass fileClass = (*env)->FindClass(env, "java/io/File");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (!fileClass) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    ids.path = (*env)->GetFieldID(env, fileClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                  "path", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/* -- Path operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
extern int canonicalize(char *path, const char *out, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                          jstring pathname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    jstring rv = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    WITH_PLATFORM_STRING(env, pathname, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        char canonicalPath[JVM_MAXPATHLEN];
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   101
        if (canonicalize((char *)path,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                         canonicalPath, JVM_MAXPATHLEN) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } 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
   105
#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
   106
            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
   107
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            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
   109
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
/* -- Attribute accessors -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
statMode(const char *path, int *mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   122
    struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   123
    if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   124
        *mode = sb.st_mode;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   125
        return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
Java_java_io_UnixFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                                  jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    jint rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            int fmt = mode & S_IFMT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            rv = (jint) (java_io_FileSystem_BA_EXISTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                  | ((fmt == S_IFREG) ? java_io_FileSystem_BA_REGULAR : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                  | ((fmt == S_IFDIR) ? java_io_FileSystem_BA_DIRECTORY : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                        jobject file, jint a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    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
   154
    int mode = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    case java_io_FileSystem_ACCESS_READ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        mode = R_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    case java_io_FileSystem_ACCESS_WRITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        mode = W_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    case java_io_FileSystem_ACCESS_EXECUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        mode = X_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    default: assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (access(path, mode) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                          jobject file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                          jint access,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                          jboolean enable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                          jboolean owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    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
   186
        int amode = 0;
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   187
        int mode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        switch (access) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        case java_io_FileSystem_ACCESS_READ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                amode = S_IRUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                amode = S_IRUSR | S_IRGRP | S_IROTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        case java_io_FileSystem_ACCESS_WRITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                amode = S_IWUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                amode = S_IWUSR | S_IWGRP | S_IWOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        case java_io_FileSystem_ACCESS_EXECUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                amode = S_IXUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                amode = S_IXUSR | S_IXGRP | S_IXOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (enable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                mode |= amode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                mode &= ~amode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (chmod(path, mode) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                                jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    jlong rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    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
   230
        struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   231
        if (stat64(path, &sb) == 0) {
45297
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   232
#if defined(_AIX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   233
            rv =  (jlong)sb.st_mtime * 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   234
            rv += (jlong)sb.st_mtime_n / 1000000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   235
#elif defined(MACOSX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   236
            rv  = (jlong)sb.st_mtimespec.tv_sec * 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   237
            rv += (jlong)sb.st_mtimespec.tv_nsec / 1000000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   238
#else
45178
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   239
            rv  = (jlong)sb.st_mtim.tv_sec * 1000;
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   240
            rv += (jlong)sb.st_mtim.tv_nsec / 1000000;
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   241
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                      jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    jlong rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    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
   255
        struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   256
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   257
            rv = sb.st_size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
/* -- File operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                                  jstring pathname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    WITH_PLATFORM_STRING(env, pathname, path) {
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   274
        FD fd;
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   275
        /* The root directory always exists */
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   276
        if (strcmp (path, "/")) {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   277
            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
   278
            if (fd < 0) {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   279
                if (errno != EEXIST)
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   280
                    JNU_ThrowIOExceptionWithLastError(env, path);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   281
            } else {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   282
                if (close(fd) == -1)
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   283
                    JNU_ThrowIOExceptionWithLastError(env, path);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   284
                rv = JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
Java_java_io_UnixFileSystem_delete0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                    jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (remove(path) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                 jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    DIR *dir = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    struct dirent64 *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    struct dirent64 *result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    int len, maxlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    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
   316
    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
   317
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   318
    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
   319
    CHECK_NULL_RETURN(str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        dir = opendir(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    if (dir == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    if (ptr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /* Allocate an initial String array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    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
   336
    rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    if (rv == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /* Scan the directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    while ((readdir64_r(dir, ptr, &result) == 0)  && (result != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        jstring name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (len == maxlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            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
   346
            rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (rv == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            (*env)->DeleteLocalRef(env, old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
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
   351
#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
   352
        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
   353
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        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
   355
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (name == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        (*env)->SetObjectArrayElement(env, rv, len++, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        (*env)->DeleteLocalRef(env, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /* Copy the final results into an appropriately-sized array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    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
   365
    rv = (*env)->NewObjectArray(env, len, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if (rv == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    if (JNU_CopyObjectArray(env, rv, old, len) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 error:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
Java_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                            jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (mkdir(path, 0777) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                    jobject from, jobject to)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    WITH_FIELD_PLATFORM_STRING(env, from, ids.path, fromPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        WITH_FIELD_PLATFORM_STRING(env, to, ids.path, toPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (rename(fromPath, toPath) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } END_PLATFORM_STRING(env, toPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    } END_PLATFORM_STRING(env, fromPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                                jobject file, jlong time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    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
   419
        struct stat64 sb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   421
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   422
            struct timeval tv[2];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   424
            /* Preserve access time */
45297
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   425
#if defined(_AIX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   426
            tv[0].tv_sec = sb.st_atime;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   427
            tv[0].tv_usec = sb.st_atime_n / 1000;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   428
#elif defined(MACOSX)
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   429
            tv[0].tv_sec = sb.st_atimespec.tv_sec;
df90da0c10aa 8181207: 8177809 breaks AIX 5.3, 6.1 builds
stuefe
parents: 45178
diff changeset
   430
            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
   431
#else
45178
9ff621041842 8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents: 42944
diff changeset
   432
            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
   433
            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
   434
#endif
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   435
            /* Change last-modified time */
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   436
            tv[1].tv_sec = time / 1000;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   437
            tv[1].tv_usec = (time % 1000) * 1000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   439
            if (utimes(path, tv) == 0)
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   440
                rv = JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                        jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                     jobject file, jint t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    jlong rv = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    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
   472
#ifdef MACOSX
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   473
        struct statfs fsstat;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   474
#else
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   475
        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
   476
#endif
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   477
        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
   478
#ifdef MACOSX
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   479
        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
   480
            switch(t) {
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   481
                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
   482
                    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
   483
                                   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
   484
                    break;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   485
                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
   486
                    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
   487
                                   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
   488
                    break;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   489
                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
   490
                    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
   491
                                   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
   492
                    break;
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   493
                default:
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   494
                    assert(0);
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   495
            }
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   496
        }
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   497
#else
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   498
        if (statvfs64(path, &fsstat) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            switch(t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            case java_io_FileSystem_SPACE_TOTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                               long_to_jlong(fsstat.f_blocks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            case java_io_FileSystem_SPACE_FREE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                               long_to_jlong(fsstat.f_bfree));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            case java_io_FileSystem_SPACE_USABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                               long_to_jlong(fsstat.f_bavail));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
31144
8154c9d7bc32 8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents: 25859
diff changeset
   516
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}
42777
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   520
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   521
JNIEXPORT jlong JNICALL
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   522
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
   523
                                        jstring pathname)
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   524
{
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   525
    jlong length = -1;
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   526
    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
   527
        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
   528
    } END_PLATFORM_STRING(env, path);
a94fc33e9866 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents: 31144
diff changeset
   529
    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
   530
}