Skip to content

Commit 9f6d5b4

Browse files
dmlloydBrian Burkhalter
authored and
Brian Burkhalter
committedOct 28, 2024
8343020: (fs) Add support for SecureDirectoryStream on macOS
Reviewed-by: bpb, alanb
1 parent 1341b81 commit 9f6d5b4

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed
 

‎src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static boolean openatSupported() {
569569
}
570570

571571
/**
572-
* Supports futimes or futimesat
572+
* Supports futimes
573573
*/
574574
static boolean futimesSupported() {
575575
return (capabilities & SUPPORTS_FUTIMES) != 0;

‎src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ typedef int openat_func(int, const char *, int, ...);
204204
typedef int fstatat_func(int, const char *, struct stat *, int);
205205
typedef int unlinkat_func(int, const char*, int);
206206
typedef int renameat_func(int, const char*, int, const char*);
207-
typedef int futimesat_func(int, const char *, const struct timeval *);
207+
typedef int futimes_func(int, const struct timeval *);
208208
typedef int futimens_func(int, const struct timespec *);
209209
typedef int lutimes_func(const char *, const struct timeval *);
210210
typedef DIR* fdopendir_func(int);
@@ -217,7 +217,7 @@ static openat_func* my_openat_func = NULL;
217217
static fstatat_func* my_fstatat_func = NULL;
218218
static unlinkat_func* my_unlinkat_func = NULL;
219219
static renameat_func* my_renameat_func = NULL;
220-
static futimesat_func* my_futimesat_func = NULL;
220+
static futimes_func* my_futimes_func = NULL;
221221
static futimens_func* my_futimens_func = NULL;
222222
static lutimes_func* my_lutimes_func = NULL;
223223
static fdopendir_func* my_fdopendir_func = NULL;
@@ -363,8 +363,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
363363
/* system calls that might not be available at run time */
364364

365365
#if defined(_ALLBSD_SOURCE)
366-
my_openat_func = (openat_func*)dlsym(RTLD_DEFAULT, "openat");
367-
my_fstatat_func = (fstatat_func*)dlsym(RTLD_DEFAULT, "fstatat");
366+
my_openat_func = (openat_func*) openat;
367+
my_fstatat_func = (fstatat_func*) fstatat;
368368
#else
369369
// Make sure we link to the 64-bit version of the functions
370370
my_openat_func = (openat_func*) dlsym(RTLD_DEFAULT, "openat64");
@@ -373,22 +373,22 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
373373
my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
374374
my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
375375
#if defined(__linux__) && defined(__arm__)
376-
my_futimesat_func = (futimesat_func*) lookup_time_t_function("futimesat",
377-
"__futimesat64");
376+
my_futimes_func = (futimes_func*) lookup_time_t_function("futimes",
377+
"__futimes64");
378378
my_lutimes_func = (lutimes_func*) lookup_time_t_function("lutimes",
379379
"__lutimes64");
380380
my_futimens_func = (futimens_func*) lookup_time_t_function("futimens",
381381
"__futimens64");
382382
#else
383-
#ifndef _ALLBSD_SOURCE
384-
my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
383+
my_futimes_func = (futimes_func*) dlsym(RTLD_DEFAULT, "futimes");
385384
my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes");
386-
#endif
387385
my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens");
388386
#endif
389387
#if defined(_AIX)
390388
// Make sure we link to the 64-bit version of the function
391389
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
390+
#elif defined(_ALLBSD_SOURCE)
391+
my_fdopendir_func = (fdopendir_func*) fdopendir;
392392
#else
393393
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
394394
#endif
@@ -399,13 +399,13 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
399399
my_fstatat_func = (fstatat_func*)&fstatat_wrapper;
400400
#endif
401401

402-
/* supports futimes or futimesat, futimens, and/or lutimes */
402+
/* supports futimes, futimens, and/or lutimes */
403403

404404
#ifdef _ALLBSD_SOURCE
405405
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
406406
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
407407
#else
408-
if (my_futimesat_func != NULL)
408+
if (my_futimes_func != NULL)
409409
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
410410
if (my_lutimes_func != NULL)
411411
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
@@ -417,7 +417,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
417417

418418
if (my_openat_func != NULL && my_fstatat_func != NULL &&
419419
my_unlinkat_func != NULL && my_renameat_func != NULL &&
420-
my_futimesat_func != NULL && my_fdopendir_func != NULL)
420+
my_futimes_func != NULL && my_fdopendir_func != NULL)
421421
{
422422
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_OPENAT;
423423
}
@@ -914,11 +914,11 @@ Java_sun_nio_fs_UnixNativeDispatcher_futimes0(JNIEnv* env, jclass this, jint fil
914914
#ifdef _ALLBSD_SOURCE
915915
RESTARTABLE(futimes(filedes, &times[0]), err);
916916
#else
917-
if (my_futimesat_func == NULL) {
918-
JNU_ThrowInternalError(env, "my_futimesat_func is NULL");
917+
if (my_futimes_func == NULL) {
918+
JNU_ThrowInternalError(env, "my_futimes_func is NULL");
919919
return;
920920
}
921-
RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
921+
RESTARTABLE((*my_futimes_func)(filedes, &times[0]), err);
922922
#endif
923923
if (err == -1) {
924924
throwUnixException(env, errno);

‎test/jdk/java/nio/file/DirectoryStream/SecureDS.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
*/
2323

2424
/* @test
25-
* @bug 4313887 6838333
25+
* @bug 4313887 6838333 8343020
2626
* @summary Unit test for java.nio.file.SecureDirectoryStream
27+
* @requires (os.family == "linux" | os.family == "mac")
2728
* @library ..
2829
*/
2930

@@ -45,11 +46,7 @@ public static void main(String[] args) throws IOException {
4546
DirectoryStream<Path> stream = newDirectoryStream(dir);
4647
stream.close();
4748
if (!(stream instanceof SecureDirectoryStream)) {
48-
if (System.getProperty("os.name").equals("Linux"))
49-
throw new AssertionError(
50-
"SecureDirectoryStream not supported.");
51-
System.out.println("SecureDirectoryStream not supported.");
52-
return;
49+
throw new AssertionError("SecureDirectoryStream not supported.");
5350
}
5451

5552
supportsSymbolicLinks = TestUtil.supportsSymbolicLinks(dir);

0 commit comments

Comments
 (0)
Please sign in to comment.