mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8341282: (fs) Move creation time fallback logic to Java layer (Linux)
Reviewed-by: sgehwolf, alanb
This commit is contained in:
parent
f1ea57f06a
commit
3ee94e040a
2 changed files with 19 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -58,6 +58,7 @@ class UnixFileAttributes
|
|||
private long st_ctime_nsec;
|
||||
private long st_birthtime_sec;
|
||||
private long st_birthtime_nsec;
|
||||
private boolean birthtime_available;
|
||||
|
||||
// created lazily
|
||||
private volatile UserPrincipal owner;
|
||||
|
@ -163,10 +164,10 @@ class UnixFileAttributes
|
|||
|
||||
@Override
|
||||
public FileTime creationTime() {
|
||||
if (UnixNativeDispatcher.birthtimeSupported()) {
|
||||
if (UnixNativeDispatcher.birthtimeSupported() && birthtime_available) {
|
||||
return toFileTime(st_birthtime_sec, st_birthtime_nsec);
|
||||
} else {
|
||||
// return last modified when birth time not supported
|
||||
// return last modified when birth time unsupported or unavailable
|
||||
return lastModifiedTime();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,6 +184,7 @@ static jfieldID attrs_st_birthtime_sec;
|
|||
#if defined(__linux__) // Linux has nsec granularity if supported
|
||||
static jfieldID attrs_st_birthtime_nsec;
|
||||
#endif
|
||||
static jfieldID attrs_birthtime_available;
|
||||
|
||||
static jfieldID attrs_f_frsize;
|
||||
static jfieldID attrs_f_blocks;
|
||||
|
@ -332,6 +333,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
|
|||
attrs_st_birthtime_nsec = (*env)->GetFieldID(env, clazz, "st_birthtime_nsec", "J");
|
||||
CHECK_NULL_RETURN(attrs_st_birthtime_nsec, 0);
|
||||
#endif
|
||||
attrs_birthtime_available = (*env)->GetFieldID(env, clazz, "birthtime_available", "Z");
|
||||
CHECK_NULL_RETURN(attrs_birthtime_available, 0);
|
||||
|
||||
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileStoreAttributes");
|
||||
CHECK_NULL_RETURN(clazz, 0);
|
||||
|
@ -620,19 +623,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_mtime_sec, (jlong)buf->stx_mtime.tv_sec);
|
||||
(*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->stx_ctime.tv_sec);
|
||||
|
||||
// Check mask for birth time and set flag accordingly. The birth time is
|
||||
// filled in if and only if the STATX_BTIME bit is set in the mask.
|
||||
// Although the statx system call might be supported by the operating
|
||||
// system, the birth time is not necessarily supported by the file system.
|
||||
if ((buf->stx_mask & STATX_BTIME) != 0) {
|
||||
// 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);
|
||||
(*env)->SetBooleanField(env, attrs, attrs_birthtime_available, (jboolean)JNI_TRUE);
|
||||
(*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)->SetBooleanField(env, attrs, attrs_birthtime_available, (jboolean)JNI_FALSE);
|
||||
}
|
||||
|
||||
(*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_ctime_nsec, (jlong)buf->stx_ctime.tv_nsec);
|
||||
|
@ -661,7 +664,9 @@ static void copy_stat_attributes(JNIEnv* env, struct stat* buf, jobject attrs) {
|
|||
(*env)->SetLongField(env, attrs, attrs_st_ctime_sec, (jlong)buf->st_ctime);
|
||||
|
||||
#ifdef _DARWIN_FEATURE_64_BIT_INODE
|
||||
// birthtime_available defaults to 'false'; on Darwin, it is always true
|
||||
(*env)->SetLongField(env, attrs, attrs_st_birthtime_sec, (jlong)buf->st_birthtime);
|
||||
(*env)->SetBooleanField(env, attrs, attrs_birthtime_available, (jboolean)JNI_TRUE);
|
||||
// rely on default value of 0 for st_birthtime_nsec field on Darwin
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue