This commit is contained in:
Alan Bateman 2008-06-07 16:11:57 +01:00
commit e44b665297
8 changed files with 76 additions and 173 deletions

View File

@ -43,7 +43,7 @@ class NativeThreadSet {
// //
int add() { int add() {
long th = NativeThread.current(); long th = NativeThread.current();
if (th <= 0) if (th == -1)
return -1; return -1;
synchronized (this) { synchronized (this) {
int start = 0; int start = 0;

View File

@ -34,14 +34,14 @@ package sun.nio.ch;
// upon which Java threads are built, and defines a simple signal mechanism // upon which Java threads are built, and defines a simple signal mechanism
// that can be used to release a native thread from a blocking I/O operation. // that can be used to release a native thread from a blocking I/O operation.
// On systems that do not require this type of signalling, the current() method // On systems that do not require this type of signalling, the current() method
// always returns zero and the signal(long) method has no effect. // always returns -1 and the signal(long) method has no effect.
class NativeThread { class NativeThread {
// Returns an opaque token representing the native thread underlying the // Returns an opaque token representing the native thread underlying the
// invoking Java thread. On systems that do not require signalling, this // invoking Java thread. On systems that do not require signalling, this
// method always returns zero. // method always returns -1.
// //
static native long current(); static native long current();

View File

@ -58,70 +58,6 @@ Java_java_io_UnixFileSystem_initIDs(JNIEnv *env, jclass cls)
"path", "Ljava/lang/String;"); "path", "Ljava/lang/String;");
} }
/* -- Large-file support -- */
/* LINUX_FIXME: ifdef __solaris__ here is wrong. We need to move the
* definition of stat64 into a solaris_largefile.h and create a
* linux_largefile.h with a good stat64 structure to compile on
* glibc2.0 based systems.
*/
#if defined(__solaris__) && !defined(_LFS_LARGEFILE) || !_LFS_LARGEFILE
/* The stat64 structure must be provided for systems without large-file support
(e.g., Solaris 2.5.1). These definitions are copied from the Solaris 2.6
<sys/stat.h> and <sys/types.h> files.
*/
typedef longlong_t off64_t; /* offsets within files */
typedef u_longlong_t ino64_t; /* expanded inode type */
typedef longlong_t blkcnt64_t; /* count of file blocks */
struct stat64 {
dev_t st_dev;
long st_pad1[3];
ino64_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
long st_pad2[2];
off64_t st_size;
timestruc_t st_atim;
timestruc_t st_mtim;
timestruc_t st_ctim;
long st_blksize;
blkcnt64_t st_blocks;
char st_fstype[_ST_FSTYPSZ];
long st_pad4[8];
};
#endif /* !_LFS_LARGEFILE */
typedef int (*STAT64)(const char *, struct stat64 *);
#if defined(__linux__) && defined(_LARGEFILE64_SOURCE)
static STAT64 stat64_ptr = &stat64;
#else
static STAT64 stat64_ptr = NULL;
#endif
#ifndef __linux__
#ifdef __GNUC__
static void init64IO(void) __attribute__((constructor));
#else
#pragma init(init64IO)
#endif
#endif
static void init64IO(void) {
void *handle = dlopen(0, RTLD_LAZY);
stat64_ptr = (STAT64) dlsym(handle, "_stat64");
dlclose(handle);
}
/* -- Path operations -- */ /* -- Path operations -- */
extern int canonicalize(char *path, const char *out, int len); extern int canonicalize(char *path, const char *out, int len);
@ -151,18 +87,10 @@ Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
static jboolean static jboolean
statMode(const char *path, int *mode) statMode(const char *path, int *mode)
{ {
if (stat64_ptr) { struct stat64 sb;
struct stat64 sb; if (stat64(path, &sb) == 0) {
if (((*stat64_ptr)(path, &sb)) == 0) { *mode = sb.st_mode;
*mode = sb.st_mode; return JNI_TRUE;
return JNI_TRUE;
}
} else {
struct stat sb;
if (stat(path, &sb) == 0) {
*mode = sb.st_mode;
return JNI_TRUE;
}
} }
return JNI_FALSE; return JNI_FALSE;
} }
@ -266,16 +194,9 @@ Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
jlong rv = 0; jlong rv = 0;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
if (stat64_ptr) { struct stat64 sb;
struct stat64 sb; if (stat64(path, &sb) == 0) {
if (((*stat64_ptr)(path, &sb)) == 0) { rv = 1000 * (jlong)sb.st_mtime;
rv = 1000 * (jlong)sb.st_mtime;
}
} else {
struct stat sb;
if (stat(path, &sb) == 0) {
rv = 1000 * (jlong)sb.st_mtime;
}
} }
} END_PLATFORM_STRING(env, path); } END_PLATFORM_STRING(env, path);
return rv; return rv;
@ -289,16 +210,9 @@ Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
jlong rv = 0; jlong rv = 0;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
if (stat64_ptr) { struct stat64 sb;
struct stat64 sb; if (stat64(path, &sb) == 0) {
if (((*stat64_ptr)(path, &sb)) == 0) { rv = sb.st_size;
rv = sb.st_size;
}
} else {
struct stat sb;
if (stat(path, &sb) == 0) {
rv = sb.st_size;
}
} }
} END_PLATFORM_STRING(env, path); } END_PLATFORM_STRING(env, path);
return rv; return rv;
@ -447,15 +361,6 @@ Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this,
return rv; return rv;
} }
/* Bug in solaris /usr/include/sys/time.h? */
#ifdef __solaris__
extern int utimes(const char *, const struct timeval *);
#elif defined(__linux___)
extern int utimes(const char *, struct timeval *);
#endif
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this, Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
jobject file, jlong time) jobject file, jlong time)
@ -463,47 +368,22 @@ Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
jboolean rv = JNI_FALSE; jboolean rv = JNI_FALSE;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct timeval tv[2]; struct stat64 sb;
#ifdef __solaris__
timestruc_t ts;
if (stat64_ptr) { if (stat64(path, &sb) == 0) {
struct stat64 sb; struct timeval tv[2];
if (((*stat64_ptr)(path, &sb)) == 0)
ts = sb.st_atim; /* Preserve access time */
else tv[0].tv_sec = sb.st_atime;
goto error; tv[0].tv_usec = 0;
} else {
struct stat sb; /* Change last-modified time */
if (stat(path, &sb) == 0) tv[1].tv_sec = time / 1000;
ts = sb.st_atim; tv[1].tv_usec = (time % 1000) * 1000;
else
goto error; if (utimes(path, tv) == 0)
rv = JNI_TRUE;
} }
#endif
/* Preserve access time */
#ifdef __linux__
struct stat sb;
if (stat(path, &sb) == 0) {
tv[0].tv_sec = sb.st_atime;
tv[0].tv_usec = 0;
}
#else
tv[0].tv_sec = ts.tv_sec;
tv[0].tv_usec = ts.tv_nsec / 1000;
#endif
/* Change last-modified time */
tv[1].tv_sec = time / 1000;
tv[1].tv_usec = (time % 1000) * 1000;
if (utimes(path, tv) >= 0)
rv = JNI_TRUE;
error: ;
} END_PLATFORM_STRING(env, path); } END_PLATFORM_STRING(env, path);
return rv; return rv;

View File

@ -31,7 +31,7 @@ package sun.nio.ch;
class NativeThread { class NativeThread {
static long current() { return 0; } static long current() { return -1; }
static void signal(long nt) { } static void signal(long nt) { }

View File

@ -229,26 +229,29 @@ JNIEXPORT jboolean
JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this, JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this,
jobject file, jint access) jobject file, jint access)
{ {
jboolean rv = JNI_FALSE; DWORD attr;
int mode;
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
if (pathbuf == NULL) if (pathbuf == NULL)
return JNI_FALSE; return JNI_FALSE;
attr = GetFileAttributesW(pathbuf);
free(pathbuf);
if (attr == INVALID_FILE_ATTRIBUTES)
return JNI_FALSE;
switch (access) { switch (access) {
case java_io_FileSystem_ACCESS_READ: case java_io_FileSystem_ACCESS_READ:
case java_io_FileSystem_ACCESS_EXECUTE: case java_io_FileSystem_ACCESS_EXECUTE:
mode = 4; return JNI_TRUE;
break;
case java_io_FileSystem_ACCESS_WRITE: case java_io_FileSystem_ACCESS_WRITE:
mode = 2; /* Read-only attribute ignored on directories */
break; if ((attr & FILE_ATTRIBUTE_DIRECTORY) ||
default: assert(0); (attr & FILE_ATTRIBUTE_READONLY) == 0)
return JNI_TRUE;
else
return JNI_FALSE;
default:
assert(0);
return JNI_FALSE;
} }
if (_waccess(pathbuf, mode) == 0) {
rv = JNI_TRUE;
}
free(pathbuf);
return rv;
} }
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL

View File

@ -22,11 +22,13 @@
*/ */
/* @test /* @test
@bug 4091757 @bug 4091757 6652379
@summary Basic test for setLastModified method @summary Basic test for setLastModified method
*/ */
import java.io.*; import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class SetLastModified { public class SetLastModified {
@ -95,13 +97,24 @@ public class SetLastModified {
if (f.setLastModified(nt)) if (f.setLastModified(nt))
throw new Exception("Succeeded on non-existent file: " + f); throw new Exception("Succeeded on non-existent file: " + f);
OutputStream o = new FileOutputStream(f); // set/check last modified on files of size 1, 1GB+1, 2GB+1, ..
o.write('x'); // On Windows we only test with a tiny file as that platform doesn't
o.close(); // support sparse files by default and so the test takes too long.
ot = f.lastModified(); final long G = 1024L * 1024L * 1024L;
if (!f.setLastModified(nt)) final long MAX_POSITION =
throw new Exception("setLastModified failed on file: " + f); System.getProperty("os.name").startsWith("Windows") ? 0L : 3L*G;
ck(f, nt, f.lastModified()); long pos = 0L;
while (pos <= MAX_POSITION) {
FileChannel fc = new FileOutputStream(f).getChannel();
fc.position(pos).write(ByteBuffer.wrap("x".getBytes()));
fc.close();
ot = f.lastModified();
System.out.format("check with file size: %d\n", f.length());
if (!f.setLastModified(nt))
throw new Exception("setLastModified failed on file: " + f);
ck(f, nt, f.lastModified());
pos += G;
}
if (!f.delete()) throw new Exception("Can't delete test file " + f); if (!f.delete()) throw new Exception("Can't delete test file " + f);
if (!d2.delete()) throw new Exception("Can't delete test directory " + d2); if (!d2.delete()) throw new Exception("Can't delete test directory " + d2);

View File

@ -22,7 +22,7 @@
*/ */
/* @test /* @test
@bug 4091757 @bug 4091757 4939819
@summary Basic test for setReadOnly method @summary Basic test for setReadOnly method
*/ */
@ -59,8 +59,15 @@ public class SetReadOnly {
throw new Exception(f + ": Cannot create directory"); throw new Exception(f + ": Cannot create directory");
if (!f.setReadOnly()) if (!f.setReadOnly())
throw new Exception(f + ": Failed on directory"); throw new Exception(f + ": Failed on directory");
if (f.canWrite()) // The readonly attribute on Windows does not make a folder read-only
throw new Exception(f + ": Directory is writeable"); if (System.getProperty("os.name").startsWith("Windows")) {
if (!f.canWrite())
throw new Exception(f + ": Directory is not writeable");
} else {
if (f.canWrite())
throw new Exception(f + ": Directory is writeable");
}
if (!f.delete()) if (!f.delete())
throw new Exception(f + ": Cannot delete directory"); throw new Exception(f + ": Cannot delete directory");

View File

@ -22,7 +22,7 @@
*/ */
/* @test /* @test
* @bug 4460583 4470470 4840199 6419424 * @bug 4460583 4470470 4840199 6419424 6710579 6596323
* @summary Comprehensive test of asynchronous closing and interruption * @summary Comprehensive test of asynchronous closing and interruption
* @author Mark Reinhold * @author Mark Reinhold
*/ */
@ -582,7 +582,7 @@ public class AsyncCloseAndInterrupt {
log.println("WARNING: transferFrom/close not tested"); log.println("WARNING: transferFrom/close not tested");
return; return;
} }
if ((op == TRANSFER_TO) && TestUtil.onSolaris()) { if ((op == TRANSFER_TO) && !TestUtil.onWindows()) {
log.println("WARNING: transferTo/close not tested"); log.println("WARNING: transferTo/close not tested");
return; return;
} }