jdk/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c
changeset 13571 737b7b4bd73a
parent 5506 202f599c92aa
child 14342 8435a30053c1
equal deleted inserted replaced
13570:9ed2d9645e1c 13571:737b7b4bd73a
    26 #include "jni.h"
    26 #include "jni.h"
    27 #include "jni_util.h"
    27 #include "jni_util.h"
    28 #include "jvm.h"
    28 #include "jvm.h"
    29 #include "jlong.h"
    29 #include "jlong.h"
    30 
    30 
    31 #include <dlfcn.h>
    31 #include <strings.h>
    32 #include <errno.h>
    32 #include <errno.h>
    33 #include <sys/acl.h>
    33 #include <sys/acl.h>
       
    34 #include <sys/mnttab.h>
       
    35 #include <sys/mkdev.h>
       
    36 
       
    37 #include "jni.h"
    34 
    38 
    35 #include "sun_nio_fs_SolarisNativeDispatcher.h"
    39 #include "sun_nio_fs_SolarisNativeDispatcher.h"
       
    40 
       
    41 static jfieldID entry_name;
       
    42 static jfieldID entry_dir;
       
    43 static jfieldID entry_fstype;
       
    44 static jfieldID entry_options;
       
    45 static jfieldID entry_dev;
    36 
    46 
    37 static void throwUnixException(JNIEnv* env, int errnum) {
    47 static void throwUnixException(JNIEnv* env, int errnum) {
    38     jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
    48     jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
    39         "(I)V", errnum);
    49         "(I)V", errnum);
    40     if (x != NULL) {
    50     if (x != NULL) {
    42     }
    52     }
    43 }
    53 }
    44 
    54 
    45 JNIEXPORT void JNICALL
    55 JNIEXPORT void JNICALL
    46 Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {
    56 Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {
       
    57     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
       
    58     if (clazz == NULL)
       
    59         return;
       
    60 
       
    61     entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
       
    62     entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
       
    63     entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
       
    64     entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
       
    65     entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
    47 }
    66 }
    48 
    67 
    49 JNIEXPORT jint JNICALL
    68 JNIEXPORT jint JNICALL
    50 Java_sun_nio_fs_SolarisNativeDispatcher_facl(JNIEnv* env, jclass this, jint fd,
    69 Java_sun_nio_fs_SolarisNativeDispatcher_facl(JNIEnv* env, jclass this, jint fd,
    51     jint cmd, jint nentries, jlong address)
    70     jint cmd, jint nentries, jlong address)
    57     if (n == -1) {
    76     if (n == -1) {
    58         throwUnixException(env, errno);
    77         throwUnixException(env, errno);
    59     }
    78     }
    60     return (jint)n;
    79     return (jint)n;
    61 }
    80 }
       
    81 
       
    82 JNIEXPORT jint JNICALL
       
    83 Java_sun_nio_fs_SolarisNativeDispatcher_getextmntent(JNIEnv* env, jclass this,
       
    84     jlong value, jobject entry)
       
    85 {
       
    86     struct extmnttab ent;
       
    87     FILE* fp = jlong_to_ptr(value);
       
    88     jsize len;
       
    89     jbyteArray bytes;
       
    90     char* name;
       
    91     char* dir;
       
    92     char* fstype;
       
    93     char* options;
       
    94     dev_t dev;
       
    95 
       
    96     if (getextmntent(fp, &ent, 0))
       
    97         return -1;
       
    98     name = ent.mnt_special;
       
    99     dir = ent.mnt_mountp;
       
   100     fstype = ent.mnt_fstype;
       
   101     options = ent.mnt_mntopts;
       
   102     dev = makedev(ent.mnt_major, ent.mnt_minor);
       
   103     if (dev == NODEV) {
       
   104         throwUnixException(env, errno);
       
   105         return -1;
       
   106     }
       
   107 
       
   108     len = strlen(name);
       
   109     bytes = (*env)->NewByteArray(env, len);
       
   110     if (bytes == NULL)
       
   111         return -1;
       
   112     (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
       
   113     (*env)->SetObjectField(env, entry, entry_name, bytes);
       
   114 
       
   115     len = strlen(dir);
       
   116     bytes = (*env)->NewByteArray(env, len);
       
   117     if (bytes == NULL)
       
   118         return -1;
       
   119     (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
       
   120     (*env)->SetObjectField(env, entry, entry_dir, bytes);
       
   121 
       
   122     len = strlen(fstype);
       
   123     bytes = (*env)->NewByteArray(env, len);
       
   124     if (bytes == NULL)
       
   125         return -1;
       
   126     (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
       
   127     (*env)->SetObjectField(env, entry, entry_fstype, bytes);
       
   128 
       
   129     len = strlen(options);
       
   130     bytes = (*env)->NewByteArray(env, len);
       
   131     if (bytes == NULL)
       
   132         return -1;
       
   133     (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
       
   134     (*env)->SetObjectField(env, entry, entry_options, bytes);
       
   135 
       
   136     if (dev != 0)
       
   137         (*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
       
   138 
       
   139     return 0;
       
   140 }