[PATCH v2 8/8] fhandler_disk_file.cc: Use path_conv's IndexNumber

Ben Wijen ben@wijen.net
Wed Jan 20 16:10:56 GMT 2021


path_conv already knows the IndexNumber, so just use it.

This commit also fixes the potential handle leak.
---
 winsup/cygwin/fhandler_disk_file.cc | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index fe04f832b..39f914a59 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -2029,9 +2029,6 @@ readdir_get_ino (const char *path, bool dot_dot)
 {
   char *fname;
   struct stat st;
-  HANDLE hdl;
-  OBJECT_ATTRIBUTES attr;
-  IO_STATUS_BLOCK io;
   ino_t ino = 0;
 
   if (dot_dot)
@@ -2044,26 +2041,17 @@ readdir_get_ino (const char *path, bool dot_dot)
       path = fname;
     }
   path_conv pc (path, PC_SYM_NOFOLLOW | PC_POSIX | PC_KEEP_HANDLE);
-  if (pc.isspecial ())
+  if (pc.isgood_inode (pc.fai ()->InternalInformation.IndexNumber.QuadPart))
+    ino = pc.fai ()->InternalInformation.IndexNumber.QuadPart;
+  else if (pc.isspecial ())
     {
       if (!stat_worker (pc, &st))
 	ino = st.st_ino;
     }
-  else if (!pc.hasgood_inode ())
+
+  if (!ino)
     ino = hash_path_name (0, pc.get_nt_native_path ());
-  else if ((hdl = pc.handle ()) != NULL
-	   || NT_SUCCESS (NtOpenFile (&hdl, READ_CONTROL,
-				      pc.get_object_attr (attr, sec_none_nih),
-				      &io, FILE_SHARE_VALID_FLAGS,
-				      FILE_OPEN_FOR_BACKUP_INTENT
-				      | (pc.is_known_reparse_point ()
-				      ? FILE_OPEN_REPARSE_POINT : 0)))
-	  )
-    {
-      ino = pc.get_ino_by_handle (hdl);
-      if (!ino)
-	ino = hash_path_name (0, pc.get_nt_native_path ());
-    }
+
   return ino;
 }
 
-- 
2.30.0



More information about the Cygwin-patches mailing list