src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
changeset 57568 460ac76019f4
parent 54692 22866513a80e
child 58397 2d40e6a7ce8e
equal deleted inserted replaced
57567:b000362a89a0 57568:460ac76019f4
   141 typedef int openat64_func(int, const char *, int, ...);
   141 typedef int openat64_func(int, const char *, int, ...);
   142 typedef int fstatat64_func(int, const char *, struct stat64 *, int);
   142 typedef int fstatat64_func(int, const char *, struct stat64 *, int);
   143 typedef int unlinkat_func(int, const char*, int);
   143 typedef int unlinkat_func(int, const char*, int);
   144 typedef int renameat_func(int, const char*, int, const char*);
   144 typedef int renameat_func(int, const char*, int, const char*);
   145 typedef int futimesat_func(int, const char *, const struct timeval *);
   145 typedef int futimesat_func(int, const char *, const struct timeval *);
       
   146 typedef int futimens_func(int, const struct timespec *);
   146 typedef int lutimes_func(const char *, const struct timeval *);
   147 typedef int lutimes_func(const char *, const struct timeval *);
   147 typedef DIR* fdopendir_func(int);
   148 typedef DIR* fdopendir_func(int);
   148 
   149 
   149 static openat64_func* my_openat64_func = NULL;
   150 static openat64_func* my_openat64_func = NULL;
   150 static fstatat64_func* my_fstatat64_func = NULL;
   151 static fstatat64_func* my_fstatat64_func = NULL;
   151 static unlinkat_func* my_unlinkat_func = NULL;
   152 static unlinkat_func* my_unlinkat_func = NULL;
   152 static renameat_func* my_renameat_func = NULL;
   153 static renameat_func* my_renameat_func = NULL;
   153 static futimesat_func* my_futimesat_func = NULL;
   154 static futimesat_func* my_futimesat_func = NULL;
       
   155 static futimens_func* my_futimens_func = NULL;
   154 static lutimes_func* my_lutimes_func = NULL;
   156 static lutimes_func* my_lutimes_func = NULL;
   155 static fdopendir_func* my_fdopendir_func = NULL;
   157 static fdopendir_func* my_fdopendir_func = NULL;
   156 
   158 
   157 /**
   159 /**
   158  * fstatat missing from glibc on Linux.
   160  * fstatat missing from glibc on Linux.
   273     my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
   275     my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
   274 #ifndef _ALLBSD_SOURCE
   276 #ifndef _ALLBSD_SOURCE
   275     my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
   277     my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
   276     my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes");
   278     my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes");
   277 #endif
   279 #endif
       
   280     my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens");
   278 #if defined(_AIX)
   281 #if defined(_AIX)
   279     my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
   282     my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
   280 #else
   283 #else
   281     my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
   284     my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
   282 #endif
   285 #endif
   285     /* fstatat64 missing from glibc */
   288     /* fstatat64 missing from glibc */
   286     if (my_fstatat64_func == NULL)
   289     if (my_fstatat64_func == NULL)
   287         my_fstatat64_func = (fstatat64_func*)&fstatat64_wrapper;
   290         my_fstatat64_func = (fstatat64_func*)&fstatat64_wrapper;
   288 #endif
   291 #endif
   289 
   292 
   290     /* supports futimes or futimesat and/or lutimes */
   293     /* supports futimes or futimesat, futimens, and/or lutimes */
   291 
   294 
   292 #ifdef _ALLBSD_SOURCE
   295 #ifdef _ALLBSD_SOURCE
   293     capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
   296     capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
   294     capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
   297     capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
   295 #else
   298 #else
   296     if (my_futimesat_func != NULL)
   299     if (my_futimesat_func != NULL)
   297         capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
   300         capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
   298     if (my_lutimes_func != NULL)
   301     if (my_lutimes_func != NULL)
   299         capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
   302         capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
   300 #endif
   303 #endif
       
   304     if (my_futimens_func != NULL)
       
   305         capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMENS;
   301 
   306 
   302     /* supports openat, etc. */
   307     /* supports openat, etc. */
   303 
   308 
   304     if (my_openat64_func != NULL &&  my_fstatat64_func != NULL &&
   309     if (my_openat64_func != NULL &&  my_fstatat64_func != NULL &&
   305         my_unlinkat_func != NULL && my_renameat_func != NULL &&
   310         my_unlinkat_func != NULL && my_renameat_func != NULL &&
   686         JNU_ThrowInternalError(env, "my_futimesat_func is NULL");
   691         JNU_ThrowInternalError(env, "my_futimesat_func is NULL");
   687         return;
   692         return;
   688     }
   693     }
   689     RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
   694     RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
   690 #endif
   695 #endif
       
   696     if (err == -1) {
       
   697         throwUnixException(env, errno);
       
   698     }
       
   699 }
       
   700 
       
   701 JNIEXPORT void JNICALL
       
   702 Java_sun_nio_fs_UnixNativeDispatcher_futimens(JNIEnv* env, jclass this, jint filedes,
       
   703     jlong accessTime, jlong modificationTime)
       
   704 {
       
   705     struct timespec times[2];
       
   706     int err = 0;
       
   707 
       
   708     times[0].tv_sec = accessTime / 1000000000;
       
   709     times[0].tv_nsec = accessTime % 1000000000;
       
   710 
       
   711     times[1].tv_sec = modificationTime / 1000000000;
       
   712     times[1].tv_nsec = modificationTime % 1000000000;
       
   713 
       
   714     if (my_futimens_func == NULL) {
       
   715         JNU_ThrowInternalError(env, "my_futimens_func is NULL");
       
   716         return;
       
   717     }
       
   718     RESTARTABLE((*my_futimens_func)(filedes, &times[0]), err);
   691     if (err == -1) {
   719     if (err == -1) {
   692         throwUnixException(env, errno);
   720         throwUnixException(env, errno);
   693     }
   721     }
   694 }
   722 }
   695 
   723