< prev index next >

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

Print this page
rev 53271 : 8216981: Per thread IO statistics in JFR


  61 #endif
  62 
  63 #ifdef _ALLBSD_SOURCE
  64 #include <string.h>
  65 
  66 #define stat64 stat
  67 #ifndef MACOSX
  68 #define statvfs64 statvfs
  69 #endif
  70 
  71 #define open64 open
  72 #define fstat64 fstat
  73 #define lstat64 lstat
  74 #define readdir64 readdir
  75 #endif
  76 
  77 #include "jni.h"
  78 #include "jni_util.h"
  79 #include "jlong.h"
  80 


  81 #include "sun_nio_fs_UnixNativeDispatcher.h"
  82 
  83 #if defined(_AIX)
  84   #define DIR DIR64
  85   #define dirent dirent64
  86   #define opendir opendir64
  87   #define readdir readdir64
  88   #define closedir closedir64
  89 #endif
  90 
  91 /**
  92  * Size of password or group entry when not available via sysconf
  93  */
  94 #define ENT_BUF_SIZE   1024
  95 
  96 #define RESTARTABLE(_cmd, _result) do { \
  97   do { \
  98     _result = _cmd; \
  99   } while((_result == -1) && (errno == EINTR)); \
 100 } while(0)


 431     /* AIX allows close to be restarted after EINTR */
 432     RESTARTABLE(close((int)fd), res);
 433 #else
 434     res = close((int)fd);
 435 #endif
 436     if (res == -1 && errno != EINTR) {
 437         throwUnixException(env, errno);
 438     }
 439 }
 440 
 441 JNIEXPORT jint JNICALL
 442 Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
 443     jlong address, jint nbytes)
 444 {
 445     ssize_t n;
 446     void* bufp = jlong_to_ptr(address);
 447     RESTARTABLE(read((int)fd, bufp, (size_t)nbytes), n);
 448     if (n == -1) {
 449         throwUnixException(env, errno);
 450     }





 451     return (jint)n;
 452 }
 453 
 454 JNIEXPORT jint JNICALL
 455 Java_sun_nio_fs_UnixNativeDispatcher_write(JNIEnv* env, jclass this, jint fd,
 456     jlong address, jint nbytes)
 457 {
 458     ssize_t n;
 459     void* bufp = jlong_to_ptr(address);
 460     RESTARTABLE(write((int)fd, bufp, (size_t)nbytes), n);
 461     if (n == -1) {
 462         throwUnixException(env, errno);
 463     }





 464     return (jint)n;
 465 }
 466 
 467 /**
 468  * Copy stat64 members into sun.nio.fs.UnixFileAttributes
 469  */
 470 static void prepAttributes(JNIEnv* env, struct stat64* buf, jobject attrs) {
 471     (*env)->SetIntField(env, attrs, attrs_st_mode, (jint)buf->st_mode);
 472     (*env)->SetLongField(env, attrs, attrs_st_ino, (jlong)buf->st_ino);
 473     (*env)->SetLongField(env, attrs, attrs_st_dev, (jlong)buf->st_dev);
 474     (*env)->SetLongField(env, attrs, attrs_st_rdev, (jlong)buf->st_rdev);
 475     (*env)->SetIntField(env, attrs, attrs_st_nlink, (jint)buf->st_nlink);
 476     (*env)->SetIntField(env, attrs, attrs_st_uid, (jint)buf->st_uid);
 477     (*env)->SetIntField(env, attrs, attrs_st_gid, (jint)buf->st_gid);
 478     (*env)->SetLongField(env, attrs, attrs_st_size, (jlong)buf->st_size);
 479     (*env)->SetLongField(env, attrs, attrs_st_atime_sec, (jlong)buf->st_atime);
 480     (*env)->SetLongField(env, attrs, attrs_st_mtime_sec, (jlong)buf->st_mtime);
 481     (*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->st_ctime);
 482 
 483 #ifdef _DARWIN_FEATURE_64_BIT_INODE




  61 #endif
  62 
  63 #ifdef _ALLBSD_SOURCE
  64 #include <string.h>
  65 
  66 #define stat64 stat
  67 #ifndef MACOSX
  68 #define statvfs64 statvfs
  69 #endif
  70 
  71 #define open64 open
  72 #define fstat64 fstat
  73 #define lstat64 lstat
  74 #define readdir64 readdir
  75 #endif
  76 
  77 #include "jni.h"
  78 #include "jni_util.h"
  79 #include "jlong.h"
  80 
  81 #include "jvm.h"
  82 
  83 #include "sun_nio_fs_UnixNativeDispatcher.h"
  84 
  85 #if defined(_AIX)
  86   #define DIR DIR64
  87   #define dirent dirent64
  88   #define opendir opendir64
  89   #define readdir readdir64
  90   #define closedir closedir64
  91 #endif
  92 
  93 /**
  94  * Size of password or group entry when not available via sysconf
  95  */
  96 #define ENT_BUF_SIZE   1024
  97 
  98 #define RESTARTABLE(_cmd, _result) do { \
  99   do { \
 100     _result = _cmd; \
 101   } while((_result == -1) && (errno == EINTR)); \
 102 } while(0)


 433     /* AIX allows close to be restarted after EINTR */
 434     RESTARTABLE(close((int)fd), res);
 435 #else
 436     res = close((int)fd);
 437 #endif
 438     if (res == -1 && errno != EINTR) {
 439         throwUnixException(env, errno);
 440     }
 441 }
 442 
 443 JNIEXPORT jint JNICALL
 444 Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
 445     jlong address, jint nbytes)
 446 {
 447     ssize_t n;
 448     void* bufp = jlong_to_ptr(address);
 449     RESTARTABLE(read((int)fd, bufp, (size_t)nbytes), n);
 450     if (n == -1) {
 451         throwUnixException(env, errno);
 452     }
 453 
 454     if (n > 0) {
 455       JVM_callFileReadBytes(env, (jint) n);
 456     }
 457 
 458     return (jint)n;
 459 }
 460 
 461 JNIEXPORT jint JNICALL
 462 Java_sun_nio_fs_UnixNativeDispatcher_write(JNIEnv* env, jclass this, jint fd,
 463     jlong address, jint nbytes)
 464 {
 465     ssize_t n;
 466     void* bufp = jlong_to_ptr(address);
 467     RESTARTABLE(write((int)fd, bufp, (size_t)nbytes), n);
 468     if (n == -1) {
 469         throwUnixException(env, errno);
 470     }
 471 
 472     if (n > 0) {
 473       JVM_callFileWriteBytes(env, (jint) n);
 474     }
 475 
 476     return (jint)n;
 477 }
 478 
 479 /**
 480  * Copy stat64 members into sun.nio.fs.UnixFileAttributes
 481  */
 482 static void prepAttributes(JNIEnv* env, struct stat64* buf, jobject attrs) {
 483     (*env)->SetIntField(env, attrs, attrs_st_mode, (jint)buf->st_mode);
 484     (*env)->SetLongField(env, attrs, attrs_st_ino, (jlong)buf->st_ino);
 485     (*env)->SetLongField(env, attrs, attrs_st_dev, (jlong)buf->st_dev);
 486     (*env)->SetLongField(env, attrs, attrs_st_rdev, (jlong)buf->st_rdev);
 487     (*env)->SetIntField(env, attrs, attrs_st_nlink, (jint)buf->st_nlink);
 488     (*env)->SetIntField(env, attrs, attrs_st_uid, (jint)buf->st_uid);
 489     (*env)->SetIntField(env, attrs, attrs_st_gid, (jint)buf->st_gid);
 490     (*env)->SetLongField(env, attrs, attrs_st_size, (jlong)buf->st_size);
 491     (*env)->SetLongField(env, attrs, attrs_st_atime_sec, (jlong)buf->st_atime);
 492     (*env)->SetLongField(env, attrs, attrs_st_mtime_sec, (jlong)buf->st_mtime);
 493     (*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->st_ctime);
 494 
 495 #ifdef _DARWIN_FEATURE_64_BIT_INODE


< prev index next >