From 4965cdc9ad2753f7aa91711e2862d7e350168bef Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 21 Jun 2016 13:39:04 +0200 Subject: [PATCH] Use correct file info (especially inode number) for newly created files fhandler_base::open_fs has two problems: - When newly creating a file, the file info in the path_conv is incorrect. It points to info for the parent dir, not to info for the file itself (which, naturally, wasn't available before). - Fetching the file's inode number only worked for non-NFS. Both problems should be fixed now by reloading file info if the file has just been created, as well as using the new FS-agnostic path_conv::get_ino method. Signed-off-by: Corinna Vinschen --- winsup/cygwin/fhandler_disk_file.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 3da519129..f4b528446 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -1461,6 +1461,8 @@ fhandler_base::open_fs (int flags, mode_t mode) return 0; } + bool new_file = !exists (); + int res = fhandler_base::open (flags | O_DIROPEN, mode); if (!res) goto out; @@ -1479,9 +1481,13 @@ fhandler_base::open_fs (int flags, mode_t mode) return 0; } - if (pc.hasgood_inode () - && pc.isgood_inode (pc.fai ()->InternalInformation.IndexNumber.QuadPart)) - ino = pc.fai ()->InternalInformation.IndexNumber.QuadPart; + /* The file info in pc is wrong at this point for newly created files. + Refresh it before fetching any file info. */ + if (new_file) + pc.get_finfo (get_io_handle ()); + + if (pc.isgood_inode (pc.get_ino ())) + ino = pc.get_ino (); out: syscall_printf ("%d = fhandler_disk_file::open(%S, %y)", res,