7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code

Reviewed-by: andrew
This commit is contained in:
Alan Bateman 2012-08-16 11:14:42 +01:00
parent 9573fdd192
commit 3261af24cf
18 changed files with 201 additions and 136 deletions

View File

@ -277,7 +277,6 @@ FILES_java += \
sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \
sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \
\
sun/nio/fs/GnomeFileTypeDetector.java \
sun/nio/fs/BsdFileStore.java \
sun/nio/fs/BsdFileSystem.java \
sun/nio/fs/BsdFileSystemProvider.java \
@ -312,7 +311,6 @@ FILES_c += \
UnixAsynchronousServerSocketChannelImpl.c \
UnixAsynchronousSocketChannelImpl.c \
\
GnomeFileTypeDetector.c \
BsdNativeDispatcher.c \
MacOSXNativeDispatcher.c \
UnixCopyFile.c \
@ -329,7 +327,6 @@ FILES_export += \
sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \
sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \
\
sun/nio/fs/GnomeFileTypeDetector.java \
sun/nio/fs/BsdNativeDispatcher.java \
sun/nio/fs/UnixCopyFile.java \
sun/nio/fs/UnixNativeDispatcher.java

View File

@ -121,10 +121,6 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_BsdNativeDispatcher_getfsstat;
Java_sun_nio_fs_BsdNativeDispatcher_fsstatEntry;
Java_sun_nio_fs_BsdNativeDispatcher_endfsstat;
Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio;
Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio;
Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs;
Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs;
Java_sun_nio_fs_UnixNativeDispatcher_init;
Java_sun_nio_fs_UnixNativeDispatcher_getcwd;
Java_sun_nio_fs_UnixNativeDispatcher_strerror;
@ -170,7 +166,6 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_UnixNativeDispatcher_getgrgid;
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getextmntent;
Java_sun_nio_fs_UnixCopyFile_transfer;
handleSocketError;

View File

@ -143,6 +143,7 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_LinuxNativeDispatcher_fsetxattr0;
Java_sun_nio_fs_LinuxNativeDispatcher_fremovexattr0;
Java_sun_nio_fs_LinuxNativeDispatcher_setmntent0;
Java_sun_nio_fs_LinuxNativeDispatcher_getmntent;
Java_sun_nio_fs_LinuxNativeDispatcher_endmntent;
Java_sun_nio_fs_UnixNativeDispatcher_init;
Java_sun_nio_fs_UnixNativeDispatcher_getcwd;
@ -189,7 +190,6 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_UnixNativeDispatcher_getgrgid;
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getextmntent;
Java_sun_nio_fs_UnixCopyFile_transfer;
handleSocketError;

View File

@ -169,10 +169,10 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_UnixNativeDispatcher_getgrgid;
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getextmntent;
Java_sun_nio_fs_UnixCopyFile_transfer;
Java_sun_nio_fs_SolarisNativeDispatcher_init;
Java_sun_nio_fs_SolarisNativeDispatcher_facl;
Java_sun_nio_fs_SolarisNativeDispatcher_getextmntent;
Java_sun_nio_fs_SolarisWatchService_init;
Java_sun_nio_fs_SolarisWatchService_portCreate;
Java_sun_nio_fs_SolarisWatchService_portAssociate;

View File

@ -25,12 +25,15 @@
package sun.nio.fs;
import java.nio.file.FileSystems;
import java.nio.file.spi.FileTypeDetector;
import java.nio.file.spi.FileSystemProvider;
public class DefaultFileTypeDetector {
private DefaultFileTypeDetector() { }
public static FileTypeDetector create() {
return new GnomeFileTypeDetector();
FileSystemProvider provider = FileSystems.getDefault().provider();
return ((UnixFileSystemProvider)provider).getFileTypeDetector();
}
}

View File

