RFR: 8316304: (fs) Add support for BasicFileAttributes.creationTime() for Linux

Severin Gehwolf sgehwolf at openjdk.org
Thu Sep 21 17:41:39 UTC 2023


On Wed, 20 Sep 2023 12:19:57 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>>> One other thing to try is to rename prepAttributes to something like copyStatAttributes and add a copyStatXAttributes that copies the fields from the statx structure. That goes with calling stat or statx, never both.
>> 
>> OK. Just to clarify: if `statx` is available it should use it and retrieve all needed attributes from the statx call (if all attributes can be retrieved that way). Otherwise use `stat64/lstat` as before (with birth time missing).
>
>> OK. Just to clarify: if `statx` is available it should use it and retrieve all needed attributes from the statx call (if all attributes can be retrieved that way). Otherwise use `stat64/lstat` as before (with birth time missing).
> 
> Yes, I think we should think of statx as an extended stat.

@AlanBateman @gnu-andrew Thanks for your input! Here is an updated patch, now using LinuxFileSystemProvider and the logic to use `statx` is now in the linux specific directory trees. The fallback code is unchanged (using `UnixNativeDispatcher`). This version never uses both `stat64` and `statx`. It only uses `statx` if its available and uses the older `stat64` otherwise. 

On a Linux system that has `statx` (using `LastModified` from the bug):

# grep test.txt strace_out.log 
execve("./jdk-22.0.0+0/bin/java", ["./jdk-22.0.0+0/bin/java", "LastModified", "test.txt"], 0xffffe07f0b98 /* 42 vars */) = 0
[pid 17058] statx(AT_FDCWD, "test.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0
# stat test.txt 
  File: test.txt
  Size: 0         	Blocks: 0          IO Block: 65536  regular empty file
Device: fd00h/64768d	Inode: 100734611   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2023-09-21 13:14:00.464356794 -0400
Modify: 2000-01-01 01:01:00.000000000 -0500
Change: 2023-09-21 13:17:13.835434277 -0400
 Birth: 2023-09-21 13:12:13.033760507 -0400


On a Linux system that doesn't have `statx`:

# grep 'stat' strace_out.log  | grep testme
[pid  8302] stat("testme.txt", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
# stat testme.txt 
  File: ‘testme.txt’
  Size: 0         	Blocks: 0          IO Block: 65536  regular empty file
Device: fd00h/64768d	Inode: 100822778   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2023-09-21 13:09:46.459640944 -0400
Modify: 2000-01-01 01:01:00.000000000 -0500
Change: 2023-09-21 13:16:08.142395814 -0400
 Birth: -

Please let me know what you think!

FWIW, I've compiled this fine on Alpine Linux, so there aren't any glibc guards anymore.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15792#issuecomment-1730023723


More information about the nio-dev mailing list