aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Rumney2002-04-28 18:52:26 +0000
committerJason Rumney2002-04-28 18:52:26 +0000
commit93e0f0da4bbb3dc078339e3a97fac9188f0e0174 (patch)
treedae11e025742ac501358ddc3420c8ea210a8993a
parentb362c12a0f440d2afc0e5c30cca4d64e54e15c2a (diff)
downloademacs-93e0f0da4bbb3dc078339e3a97fac9188f0e0174.tar.gz
emacs-93e0f0da4bbb3dc078339e3a97fac9188f0e0174.zip
(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)
2153 } 2153 }
2154 } 2154 }
2155 2155
2156 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 2156 if (!NILP (Vw32_get_true_file_attributes)
2157 { 2157 /* No access rights required to get info. */
2158 buf->st_mode = _S_IFDIR; 2158 && (fh = CreateFile (name, 0, 0, NULL, OPEN_EXISTING,
2159 buf->st_nlink = 2; /* doesn't really matter */ 2159 FILE_FLAG_BACKUP_SEMANTICS, NULL))
2160 fake_inode = 0; /* this doesn't either I think */ 2160 != INVALID_HANDLE_VALUE)
2161 }
2162 else if (!NILP (Vw32_get_true_file_attributes)
2163 /* No access rights required to get info. */
2164 && (fh = CreateFile (name, 0, 0, NULL, OPEN_EXISTING, 0, NULL))
2165 != INVALID_HANDLE_VALUE)
2166 { 2161 {
2167 /* This is more accurate in terms of gettting the correct number 2162 /* This is more accurate in terms of gettting the correct number
2168 of links, but is quite slow (it is noticable when Emacs is 2163 of links, but is quite slow (it is noticable when Emacs is
@@ -2185,25 +2180,33 @@ stat (const char * path, struct stat * buf)
2185 fake_inode = 0; 2180 fake_inode = 0;
2186 } 2181 }
2187 2182
2188 switch (GetFileType (fh)) 2183 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2189 { 2184 {
2190 case FILE_TYPE_DISK: 2185 buf->st_mode = _S_IFDIR;
2191 buf->st_mode = _S_IFREG; 2186 }
2192 break; 2187 else
2193 case FILE_TYPE_PIPE: 2188 {
2194 buf->st_mode = _S_IFIFO; 2189 switch (GetFileType (fh))
2195 break; 2190 {
2196 case FILE_TYPE_CHAR: 2191 case FILE_TYPE_DISK:
2197 case FILE_TYPE_UNKNOWN: 2192 buf->st_mode = _S_IFREG;
2198 default: 2193 break;
2199 buf->st_mode = _S_IFCHR; 2194 case FILE_TYPE_PIPE:
2195 buf->st_mode = _S_IFIFO;
2196 break;
2197 case FILE_TYPE_CHAR:
2198 case FILE_TYPE_UNKNOWN:
2199 default:
2200 buf->st_mode = _S_IFCHR;
2201 }
2200 } 2202 }
2201 CloseHandle (fh); 2203 CloseHandle (fh);
2202 } 2204 }
2203 else 2205 else
2204 { 2206 {
2205 /* Don't bother to make this information more accurate. */ 2207 /* Don't bother to make this information more accurate. */
2206 buf->st_mode = _S_IFREG; 2208 buf->st_mode = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
2209 _S_IFREG : _S_IFDIR;
2207 buf->st_nlink = 1; 2210 buf->st_nlink = 1;
2208 fake_inode = 0; 2211 fake_inode = 0;
2209 } 2212 }
@@ -2296,21 +2299,15 @@ fstat (int desc, struct stat * buf)
2296 } 2299 }
2297 2300
2298 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 2301 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2299 {
2300 buf->st_mode = _S_IFDIR; 2302 buf->st_mode = _S_IFDIR;
2301 buf->st_nlink = 2; /* doesn't really matter */ 2303
2302 fake_inode = 0; /* this doesn't either I think */ 2304 buf->st_nlink = info.nNumberOfLinks;
2303 } 2305 /* Might as well use file index to fake inode values, but this
2304 else 2306 is not guaranteed to be unique unless we keep a handle open
2305 { 2307 all the time (even then there are situations where it is
2306 buf->st_nlink = info.nNumberOfLinks; 2308 not unique). Reputedly, there are at most 48 bits of info
2307 /* Might as well use file index to fake inode values, but this 2309 (on NTFS, presumably less on FAT). */
2308 is not guaranteed to be unique unless we keep a handle open 2310 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
2309 all the time (even then there are situations where it is
2310 not unique). Reputedly, there are at most 48 bits of info
2311 (on NTFS, presumably less on FAT). */
2312 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
2313 }
2314 2311
2315 /* MSVC defines _ino_t to be short; other libc's might not. */ 2312 /* MSVC defines _ino_t to be short; other libc's might not. */
2316 if (sizeof (buf->st_ino) == 2) 2313 if (sizeof (buf->st_ino) == 2)