@ -82,7 +82,7 @@ class LinuxFileSystem extends UnixFileSystem {
try {
for (;;) {
UnixMountEntry entry = new UnixMountEntry();
int res = getextmntent(fp, entry);
int res = getmntent(fp, entry);
if (res < 0)
break;
entries.add(entry);

View File

@ -27,6 +27,7 @@ package sun.nio.fs;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.nio.file.spi.FileTypeDetector;
import java.io.IOException;
/**
@ -96,4 +97,9 @@ public class LinuxFileSystemProvider extends UnixFileSystemProvider {
return super.readAttributes(file, type, options);
}
}
@Override
FileTypeDetector getFileTypeDetector() {
return new GnomeFileTypeDetector();
}
}

View File

@ -51,9 +51,15 @@ class LinuxNativeDispatcher extends UnixNativeDispatcher {
private static native long setmntent0(long pathAddress, long typeAddress)
throws UnixException;
/**
* int endmntent(FILE* filep);
*/
/**
* int getmntent(FILE *fp, struct mnttab *mp, int len);
*/
static native int getmntent(long fp, UnixMountEntry entry)
throws UnixException;
/**
* int endmntent(FILE* filep);
*/
static native void endmntent(long stream) throws UnixException;
/**
@ -90,7 +96,6 @@ class LinuxNativeDispatcher extends UnixNativeDispatcher {
private static native void fsetxattr0(int filedes, long nameAddress,
long valueAdddress, int valueLen) throws UnixException;
/**
* fremovexattr(int filedes, const char *name);
*/

View File

@ -30,7 +30,7 @@ import java.io.IOException;
import java.util.*;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
import static sun.nio.fs.UnixNativeDispatcher.*;
import static sun.nio.fs.SolarisNativeDispatcher.*;
/**
* Solaris implementation of FileSystem

View File

@ -27,6 +27,7 @@ package sun.nio.fs;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.nio.file.spi.FileTypeDetector;
import java.io.IOException;
/**
@ -79,4 +80,9 @@ public class SolarisFileSystemProvider extends UnixFileSystemProvider {
Util.followLinks(options));
return super.getFileAttributeView(obj, name, options);
}
@Override
FileTypeDetector getFileTypeDetector() {
return new GnomeFileTypeDetector();
}
}

View File

@ -35,6 +35,12 @@ import java.security.PrivilegedAction;
class SolarisNativeDispatcher extends UnixNativeDispatcher {
private SolarisNativeDispatcher() { }
/**
* int getextmntent(FILE *fp, struct extmnttab *mp, int len);
*/
static native int getextmntent(long fp, UnixMountEntry entry)
throws UnixException;
/**
* int facl(int filedes, int cmd, int nentries, void aclbufp)
*/

View File

@ -27,6 +27,7 @@ package sun.nio.fs;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.nio.file.spi.FileTypeDetector;
import java.nio.channels.*;
import java.net.URI;
import java.util.concurrent.ExecutorService;
@ -495,4 +496,17 @@ public abstract class UnixFileSystemProvider
return null; // keep compiler happy
}
}
/**
* Returns a {@code FileTypeDetector} for this platform.
*/
FileTypeDetector getFileTypeDetector() {
return new AbstractFileTypeDetector() {
@Override
public String implProbeContentType(Path file) {
return null;
}
};
}
}

View File

@ -497,11 +497,6 @@ class UnixNativeDispatcher {
}
private static native int getgrnam0(long nameAddress) throws UnixException;
/**
* int getextmntent(FILE *fp, struct extmnttab *mp, int len);
*/
static native int getextmntent(long fp, UnixMountEntry entry) throws UnixException;
/**
* statvfs(const char* path, struct statvfs *buf)
*/

View File

