Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/LinuxNativeDispatcher.java
32288 views
/*1* Copyright (c) 2008, 2019, 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*/2425package sun.nio.fs;2627import java.security.AccessController;28import java.security.PrivilegedAction;2930/**31* Linux specific system calls.32*/3334class LinuxNativeDispatcher extends UnixNativeDispatcher {35private LinuxNativeDispatcher() { }3637/**38* FILE *setmntent(const char *filename, const char *type);39*/40static long setmntent(byte[] filename, byte[] type) throws UnixException {41NativeBuffer pathBuffer = NativeBuffers.asNativeBuffer(filename);42NativeBuffer typeBuffer = NativeBuffers.asNativeBuffer(type);43try {44return setmntent0(pathBuffer.address(), typeBuffer.address());45} finally {46typeBuffer.release();47pathBuffer.release();48}49}50private static native long setmntent0(long pathAddress, long typeAddress)51throws UnixException;5253/**54* int getmntent(FILE *fp, struct mnttab *mp, int len);55*/5657static int getmntent(long fp, UnixMountEntry entry, int buflen) throws UnixException {58NativeBuffer buffer = NativeBuffers.getNativeBuffer(buflen);59try {60return getmntent0(fp, entry, buffer.address(), buflen);61} finally {62buffer.release();63}64}6566static native int getmntent0(long fp, UnixMountEntry entry, long buffer, int bufLen)67throws UnixException;6869/**70* int endmntent(FILE* filep);71*/72static native void endmntent(long stream) throws UnixException;7374/**75* ssize_t getline(char **lineptr, size_t *n, FILE *stream);76*/77static native int getlinelen(long stream) throws UnixException;7879/**80* ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size);81*/82static int fgetxattr(int filedes, byte[] name, long valueAddress,83int valueLen) throws UnixException84{85NativeBuffer buffer = NativeBuffers.asNativeBuffer(name);86try {87return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen);88} finally {89buffer.release();90}91}9293private static native int fgetxattr0(int filedes, long nameAddress,94long valueAdddress, int valueLen) throws UnixException;9596/**97* fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags);98*/99static void fsetxattr(int filedes, byte[] name, long valueAddress,100int valueLen) throws UnixException101{102NativeBuffer buffer = NativeBuffers.asNativeBuffer(name);103try {104fsetxattr0(filedes, buffer.address(), valueAddress, valueLen);105} finally {106buffer.release();107}108}109110private static native void fsetxattr0(int filedes, long nameAddress,111long valueAdddress, int valueLen) throws UnixException;112113/**114* fremovexattr(int filedes, const char *name);115*/116static void fremovexattr(int filedes, byte[] name) throws UnixException {117NativeBuffer buffer = NativeBuffers.asNativeBuffer(name);118try {119fremovexattr0(filedes, buffer.address());120} finally {121buffer.release();122}123}124125private static native void fremovexattr0(int filedes, long nameAddress)126throws UnixException;127128/**129* size_t flistxattr(int filedes, const char *list, size_t size)130*/131static native int flistxattr(int filedes, long listAddress, int size)132throws UnixException;133134// initialize135private static native void init();136137static {138AccessController.doPrivileged(new PrivilegedAction<Void>() {139public Void run() {140System.loadLibrary("nio");141return null;142}});143init();144}145}146147148