comparison src/w32.c @ 44927:1f6fdc21ea67

(stat, fstat): Use file index information to generate inodes for directories where available.
author Jason Rumney <jasonr@gnu.org>
date Sun, 28 Apr 2002 18:52:26 +0000
parents 81e8a128e49f
children f46982d9ac50
comparison
equal deleted inserted replaced
44926:69639ae98236 44927:1f6fdc21ea67
2151 } 2151 }
2152 FindClose (fh); 2152 FindClose (fh);
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
2169 making a list of file name completions). */ 2164 making a list of file name completions). */
2170 BY_HANDLE_FILE_INFORMATION info; 2165 BY_HANDLE_FILE_INFORMATION info;
2183 { 2178 {
2184 buf->st_nlink = 1; 2179 buf->st_nlink = 1;
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 }
2210 2213
2211 #if 0 2214 #if 0
2294 info.ftLastAccessTime = utc_base_ft; 2297 info.ftLastAccessTime = utc_base_ft;
2295 info.ftLastWriteTime = utc_base_ft; 2298 info.ftLastWriteTime = utc_base_ft;
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)
2317 buf->st_ino = fake_inode ^ (fake_inode >> 16); 2314 buf->st_ino = fake_inode ^ (fake_inode >> 16);
2318 else 2315 else