src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58397 2d40e6a7ce8e
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     1
/*
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
     2
 * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     4
 *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
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: 3328
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3328
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    10
 *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    15
 * accompanied this code).
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    16
 *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3328
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3328
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3328
diff changeset
    23
 * questions.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    24
 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    25
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    26
#include <stdio.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    27
#include <stdlib.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    28
#include <limits.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    29
#include <fcntl.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    30
#include <dirent.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    31
#include <unistd.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    32
#include <errno.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    33
#include <dlfcn.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    34
#include <sys/types.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    35
#include <sys/stat.h>
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    36
#ifdef MACOSX
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    37
#include <sys/param.h>
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    38
#include <sys/mount.h>
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    39
#else
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    40
#include <sys/statvfs.h>
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    41
#endif
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    42
#include <sys/time.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    43
40182
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    44
/* For POSIX-compliant getpwuid_r, getgrgid_r on Solaris */
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    45
#if defined(__solaris__)
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    46
#define _POSIX_PTHREAD_SEMANTICS
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    47
#endif
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    48
#include <pwd.h>
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    49
#include <grp.h>
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
    50
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    51
#ifdef __solaris__
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    52
#include <strings.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    53
#endif
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    54
40800
bd4117559e3f 8165643: SecureDirectoryStream doesn't work on linux non-x86
martin
parents: 40182
diff changeset
    55
#ifdef __linux__
bd4117559e3f 8165643: SecureDirectoryStream doesn't work on linux non-x86
martin
parents: 40182
diff changeset
    56
#include <sys/syscall.h>
bd4117559e3f 8165643: SecureDirectoryStream doesn't work on linux non-x86
martin
parents: 40182
diff changeset
    57
#endif
bd4117559e3f 8165643: SecureDirectoryStream doesn't work on linux non-x86
martin
parents: 40182
diff changeset
    58
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
    59
#if defined(__linux__) || defined(_AIX)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    60
#include <string.h>
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    61
#endif
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    62
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    63
#ifdef _ALLBSD_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    64
#include <string.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    65
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    66
#define stat64 stat
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    67
#ifndef MACOSX
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    68
#define statvfs64 statvfs
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
    69
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    70
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    71
#define open64 open
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    72
#define fstat64 fstat
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    73
#define lstat64 lstat
51102
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
    74
#define readdir64 readdir
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    75
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
    76
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    77
#include "jni.h"
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    78
#include "jni_util.h"
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    79
#include "jlong.h"
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    80
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    81
#include "sun_nio_fs_UnixNativeDispatcher.h"
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    82
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
    83
#if defined(_AIX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
    84
  #define DIR DIR64
51597
4c78f4fd8370 8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64
bpb
parents: 51309
diff changeset
    85
  #define dirent dirent64
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
    86
  #define opendir opendir64
51597
4c78f4fd8370 8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64
bpb
parents: 51309
diff changeset
    87
  #define readdir readdir64
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
    88
  #define closedir closedir64
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
    89
#endif
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
    90
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
    91
/**
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
    92
 * Size of password or group entry when not available via sysconf
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
    93
 */
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
    94
#define ENT_BUF_SIZE   1024
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
    95
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    96
#define RESTARTABLE(_cmd, _result) do { \
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    97
  do { \
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    98
    _result = _cmd; \
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    99
  } while((_result == -1) && (errno == EINTR)); \
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   100
} while(0)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   101
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
   102
#define RESTARTABLE_RETURN_PTR(_cmd, _result) do { \
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
   103
  do { \
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
   104
    _result = _cmd; \
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
   105
  } while((_result == NULL) && (errno == EINTR)); \
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
   106
} while(0)
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
   107
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   108
static jfieldID attrs_st_mode;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   109
static jfieldID attrs_st_ino;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   110
static jfieldID attrs_st_dev;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   111
static jfieldID attrs_st_rdev;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   112
static jfieldID attrs_st_nlink;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   113
static jfieldID attrs_st_uid;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   114
static jfieldID attrs_st_gid;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   115
static jfieldID attrs_st_size;
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   116
static jfieldID attrs_st_atime_sec;
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   117
static jfieldID attrs_st_atime_nsec;
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   118
static jfieldID attrs_st_mtime_sec;
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   119
static jfieldID attrs_st_mtime_nsec;
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   120
static jfieldID attrs_st_ctime_sec;
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   121
static jfieldID attrs_st_ctime_nsec;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   122
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   123
#ifdef _DARWIN_FEATURE_64_BIT_INODE
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   124
static jfieldID attrs_st_birthtime_sec;
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   125
#endif
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   126
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   127
static jfieldID attrs_f_frsize;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   128
static jfieldID attrs_f_blocks;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   129
static jfieldID attrs_f_bfree;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   130
static jfieldID attrs_f_bavail;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   131
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   132
static jfieldID entry_name;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   133
static jfieldID entry_dir;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   134
static jfieldID entry_fstype;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   135
static jfieldID entry_options;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   136
static jfieldID entry_dev;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   137
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   138
/**
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   139
 * System calls that may not be available at run time.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   140
 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   141
typedef int openat64_func(int, const char *, int, ...);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   142
typedef int fstatat64_func(int, const char *, struct stat64 *, int);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   143
typedef int unlinkat_func(int, const char*, int);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   144
typedef int renameat_func(int, const char*, int, const char*);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   145
typedef int futimesat_func(int, const char *, const struct timeval *);
57568
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   146
typedef int futimens_func(int, const struct timespec *);
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   147
typedef int lutimes_func(const char *, const struct timeval *);
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   148
typedef DIR* fdopendir_func(int);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   149
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   150
static openat64_func* my_openat64_func = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   151
static fstatat64_func* my_fstatat64_func = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   152
static unlinkat_func* my_unlinkat_func = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   153
static renameat_func* my_renameat_func = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   154
static futimesat_func* my_futimesat_func = NULL;
57568
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   155
static futimens_func* my_futimens_func = NULL;
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   156
static lutimes_func* my_lutimes_func = NULL;
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   157
static fdopendir_func* my_fdopendir_func = NULL;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   158
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   159
/**
52641
09a3f379b927 8214078: (fs) SecureDirectoryStream not supported on arm32
alanb
parents: 51597
diff changeset
   160
 * fstatat missing from glibc on Linux.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   161
 */
52641
09a3f379b927 8214078: (fs) SecureDirectoryStream not supported on arm32
alanb
parents: 51597
diff changeset
   162
