Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c
32288 views
/*1* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni.h"26#include "jni_util.h"27#include "jvm.h"28#include "jlong.h"2930#include <strings.h>31#include <errno.h>32#include <sys/acl.h>33#include <sys/mnttab.h>34#include <sys/mkdev.h>3536#include "jni.h"3738#include "sun_nio_fs_SolarisNativeDispatcher.h"3940static jfieldID entry_name;41static jfieldID entry_dir;42static jfieldID entry_fstype;43static jfieldID entry_options;44static jfieldID entry_dev;4546static void throwUnixException(JNIEnv* env, int errnum) {47jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",48"(I)V", errnum);49if (x != NULL) {50(*env)->Throw(env, x);51}52}5354JNIEXPORT void JNICALL55Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {56clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");57CHECK_NULL(clazz);58entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");59CHECK_NULL(entry_name);60entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");61CHECK_NULL(entry_dir);62entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");63CHECK_NULL(entry_fstype);64entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");65CHECK_NULL(entry_options);66entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");67CHECK_NULL(entry_dev);68}6970JNIEXPORT jint JNICALL71Java_sun_nio_fs_SolarisNativeDispatcher_facl(JNIEnv* env, jclass this, jint fd,72jint cmd, jint nentries, jlong address)73{74void* aclbufp = jlong_to_ptr(address);75int n = -1;7677n = facl((int)fd, (int)cmd, (int)nentries, aclbufp);78if (n == -1) {79throwUnixException(env, errno);80}81return (jint)n;82}8384JNIEXPORT jint JNICALL85Java_sun_nio_fs_SolarisNativeDispatcher_getextmntent(JNIEnv* env, jclass this,86jlong value, jobject entry)87{88struct extmnttab ent;89FILE* fp = jlong_to_ptr(value);90jsize len;91jbyteArray bytes;92char* name;93char* dir;94char* fstype;95char* options;96dev_t dev;9798if (getextmntent(fp, &ent, 0))99return -1;100name = ent.mnt_special;101dir = ent.mnt_mountp;102fstype = ent.mnt_fstype;103options = ent.mnt_mntopts;104dev = makedev(ent.mnt_major, ent.mnt_minor);105if (dev == NODEV) {106throwUnixException(env, errno);107return -1;108}109110len = strlen(name);111bytes = (*env)->NewByteArray(env, len);112if (bytes == NULL)113return -1;114(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);115(*env)->SetObjectField(env, entry, entry_name, bytes);116117len = strlen(dir);118bytes = (*env)->NewByteArray(env, len);119if (bytes == NULL)120return -1;121(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);122(*env)->SetObjectField(env, entry, entry_dir, bytes);123124len = strlen(fstype);125bytes = (*env)->NewByteArray(env, len);126if (bytes == NULL)127return -1;128(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);129(*env)->SetObjectField(env, entry, entry_fstype, bytes);130131len = strlen(options);132bytes = (*env)->NewByteArray(env, len);133if (bytes == NULL)134return -1;135(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);136(*env)->SetObjectField(env, entry, entry_options, bytes);137138if (dev != 0)139(*env)->SetLongField(env, entry, entry_dev, (jlong)dev);140141return 0;142}143144145