summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Rumney <jasonr@gnu.org>2002-04-28 18:52:26 +0000
committerJason Rumney <jasonr@gnu.org>2002-04-28 18:52:26 +0000
commit93e0f0da4bbb3dc078339e3a97fac9188f0e0174 (patch)
treedae11e025742ac501358ddc3420c8ea210a8993a
parentb362c12a0f440d2afc0e5c30cca4d64e54e15c2a (diff)
downloademacs-93e0f0da4bbb3dc078339e3a97fac9188f0e0174.tar.gz
(stat, fstat): Use file index information to generate
inodes for directories where available.
-rw-r--r--src/w32.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/w32.c b/src/w32.c
index 718869978e4..175d89d3609 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -2153,16 +2153,11 @@ stat (const char * path, struct stat * buf)
}
}
- if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- buf->st_mode = _S_IFDIR;
- buf->st_nlink = 2; /* doesn't really matter */
- fake_inode = 0; /* this doesn't either I think */
- }
- else if (!NILP (Vw32_get_true_file_attributes)
- /* No access rights required to get info. */
- && (fh = CreateFile (name, 0, 0, NULL, OPEN_EXISTING, 0, NULL))
- != INVALID_HANDLE_VALUE)
+ if (!NILP (Vw32_get_true_file_attributes)
+ /* No access rights required to get info. */
+ && (fh = CreateFile (name, 0, 0, NULL, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, NULL))
+ != INVALID_HANDLE_VALUE)
{
/* This is more accurate in terms of gettting the correct number
of links, but is quite slow (it is noticable when Emacs is
@@ -2185,25 +2180,33 @@ stat (const char * path, struct stat * buf)
fake_inode = 0;
}
- switch (GetFileType (fh))
+ if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
- case FILE_TYPE_DISK:
- buf->st_mode = _S_IFREG;
- break;
- case FILE_TYPE_PIPE:
- buf->st_mode = _S_IFIFO;
- break;
- case FILE_TYPE_CHAR:
- case FILE_TYPE_UNKNOWN:
- default:
- buf->st_mode = _S_IFCHR;
+ buf->st_mode = _S_IFDIR;
+ }
+ else
+ {
+ switch (GetFileType (fh))
+ {
+ case FILE_TYPE_DISK:
+ buf->st_mode = _S_IFREG;
+ break;
+ case FILE_TYPE_PIPE:
+ buf->st_mode = _S_IFIFO;
+ break;
+ case FILE_TYPE_CHAR:
+ case FILE_TYPE_UNKNOWN:
+ default:
+ buf->st_mode = _S_IFCHR;
+ }
}
CloseHandle (fh);
}
else
{
/* Don't bother to make this information more accurate. */
- buf->st_mode = _S_IFREG;
+ buf->st_mode = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
+ _S_IFREG : _S_IFDIR;
buf->st_nlink = 1;
fake_inode = 0;
}
@@ -2296,21 +2299,15 @@ fstat (int desc, struct stat * buf)
}
if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
buf->st_mode = _S_IFDIR;
- buf->st_nlink = 2; /* doesn't really matter */
- fake_inode = 0; /* this doesn't either I think */
- }
- else
- {
- buf->st_nlink = info.nNumberOfLinks;
- /* Might as well use file index to fake inode values, but this
- is not guaranteed to be unique unless we keep a handle open
- all the time (even then there are situations where it is
- not unique). Reputedly, there are at most 48 bits of info
- (on NTFS, presumably less on FAT). */
- fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
- }
+
+ buf->st_nlink = info.nNumberOfLinks;
+ /* Might as well use file index to fake inode values, but this
+ is not guaranteed to be unique unless we keep a handle open
+ all the time (even then there are situations where it is
+ not unique). Reputedly, there are at most 48 bits of info
+ (on NTFS, presumably less on FAT). */
+ fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
/* MSVC defines _ino_t to be short; other libc's might not. */
if (sizeof (buf->st_ino) == 2)