From: corinna DOT vinschen AT cityweb DOT de (Corinna Vinschen) Subject: Patch to 990126: Handling of directories and i-node-numbers 29 Jan 1999 03:41:10 -0800 Message-ID: <36B19184.F89F7FD5.cygnus.cygwin32.developers@cityweb.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: cygwin32-developers AT cygnus DOT com, Christopher Faylor Hi! The following patch has two advantages: With WinNT, directories are using the same fhandler_disk_file::fstat() call as regular files. It handles now i-node numbers, which are returned by GetFileInformationByHandle() so, that the i-node numbers of two links to the same file are the same. I have checked this out on two file systems with more than 100000 files: The or'd High and Low part of the nFileIndex seems to be unique. Together with the above mentioned directory patch, e.g. ls -i . and ls -i `pwd` return the same i-node number in WinNT. Unfortunately, this patch is useless with Win9X. Regards, Corinna ChangeLog: ========== * fhandler.cc (fhandler_disk_file::fstat): Handles directories, returns unique i-node number. * syscalls.cc (stat_worker): On WinNT, stat_worker calls fhandler_disk_file::fstat for directories, too. Index: fhandler.cc =================================================================== RCS file: /src/cvsroot/winsup-990126/fhandler.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -1 -r1.1 -r1.2 --- fhandler.cc 1999/01/29 09:33:41 1.1 +++ fhandler.cc 1999/01/29 09:49:20 1.2 @@ -804,3 +804,3 @@ fhandler_disk_file::fstat (struct stat * buf->st_size = local.nFileSizeLow; - buf->st_ino = local.nFileIndexLow ^ get_namehash (); + buf->st_ino = local.nFileIndexHigh | local.nFileIndexLow; buf->st_blksize = S_BLKSIZE; @@ -814,2 +814,4 @@ fhandler_disk_file::fstat (struct stat * buf->st_mode |= S_IFLNK; + else if (local.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + buf->st_mode |= S_IFDIR; else @@ -836,3 +838,6 @@ fhandler_disk_file::fstat (struct stat * case FILE_TYPE_DISK: - buf->st_mode |= S_IFREG; + if (local.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + buf->st_mode |= S_IFDIR; + else + buf->st_mode |= S_IFREG; if (get_execable_p ()) Index: syscalls.cc =================================================================== RCS file: /src/cvsroot/winsup-990126/syscalls.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -1 -r1.1 -r1.2 --- syscalls.cc 1999/01/29 09:33:44 1.1 +++ syscalls.cc 1999/01/29 09:49:19 1.2 @@ -1209,3 +1209,16 @@ stat_worker (const char *caller, const c debug_printf ("%d = GetFileAttributesA (%s)", atts, win32_name); - if (atts == -1 || !(atts & FILE_ATTRIBUTE_DIRECTORY)) + if (os_being_run == winNT) + { + fhandler_disk_file fh (NULL); + + if (fh.open (real_path, O_RDONLY | O_BINARY | O_DIROPEN | + (nofollow ? O_NOSYMLINK : 0), 0)) + { + res = fh.fstat (buf); + fh.close (); + if (atts != -1 && (atts & FILE_ATTRIBUTE_DIRECTORY)) + buf->st_nlink = num_entries (win32_name); + } + } + else if (atts == -1 || !(atts & FILE_ATTRIBUTE_DIRECTORY)) {