@ -46,8 +46,6 @@ static jfieldID entry_name;
static jfieldID entry_dir;
static jfieldID entry_fstype;
static jfieldID entry_options;
static jfieldID entry_dev;
struct fsstat_iter {
struct statfs *buf;
@ -81,7 +79,6 @@ Java_sun_nio_fs_BsdNativeDispatcher_initIDs(JNIEnv* env, jclass this)
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
}
JNIEXPORT jlong JNICALL
@ -160,7 +157,6 @@ Java_sun_nio_fs_BsdNativeDispatcher_fsstatEntry(JNIEnv* env, jclass this,
options="ro";
else
options="";
dev = 0;
iter->pos++;
@ -192,9 +188,6 @@ Java_sun_nio_fs_BsdNativeDispatcher_fsstatEntry(JNIEnv* env, jclass this,
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
(*env)->SetObjectField(env, entry, entry_options, bytes);
if (dev != 0)
(*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
return 0;
}
@ -208,3 +201,4 @@ Java_sun_nio_fs_BsdNativeDispatcher_endfsstat(JNIEnv* env, jclass this, jlong va
free(iter);
}
}

View File

@ -35,7 +35,7 @@
#include <strings.h>
#endif
#if defined(__linux__) || defined(__APPLE__)
#if defined(__linux__)
#include <string.h>
#endif

View File

@ -29,6 +29,7 @@
#include "jlong.h"
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <errno.h>
#include <mntent.h>
@ -45,6 +46,11 @@ fsetxattr_func* my_fsetxattr_func = NULL;
fremovexattr_func* my_fremovexattr_func = NULL;
flistxattr_func* my_flistxattr_func = NULL;
static jfieldID entry_name;
static jfieldID entry_dir;
static jfieldID entry_fstype;
static jfieldID entry_options;
static void throwUnixException(JNIEnv* env, int errnum) {
jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
"(I)V", errnum);
@ -60,6 +66,15 @@ Java_sun_nio_fs_LinuxNativeDispatcher_init(JNIEnv *env, jclass clazz)
my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr");
my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr");
my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr");
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL)
return;
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
}
JNIEXPORT jint JNICALL
@ -151,6 +166,61 @@ Java_sun_nio_fs_LinuxNativeDispatcher_setmntent0(JNIEnv* env, jclass this, jlong
return ptr_to_jlong(fp);
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_LinuxNativeDispatcher_getmntent(JNIEnv* env, jclass this,
jlong value, jobject entry)
{
struct mntent ent;
char buf[1024];
int buflen = sizeof(buf);
struct mntent* m;
FILE* fp = jlong_to_ptr(value);
jsize len;
jbyteArray bytes;
char* name;
char* dir;
char* fstype;
char* options;
m = getmntent_r(fp, &ent, (char*)&buf, buflen);
if (m == NULL)
return -1;
name = m->mnt_fsname;
dir = m->mnt_dir;
fstype = m->mnt_type;
options = m->mnt_opts;
len = strlen(name);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
(*env)->SetObjectField(env, entry, entry_name, bytes);
len = strlen(dir);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
(*env)->SetObjectField(env, entry, entry_dir, bytes);
len = strlen(fstype);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
(*env)->SetObjectField(env, entry, entry_fstype, bytes);
len = strlen(options);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
(*env)->SetObjectField(env, entry, entry_options, bytes);
return 0;
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_LinuxNativeDispatcher_endmntent(JNIEnv* env, jclass this, jlong stream)
{

View File

@ -28,12 +28,22 @@
#include "jvm.h"
#include "jlong.h"
#include <dlfcn.h>
#include <strings.h>
#include <errno.h>
#include <sys/acl.h>
#include <sys/mnttab.h>
#include <sys/mkdev.h>
#include "jni.h"
#include "sun_nio_fs_SolarisNativeDispatcher.h"
static jfieldID entry_name;
static jfieldID entry_dir;
static jfieldID entry_fstype;
static jfieldID entry_options;
static jfieldID entry_dev;
static void throwUnixException(JNIEnv* env, int errnum) {
jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
"(I)V", errnum);
@ -44,6 +54,15 @@ static void throwUnixException(JNIEnv* env, int errnum) {
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL)
return;
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
}
JNIEXPORT jint JNICALL
@ -59,3 +78,63 @@ Java_sun_nio_fs_SolarisNativeDispatcher_facl(JNIEnv* env, jclass this, jint fd,
}
return (jint)n;
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_SolarisNativeDispatcher_getextmntent(JNIEnv* env, jclass this,
jlong value, jobject entry)
{
struct extmnttab ent;
FILE* fp = jlong_to_ptr(value);
jsize len;
jbyteArray bytes;
char* name;
char* dir;
char* fstype;
char* options;
dev_t dev;
if (getextmntent(fp, &ent, 0))
return -1;
name = ent.mnt_special;
dir = ent.mnt_mountp;
fstype = ent.mnt_fstype;
options = ent.mnt_mntopts;
dev = makedev(ent.mnt_major, ent.mnt_minor);
if (dev == NODEV) {
throwUnixException(env, errno);
return -1;
}
len = strlen(name);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
(*env)->SetObjectField(env, entry, entry_name, bytes);
len = strlen(dir);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
(*env)->SetObjectField(env, entry, entry_dir, bytes);
len = strlen(fstype);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
(*env)->SetObjectField(env, entry, entry_fstype, bytes);
len = strlen(options);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
(*env)->SetObjectField(env, entry, entry_options, bytes);
if (dev != 0)
(*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
return 0;
}

View File

@ -40,13 +40,10 @@
#ifdef __solaris__
#include <strings.h>
#include <sys/mnttab.h>
#include <sys/mkdev.h>
#endif
#ifdef __linux__
#include <string.h>
#include <mntent.h>
#endif
#ifdef _ALLBSD_SOURCE
@ -1083,105 +1080,3 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
return gid;
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_getextmntent(JNIEnv* env, jclass this,
jlong value, jobject entry)
{
#ifdef __solaris__
struct extmnttab ent;
#elif defined(_ALLBSD_SOURCE)
char buf[1024];
char *str;
char *last;
#else
struct mntent ent;
char buf[1024];
int buflen = sizeof(buf);
struct mntent* m;
#endif
FILE* fp = jlong_to_ptr(value);
jsize len;
jbyteArray bytes;
char* name;
char* dir;
char* fstype;
char* options;
dev_t dev;
#ifdef __solaris__
if (getextmntent(fp, &ent, 0))
return -1;
name = ent.mnt_special;
dir = ent.mnt_mountp;
fstype = ent.mnt_fstype;
options = ent.mnt_mntopts;
dev = makedev(ent.mnt_major, ent.mnt_minor);
if (dev == NODEV) {
/* possible bug on Solaris 8 and 9 */
throwUnixException(env, errno);
return -1;
}
#elif defined(_ALLBSD_SOURCE)
again:
if (!(str = fgets(buf, sizeof(buf), fp)))
return -1;
name = strtok_r(str, " \t\n", &last);
if (name == NULL)
return -1;
// skip comments
if (*name == '#')
goto again;
dir = strtok_r((char *)NULL, " \t\n", &last);
fstype = strtok_r((char *)NULL, " \t\n", &last);
options = strtok_r((char *)NULL, " \t\n", &last);
if (options == NULL)
return -1;
dev = 0;
#else
m = getmntent_r(fp, &ent, (char*)&buf, buflen);
if (m == NULL)
return -1;
name = m->mnt_fsname;
dir = m->mnt_dir;
fstype = m->mnt_type;
options = m->mnt_opts;
dev = 0;
#endif
len = strlen(name);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
(*env)->SetObjectField(env, entry, entry_name, bytes);
len = strlen(dir);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
(*env)->SetObjectField(env, entry, entry_dir, bytes);
len = strlen(fstype);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
(*env)->SetObjectField(env, entry, entry_fstype, bytes);
len = strlen(options);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
(*env)->SetObjectField(env, entry, entry_options, bytes);
if (dev != 0)
(*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
return 0;
}