#if defined(__linux__) && (defined(__i386) || defined(__arm__))
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   163
#define FSTATAT64_SYSCALL_AVAILABLE
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   164
static int fstatat64_wrapper(int dfd, const char *path,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   165
                             struct stat64 *statbuf, int flag)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   166
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   167
    #ifndef __NR_fstatat64
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   168
    #define __NR_fstatat64  300
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   169
    #endif
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   170
    return syscall(__NR_fstatat64, dfd, path, statbuf, flag);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   171
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   172
#endif
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   173
40800
bd4117559e3f 8165643: SecureDirectoryStream doesn't work on linux non-x86
martin
parents: 40182
diff changeset
   174
#if defined(__linux__) && defined(_LP64) && defined(__NR_newfstatat)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   175
#define FSTATAT64_SYSCALL_AVAILABLE
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   176
static int fstatat64_wrapper(int dfd, const char *path,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   177
                             struct stat64 *statbuf, int flag)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   178
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   179
    return syscall(__NR_newfstatat, dfd, path, statbuf, flag);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   180
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   181
#endif
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   182
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   183
/**
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   184
 * Call this to throw an internal UnixException when a system/library
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   185
 * call fails
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   186
 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   187
static void throwUnixException(JNIEnv* env, int errnum) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   188
    jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   189
        "(I)V", errnum);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   190
    if (x != NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   191
        (*env)->Throw(env, x);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   192
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   193
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   194
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   195
/**
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   196
 * Initialization
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   197
 */
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   198
JNIEXPORT jint JNICALL
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   199
Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   200
{
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   201
    jint capabilities = 0;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   202
    jclass clazz;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   203
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   204
    clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileAttributes");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   205
    CHECK_NULL_RETURN(clazz, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   206
    attrs_st_mode = (*env)->GetFieldID(env, clazz, "st_mode", "I");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   207
    CHECK_NULL_RETURN(attrs_st_mode, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   208
    attrs_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   209
    CHECK_NULL_RETURN(attrs_st_ino, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   210
    attrs_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   211
    CHECK_NULL_RETURN(attrs_st_dev, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   212
    attrs_st_rdev = (*env)->GetFieldID(env, clazz, "st_rdev", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   213
    CHECK_NULL_RETURN(attrs_st_rdev, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   214
    attrs_st_nlink = (*env)->GetFieldID(env, clazz, "st_nlink", "I");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   215
    CHECK_NULL_RETURN(attrs_st_nlink, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   216
    attrs_st_uid = (*env)->GetFieldID(env, clazz, "st_uid", "I");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   217
    CHECK_NULL_RETURN(attrs_st_uid, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   218
    attrs_st_gid = (*env)->GetFieldID(env, clazz, "st_gid", "I");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   219
    CHECK_NULL_RETURN(attrs_st_gid, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   220
    attrs_st_size = (*env)->GetFieldID(env, clazz, "st_size", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   221
    CHECK_NULL_RETURN(attrs_st_size, 0);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   222
    attrs_st_atime_sec = (*env)->GetFieldID(env, clazz, "st_atime_sec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   223
    CHECK_NULL_RETURN(attrs_st_atime_sec, 0);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   224
    attrs_st_atime_nsec = (*env)->GetFieldID(env, clazz, "st_atime_nsec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   225
    CHECK_NULL_RETURN(attrs_st_atime_nsec, 0);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   226
    attrs_st_mtime_sec = (*env)->GetFieldID(env, clazz, "st_mtime_sec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   227
    CHECK_NULL_RETURN(attrs_st_mtime_sec, 0);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   228
    attrs_st_mtime_nsec = (*env)->GetFieldID(env, clazz, "st_mtime_nsec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   229
    CHECK_NULL_RETURN(attrs_st_mtime_nsec, 0);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   230
    attrs_st_ctime_sec = (*env)->GetFieldID(env, clazz, "st_ctime_sec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   231
    CHECK_NULL_RETURN(attrs_st_ctime_sec, 0);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   232
    attrs_st_ctime_nsec = (*env)->GetFieldID(env, clazz, "st_ctime_nsec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   233
    CHECK_NULL_RETURN(attrs_st_ctime_nsec, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   234
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   235
#ifdef _DARWIN_FEATURE_64_BIT_INODE
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   236
    attrs_st_birthtime_sec = (*env)->GetFieldID(env, clazz, "st_birthtime_sec", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   237
    CHECK_NULL_RETURN(attrs_st_birthtime_sec, 0);
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   238
#endif
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   239
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   240
    clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileStoreAttributes");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   241
    CHECK_NULL_RETURN(clazz, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   242
    attrs_f_frsize = (*env)->GetFieldID(env, clazz, "f_frsize", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   243
    CHECK_NULL_RETURN(attrs_f_frsize, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   244
    attrs_f_blocks = (*env)->GetFieldID(env, clazz, "f_blocks", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   245
    CHECK_NULL_RETURN(attrs_f_blocks, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   246
    attrs_f_bfree = (*env)->GetFieldID(env, clazz, "f_bfree", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   247
    CHECK_NULL_RETURN(attrs_f_bfree, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   248
    attrs_f_bavail = (*env)->GetFieldID(env, clazz, "f_bavail", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   249
    CHECK_NULL_RETURN(attrs_f_bavail, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   250
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   251
    clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   252
    CHECK_NULL_RETURN(clazz, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   253
    entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   254
    CHECK_NULL_RETURN(entry_name, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   255
    entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   256
    CHECK_NULL_RETURN(entry_dir, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   257
    entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   258
    CHECK_NULL_RETURN(entry_fstype, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   259
    entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   260
    CHECK_NULL_RETURN(entry_options, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   261
    entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 22597
diff changeset
   262
    CHECK_NULL_RETURN(entry_dev, 0);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   263
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   264
    /* system calls that might not be available at run time */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   265
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   266
#if (defined(__solaris__) && defined(_LP64)) || defined(_ALLBSD_SOURCE)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   267
    /* Solaris 64-bit does not have openat64/fstatat64 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   268
    my_openat64_func = (openat64_func*)dlsym(RTLD_DEFAULT, "openat");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   269
    my_fstatat64_func = (fstatat64_func*)dlsym(RTLD_DEFAULT, "fstatat");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   270
#else
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   271
    my_openat64_func = (openat64_func*) dlsym(RTLD_DEFAULT, "openat64");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   272
    my_fstatat64_func = (fstatat64_func*) dlsym(RTLD_DEFAULT, "fstatat64");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   273
#endif
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   274
    my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   275
    my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   276
#ifndef _ALLBSD_SOURCE
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   277
    my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   278
    my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes");
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   279
#endif
57568
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   280
    my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens");
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
   281
#if defined(_AIX)
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
   282
    my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
   283
#else
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   284
    my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
42944
641db7ce5057 8171906: Changes for 8148023 break AIX build
clanger
parents: 40800
diff changeset
   285
#endif
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   286
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   287
#if defined(FSTATAT64_SYSCALL_AVAILABLE)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   288
    /* fstatat64 missing from glibc */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   289
    if (my_fstatat64_func == NULL)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   290
        my_fstatat64_func = (fstatat64_func*)&fstatat64_wrapper;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   291
#endif
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   292
57568
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   293
    /* supports futimes or futimesat, futimens, and/or lutimes */
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   294
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   295
#ifdef _ALLBSD_SOURCE
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   296
    capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   297
    capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   298
#else
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   299
    if (my_futimesat_func != NULL)
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   300
        capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   301
    if (my_lutimes_func != NULL)
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   302
        capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   303
#endif
57568
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   304
    if (my_futimens_func != NULL)
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   305
        capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMENS;
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   306
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   307
    /* supports openat, etc. */
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   308
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   309
    if (my_openat64_func != NULL &&  my_fstatat64_func != NULL &&
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   310
        my_unlinkat_func != NULL && my_renameat_func != NULL &&
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   311
        my_futimesat_func != NULL && my_fdopendir_func != NULL)
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   312
    {
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   313
        capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_OPENAT;
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   314
    }
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   315
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   316
    /* supports file birthtime */
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   317
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   318
#ifdef _DARWIN_FEATURE_64_BIT_INODE
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   319
    capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_BIRTHTIME;
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   320
#endif
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   321
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   322
    return capabilities;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   323
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   324
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   325
JNIEXPORT jbyteArray JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   326
Java_sun_nio_fs_UnixNativeDispatcher_getcwd(JNIEnv* env, jclass this) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   327
    jbyteArray result = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   328
    char buf[PATH_MAX+1];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   329
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   330
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   331
    char* cwd = getcwd(buf, sizeof(buf));
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   332
    if (cwd == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   333
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   334
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   335
        jsize len = (jsize)strlen(buf);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   336
        result = (*env)->NewByteArray(env, len);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   337
        if (result != NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   338
            (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)buf);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   339
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   340
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   341
    return result;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   342
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   343
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   344
JNIEXPORT jbyteArray
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   345
Java_sun_nio_fs_UnixNativeDispatcher_strerror(JNIEnv* env, jclass this, jint error)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   346
{
32846
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 31145
diff changeset
   347
    char tmpbuf[1024];
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   348
    jsize len;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   349
    jbyteArray bytes;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   350
32846
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 31145
diff changeset
   351
    getErrorString((int)errno, tmpbuf, sizeof(tmpbuf));
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 31145
diff changeset
   352
    len = strlen(tmpbuf);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   353
    bytes = (*env)->NewByteArray(env, len);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   354
    if (bytes != NULL) {
32846
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 31145
diff changeset
   355
        (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)tmpbuf);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   356
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   357
    return bytes;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   358
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   359
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   360
JNIEXPORT jint
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   361
Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   362
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   363
    int res = -1;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   364
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   365
    RESTARTABLE(dup((int)fd), res);
26209
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   366
    if (res == -1) {
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   367
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   368
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   369
    return (jint)res;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   370
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   371
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   372
JNIEXPORT jlong JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   373
Java_sun_nio_fs_UnixNativeDispatcher_fopen0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   374
    jlong pathAddress, jlong modeAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   375
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   376
    FILE* fp = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   377
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   378
    const char* mode = (const char*)jlong_to_ptr(modeAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   379
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   380
    do {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   381
        fp = fopen(path, mode);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   382
    } while (fp == NULL && errno == EINTR);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   383
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   384
    if (fp == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   385
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   386
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   387
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   388
    return ptr_to_jlong(fp);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   389
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   390
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   391
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   392
Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   393
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   394
    FILE* fp = jlong_to_ptr(stream);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   395
26209
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   396
    /* NOTE: fclose() wrapper is only used with read-only streams.
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   397
     * If it ever is used with write streams, it might be better to add
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   398
     * RESTARTABLE(fflush(fp)) before closing, to make sure the stream
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   399
     * is completely written even if fclose() failed.
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   400
     */
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   401
    if (fclose(fp) == EOF && errno != EINTR) {
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   402
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   403
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   404
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   405
58397
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   406
JNIEXPORT void JNICALL
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   407
Java_sun_nio_fs_UnixNativeDispatcher_rewind(JNIEnv* env, jclass this, jlong stream)
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   408
{
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   409
    FILE* fp = jlong_to_ptr(stream);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   410
    int saved_errno;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   411
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   412
    errno = 0;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   413
    rewind(fp);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   414
    saved_errno = errno;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   415
    if (ferror(fp)) {
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   416
        throwUnixException(env, saved_errno);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   417
    }
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   418
}
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   419
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   420
/**
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   421
 * This function returns line length without NUL terminator or -1 on EOF.
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   422
 */
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   423
JNIEXPORT jint JNICALL
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   424
Java_sun_nio_fs_UnixNativeDispatcher_getlinelen(JNIEnv* env, jclass this, jlong stream)
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   425
{
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   426
    FILE* fp = jlong_to_ptr(stream);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   427
    size_t lineSize = 0;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   428
    char * lineBuffer = NULL;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   429
    int saved_errno;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   430
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   431
    ssize_t res = getline(&lineBuffer, &lineSize, fp);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   432
    saved_errno = errno;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   433
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   434
    /* Should free lineBuffer no matter result, according to man page */
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   435
    if (lineBuffer != NULL)
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   436
        free(lineBuffer);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   437
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   438
    if (feof(fp))
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   439
        return -1;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   440
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   441
    /* On successfull return res >= 0, otherwise res is -1 */
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   442
    if (res == -1)
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   443
        throwUnixException(env, saved_errno);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   444
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   445
    if (res > INT_MAX)
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   446
        throwUnixException(env, EOVERFLOW);
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   447
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   448
    return (jint)res;
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   449
}
2d40e6a7ce8e 8229872: (fs) Increase buffer size used with getmntent
vkempik
parents: 57568
diff changeset
   450
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   451
JNIEXPORT jint JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   452
Java_sun_nio_fs_UnixNativeDispatcher_open0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   453
    jlong pathAddress, jint oflags, jint mode)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   454
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   455
    jint fd;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   456
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   457
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   458
    RESTARTABLE(open64(path, (int)oflags, (mode_t)mode), fd);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   459
    if (fd == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   460
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   461
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   462
    return fd;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   463
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   464
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   465
JNIEXPORT jint JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   466
Java_sun_nio_fs_UnixNativeDispatcher_openat0(JNIEnv* env, jclass this, jint dfd,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   467
    jlong pathAddress, jint oflags, jint mode)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   468
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   469
    jint fd;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   470
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   471
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   472
    if (my_openat64_func == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   473
        JNU_ThrowInternalError(env, "should not reach here");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   474
        return -1;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   475
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   476
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   477
    RESTARTABLE((*my_openat64_func)(dfd, path, (int)oflags, (mode_t)mode), fd);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   478
    if (fd == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   479
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   480
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   481
    return fd;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   482
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   483
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   484
JNIEXPORT void JNICALL
34537
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 32846
diff changeset
   485
Java_sun_nio_fs_UnixNativeDispatcher_close0(JNIEnv* env, jclass this, jint fd) {
51102
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   486
    int res;
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   487
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   488
#if defined(_AIX)
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   489
    /* AIX allows close to be restarted after EINTR */
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   490
    RESTARTABLE(close((int)fd), res);
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   491
#else
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   492
    res = close((int)fd);
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   493
#endif
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   494
    if (res == -1 && errno != EINTR) {
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   495
        throwUnixException(env, errno);
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   496
    }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   497
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   498
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   499
JNIEXPORT jint JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   500
Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   501
    jlong address, jint nbytes)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   502
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   503
    ssize_t n;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   504
    void* bufp = jlong_to_ptr(address);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   505
    RESTARTABLE(read((int)fd, bufp, (size_t)nbytes), n);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   506
    if (n == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   507
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   508
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   509
    return (jint)n;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   510
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   511
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   512
JNIEXPORT jint JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   513
Java_sun_nio_fs_UnixNativeDispatcher_write(JNIEnv* env, jclass this, jint fd,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   514
    jlong address, jint nbytes)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   515
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   516
    ssize_t n;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   517
    void* bufp = jlong_to_ptr(address);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   518
    RESTARTABLE(write((int)fd, bufp, (size_t)nbytes), n);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   519
    if (n == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   520
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   521
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   522
    return (jint)n;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   523
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   524
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   525
/**
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   526
 * Copy stat64 members into sun.nio.fs.UnixFileAttributes
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   527
 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   528
static void prepAttributes(JNIEnv* env, struct stat64* buf, jobject attrs) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   529
    (*env)->SetIntField(env, attrs, attrs_st_mode, (jint)buf->st_mode);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   530
    (*env)->SetLongField(env, attrs, attrs_st_ino, (jlong)buf->st_ino);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   531
    (*env)->SetLongField(env, attrs, attrs_st_dev, (jlong)buf->st_dev);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   532
    (*env)->SetLongField(env, attrs, attrs_st_rdev, (jlong)buf->st_rdev);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   533
    (*env)->SetIntField(env, attrs, attrs_st_nlink, (jint)buf->st_nlink);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   534
    (*env)->SetIntField(env, attrs, attrs_st_uid, (jint)buf->st_uid);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   535
    (*env)->SetIntField(env, attrs, attrs_st_gid, (jint)buf->st_gid);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   536
    (*env)->SetLongField(env, attrs, attrs_st_size, (jlong)buf->st_size);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   537
    (*env)->SetLongField(env, attrs, attrs_st_atime_sec, (jlong)buf->st_atime);
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   538
    (*env)->SetLongField(env, attrs, attrs_st_mtime_sec, (jlong)buf->st_mtime);
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   539
    (*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->st_ctime);
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   540
17154
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   541
#ifdef _DARWIN_FEATURE_64_BIT_INODE
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   542
    (*env)->SetLongField(env, attrs, attrs_st_birthtime_sec, (jlong)buf->st_birthtime);
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   543
#endif
e8991539c4d7 8011536: (fs) BasicFileAttributes.creationTime() should return birth time (mac)
alanb
parents: 15275
diff changeset
   544
48204
b27d2f69e552 8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
bpb
parents: 47216
diff changeset
   545
#ifndef MACOSX
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   546
    (*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->st_atim.tv_nsec);
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   547
    (*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->st_mtim.tv_nsec);
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   548
    (*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctim.tv_nsec);
48204
b27d2f69e552 8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
bpb
parents: 47216
diff changeset
   549
#else
b27d2f69e552 8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
bpb
parents: 47216
diff changeset
   550
    (*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->st_atimespec.tv_nsec);
b27d2f69e552 8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
bpb
parents: 47216
diff changeset
   551
    (*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->st_mtimespec.tv_nsec);
b27d2f69e552 8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
bpb
parents: 47216
diff changeset
   552
    (*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctimespec.tv_nsec);
15275
6e5b8f8361eb 6939260: (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
alanb
parents: 14342
diff changeset
   553
#endif
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   554
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   555
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   556
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   557
Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   558
    jlong pathAddress, jobject attrs)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   559
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   560
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   561
    struct stat64 buf;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   562
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   563
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   564
    RESTARTABLE(stat64(path, &buf), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   565
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   566
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   567
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   568
        prepAttributes(env, &buf, attrs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   569
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   570
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   571
37346
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   572
JNIEXPORT jint JNICALL
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   573
Java_sun_nio_fs_UnixNativeDispatcher_stat1(JNIEnv* env, jclass this, jlong pathAddress) {
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   574
    int err;
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   575
    struct stat64 buf;
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   576
    const char* path = (const char*)jlong_to_ptr(pathAddress);
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   577
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   578
    RESTARTABLE(stat64(path, &buf), err);
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   579
    if (err == -1) {
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   580
        return 0;
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   581
    } else {
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   582
        return (jint)buf.st_mode;
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   583
    }
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   584
}
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
   585
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   586
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   587
Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   588
    jlong pathAddress, jobject attrs)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   589
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   590
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   591
    struct stat64 buf;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   592
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   593
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   594
    RESTARTABLE(lstat64(path, &buf), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   595
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   596
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   597
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   598
        prepAttributes(env, &buf, attrs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   599
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   600
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   601
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   602
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   603
Java_sun_nio_fs_UnixNativeDispatcher_fstat(JNIEnv* env, jclass this, jint fd,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   604
    jobject attrs)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   605
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   606
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   607
    struct stat64 buf;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   608
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   609
    RESTARTABLE(fstat64((int)fd, &buf), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   610
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   611
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   612
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   613
        prepAttributes(env, &buf, attrs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   614
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   615
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   616
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   617
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   618
Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   619
    jlong pathAddress, jint flag, jobject attrs)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   620
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   621
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   622
    struct stat64 buf;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   623
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   624
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   625
    if (my_fstatat64_func == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   626
        JNU_ThrowInternalError(env, "should not reach here");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   627
        return;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   628
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   629
    RESTARTABLE((*my_fstatat64_func)((int)dfd, path, &buf, (int)flag), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   630
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   631
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   632
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   633
        prepAttributes(env, &buf, attrs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   634
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   635
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   636
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   637
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   638
Java_sun_nio_fs_UnixNativeDispatcher_chmod0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   639
    jlong pathAddress, jint mode)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   640
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   641
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   642
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   643
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   644
    RESTARTABLE(chmod(path, (mode_t)mode), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   645
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   646
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   647
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   648
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   649
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   650
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   651
Java_sun_nio_fs_UnixNativeDispatcher_fchmod(JNIEnv* env, jclass this, jint filedes,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   652
    jint mode)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   653
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   654
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   655
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   656
    RESTARTABLE(fchmod((int)filedes, (mode_t)mode), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   657
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   658
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   659
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   660
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   661
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   662
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   663
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   664
Java_sun_nio_fs_UnixNativeDispatcher_chown0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   665
    jlong pathAddress, jint uid, jint gid)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   666
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   667
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   668
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   669
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   670
    RESTARTABLE(chown(path, (uid_t)uid, (gid_t)gid), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   671
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   672
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   673
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   674
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   675
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   676
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   677
Java_sun_nio_fs_UnixNativeDispatcher_lchown0(JNIEnv* env, jclass this, jlong pathAddress, jint uid, jint gid)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   678
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   679
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   680
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   681
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   682
    RESTARTABLE(lchown(path, (uid_t)uid, (gid_t)gid), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   683
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   684
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   685
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   686
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   687
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   688
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   689
Java_sun_nio_fs_UnixNativeDispatcher_fchown(JNIEnv* env, jclass this, jint filedes, jint uid, jint gid)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   690
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   691
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   692
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   693
    RESTARTABLE(fchown(filedes, (uid_t)uid, (gid_t)gid), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   694
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   695
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   696
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   697
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   698
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   699
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   700
Java_sun_nio_fs_UnixNativeDispatcher_utimes0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   701
    jlong pathAddress, jlong accessTime, jlong modificationTime)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   702
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   703
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   704
    struct timeval times[2];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   705
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   706
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   707
    times[0].tv_sec = accessTime / 1000000;
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   708
    times[0].tv_usec = accessTime % 1000000;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   709
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   710
    times[1].tv_sec = modificationTime / 1000000;
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   711
    times[1].tv_usec = modificationTime % 1000000;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   712
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   713
    RESTARTABLE(utimes(path, &times[0]), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   714
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   715
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   716
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   717
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   718
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   719
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   720
Java_sun_nio_fs_UnixNativeDispatcher_futimes(JNIEnv* env, jclass this, jint filedes,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   721
    jlong accessTime, jlong modificationTime)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   722
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   723
    struct timeval times[2];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   724
    int err = 0;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   725
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   726
    times[0].tv_sec = accessTime / 1000000;
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   727
    times[0].tv_usec = accessTime % 1000000;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   728
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   729
    times[1].tv_sec = modificationTime / 1000000;
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   730
    times[1].tv_usec = modificationTime % 1000000;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   731
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   732
#ifdef _ALLBSD_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   733
    RESTARTABLE(futimes(filedes, &times[0]), err);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   734
#else
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   735
    if (my_futimesat_func == NULL) {
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   736
        JNU_ThrowInternalError(env, "my_futimesat_func is NULL");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   737
        return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   738
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   739
    RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   740
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   741
    if (err == -1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11833
diff changeset
   742
        throwUnixException(env, errno);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   743
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   744
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   745
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   746
JNIEXPORT void JNICALL
57568
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   747
Java_sun_nio_fs_UnixNativeDispatcher_futimens(JNIEnv* env, jclass this, jint filedes,
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   748
    jlong accessTime, jlong modificationTime)
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   749
{
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   750
    struct timespec times[2];
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   751
    int err = 0;
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   752
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   753
    times[0].tv_sec = accessTime / 1000000000;
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   754
    times[0].tv_nsec = accessTime % 1000000000;
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   755
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   756
    times[1].tv_sec = modificationTime / 1000000000;
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   757
    times[1].tv_nsec = modificationTime % 1000000000;
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   758
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   759
    if (my_futimens_func == NULL) {
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   760
        JNU_ThrowInternalError(env, "my_futimens_func is NULL");
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   761
        return;
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   762
    }
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   763
    RESTARTABLE((*my_futimens_func)(filedes, &times[0]), err);
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   764
    if (err == -1) {
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   765
        throwUnixException(env, errno);
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   766
    }
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   767
}
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   768
460ac76019f4 8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
bpb
parents: 54692
diff changeset
   769
JNIEXPORT void JNICALL
54692
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   770
Java_sun_nio_fs_UnixNativeDispatcher_lutimes0(JNIEnv* env, jclass this,
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   771
    jlong pathAddress, jlong accessTime, jlong modificationTime)
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   772
{
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   773
    int err;
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   774
    struct timeval times[2];
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   775
    const char* path = (const char*)jlong_to_ptr(pathAddress);
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   776
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   777
    times[0].tv_sec = accessTime / 1000000;
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   778
    times[0].tv_usec = accessTime % 1000000;
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   779
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   780
    times[1].tv_sec = modificationTime / 1000000;
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   781
    times[1].tv_usec = modificationTime % 1000000;
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   782
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   783
#ifdef _ALLBSD_SOURCE
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   784
    RESTARTABLE(lutimes(path, &times[0]), err);
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   785
#else
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   786
    if (my_lutimes_func == NULL) {
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   787
        JNU_ThrowInternalError(env, "my_lutimes_func is NULL");
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   788
        return;
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   789
    }
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   790
    RESTARTABLE((*my_lutimes_func)(path, &times[0]), err);
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   791
#endif
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   792
    if (err == -1) {
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   793
        throwUnixException(env, errno);
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   794
    }
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   795
}
22866513a80e 8220793: (fs) No support for changing modification time of symlink
bpb
parents: 52641
diff changeset
   796
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   797
JNIEXPORT jlong JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   798
Java_sun_nio_fs_UnixNativeDispatcher_opendir0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   799
    jlong pathAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   800
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   801
    DIR* dir;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   802
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   803
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   804
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   805
    dir = opendir(path);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   806
    if (dir == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   807
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   808
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   809
    return ptr_to_jlong(dir);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   810
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   811
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   812
JNIEXPORT jlong JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   813
Java_sun_nio_fs_UnixNativeDispatcher_fdopendir(JNIEnv* env, jclass this, int dfd) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   814
    DIR* dir;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   815
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   816
    if (my_fdopendir_func == NULL) {
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   817
        JNU_ThrowInternalError(env, "should not reach here");
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   818
        return (jlong)-1;
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   819
    }
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   820
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   821
    /* EINTR not listed as a possible error */
3328
c7e12ed68f87 6864319: (fs) Eliminate static dependency on fdopendir (lnx)
alanb
parents: 3065
diff changeset
   822
    dir = (*my_fdopendir_func)((int)dfd);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   823
    if (dir == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   824
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   825
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   826
    return ptr_to_jlong(dir);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   827
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   828
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   829
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   830
Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   831
    DIR* dirp = jlong_to_ptr(dir);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   832
26209
f7860e8501d8 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
igerasim
parents: 25859
diff changeset
   833
    if (closedir(dirp) == -1 && errno != EINTR) {
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   834
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   835
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   836
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   837
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   838
JNIEXPORT jbyteArray JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   839
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   840
    DIR* dirp = jlong_to_ptr(value);
51597
4c78f4fd8370 8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64
bpb
parents: 51309
diff changeset
   841
    struct dirent* ptr;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   842
51102
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   843
    errno = 0;
51597
4c78f4fd8370 8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64
bpb
parents: 51309
diff changeset
   844
    ptr = readdir(dirp);
51102
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   845
    if (ptr == NULL) {
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   846
        if (errno != 0) {
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   847
            throwUnixException(env, errno);
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   848
        }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   849
        return NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   850
    } else {
51102
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   851
        jsize len = strlen(ptr->d_name);
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   852
        jbyteArray bytes = (*env)->NewByteArray(env, len);
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   853
        if (bytes != NULL) {
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   854
            (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)(ptr->d_name));
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   855
        }
51102
90144bc10fe6 8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed
alanb
parents: 48204
diff changeset
   856
        return bytes;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   857
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   858
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   859
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   860
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   861
Java_sun_nio_fs_UnixNativeDispatcher_mkdir0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   862
    jlong pathAddress, jint mode)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   863
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   864
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   865
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   866
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   867
    if (mkdir(path, (mode_t)mode) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   868
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   869
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   870
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   871
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   872
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   873
Java_sun_nio_fs_UnixNativeDispatcher_rmdir0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   874
    jlong pathAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   875
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   876
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   877
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   878
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   879
    if (rmdir(path) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   880
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   881
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   882
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   883
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   884
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   885
Java_sun_nio_fs_UnixNativeDispatcher_link0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   886
    jlong existingAddress, jlong newAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   887
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   888
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   889
    const char* existing = (const char*)jlong_to_ptr(existingAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   890
    const char* newname = (const char*)jlong_to_ptr(newAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   891
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   892
    RESTARTABLE(link(existing, newname), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   893
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   894
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   895
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   896
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   897
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   898
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   899
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   900
Java_sun_nio_fs_UnixNativeDispatcher_unlink0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   901
    jlong pathAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   902
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   903
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   904
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   905
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   906
    if (unlink(path) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   907
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   908
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   909
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   910
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   911
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   912
Java_sun_nio_fs_UnixNativeDispatcher_unlinkat0(JNIEnv* env, jclass this, jint dfd,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   913
                                               jlong pathAddress, jint flags)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   914
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   915
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   916
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   917
    if (my_unlinkat_func == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   918
        JNU_ThrowInternalError(env, "should not reach here");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   919
        return;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   920
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   921
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   922
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   923
    if ((*my_unlinkat_func)((int)dfd, path, (int)flags) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   924
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   925
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   926
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   927
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   928
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   929
Java_sun_nio_fs_UnixNativeDispatcher_rename0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   930
    jlong fromAddress, jlong toAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   931
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   932
    const char* from = (const char*)jlong_to_ptr(fromAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   933
    const char* to = (const char*)jlong_to_ptr(toAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   934
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   935
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   936
    if (rename(from, to) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   937
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   938
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   939
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   940
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   941
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   942
Java_sun_nio_fs_UnixNativeDispatcher_renameat0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   943
    jint fromfd, jlong fromAddress, jint tofd, jlong toAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   944
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   945
    const char* from = (const char*)jlong_to_ptr(fromAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   946
    const char* to = (const char*)jlong_to_ptr(toAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   947
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   948
    if (my_renameat_func == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   949
        JNU_ThrowInternalError(env, "should not reach here");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   950
        return;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   951
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   952
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   953
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   954
    if ((*my_renameat_func)((int)fromfd, from, (int)tofd, to) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   955
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   956
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   957
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   958
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   959
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   960
Java_sun_nio_fs_UnixNativeDispatcher_symlink0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   961
    jlong targetAddress, jlong linkAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   962
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   963
    const char* target = (const char*)jlong_to_ptr(targetAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   964
    const char* link = (const char*)jlong_to_ptr(linkAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   965
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   966
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   967
    if (symlink(target, link) == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   968
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   969
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   970
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   971
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   972
JNIEXPORT jbyteArray JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   973
Java_sun_nio_fs_UnixNativeDispatcher_readlink0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   974
    jlong pathAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   975
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   976
    jbyteArray result = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   977
    char target[PATH_MAX+1];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   978
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   979
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   980
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   981
    int n = readlink(path, target, sizeof(target));
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   982
    if (n == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   983
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   984
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   985
        jsize len;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   986
        if (n == sizeof(target)) {
51309
13e2e64337be 8186766: UnixNativeDispatcher::readlink() may truncate overlong paths
bpb
parents: 51102
diff changeset
   987
            /* Traditionally readlink(2) should not return more than */
13e2e64337be 8186766: UnixNativeDispatcher::readlink() may truncate overlong paths
bpb
parents: 51102
diff changeset
   988
            /* PATH_MAX bytes (no terminating null byte is appended). */
13e2e64337be 8186766: UnixNativeDispatcher::readlink() may truncate overlong paths
bpb
parents: 51102
diff changeset
   989
            throwUnixException(env, ENAMETOOLONG);
13e2e64337be 8186766: UnixNativeDispatcher::readlink() may truncate overlong paths
bpb
parents: 51102
diff changeset
   990
            return NULL;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   991
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   992
        target[n] = '\0';
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   993
        len = (jsize)strlen(target);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   994
        result = (*env)->NewByteArray(env, len);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   995
        if (result != NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   996
            (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)target);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   997
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   998
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   999
    return result;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1000
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1001
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1002
JNIEXPORT jbyteArray JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1003
Java_sun_nio_fs_UnixNativeDispatcher_realpath0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1004
    jlong pathAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1005
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1006
    jbyteArray result = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1007
    char resolved[PATH_MAX+1];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1008
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1009
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1010
    /* EINTR not listed as a possible error */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1011
    if (realpath(path, resolved) == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1012
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1013
    } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1014
        jsize len = (jsize)strlen(resolved);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1015
        result = (*env)->NewByteArray(env, len);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1016
        if (result != NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1017
            (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)resolved);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1018
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1019
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1020
    return result;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1021
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1022
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1023
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1024
Java_sun_nio_fs_UnixNativeDispatcher_access0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1025
    jlong pathAddress, jint amode)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1026
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1027
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1028
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1029
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1030
    RESTARTABLE(access(path, (int)amode), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1031
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1032
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1033
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1034
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1035
37346
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1036
JNIEXPORT jboolean JNICALL
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1037
Java_sun_nio_fs_UnixNativeDispatcher_exists0(JNIEnv* env, jclass this, jlong pathAddress) {
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1038
    int err;
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1039
    const char* path = (const char*)jlong_to_ptr(pathAddress);
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1040
    RESTARTABLE(access(path, F_OK), err);
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1041
    return (err == 0) ? JNI_TRUE : JNI_FALSE;
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1042
}
931e55c1287d 8154077: (fs) Reduce number of file system classes loaded during startup
alanb
parents: 34537
diff changeset
  1043
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1044
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1045
Java_sun_nio_fs_UnixNativeDispatcher_statvfs0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1046
    jlong pathAddress, jobject attrs)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1047
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1048
    int err;
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1049
#ifdef MACOSX
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1050
    struct statfs buf;
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1051
#else
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1052
    struct statvfs64 buf;
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1053
#endif
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1054
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1055
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1056
#ifdef MACOSX
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1057
    RESTARTABLE(statfs(path, &buf), err);
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1058
#else
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1059
    RESTARTABLE(statvfs64(path, &buf), err);
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1060
#endif
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1061
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1062
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1063
    } else {
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1064
#ifdef _AIX
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1065
        /* AIX returns ULONG_MAX in buf.f_blocks for the /proc file system. */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1066
        /* This is too big for a Java signed long and fools various tests.  */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1067
        if (buf.f_blocks == ULONG_MAX) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1068
            buf.f_blocks = 0;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1069
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1070
        /* The number of free or available blocks can never exceed the total number of blocks */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1071
        if (buf.f_blocks == 0) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1072
            buf.f_bfree = 0;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1073
            buf.f_bavail = 0;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1074
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 17154
diff changeset
  1075
#endif
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1076
#ifdef MACOSX
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1077
        (*env)->SetLongField(env, attrs, attrs_f_frsize, long_to_jlong(buf.f_bsize));
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1078
#else
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1079
        (*env)->SetLongField(env, attrs, attrs_f_frsize, long_to_jlong(buf.f_frsize));
31145
af4093895e5f 8081843: (fs) FileStore.getTotalSpace returns unexpected results with >2TB file systems
bpb
parents: 26209
diff changeset
  1080
#endif
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1081
        (*env)->SetLongField(env, attrs, attrs_f_blocks, long_to_jlong(buf.f_blocks));
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1082
        (*env)->SetLongField(env, attrs, attrs_f_bfree,  long_to_jlong(buf.f_bfree));
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1083
        (*env)->SetLongField(env, attrs, attrs_f_bavail, long_to_jlong(buf.f_bavail));
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1084
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1085
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1086
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1087
JNIEXPORT jlong JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1088
Java_sun_nio_fs_UnixNativeDispatcher_pathconf0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1089
    jlong pathAddress, jint name)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1090
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1091
    long err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1092
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1093
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1094
    err = pathconf(path, (int)name);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1095
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1096
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1097
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1098
    return (jlong)err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1099
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1100
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1101
JNIEXPORT jlong JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1102
Java_sun_nio_fs_UnixNativeDispatcher_fpathconf(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1103
    jint fd, jint name)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1104
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1105
    long err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1106
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1107
    err = fpathconf((int)fd, (int)name);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1108
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1109
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1110
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1111
    return (jlong)err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1112
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1113
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1114
JNIEXPORT void JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1115
Java_sun_nio_fs_UnixNativeDispatcher_mknod0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1116
    jlong pathAddress, jint mode, jlong dev)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1117
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1118
    int err;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1119
    const char* path = (const char*)jlong_to_ptr(pathAddress);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1120
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1121
    RESTARTABLE(mknod(path, (mode_t)mode, (dev_t)dev), err);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1122
    if (err == -1) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1123
        throwUnixException(env, errno);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1124
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1125
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1126
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1127
JNIEXPORT jbyteArray JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1128
Java_sun_nio_fs_UnixNativeDispatcher_getpwuid(JNIEnv* env, jclass this, jint uid)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1129
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1130
    jbyteArray result = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1131
    int buflen;
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1132
    char* pwbuf;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1133
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1134
    /* allocate buffer for password record */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1135
    buflen = (int)sysconf(_SC_GETPW_R_SIZE_MAX);
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1136
    if (buflen == -1)
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1137
        buflen = ENT_BUF_SIZE;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1138
    pwbuf = (char*)malloc(buflen);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1139
    if (pwbuf == NULL) {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1140
        JNU_ThrowOutOfMemoryError(env, "native heap");
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1141
    } else {
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1142
        struct passwd pwent;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1143
        struct passwd* p = NULL;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1144
        int res = 0;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1145
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1146
        errno = 0;
40182
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
  1147
        RESTARTABLE(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen, &p), res);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1148
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1149
        if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1150
            /* not found or error */
9688
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1151
            if (errno == 0)
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1152
                errno = ENOENT;
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1153
            throwUnixException(env, errno);
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1154
        } else {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1155
            jsize len = strlen(p->pw_name);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1156
            result = (*env)->NewByteArray(env, len);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1157
            if (result != NULL) {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1158
                (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)(p->pw_name));
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1159
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1160
        }
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1161
        free(pwbuf);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1162
    }
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1163
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1164
    return result;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1165
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1166
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1167
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1168
JNIEXPORT jbyteArray JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1169
Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1170
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1171
    jbyteArray result = NULL;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1172
    int buflen;
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1173
    int retry;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1174
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1175
    /* initial size of buffer for group record */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1176
    buflen = (int)sysconf(_SC_GETGR_R_SIZE_MAX);
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1177
    if (buflen == -1)
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1178
        buflen = ENT_BUF_SIZE;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1179
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1180
    do {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1181
        struct group grent;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1182
        struct group* g = NULL;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1183
        int res = 0;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1184
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1185
        char* grbuf = (char*)malloc(buflen);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1186
        if (grbuf == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1187
            JNU_ThrowOutOfMemoryError(env, "native heap");
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1188
            return NULL;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1189
        }
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1190
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1191
        errno = 0;
40182
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
  1192
        RESTARTABLE(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen, &g), res);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1193
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1194
        retry = 0;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1195
        if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1196
            /* not found or error */
9688
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1197
            if (errno == ERANGE) {
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1198
                /* insufficient buffer size so need larger buffer */
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1199
                buflen += ENT_BUF_SIZE;
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1200
                retry = 1;
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1201
            } else {
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1202
                if (errno == 0)
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1203
                    errno = ENOENT;
2ef6a91ab99f 7043788: (fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database
alanb
parents: 9035
diff changeset
  1204
                throwUnixException(env, errno);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1205
            }
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1206
        } else {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1207
            jsize len = strlen(g->gr_name);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1208
            result = (*env)->NewByteArray(env, len);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1209
            if (result != NULL) {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1210
                (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)(g->gr_name));
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1211
            }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1212
        }
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1213
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1214
        free(grbuf);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1215
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1216
    } while (retry);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1217
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1218
    return result;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1219
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1220
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1221
JNIEXPORT jint JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1222
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1223
    jlong nameAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1224
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1225
    jint uid = -1;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1226
    int buflen;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1227
    char* pwbuf;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1228
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1229
    /* allocate buffer for password record */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1230
    buflen = (int)sysconf(_SC_GETPW_R_SIZE_MAX);
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1231
    if (buflen == -1)
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1232
        buflen = ENT_BUF_SIZE;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1233
    pwbuf = (char*)malloc(buflen);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1234
    if (pwbuf == NULL) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1235
        JNU_ThrowOutOfMemoryError(env, "native heap");
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1236
    } else {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1237
        struct passwd pwent;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1238
        struct passwd* p = NULL;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1239
        int res = 0;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1240
        const char* name = (const char*)jlong_to_ptr(nameAddress);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1241
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1242
        errno = 0;
40182
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
  1243
        RESTARTABLE(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen, &p), res);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1244
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1245
        if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1246
            /* not found or error */
11109
f93eafffdf23 7115070: (fs) lookupPrincipalByName/lookupPrincipalByGroupName should treat ESRCH as not found
ngmr
parents: 9688
diff changeset
  1247
            if (errno != 0 && errno != ENOENT && errno != ESRCH)
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1248
                throwUnixException(env, errno);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1249
        } else {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1250
            uid = p->pw_uid;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1251
        }
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1252
        free(pwbuf);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1253
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1254
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1255
    return uid;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1256
}
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1257
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1258
JNIEXPORT jint JNICALL
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1259
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1260
    jlong nameAddress)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1261
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1262
    jint gid = -1;
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1263
    int buflen, retry;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1264
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1265
    /* initial size of buffer for group record */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1266
    buflen = (int)sysconf(_SC_GETGR_R_SIZE_MAX);
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1267
    if (buflen == -1)
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1268
        buflen = ENT_BUF_SIZE;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1269
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1270
    do {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1271
        struct group grent;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1272
        struct group* g = NULL;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1273
        int res = 0;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1274
        char *grbuf;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1275
        const char* name = (const char*)jlong_to_ptr(nameAddress);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1276
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1277
        grbuf = (char*)malloc(buflen);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1278
        if (grbuf == NULL) {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1279
            JNU_ThrowOutOfMemoryError(env, "native heap");
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1280
            return -1;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1281
        }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1282
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1283
        errno = 0;
40182
1e16a8fd76ba 8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents: 37346
diff changeset
  1284
        RESTARTABLE(getgrnam_r(name, &grent, grbuf, (size_t)buflen, &g), res);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1285
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1286
        retry = 0;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1287
        if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1288
            /* not found or error */
11109
f93eafffdf23 7115070: (fs) lookupPrincipalByName/lookupPrincipalByGroupName should treat ESRCH as not found
ngmr
parents: 9688
diff changeset
  1289
            if (errno != 0 && errno != ENOENT && errno != ESRCH) {
8171
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1290
                if (errno == ERANGE) {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1291
                    /* insufficient buffer size so need larger buffer */
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1292
                    buflen += ENT_BUF_SIZE;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1293
                    retry = 1;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1294
                } else {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1295
                    throwUnixException(env, errno);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1296
                }
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1297
            }
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1298
        } else {
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1299
            gid = g->gr_gid;
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1300
        }
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1301
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1302
        free(grbuf);
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1303
71793028dd76 7014794: (file) lookupPrincipalByGroupName fails to find large NIS groups
alanb
parents: 5506
diff changeset
  1304
    } while (retry);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1305
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1306
    return gid;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
  1307
}