Skip to content
Snippets Groups Projects
Commit f95f7f4a authored by Severin Gehwolf's avatar Severin Gehwolf
Browse files

8338696: (fs) BasicFileAttributes.creationTime() falls back to epoch if birth...

8338696: (fs) BasicFileAttributes.creationTime() falls back to epoch if birth time is unavailable (Linux)

Backport-of: c89a1c35bda9002ee687b3fa267f3ef9cba78b00
parent aa46c353
No related branches found
No related tags found
No related merge requests found
...@@ -154,9 +154,10 @@ struct my_statx ...@@ -154,9 +154,10 @@ struct my_statx
#define STATX_MODE 0x00000002U #define STATX_MODE 0x00000002U
#endif #endif
#ifndef STATX_ALL //
#define STATX_ALL (STATX_BTIME | STATX_BASIC_STATS) // STATX_ALL is deprecated; use a different name to avoid confusion.
#endif //
#define LOCAL_STATX_ALL (STATX_BASIC_STATS | STATX_BTIME)
#ifndef AT_FDCWD #ifndef AT_FDCWD
#define AT_FDCWD -100 #define AT_FDCWD -100
...@@ -632,8 +633,19 @@ static void copy_statx_attributes(JNIEnv* env, struct my_statx* buf, jobject att ...@@ -632,8 +633,19 @@ static void copy_statx_attributes(JNIEnv* env, struct my_statx* buf, jobject att
(*env)->SetLongField(env, attrs, attrs_st_atime_sec, (jlong)buf->stx_atime.tv_sec); (*env)->SetLongField(env, attrs, attrs_st_atime_sec, (jlong)buf->stx_atime.tv_sec);
(*env)->SetLongField(env, attrs, attrs_st_mtime_sec, (jlong)buf->stx_mtime.tv_sec); (*env)->SetLongField(env, attrs, attrs_st_mtime_sec, (jlong)buf->stx_mtime.tv_sec);
(*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->stx_ctime.tv_sec); (*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->stx_ctime.tv_sec);
(*env)->SetLongField(env, attrs, attrs_st_birthtime_sec, (jlong)buf->stx_btime.tv_sec); if ((buf->stx_mask & STATX_BTIME) != 0) {
(*env)->SetLongField(env, attrs, attrs_st_birthtime_nsec, (jlong)buf->stx_btime.tv_nsec); // Birth time was filled in so use it
(*env)->SetLongField(env, attrs, attrs_st_birthtime_sec,
(jlong)buf->stx_btime.tv_sec);
(*env)->SetLongField(env, attrs, attrs_st_birthtime_nsec,
(jlong)buf->stx_btime.tv_nsec);
} else {
// Birth time was not filled in: fall back to last modification time
(*env)->SetLongField(env, attrs, attrs_st_birthtime_sec,
(jlong)buf->stx_mtime.tv_sec);
(*env)->SetLongField(env, attrs, attrs_st_birthtime_nsec,
(jlong)buf->stx_mtime.tv_nsec);
}
(*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->stx_atime.tv_nsec); (*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->stx_atime.tv_nsec);
(*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->stx_mtime.tv_nsec); (*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->stx_mtime.tv_nsec);
(*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->stx_ctime.tv_nsec); (*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->stx_ctime.tv_nsec);
...@@ -687,7 +699,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this, ...@@ -687,7 +699,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this,
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
int flags = AT_STATX_SYNC_AS_STAT; int flags = AT_STATX_SYNC_AS_STAT;
unsigned int mask = STATX_ALL; unsigned int mask = LOCAL_STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// Prefer statx over stat64 on Linux if it's available // Prefer statx over stat64 on Linux if it's available
...@@ -748,7 +760,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this, ...@@ -748,7 +760,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this,
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
int flags = AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW; int flags = AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW;
unsigned int mask = STATX_ALL; unsigned int mask = LOCAL_STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// Prefer statx over stat64 on Linux if it's available // Prefer statx over stat64 on Linux if it's available
...@@ -779,7 +791,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstat(JNIEnv* env, jclass this, jint fd, ...@@ -779,7 +791,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstat(JNIEnv* env, jclass this, jint fd,
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
int flags = AT_EMPTY_PATH | AT_STATX_SYNC_AS_STAT; int flags = AT_EMPTY_PATH | AT_STATX_SYNC_AS_STAT;
unsigned int mask = STATX_ALL; unsigned int mask = LOCAL_STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// statx supports FD use via dirfd iff pathname is an empty string and the // statx supports FD use via dirfd iff pathname is an empty string and the
...@@ -812,7 +824,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd ...@@ -812,7 +824,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
int flags = AT_STATX_SYNC_AS_STAT; int flags = AT_STATX_SYNC_AS_STAT;
unsigned int mask = STATX_ALL; unsigned int mask = LOCAL_STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// Prefer statx over stat64 on Linux if it's available // Prefer statx over stat64 on Linux if it's available
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment