jdk/src/java.base/unix/native/libjava/UnixFileSystem_md.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 22631 jdk/src/solaris/native/java/io/UnixFileSystem_md.c@ac85b05a53f4
child 31144 8154c9d7bc32
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
     2
 * Copyright (c) 1998, 2013, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <sys/stat.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/statvfs.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#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
    41
#include "io_util_md.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "java_io_FileSystem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "java_io_UnixFileSystem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    45
#if defined(_ALLBSD_SOURCE)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    46
#define dirent64 dirent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    47
#define readdir64_r readdir_r
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    48
#define stat64 stat
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    49
#define statvfs64 statvfs
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    50
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/* -- Field IDs -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
static struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    jfieldID path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
} ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
Java_java_io_UnixFileSystem_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jclass fileClass = (*env)->FindClass(env, "java/io/File");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if (!fileClass) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    ids.path = (*env)->GetFieldID(env, fileClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                  "path", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/* -- Path operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
extern int canonicalize(char *path, const char *out, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                          jstring pathname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jstring rv = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    WITH_PLATFORM_STRING(env, pathname, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        char canonicalPath[JVM_MAXPATHLEN];
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    80
        if (canonicalize((char *)path,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                         canonicalPath, JVM_MAXPATHLEN) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        } 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
    84
#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
    85
            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
    86
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            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
    88
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/* -- Attribute accessors -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
statMode(const char *path, int *mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   101
    struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   102
    if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   103
        *mode = sb.st_mode;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   104
        return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
Java_java_io_UnixFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                                  jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    jint rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            int fmt = mode & S_IFMT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            rv = (jint) (java_io_FileSystem_BA_EXISTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                  | ((fmt == S_IFREG) ? java_io_FileSystem_BA_REGULAR : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                  | ((fmt == S_IFDIR) ? java_io_FileSystem_BA_DIRECTORY : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                        jobject file, jint a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    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
   133
    int mode = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    case java_io_FileSystem_ACCESS_READ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        mode = R_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    case java_io_FileSystem_ACCESS_WRITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        mode = W_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    case java_io_FileSystem_ACCESS_EXECUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        mode = X_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    default: assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (access(path, mode) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                          jobject file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                          jint access,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                          jboolean enable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                          jboolean owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    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
   165
        int amode = 0;
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   166
        int mode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        switch (access) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        case java_io_FileSystem_ACCESS_READ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                amode = S_IRUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                amode = S_IRUSR | S_IRGRP | S_IROTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        case java_io_FileSystem_ACCESS_WRITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                amode = S_IWUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                amode = S_IWUSR | S_IWGRP | S_IWOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        case java_io_FileSystem_ACCESS_EXECUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (owneronly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                amode = S_IXUSR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                amode = S_IXUSR | S_IXGRP | S_IXOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (enable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                mode |= amode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                mode &= ~amode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (chmod(path, mode) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                                jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    jlong rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    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
   209
        struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   210
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   211
            rv = 1000 * (jlong)sb.st_mtime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                      jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jlong rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    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
   225
        struct stat64 sb;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   226
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   227
            rv = sb.st_size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
/* -- File operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                                  jstring pathname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    WITH_PLATFORM_STRING(env, pathname, path) {
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   244
        FD fd;
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   245
        /* The root directory always exists */
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   246
        if (strcmp (path, "/")) {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   247
            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
   248
            if (fd < 0) {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   249
                if (errno != EEXIST)
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   250
                    JNU_ThrowIOExceptionWithLastError(env, path);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   251
            } else {
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   252
                if (close(fd) == -1)
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   253
                    JNU_ThrowIOExceptionWithLastError(env, path);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
   254
                rv = JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
Java_java_io_UnixFileSystem_delete0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                    jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (remove(path) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                 jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    DIR *dir = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    struct dirent64 *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    struct dirent64 *result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    int len, maxlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    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
   286
    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
   287
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 16476
diff changeset
   288
    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
   289
    CHECK_NULL_RETURN(str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        dir = opendir(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    if (dir == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    if (ptr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /* Allocate an initial String array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    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
   306
    rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    if (rv == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /* Scan the directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    while ((readdir64_r(dir, ptr, &result) == 0)  && (result != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        jstring name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (len == maxlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            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
   316
            rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            if (rv == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            (*env)->DeleteLocalRef(env, old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
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
   321
#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
   322
        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
   323
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        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
   325
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (name == NULL) goto error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        (*env)->SetObjectArrayElement(env, rv, len++, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        (*env)->DeleteLocalRef(env, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /* Copy the final results into an appropriately-sized array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    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
   335
    rv = (*env)->NewObjectArray(env, len, str_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    if (rv == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    if (JNU_CopyObjectArray(env, rv, old, len) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 error:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    closedir(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
Java_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                            jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (mkdir(path, 0777) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                    jobject from, jobject to)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    WITH_FIELD_PLATFORM_STRING(env, from, ids.path, fromPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        WITH_FIELD_PLATFORM_STRING(env, to, ids.path, toPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (rename(fromPath, toPath) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        } END_PLATFORM_STRING(env, toPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    } END_PLATFORM_STRING(env, fromPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                                jobject file, jlong time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    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
   389
        struct stat64 sb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   391
        if (stat64(path, &sb) == 0) {
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   392
            struct timeval tv[2];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   394
            /* Preserve access time */
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   395
            tv[0].tv_sec = sb.st_atime;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   396
            tv[0].tv_usec = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   398
            /* Change last-modified time */
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   399
            tv[1].tv_sec = time / 1000;
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   400
            tv[1].tv_usec = (time % 1000) * 1000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
692
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   402
            if (utimes(path, tv) == 0)
50a393caed65 6652379: File.setLastModified fails on large files (lnx only)
alanb
parents: 2
diff changeset
   403
                rv = JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                        jobject file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    jboolean rv = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        int mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (statMode(path, &mode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            if (chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                rv = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                     jobject file, jint t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    jlong rv = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
4981
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   435
        struct statvfs64 fsstat;
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   436
        memset(&fsstat, 0, sizeof(fsstat));
3a3f498acc86 6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents: 715
diff changeset
   437
        if (statvfs64(path, &fsstat) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            switch(t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            case java_io_FileSystem_SPACE_TOTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                               long_to_jlong(fsstat.f_blocks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            case java_io_FileSystem_SPACE_FREE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                               long_to_jlong(fsstat.f_bfree));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            case java_io_FileSystem_SPACE_USABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                               long_to_jlong(fsstat.f_bavail));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                assert(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    } END_PLATFORM_STRING(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}