771
|
1 /* Utility and Unix shadow routines under MS Windows (WIN32_NATIVE defined).
|
428
|
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
771
|
3 Copyright (C) 2000, 2001, 2002 Ben Wing.
|
428
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to the Free
|
|
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
20 02111-1307, USA.
|
|
21
|
771
|
22 */
|
428
|
23
|
771
|
24 /* Authorship:
|
428
|
25
|
771
|
26 Geoff Voelker (voelker@cs.washington.edu) 7-29-94
|
|
27 Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au>
|
|
28 Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org>
|
|
29 (Note: Sync messages from Marc Paquette may indicate
|
|
30 incomplete synching, so beware.)
|
|
31 Synched (completely!) with Emacs 20.6 by Ben Wing, 6-23-00.
|
|
32 Largely rewritten by Ben Wing for XEmacs Mule support.
|
|
33 Synched (completely!) with Emacs 21.1.103 by Ben Wing, 6-13-01.
|
|
34 */
|
|
35
|
|
36 /* This file Mule-ized by Ben Wing, 6-23-00. */
|
428
|
37
|
|
38 #include <config.h>
|
|
39 #include "lisp.h"
|
|
40
|
592
|
41 #include "buffer.h"
|
872
|
42 #include "process.h"
|
592
|
43
|
859
|
44 #include "sysdir.h"
|
|
45 #include "sysfile.h"
|
428
|
46 #include "sysproc.h"
|
442
|
47 #include "syspwd.h"
|
859
|
48 #include "syssignal.h"
|
|
49 #include "systime.h"
|
428
|
50
|
442
|
51 #include "syswindows.h"
|
428
|
52
|
771
|
53 /* Control whether stat() attempts to determine file type and link count
|
|
54 exactly, at the expense of slower operation. Since true hard links
|
|
55 are supported on NTFS volumes, this is only relevant on NT. */
|
|
56 Lisp_Object Vmswindows_get_true_file_attributes;
|
428
|
57
|
771
|
58 /* Vmswindows_generate_fake_inodes; deleted */
|
|
59
|
|
60 Fixnum mswindows_fake_unix_uid;
|
428
|
61
|
|
62 /* Emulate getpwuid, getpwnam and others. */
|
|
63
|
771
|
64 static struct passwd the_passwd =
|
428
|
65 {
|
771
|
66 "",
|
|
67 "",
|
428
|
68 0,
|
|
69 0,
|
|
70 0,
|
771
|
71 "",
|
|
72 "",
|
|
73 "",
|
428
|
74 };
|
|
75
|
|
76 uid_t
|
442
|
77 getuid (void)
|
440
|
78 {
|
771
|
79 return mswindows_fake_unix_uid;
|
428
|
80 }
|
|
81
|
|
82 uid_t
|
442
|
83 geteuid (void)
|
428
|
84 {
|
771
|
85 /* Emacs 20.6 says: [[I could imagine arguing for checking to see
|
|
86 whether the user is in the Administrators group and returning a
|
|
87 UID of 0 for that case, but I don't know how wise that would be
|
|
88 in the long run.]] */
|
|
89 return mswindows_fake_unix_uid;
|
428
|
90 }
|
|
91
|
|
92 gid_t
|
442
|
93 getgid (void)
|
428
|
94 {
|
|
95 return the_passwd.pw_gid;
|
|
96 }
|
|
97
|
|
98 gid_t
|
442
|
99 getegid (void)
|
428
|
100 {
|
|
101 return getgid ();
|
|
102 }
|
|
103
|
|
104 struct passwd *
|
|
105 getpwuid (uid_t uid)
|
|
106 {
|
771
|
107 if (uid == mswindows_fake_unix_uid)
|
440
|
108 {
|
|
109 the_passwd.pw_gid = the_passwd.pw_uid = uid;
|
|
110 return &the_passwd;
|
|
111 }
|
|
112 else
|
|
113 return NULL;
|
428
|
114 }
|
|
115
|
|
116 struct passwd *
|
867
|
117 getpwnam (const Ibyte *name)
|
428
|
118 {
|
|
119 struct passwd *pw;
|
|
120
|
|
121 pw = getpwuid (getuid ());
|
|
122 if (!pw)
|
|
123 return pw;
|
|
124
|
771
|
125 if (qxestrcasecmp_i18n (name, pw->pw_name))
|
428
|
126 return NULL;
|
|
127
|
|
128 return pw;
|
|
129 }
|
|
130
|
771
|
131 static void
|
442
|
132 init_user_info (void)
|
428
|
133 {
|
440
|
134 /* This code is pretty much of ad hoc nature. There is no unix-like
|
|
135 UIDs under Windows NT. There is no concept of root user, because
|
|
136 all security is ACL-based. Instead, let's use a simple variable,
|
|
137 nt-fake-unix-uid, which would allow the user to have a uid of
|
|
138 choice. --kkm, 02/03/2000 */
|
|
139 #if 0
|
428
|
140 /* Find the user's real name by opening the process token and
|
|
141 looking up the name associated with the user-sid in that token.
|
|
142
|
|
143 Use the relative portion of the identifier authority value from
|
|
144 the user-sid as the user id value (same for group id using the
|
|
145 primary group sid from the process token). */
|
|
146
|
771
|
147 TOKEN_USER sidinfo;
|
|
148 Extbyte name[256], domain[256];
|
|
149 Charcount length = sizeof (name) / XETCHAR_SIZE;
|
|
150 Charcount dlength = sizeof (domain) / XETCHAR_SIZE;
|
|
151 DWORD trash;
|
|
152 HANDLE token = NULL;
|
|
153 SID_NAME_USE user_type;
|
428
|
154
|
|
155 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)
|
771
|
156 && GetTokenInformation (token, TokenUser, &sidinfo, sizeof (sidinfo),
|
|
157 &trash)
|
|
158 && qxeLookupAccountSid (NULL, sidinfo.User.Sid, name, &length,
|
|
159 domain, &dlength, &user_type))
|
428
|
160 {
|
771
|
161 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
|
428
|
162 /* Determine a reasonable uid value. */
|
771
|
163 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
|
428
|
164 {
|
|
165 the_passwd.pw_uid = 0;
|
|
166 the_passwd.pw_gid = 0;
|
|
167 }
|
|
168 else
|
|
169 {
|
|
170 SID_IDENTIFIER_AUTHORITY * pSIA;
|
771
|
171 TOKEN_PRIMARY_GROUP group;
|
428
|
172
|
771
|
173 pSIA = GetSidIdentifierAuthority (sidinfo.User.Sid);
|
428
|
174 /* I believe the relative portion is the last 4 bytes (of 6)
|
|
175 with msb first. */
|
|
176 the_passwd.pw_uid = ((pSIA->Value[2] << 24) +
|
|
177 (pSIA->Value[3] << 16) +
|
|
178 (pSIA->Value[4] << 8) +
|
|
179 (pSIA->Value[5] << 0));
|
|
180 /* restrict to conventional uid range for normal users */
|
|
181 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
|
|
182
|
|
183 /* Get group id */
|
|
184 if (GetTokenInformation (token, TokenPrimaryGroup,
|
771
|
185 &group, sizeof (group), &trash))
|
428
|
186 {
|
|
187 SID_IDENTIFIER_AUTHORITY * pSIA;
|
|
188
|
771
|
189 pSIA = GetSidIdentifierAuthority (group.PrimaryGroup);
|
428
|
190 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
|
|
191 (pSIA->Value[3] << 16) +
|
|
192 (pSIA->Value[4] << 8) +
|
|
193 (pSIA->Value[5] << 0));
|
|
194 /* I don't know if this is necessary, but for safety... */
|
|
195 the_passwd.pw_gid = the_passwd.pw_gid % 60001;
|
|
196 }
|
|
197 else
|
|
198 the_passwd.pw_gid = the_passwd.pw_uid;
|
|
199 }
|
|
200 }
|
|
201 /* If security calls are not supported (presumably because we
|
|
202 are running under Windows 95), fallback to this. */
|
771
|
203 else if (qxeGetUserName (name, &length))
|
428
|
204 {
|
771
|
205 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
|
|
206 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
|
428
|
207 the_passwd.pw_uid = 0;
|
|
208 else
|
|
209 the_passwd.pw_uid = 123;
|
|
210 the_passwd.pw_gid = the_passwd.pw_uid;
|
|
211 }
|
|
212 else
|
|
213 {
|
771
|
214 the_passwd.pw_name = "unknown";
|
428
|
215 the_passwd.pw_uid = 123;
|
|
216 the_passwd.pw_gid = 123;
|
|
217 }
|
|
218
|
440
|
219 if (token)
|
|
220 CloseHandle (token);
|
|
221 #else
|
|
222 /* Obtain only logon id here, uid part is moved to getuid */
|
771
|
223 DWORD length = UNLEN + 1;
|
|
224 Extbyte name[MAX_XETCHAR_SIZE * (UNLEN + 1)];
|
|
225 if (qxeGetUserName (name, &length))
|
|
226 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
|
440
|
227 else
|
771
|
228 the_passwd.pw_name = "unknown";
|
440
|
229 #endif
|
|
230
|
771
|
231 #if 0
|
428
|
232 /* Ensure HOME and SHELL are defined. */
|
|
233 /*
|
|
234 * With XEmacs, setting $HOME is deprecated.
|
|
235 */
|
771
|
236 if (egetenv ("HOME") == NULL)
|
|
237 eputenv ("HOME=c:/");
|
428
|
238 #endif
|
|
239
|
611
|
240 /* Set dir from environment variables. */
|
771
|
241 the_passwd.pw_dir = (char *) qxestrdup (get_home_directory ());
|
611
|
242 /* We used to set pw_shell here, but the order is wrong (SHELL gets
|
853
|
243 initted in process.c, called later in the init process) and pw_shell
|
611
|
244 is not used anywhere. */
|
428
|
245 }
|
|
246
|
771
|
247 /* Parse the root part of file name, if present. Return length and
|
867
|
248 optionally store pointer to Ibyte after root. */
|
771
|
249 static Bytecount
|
867
|
250 parse_root (Ibyte *name, Ibyte **pPath)
|
428
|
251 {
|
867
|
252 Ibyte *start = name;
|
428
|
253
|
|
254 if (name == NULL)
|
|
255 return 0;
|
|
256
|
|
257 /* find the root name of the volume if given */
|
|
258 if (isalpha (name[0]) && name[1] == ':')
|
|
259 {
|
|
260 /* skip past drive specifier */
|
|
261 name += 2;
|
|
262 if (IS_DIRECTORY_SEP (name[0]))
|
|
263 name++;
|
|
264 }
|
|
265 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
|
|
266 {
|
|
267 int slashes = 2;
|
|
268 name += 2;
|
|
269 do
|
|
270 {
|
|
271 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
|
|
272 break;
|
|
273 name++;
|
|
274 }
|
771
|
275 while (*name);
|
428
|
276 if (IS_DIRECTORY_SEP (name[0]))
|
|
277 name++;
|
|
278 }
|
|
279
|
|
280 if (pPath)
|
|
281 *pPath = name;
|
|
282
|
|
283 return name - start;
|
|
284 }
|
|
285
|
|
286 /* Get long base name for name; name is assumed to be absolute. */
|
867
|
287 static Ibyte *
|
|
288 get_long_basename (Ibyte *name)
|
428
|
289 {
|
771
|
290 WIN32_FIND_DATAW find_data;
|
428
|
291 HANDLE dir_handle;
|
771
|
292 Extbyte *nameext;
|
428
|
293
|
771
|
294 /* must be valid filename, no wild cards or other invalid characters */
|
|
295 if (qxestrpbrk (name, "*?|<>\""))
|
|
296 return 0;
|
428
|
297
|
771
|
298 C_STRING_TO_TSTR (name, nameext);
|
|
299 dir_handle = qxeFindFirstFile (nameext, &find_data);
|
428
|
300 if (dir_handle != INVALID_HANDLE_VALUE)
|
|
301 {
|
867
|
302 Ibyte *fileint;
|
771
|
303
|
|
304 TSTR_TO_C_STRING_MALLOC (find_data.cFileName, fileint);
|
428
|
305 FindClose (dir_handle);
|
771
|
306 return fileint;
|
428
|
307 }
|
771
|
308 return 0;
|
428
|
309 }
|
|
310
|
|
311 /* Get long name for file, if possible (assumed to be absolute). */
|
867
|
312 Ibyte *
|
|
313 mswindows_get_long_filename (Ibyte *name)
|
428
|
314 {
|
867
|
315 Ibyte *full = mswindows_canonicalize_filename (name);
|
|
316 Ibyte *p;
|
|
317 Ibyte *q;
|
771
|
318 DECLARE_EISTRING (o);
|
|
319 Bytecount len;
|
428
|
320
|
|
321 /* Copy root part verbatim. */
|
|
322 len = parse_root (full, &p);
|
771
|
323 eicpy_raw (o, full, len);
|
428
|
324
|
771
|
325 while (p != NULL && *p)
|
428
|
326 {
|
867
|
327 Ibyte *component;
|
771
|
328
|
428
|
329 q = p;
|
771
|
330 p = qxestrchr (q, '\\');
|
428
|
331 if (p) *p = '\0';
|
771
|
332 component = get_long_basename (full);
|
|
333 if (component)
|
428
|
334 {
|
771
|
335 eicat_rawz (o, component);
|
428
|
336 if (p != NULL)
|
|
337 {
|
|
338 *p++ = '\\';
|
771
|
339 eicat_ch (o, '\\');
|
428
|
340 }
|
771
|
341 xfree (component);
|
428
|
342 }
|
|
343 else
|
771
|
344 {
|
|
345 xfree (full);
|
|
346 return 0;
|
|
347 }
|
428
|
348 }
|
|
349
|
771
|
350 xfree (full);
|
|
351 return eicpyout_malloc (o, 0);
|
428
|
352 }
|
|
353
|
771
|
354 static int
|
867
|
355 is_unc_volume (const Ibyte *filename)
|
771
|
356 {
|
867
|
357 const Ibyte *ptr = filename;
|
428
|
358
|
771
|
359 if (!IS_DIRECTORY_SEP (ptr[0]) || !IS_DIRECTORY_SEP (ptr[1]) || !ptr[2])
|
|
360 return 0;
|
|
361
|
|
362 if (qxestrpbrk (ptr + 2, "*?|<>\"\\/"))
|
|
363 return 0;
|
|
364
|
|
365 return 1;
|
428
|
366 }
|
|
367
|
771
|
368 /* NOTE: Value returned is still in external format. Callers need to
|
|
369 convert. */
|
707
|
370 #define REG_ROOT "SOFTWARE\\XEmacs\\XEmacs"
|
428
|
371
|
771
|
372 static LPBYTE
|
867
|
373 nt_get_resource (Ibyte *key, LPDWORD lpdwtype)
|
428
|
374 {
|
|
375 LPBYTE lpvalue;
|
|
376 HKEY hrootkey = NULL;
|
|
377 DWORD cbData;
|
771
|
378 Extbyte *keyext;
|
|
379
|
|
380 C_STRING_TO_TSTR (key, keyext);
|
428
|
381
|
|
382 /* Check both the current user and the local machine to see if
|
|
383 we have any resources. */
|
|
384
|
771
|
385 if (qxeRegOpenKeyEx (HKEY_CURRENT_USER, XETEXT (REG_ROOT), 0, KEY_READ,
|
|
386 &hrootkey) == ERROR_SUCCESS)
|
428
|
387 {
|
|
388 lpvalue = NULL;
|
|
389
|
771
|
390 if (qxeRegQueryValueEx (hrootkey, keyext, NULL, NULL, NULL,
|
|
391 &cbData) == ERROR_SUCCESS
|
428
|
392 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
|
771
|
393 && qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
|
|
394 &cbData) == ERROR_SUCCESS)
|
|
395 return (lpvalue);
|
428
|
396
|
|
397 if (lpvalue) xfree (lpvalue);
|
|
398
|
|
399 RegCloseKey (hrootkey);
|
|
400 }
|
|
401
|
771
|
402 if (qxeRegOpenKeyEx (HKEY_LOCAL_MACHINE, XETEXT (REG_ROOT), 0, KEY_READ,
|
|
403 &hrootkey) == ERROR_SUCCESS)
|
428
|
404 {
|
|
405 lpvalue = NULL;
|
|
406
|
771
|
407 if (qxeRegQueryValueEx (hrootkey, keyext, NULL, NULL, NULL,
|
|
408 &cbData) == ERROR_SUCCESS &&
|
428
|
409 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
|
771
|
410 qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
|
|
411 &cbData) == ERROR_SUCCESS)
|
|
412 return (lpvalue);
|
428
|
413
|
|
414 if (lpvalue) xfree (lpvalue);
|
|
415
|
|
416 RegCloseKey (hrootkey);
|
|
417 }
|
|
418
|
|
419 return (NULL);
|
|
420 }
|
|
421
|
|
422 void
|
814
|
423 init_mswindows_environment (void)
|
428
|
424 {
|
|
425 /* Check for environment variables and use registry if they don't exist */
|
771
|
426 /* Emacs 20.6 sets default values for these; not necessary here because
|
|
427 we already supply them. (except SHELL, which is set in init_user_info().)
|
|
428 Emacs 20.6 messes with TMPDIR; not necessary here. */
|
428
|
429 {
|
|
430 int i;
|
|
431 LPBYTE lpval;
|
|
432 DWORD dwType;
|
|
433
|
771
|
434 static Char_ASCII *env_vars[] =
|
428
|
435 {
|
|
436 "HOME",
|
|
437 "EMACSLOADPATH",
|
|
438 "EMACSDEBUGPATHS",
|
|
439 "SHELL",
|
|
440 "CMDPROXY",
|
|
441 "EMACSDATA",
|
|
442 "EMACSPATH",
|
|
443 "EMACSPACKAGEPATH",
|
771
|
444 "EMACSLOCKMETHOD",
|
428
|
445 "INFOPATH"
|
|
446 };
|
771
|
447 #if defined (HEAP_IN_DATA) && !defined (PDUMP)
|
430
|
448 cache_system_info ();
|
|
449 #endif
|
771
|
450
|
|
451 #if 0 /* FSF 21.1 */
|
|
452 /* !!#### i think i already do the equivalent elsewhere.
|
|
453 delete when i'm sure i do.
|
|
454 (but maybe i should be playing with LANG when the user changes
|
|
455 the locale, so that subprocesses get it right.) */
|
|
456 /* Get default locale info and use it for LANG. */
|
|
457 if (GetLocaleInfo (LOCALE_USER_DEFAULT,
|
|
458 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
|
|
459 locale_name, sizeof (locale_name)))
|
|
460 {
|
|
461 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
|
|
462 {
|
|
463 if (strcmp (env_vars[i].name, "LANG") == 0)
|
|
464 {
|
|
465 env_vars[i].def_value = locale_name;
|
|
466 break;
|
|
467 }
|
|
468 }
|
|
469 }
|
|
470 #endif /* 0 */
|
|
471
|
428
|
472 for (i = 0; i < countof (env_vars); i++)
|
|
473 {
|
771
|
474 if (!egetenv (env_vars[i]) &&
|
428
|
475 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
|
|
476 {
|
|
477 if (dwType == REG_EXPAND_SZ)
|
|
478 {
|
771
|
479 Extbyte *buf = NULL;
|
867
|
480 Ibyte *envval;
|
771
|
481 Charcount cch;
|
428
|
482
|
771
|
483 cch = qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, 0);
|
851
|
484 buf = (Extbyte *) ALLOCA (cch * XETCHAR_SIZE);
|
771
|
485 qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, cch);
|
|
486 TSTR_TO_C_STRING (buf, envval);
|
|
487 eputenv (env_vars[i], envval);
|
428
|
488 }
|
|
489 else if (dwType == REG_SZ)
|
|
490 {
|
867
|
491 Ibyte *envval;
|
771
|
492
|
|
493 TSTR_TO_C_STRING (lpval, envval);
|
|
494 eputenv (env_vars[i], envval);
|
428
|
495 }
|
|
496
|
|
497 xfree (lpval);
|
|
498 }
|
|
499 }
|
|
500 }
|
|
501
|
|
502 /* Another special case: on NT, the PATH variable is actually named
|
|
503 "Path" although cmd.exe (perhaps NT itself) arranges for
|
|
504 environment variable lookup and setting to be case insensitive.
|
|
505 However, Emacs assumes a fully case sensitive environment, so we
|
|
506 need to change "Path" to "PATH" to match the expectations of
|
771
|
507 various elisp packages.
|
428
|
508
|
|
509 The same applies to COMSPEC. */
|
|
510 {
|
771
|
511 Lisp_Object tail;
|
428
|
512
|
771
|
513 EXTERNAL_LIST_LOOP (tail, Vprocess_environment)
|
|
514 {
|
|
515 Lisp_Object str = XCAR (tail);
|
|
516 if (STRINGP (str))
|
|
517 {
|
867
|
518 Ibyte *dat = XSTRING_DATA (str);
|
771
|
519 if (qxestrncasecmp (dat, "PATH=", 5) == 0)
|
|
520 memcpy (dat, "PATH=", 5);
|
|
521 else if (qxestrncasecmp (dat, "COMSPEC=", 8) == 0)
|
|
522 memcpy (dat, "COMSPEC=", 8);
|
|
523 }
|
|
524 }
|
428
|
525 }
|
|
526
|
|
527 init_user_info ();
|
|
528 }
|
|
529
|
771
|
530 /* Emacs 20.6 contains a routine get_emacs_configuration() here to set
|
|
531 EMACS_CONFIGURATION. */
|
428
|
532 #ifndef HAVE_X_WINDOWS
|
|
533 /* X11R6 on NT provides the single parameter version of this command. */
|
|
534
|
|
535 #include <sys/timeb.h>
|
|
536
|
|
537 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
|
|
538 void
|
|
539 gettimeofday (struct timeval *tv, struct timezone *tz)
|
|
540 {
|
|
541 struct _timeb tb;
|
|
542 _ftime (&tb);
|
|
543
|
|
544 tv->tv_sec = tb.time;
|
|
545 tv->tv_usec = tb.millitm * 1000L;
|
|
546 if (tz)
|
|
547 {
|
|
548 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
|
|
549 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
|
|
550 }
|
|
551 }
|
|
552
|
|
553 #endif /* HAVE_X_WINDOWS */
|
|
554
|
771
|
555
|
428
|
556 /* ------------------------------------------------------------------------- */
|
771
|
557 /* IO support and wrapper functions for Win32 API. */
|
428
|
558 /* ------------------------------------------------------------------------- */
|
|
559
|
771
|
560 typedef struct volume_info_data
|
428
|
561 {
|
771
|
562 struct volume_info_data *next;
|
428
|
563
|
|
564 /* time when info was obtained */
|
771
|
565 DWORD timestamp;
|
428
|
566
|
|
567 /* actual volume info */
|
867
|
568 Ibyte *root_dir;
|
771
|
569 DWORD serialnum;
|
|
570 DWORD maxcomp;
|
|
571 DWORD flags;
|
867
|
572 Ibyte *name;
|
|
573 Ibyte *type;
|
428
|
574 } volume_info_data;
|
|
575
|
|
576 /* Global referenced by various functions. */
|
|
577 static volume_info_data volume_info;
|
|
578
|
|
579 /* Vector to indicate which drives are local and fixed (for which cached
|
|
580 data never expires). */
|
|
581 static BOOL fixed_drives[26];
|
|
582
|
|
583 /* Consider cached volume information to be stale if older than 10s,
|
|
584 at least for non-local drives. Info for fixed drives is never stale. */
|
|
585 #define DRIVE_INDEX( c ) ( (c) <= 'Z' ? (c) - 'A' : (c) - 'a' )
|
|
586 #define VOLINFO_STILL_VALID( root_dir, info ) \
|
|
587 ( ( isalpha (root_dir[0]) && \
|
|
588 fixed_drives[ DRIVE_INDEX (root_dir[0]) ] ) \
|
|
589 || GetTickCount () - info->timestamp < 10000 )
|
|
590
|
|
591 /* Cache support functions. */
|
|
592
|
|
593 /* Simple linked list with linear search is sufficient. */
|
|
594 static volume_info_data *volume_cache = NULL;
|
|
595
|
|
596 static volume_info_data *
|
867
|
597 lookup_volume_info (Ibyte *root_dir)
|
428
|
598 {
|
771
|
599 volume_info_data *info;
|
428
|
600
|
|
601 for (info = volume_cache; info; info = info->next)
|
771
|
602 if (qxestrcasecmp_i18n (info->root_dir, root_dir) == 0)
|
428
|
603 break;
|
|
604 return info;
|
|
605 }
|
|
606
|
|
607 static void
|
867
|
608 add_volume_info (Ibyte *root_dir, volume_info_data *info)
|
428
|
609 {
|
771
|
610 info->root_dir = qxestrdup (root_dir);
|
428
|
611 info->next = volume_cache;
|
|
612 volume_cache = info;
|
|
613 }
|
|
614
|
|
615
|
|
616 /* Wrapper for GetVolumeInformation, which uses caching to avoid
|
|
617 performance penalty (~2ms on 486 for local drives, 7.5ms for local
|
|
618 cdrom drive, ~5-10ms or more for remote drives on LAN). */
|
771
|
619 static volume_info_data *
|
867
|
620 get_cached_volume_information (Ibyte *root_dir)
|
428
|
621 {
|
771
|
622 volume_info_data *info;
|
867
|
623 Ibyte *default_root;
|
428
|
624
|
|
625 /* NULL for root_dir means use root from current directory. */
|
|
626 if (root_dir == NULL)
|
|
627 {
|
771
|
628 Charcount nchars = qxeGetCurrentDirectory (0, NULL);
|
|
629 Extbyte *rootext;
|
|
630
|
|
631 if (!nchars)
|
428
|
632 return NULL;
|
771
|
633 rootext = alloca_extbytes (nchars * XETCHAR_SIZE);
|
|
634 if (!qxeGetCurrentDirectory (nchars, rootext))
|
|
635 return NULL;
|
|
636 TSTR_TO_C_STRING (rootext, default_root);
|
428
|
637 parse_root (default_root, &root_dir);
|
|
638 *root_dir = 0;
|
|
639 root_dir = default_root;
|
|
640 }
|
|
641
|
|
642 /* Local fixed drives can be cached permanently. Removable drives
|
|
643 cannot be cached permanently, since the volume name and serial
|
|
644 number (if nothing else) can change. Remote drives should be
|
|
645 treated as if they are removable, since there is no sure way to
|
|
646 tell whether they are or not. Also, the UNC association of drive
|
|
647 letters mapped to remote volumes can be changed at any time (even
|
|
648 by other processes) without notice.
|
|
649
|
|
650 As a compromise, so we can benefit from caching info for remote
|
|
651 volumes, we use a simple expiry mechanism to invalidate cache
|
|
652 entries that are more than ten seconds old. */
|
|
653
|
|
654 #if 0
|
|
655 /* No point doing this, because WNetGetConnection is even slower than
|
|
656 GetVolumeInformation, consistently taking ~50ms on a 486 (FWIW,
|
|
657 GetDriveType is about the only call of this type which does not
|
|
658 involve network access, and so is extremely quick). */
|
|
659
|
|
660 /* Map drive letter to UNC if remote. */
|
771
|
661 if (isalpha (root_dir[0]) && !fixed [DRIVE_INDEX (root_dir[0])])
|
428
|
662 {
|
771
|
663 Extbyte remote_name[256 * XETCHAR_SIZE];
|
867
|
664 Ibyte drive[3] = { root_dir[0], ':' };
|
771
|
665 Extbyte *driveext;
|
428
|
666
|
771
|
667 C_STRING_TO_TSTR (drive, driveext);
|
|
668 if (qxeWNetGetConnection (driveext, remote_name,
|
|
669 sizeof (remote_name) / XETCHAR_SIZE)
|
428
|
670 == NO_ERROR)
|
|
671 /* do something */ ;
|
|
672 }
|
|
673 #endif
|
|
674
|
|
675 info = lookup_volume_info (root_dir);
|
|
676
|
|
677 if (info == NULL || ! VOLINFO_STILL_VALID (root_dir, info))
|
771
|
678 {
|
|
679 Extbyte name[256 * MAX_XETCHAR_SIZE];
|
|
680 DWORD serialnum;
|
|
681 DWORD maxcomp;
|
|
682 DWORD flags;
|
|
683 Extbyte type[256 * MAX_XETCHAR_SIZE];
|
428
|
684
|
771
|
685 /* Info is not cached, or is stale. */
|
|
686 if (!qxeGetVolumeInformation (root_dir,
|
|
687 name, sizeof (name) / XETCHAR_SIZE,
|
|
688 &serialnum,
|
|
689 &maxcomp,
|
|
690 &flags,
|
|
691 type, sizeof (type) / XETCHAR_SIZE))
|
|
692 return NULL;
|
428
|
693
|
771
|
694 /* Cache the volume information for future use, overwriting existing
|
|
695 entry if present. */
|
|
696 if (info == NULL)
|
|
697 {
|
|
698 info = (volume_info_data *) xmalloc (sizeof (volume_info_data));
|
|
699 add_volume_info (root_dir, info);
|
|
700 }
|
|
701 else
|
|
702 {
|
|
703 xfree (info->name);
|
|
704 xfree (info->type);
|
|
705 }
|
428
|
706
|
771
|
707 TSTR_TO_C_STRING_MALLOC (name, info->name);
|
|
708 info->serialnum = serialnum;
|
|
709 info->maxcomp = maxcomp;
|
|
710 info->flags = flags;
|
|
711 TSTR_TO_C_STRING_MALLOC (type, info->type);
|
|
712 info->timestamp = GetTickCount ();
|
|
713 }
|
428
|
714
|
|
715 return info;
|
|
716 }
|
|
717
|
|
718 /* Get information on the volume where name is held; set path pointer to
|
|
719 start of pathname in name (past UNC header\volume header if present). */
|
771
|
720 static int
|
867
|
721 get_volume_info (const Ibyte *name, const Ibyte **pPath)
|
428
|
722 {
|
771
|
723 /* We probably only need a couple of bytes, but let's be generous in
|
|
724 case this function gets changed */
|
867
|
725 Ibyte *temp = alloca_array (Ibyte, qxestrlen (name) + 10);
|
|
726 Ibyte *rootname = NULL; /* default to current volume */
|
771
|
727 volume_info_data *info;
|
428
|
728
|
|
729 if (name == NULL)
|
|
730 return FALSE;
|
|
731
|
|
732 /* find the root name of the volume if given */
|
|
733 if (isalpha (name[0]) && name[1] == ':')
|
|
734 {
|
|
735 rootname = temp;
|
|
736 temp[0] = *name++;
|
|
737 temp[1] = *name++;
|
|
738 temp[2] = '\\';
|
|
739 temp[3] = 0;
|
|
740 }
|
|
741 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
|
|
742 {
|
867
|
743 Ibyte *str = temp;
|
428
|
744 int slashes = 4;
|
|
745 rootname = temp;
|
|
746 do
|
|
747 {
|
|
748 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
|
|
749 break;
|
|
750 *str++ = *name++;
|
|
751 }
|
771
|
752 while (*name);
|
428
|
753
|
|
754 *str++ = '\\';
|
|
755 *str = 0;
|
|
756 }
|
|
757
|
|
758 if (pPath)
|
|
759 *pPath = name;
|
|
760
|
771
|
761 info = get_cached_volume_information (rootname);
|
428
|
762 if (info != NULL)
|
|
763 {
|
|
764 /* Set global referenced by other functions. */
|
|
765 volume_info = *info;
|
|
766 return TRUE;
|
|
767 }
|
|
768 return FALSE;
|
|
769 }
|
|
770
|
771
|
771 /* XEmacs: Everything referring to map_win32_filename() aka map_w32_filename()
|
|
772 removed; it was only for NT 3.1, which we hereby do not support. (NT 3.5
|
|
773 predates Windows 95!) */
|
428
|
774
|
771
|
775 static int
|
867
|
776 is_exec (const Ibyte *name)
|
771
|
777 {
|
867
|
778 Ibyte *p = qxestrrchr (name, '.');
|
771
|
779 return (p != NULL && (qxestrcasecmp (p, ".exe") == 0 ||
|
|
780 qxestrcasecmp (p, ".com") == 0 ||
|
|
781 qxestrcasecmp (p, ".bat") == 0 ||
|
|
782 qxestrcasecmp (p, ".cmd") == 0));
|
428
|
783 }
|
|
784
|
|
785 /* Emulate the Unix directory procedures opendir, closedir,
|
|
786 and readdir. We can't use the procedures supplied in sysdep.c,
|
|
787 so we provide them here. */
|
|
788
|
|
789 struct direct dir_static; /* simulated directory contents */
|
|
790 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE;
|
771
|
791 /* dir_is_fat deleted */
|
867
|
792 static Ibyte *dir_pathname;
|
771
|
793 static WIN32_FIND_DATAW dir_find_data;
|
|
794
|
|
795 /* Support shares on a network resource as subdirectories of a read-only
|
|
796 root directory. */
|
|
797 static HANDLE wnet_enum_handle = INVALID_HANDLE_VALUE;
|
867
|
798 static HANDLE open_unc_volume (const Ibyte *);
|
|
799 static Ibyte *read_unc_volume (HANDLE);
|
771
|
800 static int close_unc_volume (HANDLE);
|
428
|
801
|
|
802 DIR *
|
867
|
803 mswindows_opendir (const Ibyte *filename)
|
428
|
804 {
|
|
805 DIR *dirp;
|
|
806
|
|
807 /* Opening is done by FindFirstFile. However, a read is inherent to
|
|
808 this operation, so we defer the open until read time. */
|
|
809
|
771
|
810 if (dir_find_handle != INVALID_HANDLE_VALUE)
|
428
|
811 return NULL;
|
771
|
812 if (wnet_enum_handle != INVALID_HANDLE_VALUE)
|
428
|
813 return NULL;
|
|
814
|
771
|
815 if (is_unc_volume (filename))
|
|
816 {
|
|
817 wnet_enum_handle = open_unc_volume (filename);
|
|
818 if (wnet_enum_handle == INVALID_HANDLE_VALUE)
|
|
819 return NULL;
|
|
820 }
|
428
|
821
|
771
|
822 if (!(dirp = xnew_and_zero (DIR)))
|
|
823 return NULL;
|
|
824
|
|
825 if (dir_pathname)
|
|
826 xfree (dir_pathname);
|
|
827 dir_pathname = qxestrdup (filename);
|
428
|
828
|
|
829 return dirp;
|
|
830 }
|
|
831
|
442
|
832 int
|
771
|
833 mswindows_closedir (DIR *dirp)
|
428
|
834 {
|
771
|
835 int retval;
|
442
|
836
|
428
|
837 /* If we have a find-handle open, close it. */
|
|
838 if (dir_find_handle != INVALID_HANDLE_VALUE)
|
|
839 {
|
771
|
840 retval = FindClose (dir_find_handle) ? 0 : -1;
|
428
|
841 dir_find_handle = INVALID_HANDLE_VALUE;
|
|
842 }
|
771
|
843 else if (wnet_enum_handle != INVALID_HANDLE_VALUE)
|
|
844 {
|
|
845 retval = close_unc_volume (wnet_enum_handle);
|
|
846 wnet_enum_handle = INVALID_HANDLE_VALUE;
|
|
847 }
|
428
|
848 xfree (dirp);
|
771
|
849
|
|
850 return retval;
|
|
851 }
|
|
852
|
|
853 struct direct *
|
|
854 mswindows_readdir (DIR *dirp)
|
|
855 {
|
867
|
856 Ibyte *val;
|
771
|
857 int need_to_free = 0;
|
|
858
|
|
859 if (wnet_enum_handle != INVALID_HANDLE_VALUE)
|
|
860 {
|
|
861 if (!(val = read_unc_volume (wnet_enum_handle)))
|
|
862 return NULL;
|
|
863 need_to_free = 1;
|
|
864 }
|
|
865 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */
|
|
866 else if (dir_find_handle == INVALID_HANDLE_VALUE)
|
|
867 {
|
|
868 DECLARE_EISTRING (filename);
|
867
|
869 Ichar lastch;
|
771
|
870
|
|
871 eicpy_rawz (filename, dir_pathname);
|
|
872 lastch = eigetch_char (filename, eicharlen (filename) - 1);
|
|
873 if (!IS_DIRECTORY_SEP (lastch))
|
|
874 eicat_ch (filename, '\\');
|
|
875 eicat_ch (filename, '*');
|
|
876 eito_external (filename, Qmswindows_tstr);
|
|
877
|
|
878 dir_find_handle = qxeFindFirstFile (eiextdata (filename),
|
|
879 &dir_find_data);
|
|
880
|
|
881 if (dir_find_handle == INVALID_HANDLE_VALUE)
|
|
882 return NULL;
|
|
883 TSTR_TO_C_STRING (dir_find_data.cFileName, val);
|
|
884 }
|
|
885 else
|
|
886 {
|
|
887 if (!qxeFindNextFile (dir_find_handle, &dir_find_data))
|
|
888 return NULL;
|
|
889 TSTR_TO_C_STRING (dir_find_data.cFileName, val);
|
|
890 }
|
|
891
|
|
892 /* XEmacs never uses this value, so don't bother making it match
|
|
893 value returned by qxe_stat(). */
|
|
894 dir_static.d_ino = 1;
|
|
895
|
|
896 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
|
|
897 dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
898
|
|
899 {
|
|
900 DECLARE_EISTRING (found);
|
|
901 Bytecount namlen;
|
|
902
|
|
903 eicpy_rawz (found, val);
|
|
904 if (need_to_free)
|
|
905 xfree (val);
|
|
906
|
|
907 if (!NILP (Vmswindows_downcase_file_names))
|
|
908 eilwr (found);
|
|
909
|
|
910 namlen = min (eilen (found), sizeof (dir_static.d_name) - 1);
|
|
911 strncpy (dir_static.d_name, (char *) eidata (found), namlen);
|
|
912 dir_static.d_name[namlen] = '\0';
|
|
913 dir_static.d_namlen = (unsigned short) namlen;
|
|
914 }
|
|
915
|
|
916 return &dir_static;
|
|
917 }
|
|
918
|
|
919 static HANDLE
|
867
|
920 open_unc_volume (const Ibyte *path)
|
771
|
921 {
|
|
922 NETRESOURCEW nr;
|
|
923 HANDLE henum;
|
|
924 int result;
|
|
925
|
|
926 nr.dwScope = RESOURCE_GLOBALNET;
|
|
927 nr.dwType = RESOURCETYPE_DISK;
|
|
928 nr.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
|
|
929 nr.dwUsage = RESOURCEUSAGE_CONTAINER;
|
|
930 nr.lpLocalName = NULL;
|
|
931 C_STRING_TO_TSTR (path, nr.lpRemoteName);
|
|
932 nr.lpComment = NULL;
|
|
933 nr.lpProvider = NULL;
|
|
934
|
|
935 result = qxeWNetOpenEnum (RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
|
|
936 RESOURCEUSAGE_CONNECTABLE, &nr, &henum);
|
|
937
|
|
938 if (result == NO_ERROR)
|
|
939 return henum;
|
|
940 else
|
|
941 return INVALID_HANDLE_VALUE;
|
|
942 }
|
|
943
|
867
|
944 static Ibyte *
|
771
|
945 read_unc_volume (HANDLE henum)
|
|
946 {
|
|
947 int count;
|
|
948 int result;
|
|
949 Extbyte buf[16384];
|
867
|
950 Ibyte *ptr;
|
771
|
951 Bytecount bufsize = sizeof (buf);
|
|
952
|
|
953 count = 1;
|
|
954 /* #### we should just be querying the size and then allocating the
|
|
955 right amount, like for all similar API's. but the docs say this ?!
|
|
956
|
|
957 An application cannot set the lpBuffer parameter to NULL and
|
|
958 retrieve the required buffer size from the lpBufferSize
|
|
959 parameter. Instead, the application should allocate a buffer of a
|
|
960 reasonable size -- 16 kilobytes (K) is typical -- and use the value
|
|
961 of lpBufferSize for error detection.
|
|
962 */
|
|
963
|
|
964 result = qxeWNetEnumResource (wnet_enum_handle, &count, buf, &bufsize);
|
|
965 if (result != NO_ERROR)
|
|
966 return NULL;
|
|
967
|
|
968 /* WNetEnumResource returns \\resource\share...skip forward to "share". */
|
|
969 TSTR_TO_C_STRING (((LPNETRESOURCEW) buf)->lpRemoteName, ptr);
|
867
|
970 INC_IBYTEPTR (ptr);
|
|
971 INC_IBYTEPTR (ptr);
|
|
972 while (*ptr && !IS_DIRECTORY_SEP (itext_ichar (ptr)))
|
|
973 INC_IBYTEPTR (ptr);
|
|
974 INC_IBYTEPTR (ptr);
|
771
|
975
|
|
976 return qxestrdup (ptr);
|
|
977 }
|
|
978
|
|
979 static int
|
|
980 close_unc_volume (HANDLE henum)
|
|
981 {
|
|
982 if (henum != INVALID_HANDLE_VALUE)
|
|
983 return WNetCloseEnum (henum) == NO_ERROR ? 0 : -1;
|
442
|
984 else
|
|
985 return -1;
|
428
|
986 }
|
|
987
|
771
|
988 static DWORD
|
867
|
989 unc_volume_file_attributes (const Ibyte *path)
|
428
|
990 {
|
771
|
991 HANDLE henum;
|
|
992 DWORD attrs;
|
|
993
|
|
994 henum = open_unc_volume (path);
|
|
995 if (henum == INVALID_HANDLE_VALUE)
|
|
996 return -1;
|
|
997
|
|
998 attrs = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY;
|
|
999
|
|
1000 close_unc_volume (henum);
|
428
|
1001
|
771
|
1002 return attrs;
|
|
1003 }
|
|
1004
|
|
1005 int
|
867
|
1006 mswindows_access (const Ibyte *path, int mode)
|
771
|
1007 {
|
|
1008 DWORD attributes;
|
428
|
1009
|
771
|
1010 /* MSVC implementation doesn't recognize D_OK. */
|
|
1011 if (is_unc_volume (path))
|
|
1012 {
|
|
1013 attributes = unc_volume_file_attributes (path);
|
|
1014 if (attributes == -1)
|
|
1015 {
|
|
1016 errno = EACCES;
|
|
1017 return -1;
|
|
1018 }
|
428
|
1019 }
|
|
1020 else
|
|
1021 {
|
771
|
1022 Extbyte *pathext;
|
|
1023
|
|
1024 C_STRING_TO_TSTR (path, pathext);
|
|
1025 if ((attributes = qxeGetFileAttributes (pathext)) == -1)
|
|
1026 {
|
|
1027 /* Should try mapping GetLastError to errno; for now just indicate
|
|
1028 that path doesn't exist. */
|
|
1029 errno = EACCES;
|
|
1030 return -1;
|
|
1031 }
|
428
|
1032 }
|
771
|
1033 if ((mode & X_OK) != 0 && !is_exec (path))
|
|
1034 {
|
|
1035 errno = EACCES;
|
|
1036 return -1;
|
|
1037 }
|
|
1038 if ((mode & W_OK) != 0 && (attributes & FILE_ATTRIBUTE_READONLY) != 0)
|
428
|
1039 {
|
771
|
1040 errno = EACCES;
|
|
1041 return -1;
|
428
|
1042 }
|
771
|
1043 if ((mode & D_OK) != 0 && (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
|
|
1044 {
|
|
1045 errno = EACCES;
|
|
1046 return -1;
|
|
1047 }
|
|
1048 return 0;
|
428
|
1049 }
|
|
1050
|
771
|
1051 /* This only works on NTFS volumes, but is useful to have. */
|
|
1052 /* #### NT 5.0 has a function CreateHardLink to do this directly,
|
|
1053 and it may do more things. */
|
428
|
1054 int
|
867
|
1055 mswindows_link (const Ibyte *old, const Ibyte *new)
|
428
|
1056 {
|
771
|
1057 HANDLE fileh;
|
|
1058 int result = -1;
|
|
1059
|
|
1060 if (old == NULL || new == NULL)
|
|
1061 {
|
|
1062 errno = ENOENT;
|
|
1063 return -1;
|
|
1064 }
|
|
1065
|
|
1066 C_STRING_TO_TSTR (old, old);
|
|
1067 fileh = qxeCreateFile (old, 0, 0, NULL, OPEN_EXISTING,
|
|
1068 FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
|
1069 if (fileh != INVALID_HANDLE_VALUE)
|
|
1070 {
|
|
1071 int wlen;
|
|
1072 WCHAR *newuni;
|
|
1073
|
|
1074 /* Confusingly, the "alternate" stream name field does not apply
|
|
1075 when restoring a hard link, and instead contains the actual
|
|
1076 stream data for the link (ie. the name of the link to create).
|
|
1077 The WIN32_STREAM_ID structure before the cStreamName field is
|
|
1078 the stream header, which is then immediately followed by the
|
|
1079 stream data. */
|
|
1080
|
|
1081 struct
|
|
1082 {
|
|
1083 WIN32_STREAM_ID wid;
|
|
1084 WCHAR wbuffer[MAX_PATH]; /* extra space for link name */
|
|
1085 } data;
|
|
1086
|
|
1087 TO_EXTERNAL_FORMAT (C_STRING, new,
|
|
1088 ALLOCA, (newuni, wlen), Qmswindows_unicode);
|
|
1089 if (wlen / sizeof (WCHAR) < MAX_PATH)
|
|
1090 {
|
|
1091 LPVOID context = NULL;
|
|
1092 DWORD wbytes = 0;
|
428
|
1093
|
771
|
1094 wcscpy (data.wid.cStreamName, newuni);
|
|
1095 data.wid.dwStreamId = BACKUP_LINK;
|
|
1096 data.wid.dwStreamAttributes = 0;
|
|
1097 data.wid.Size.LowPart = wlen; /* in bytes, not chars! */
|
|
1098 data.wid.Size.HighPart = 0;
|
|
1099 data.wid.dwStreamNameSize = 0;
|
|
1100
|
|
1101 if (BackupWrite (fileh, (LPBYTE)&data,
|
|
1102 offsetof (WIN32_STREAM_ID, cStreamName)
|
|
1103 + data.wid.Size.LowPart,
|
|
1104 &wbytes, FALSE, FALSE, &context)
|
|
1105 && BackupWrite (fileh, NULL, 0, &wbytes, TRUE, FALSE, &context))
|
|
1106 {
|
|
1107 /* succeeded */
|
|
1108 result = 0;
|
|
1109 }
|
|
1110 else
|
|
1111 {
|
|
1112 /* Should try mapping GetLastError to errno; for now just
|
|
1113 indicate a general error (eg. links not supported). */
|
|
1114 errno = EINVAL; // perhaps EMLINK?
|
|
1115 }
|
|
1116 }
|
|
1117
|
|
1118 CloseHandle (fileh);
|
|
1119 }
|
|
1120 else
|
|
1121 errno = ENOENT;
|
|
1122
|
|
1123 return result;
|
|
1124 }
|
|
1125
|
|
1126 /* sys_open() merged into sysdep.c sys_open() */
|
|
1127
|
|
1128 int
|
867
|
1129 mswindows_rename (const Ibyte *oldname, const Ibyte *newname)
|
771
|
1130 {
|
|
1131 int result;
|
867
|
1132 Ibyte *temp;
|
771
|
1133
|
|
1134 /* MoveFile on Windows 95 doesn't correctly change the short file name
|
428
|
1135 alias in a number of circumstances (it is not easy to predict when
|
|
1136 just by looking at oldname and newname, unfortunately). In these
|
|
1137 cases, renaming through a temporary name avoids the problem.
|
|
1138
|
771
|
1139 A second problem on Windows 95 is that renaming through a temp name when
|
428
|
1140 newname is uppercase fails (the final long name ends up in
|
|
1141 lowercase, although the short alias might be uppercase) UNLESS the
|
|
1142 long temp name is not 8.3.
|
|
1143
|
771
|
1144 So, on Windows 95 we always rename through a temp name, and we make sure
|
428
|
1145 the temp name has a long extension to ensure correct renaming. */
|
|
1146
|
771
|
1147 /* XEmacs: We sprintf() part of OLDNAME into part of OLDNAME + a number,
|
|
1148 so the following calculation should certainly be enough. */
|
428
|
1149
|
867
|
1150 temp = qxestrcpy (alloca_ibytes (2 * qxestrlen (oldname) + 100), oldname);
|
771
|
1151
|
|
1152 if (mswindows_windows9x_p)
|
428
|
1153 {
|
867
|
1154 Ibyte *o;
|
|
1155 Ibyte *p;
|
771
|
1156 int i = 0;
|
428
|
1157
|
771
|
1158 if (o = qxestrrchr (oldname, '\\'))
|
|
1159 o++;
|
|
1160 else
|
867
|
1161 o = (Ibyte *) oldname;
|
771
|
1162
|
|
1163 if (p = qxestrrchr (temp, '\\'))
|
428
|
1164 p++;
|
|
1165 else
|
|
1166 p = temp;
|
771
|
1167
|
|
1168 do
|
|
1169 {
|
|
1170 Extbyte *oldext, *tempext;
|
|
1171 /* Force temp name to require a manufactured 8.3 alias - this
|
|
1172 seems to make the second rename work properly. */
|
|
1173 qxesprintf (p, "_.%s.%u", o, i);
|
|
1174 i++;
|
|
1175 C_STRING_TO_EXTERNAL (oldname, oldext, Qfile_name);
|
|
1176 C_STRING_TO_EXTERNAL (temp, tempext, Qfile_name);
|
|
1177 result = rename (oldext, tempext);
|
|
1178 }
|
|
1179 /* This loop must surely terminate! */
|
|
1180 while (result < 0 && errno == EEXIST);
|
|
1181 if (result < 0)
|
428
|
1182 return -1;
|
|
1183 }
|
|
1184
|
771
|
1185 /* Emulate Unix behaviour - newname is deleted if it already exists
|
428
|
1186 (at least if it is a file; don't do this for directories).
|
771
|
1187
|
|
1188 Since we mustn't do this if we are just changing the case of the
|
|
1189 file name (we would end up deleting the file we are trying to
|
|
1190 rename!), we let rename detect if the destination file already
|
|
1191 exists - that way we avoid the possible pitfalls of trying to
|
|
1192 determine ourselves whether two names really refer to the same
|
|
1193 file, which is not always possible in the general case. (Consider
|
|
1194 all the permutations of shared or subst'd drives, etc.) */
|
|
1195 {
|
|
1196 Extbyte *newext, *tempext;
|
|
1197
|
|
1198 C_STRING_TO_EXTERNAL (newname, newext, Qfile_name);
|
|
1199 C_STRING_TO_EXTERNAL (temp, tempext, Qfile_name);
|
|
1200 result = rename (tempext, newext);
|
428
|
1201
|
771
|
1202 if (result < 0
|
872
|
1203 && (errno == EEXIST || errno == EACCES)
|
771
|
1204 && _chmod (newext, 0666) == 0
|
|
1205 && _unlink (newext) == 0)
|
|
1206 result = rename (tempext, newext);
|
|
1207 }
|
|
1208
|
|
1209 return result;
|
|
1210 }
|
428
|
1211
|
771
|
1212 int
|
867
|
1213 mswindows_unlink (const Ibyte *path)
|
771
|
1214 {
|
|
1215 Extbyte *pathout;
|
|
1216
|
|
1217 C_STRING_TO_EXTERNAL (path, pathout, Qfile_name);
|
|
1218 /* On Unix, unlink works without write permission. */
|
|
1219 _chmod (pathout, 0666);
|
|
1220 return _unlink (pathout);
|
428
|
1221 }
|
|
1222
|
|
1223 static FILETIME utc_base_ft;
|
592
|
1224 static long double utc_base;
|
440
|
1225 static int init = 0;
|
771
|
1226 static LARGE_INTEGER utc_base_li;
|
440
|
1227
|
771
|
1228 /* XEmacs: We seem to have a new definition of
|
|
1229 mswindows_convert_time(), although I'm not sure why. --ben */
|
428
|
1230
|
|
1231 time_t
|
771
|
1232 mswindows_convert_time (FILETIME uft)
|
440
|
1233 {
|
|
1234 time_t ret;
|
|
1235 #ifndef MAXLONGLONG
|
|
1236 SYSTEMTIME st;
|
|
1237 struct tm t;
|
|
1238 FILETIME ft;
|
|
1239 TIME_ZONE_INFORMATION tzi;
|
|
1240 DWORD tzid;
|
|
1241 #else
|
|
1242 LARGE_INTEGER lft;
|
|
1243 #endif
|
|
1244
|
|
1245 if (!init)
|
|
1246 {
|
|
1247 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
|
|
1248 SYSTEMTIME st;
|
|
1249
|
|
1250 st.wYear = 1970;
|
|
1251 st.wMonth = 1;
|
|
1252 st.wDay = 1;
|
|
1253 st.wHour = 0;
|
|
1254 st.wMinute = 0;
|
|
1255 st.wSecond = 0;
|
|
1256 st.wMilliseconds = 0;
|
|
1257
|
|
1258 SystemTimeToFileTime (&st, &utc_base_ft);
|
|
1259
|
|
1260 utc_base_li.LowPart = utc_base_ft.dwLowDateTime;
|
|
1261 utc_base_li.HighPart = utc_base_ft.dwHighDateTime;
|
|
1262
|
|
1263 init = 1;
|
|
1264 }
|
|
1265
|
|
1266 #ifdef MAXLONGLONG
|
|
1267
|
|
1268 /* On a compiler that supports long integers, do it the easy way */
|
|
1269 lft.LowPart = uft.dwLowDateTime;
|
|
1270 lft.HighPart = uft.dwHighDateTime;
|
|
1271 ret = (time_t) ((lft.QuadPart - utc_base_li.QuadPart) / 10000000);
|
|
1272
|
|
1273 #else
|
|
1274
|
|
1275 /* Do it the hard way using mktime. */
|
|
1276 FileTimeToLocalFileTime(&uft, &ft);
|
|
1277 FileTimeToSystemTime (&ft, &st);
|
|
1278 tzid = GetTimeZoneInformation (&tzi);
|
|
1279 t.tm_year = st.wYear - 1900;
|
|
1280 t.tm_mon = st.wMonth - 1;
|
|
1281 t.tm_mday = st.wDay;
|
|
1282 t.tm_hour = st.wHour;
|
|
1283 t.tm_min = st.wMinute;
|
|
1284 t.tm_sec = st.wSecond;
|
|
1285 t.tm_isdst = (tzid == TIME_ZONE_ID_DAYLIGHT);
|
|
1286 /* st.wMilliseconds not applicable */
|
|
1287 ret = mktime(&t);
|
|
1288 if (ret == -1)
|
|
1289 {
|
|
1290 ret = 0;
|
|
1291 }
|
|
1292
|
|
1293 #endif
|
|
1294
|
|
1295 return ret;
|
|
1296 }
|
428
|
1297
|
771
|
1298 static void
|
428
|
1299 convert_from_time_t (time_t time, FILETIME * pft)
|
|
1300 {
|
|
1301 long double tmp;
|
|
1302
|
|
1303 if (!init)
|
|
1304 {
|
|
1305 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
|
|
1306 SYSTEMTIME st;
|
|
1307
|
|
1308 st.wYear = 1970;
|
|
1309 st.wMonth = 1;
|
|
1310 st.wDay = 1;
|
|
1311 st.wHour = 0;
|
|
1312 st.wMinute = 0;
|
|
1313 st.wSecond = 0;
|
|
1314 st.wMilliseconds = 0;
|
|
1315
|
|
1316 SystemTimeToFileTime (&st, &utc_base_ft);
|
|
1317 utc_base = (long double) utc_base_ft.dwHighDateTime
|
|
1318 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
|
|
1319 init = 1;
|
|
1320 }
|
|
1321
|
|
1322 /* time in 100ns units since 1-Jan-1601 */
|
|
1323 tmp = (long double) time * 1e7 + utc_base;
|
|
1324 pft->dwHighDateTime = (DWORD) (tmp / (4096.0 * 1024 * 1024));
|
771
|
1325 pft->dwLowDateTime = (DWORD) (tmp - (4096.0 * 1024 * 1024) *
|
|
1326 pft->dwHighDateTime);
|
428
|
1327 }
|
|
1328
|
|
1329 #if 0
|
771
|
1330 /* A comment from Emacs 20.6:
|
|
1331
|
|
1332 No reason to keep this; faking inode values either by hashing or even
|
428
|
1333 using the file index from GetInformationByHandle, is not perfect and
|
|
1334 so by default Emacs doesn't use the inode values on Windows.
|
|
1335 Instead, we now determine file-truename correctly (except for
|
|
1336 possible drive aliasing etc). */
|
|
1337
|
771
|
1338 /* XEmacs: Removed the fake-inodes code here, which was if 0'd out.
|
|
1339 If you want it, look in w32.c in Emacs 20.6. */
|
428
|
1340 #endif
|
|
1341
|
442
|
1342 /* #### aichner@ecf.teradyne.com reported that with the library
|
|
1343 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
|
|
1344 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
|
|
1345 we opt to use non-encapsulated stat(), this should serve as
|
|
1346 a compatibility test. --kkm */
|
440
|
1347
|
771
|
1348 /* Provide fstat and utime as well as stat for consistent handling of
|
|
1349 file timestamps. */
|
442
|
1350 int
|
771
|
1351 mswindows_fstat (int desc, struct stat *buf)
|
432
|
1352 {
|
448
|
1353 HANDLE fh = (HANDLE) _get_osfhandle (desc);
|
|
1354 BY_HANDLE_FILE_INFORMATION info;
|
|
1355 DWORD fake_inode;
|
|
1356 int permission;
|
|
1357
|
|
1358 switch (GetFileType (fh) & ~FILE_TYPE_REMOTE)
|
432
|
1359 {
|
448
|
1360 case FILE_TYPE_DISK:
|
|
1361 buf->st_mode = _S_IFREG;
|
|
1362 if (!GetFileInformationByHandle (fh, &info))
|
|
1363 {
|
|
1364 errno = EACCES;
|
|
1365 return -1;
|
|
1366 }
|
|
1367 break;
|
|
1368 case FILE_TYPE_PIPE:
|
|
1369 buf->st_mode = _S_IFIFO;
|
|
1370 goto non_disk;
|
|
1371 case FILE_TYPE_CHAR:
|
|
1372 case FILE_TYPE_UNKNOWN:
|
|
1373 default:
|
|
1374 buf->st_mode = _S_IFCHR;
|
|
1375 non_disk:
|
|
1376 memset (&info, 0, sizeof (info));
|
|
1377 info.dwFileAttributes = 0;
|
|
1378 info.ftCreationTime = utc_base_ft;
|
|
1379 info.ftLastAccessTime = utc_base_ft;
|
|
1380 info.ftLastWriteTime = utc_base_ft;
|
|
1381 }
|
|
1382
|
|
1383 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1384 {
|
|
1385 buf->st_mode = _S_IFDIR;
|
|
1386 buf->st_nlink = 2; /* doesn't really matter */
|
|
1387 fake_inode = 0; /* this doesn't either I think */
|
432
|
1388 }
|
|
1389 else
|
|
1390 {
|
462
|
1391 buf->st_nlink = (short) info.nNumberOfLinks;
|
448
|
1392 /* Might as well use file index to fake inode values, but this
|
|
1393 is not guaranteed to be unique unless we keep a handle open
|
|
1394 all the time (even then there are situations where it is
|
|
1395 not unique). Reputedly, there are at most 48 bits of info
|
|
1396 (on NTFS, presumably less on FAT). */
|
|
1397 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
|
432
|
1398 }
|
448
|
1399
|
|
1400 /* MSVC defines _ino_t to be short; other libc's might not. */
|
|
1401 if (sizeof (buf->st_ino) == 2)
|
462
|
1402 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
|
448
|
1403 else
|
462
|
1404 buf->st_ino = (unsigned short) fake_inode;
|
448
|
1405
|
|
1406 /* consider files to belong to current user */
|
|
1407 buf->st_uid = 0;
|
|
1408 buf->st_gid = 0;
|
|
1409
|
|
1410 buf->st_dev = info.dwVolumeSerialNumber;
|
|
1411 buf->st_rdev = info.dwVolumeSerialNumber;
|
|
1412
|
|
1413 buf->st_size = info.nFileSizeLow;
|
|
1414
|
|
1415 /* Convert timestamps to Unix format. */
|
771
|
1416 buf->st_mtime = mswindows_convert_time (info.ftLastWriteTime);
|
|
1417 buf->st_atime = mswindows_convert_time (info.ftLastAccessTime);
|
448
|
1418 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
|
771
|
1419 buf->st_ctime = mswindows_convert_time (info.ftCreationTime);
|
448
|
1420 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
|
|
1421
|
|
1422 /* determine rwx permissions */
|
|
1423 if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
1424 permission = _S_IREAD;
|
|
1425 else
|
|
1426 permission = _S_IREAD | _S_IWRITE;
|
|
1427
|
|
1428 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1429 permission |= _S_IEXEC;
|
771
|
1430 else
|
|
1431 {
|
|
1432 #if 0 /* no way of knowing the filename */
|
867
|
1433 Ibyte *p = qxestrrchr (name, '.');
|
771
|
1434 if (p != NULL &&
|
|
1435 (qxestrcasecmp (p, ".exe") == 0 ||
|
|
1436 qxestrcasecmp (p, ".com") == 0 ||
|
|
1437 qxestrcasecmp (p, ".bat") == 0 ||
|
|
1438 qxestrcasecmp (p, ".cmd") == 0))
|
|
1439 permission |= _S_IEXEC;
|
|
1440 #endif
|
|
1441 }
|
448
|
1442
|
|
1443 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
|
|
1444
|
|
1445 return 0;
|
432
|
1446 }
|
|
1447
|
428
|
1448 /* MSVC stat function can't cope with UNC names and has other bugs, so
|
|
1449 replace it with our own. This also allows us to calculate consistent
|
|
1450 inode values without hacks in the main Emacs code. */
|
|
1451 int
|
867
|
1452 mswindows_stat (const Ibyte *path, struct stat *buf)
|
428
|
1453 {
|
867
|
1454 Ibyte *name, *r;
|
771
|
1455 WIN32_FIND_DATAW wfd;
|
428
|
1456 HANDLE fh;
|
|
1457 DWORD fake_inode;
|
|
1458 int permission;
|
771
|
1459 Bytecount len;
|
428
|
1460 int rootdir = FALSE;
|
771
|
1461 Extbyte *nameext;
|
819
|
1462 int errm;
|
428
|
1463
|
|
1464 if (path == NULL || buf == NULL)
|
|
1465 {
|
|
1466 errno = EFAULT;
|
|
1467 return -1;
|
|
1468 }
|
|
1469
|
867
|
1470 name = qxestrcpy (alloca_ibytes (qxestrlen (path) + 10), path);
|
819
|
1471 errm = SetErrorMode (SEM_FAILCRITICALERRORS
|
|
1472 | SEM_NOOPENFILEERRORBOX);
|
771
|
1473
|
|
1474 get_volume_info (name, &path);
|
|
1475 /* must be valid filename, no wild cards or other invalid characters */
|
|
1476 if (qxestrpbrk (name, "*?|<>\""))
|
428
|
1477 {
|
|
1478 errno = ENOENT;
|
|
1479 return -1;
|
|
1480 }
|
|
1481
|
771
|
1482 /* If name is "c:/.." or "/.." then stat "c:/" or "/". */
|
|
1483 r = IS_DEVICE_SEP (name[1]) ? &name[2] : name;
|
|
1484 if (IS_DIRECTORY_SEP (r[0]) && r[1] == '.' && r[2] == '.' && r[3] == '\0')
|
|
1485 {
|
|
1486 r[1] = r[2] = '\0';
|
|
1487 }
|
|
1488
|
428
|
1489 /* Remove trailing directory separator, unless name is the root
|
|
1490 directory of a drive or UNC volume in which case ensure there
|
|
1491 is a trailing separator. */
|
771
|
1492 len = qxestrlen (name);
|
428
|
1493 rootdir = (path >= name + len - 1
|
|
1494 && (IS_DIRECTORY_SEP (*path) || *path == 0));
|
771
|
1495
|
|
1496 if (is_unc_volume (name))
|
|
1497 {
|
|
1498 DWORD attrs = unc_volume_file_attributes (name);
|
|
1499
|
|
1500 if (attrs == -1)
|
|
1501 return -1;
|
428
|
1502
|
771
|
1503 memset (&wfd, 0, sizeof (wfd));
|
|
1504 wfd.dwFileAttributes = attrs;
|
|
1505 wfd.ftCreationTime = utc_base_ft;
|
|
1506 wfd.ftLastAccessTime = utc_base_ft;
|
|
1507 wfd.ftLastWriteTime = utc_base_ft;
|
|
1508 /* XEmacs deleted: strcpy (wfd.cFileName, name);
|
|
1509 Not used later on. */
|
|
1510 }
|
|
1511 else if (rootdir)
|
428
|
1512 {
|
|
1513 if (!IS_DIRECTORY_SEP (name[len-1]))
|
867
|
1514 qxestrcat (name, (Ibyte *) "\\");
|
771
|
1515 C_STRING_TO_TSTR (name, nameext);
|
|
1516 if (qxeGetDriveType (nameext) < 2)
|
428
|
1517 {
|
819
|
1518 SetErrorMode (errm);
|
428
|
1519 errno = ENOENT;
|
|
1520 return -1;
|
|
1521 }
|
|
1522 memset (&wfd, 0, sizeof (wfd));
|
|
1523 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
|
1524 wfd.ftCreationTime = utc_base_ft;
|
|
1525 wfd.ftLastAccessTime = utc_base_ft;
|
|
1526 wfd.ftLastWriteTime = utc_base_ft;
|
771
|
1527 /* XEmacs deleted: strcpy (wfd.cFileName, name);
|
|
1528 Not used later on. */
|
428
|
1529 }
|
|
1530 else
|
|
1531 {
|
|
1532 if (IS_DIRECTORY_SEP (name[len-1]))
|
|
1533 name[len - 1] = 0;
|
|
1534
|
|
1535 /* (This is hacky, but helps when doing file completions on
|
|
1536 network drives.) Optimize by using information available from
|
|
1537 active readdir if possible. */
|
771
|
1538 if (dir_pathname)
|
|
1539 {
|
|
1540 len = qxestrlen (dir_pathname);
|
|
1541 if (len && IS_DIRECTORY_SEP (dir_pathname[len-1]))
|
|
1542 len--;
|
|
1543 }
|
|
1544 if (dir_find_handle != INVALID_HANDLE_VALUE
|
|
1545 && dir_pathname
|
801
|
1546 && qxestrncasecmp_i18n (dir_pathname, name, len) == 0
|
771
|
1547 && IS_DIRECTORY_SEP (name[len])
|
|
1548 && qxestrcasecmp_i18n (name + len + 1,
|
867
|
1549 (Ibyte *) dir_static.d_name) == 0)
|
428
|
1550 {
|
|
1551 /* This was the last entry returned by readdir. */
|
|
1552 wfd = dir_find_data;
|
|
1553 }
|
|
1554 else
|
|
1555 {
|
771
|
1556 C_STRING_TO_TSTR (name, nameext);
|
|
1557 fh = qxeFindFirstFile (nameext, &wfd);
|
|
1558 if (fh == INVALID_HANDLE_VALUE)
|
|
1559 {
|
819
|
1560 SetErrorMode (errm);
|
771
|
1561 errno = ENOENT;
|
|
1562 return -1;
|
|
1563 }
|
|
1564 FindClose (fh);
|
|
1565 /* XEmacs: Don't need to convert wfd.cFileName because
|
|
1566 not used later on. */
|
428
|
1567 }
|
|
1568 }
|
|
1569
|
|
1570 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1571 {
|
|
1572 buf->st_mode = _S_IFDIR;
|
|
1573 buf->st_nlink = 2; /* doesn't really matter */
|
|
1574 fake_inode = 0; /* this doesn't either I think */
|
|
1575 }
|
771
|
1576 else
|
428
|
1577 {
|
771
|
1578 if (!NILP (Vmswindows_get_true_file_attributes))
|
|
1579 C_STRING_TO_TSTR (name, nameext);
|
|
1580 if (!NILP (Vmswindows_get_true_file_attributes)
|
|
1581 /* No access rights required to get info. */
|
|
1582 && (fh = qxeCreateFile (nameext, 0, 0, NULL, OPEN_EXISTING, 0, NULL))
|
|
1583 != INVALID_HANDLE_VALUE)
|
|
1584 {
|
|
1585 /* This is more accurate in terms of gettting the correct number
|
|
1586 of links, but is quite slow (it is noticable when Emacs is
|
|
1587 making a list of file name completions). */
|
|
1588 BY_HANDLE_FILE_INFORMATION info;
|
428
|
1589
|
771
|
1590 if (GetFileInformationByHandle (fh, &info))
|
|
1591 {
|
|
1592 buf->st_nlink = (short) info.nNumberOfLinks;
|
|
1593 /* Might as well use file index to fake inode values, but this
|
|
1594 is not guaranteed to be unique unless we keep a handle open
|
|
1595 all the time (even then there are situations where it is
|
|
1596 not unique). Reputedly, there are at most 48 bits of info
|
|
1597 (on NTFS, presumably less on FAT). */
|
|
1598 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
|
|
1599 }
|
|
1600 else
|
|
1601 {
|
|
1602 buf->st_nlink = 1;
|
|
1603 fake_inode = 0;
|
|
1604 }
|
428
|
1605
|
|
1606 switch (GetFileType (fh))
|
|
1607 {
|
|
1608 case FILE_TYPE_DISK:
|
|
1609 buf->st_mode = _S_IFREG;
|
|
1610 break;
|
|
1611 case FILE_TYPE_PIPE:
|
|
1612 buf->st_mode = _S_IFIFO;
|
|
1613 break;
|
|
1614 case FILE_TYPE_CHAR:
|
|
1615 case FILE_TYPE_UNKNOWN:
|
|
1616 default:
|
|
1617 buf->st_mode = _S_IFCHR;
|
|
1618 }
|
|
1619 CloseHandle (fh);
|
|
1620 }
|
|
1621 else
|
|
1622 {
|
771
|
1623 /* Don't bother to make this information more accurate. */
|
|
1624 buf->st_mode = _S_IFREG;
|
|
1625 buf->st_nlink = 1;
|
|
1626 fake_inode = 0;
|
428
|
1627 }
|
|
1628 }
|
|
1629
|
819
|
1630 SetErrorMode (errm);
|
|
1631
|
428
|
1632 #if 0
|
771
|
1633 /* XEmacs: Removed the fake-inodes code here, which was if 0'd out.
|
|
1634 If you want it, look in w32.c in Emacs 20.6. */
|
428
|
1635 #endif
|
|
1636
|
771
|
1637 /* MSVC defines _ino_t to be short; other libc's might not. */
|
|
1638 if (sizeof (buf->st_ino) == 2)
|
|
1639 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
|
|
1640 else
|
|
1641 buf->st_ino = (unsigned short) fake_inode;
|
428
|
1642
|
|
1643 /* consider files to belong to current user */
|
771
|
1644 buf->st_uid = the_passwd.pw_uid;
|
|
1645 buf->st_gid = the_passwd.pw_gid;
|
428
|
1646
|
771
|
1647 /* volume_info is set by get_volume_info */
|
428
|
1648 buf->st_dev = volume_info.serialnum;
|
|
1649 buf->st_rdev = volume_info.serialnum;
|
|
1650
|
771
|
1651
|
428
|
1652 buf->st_size = wfd.nFileSizeLow;
|
|
1653
|
|
1654 /* Convert timestamps to Unix format. */
|
771
|
1655 buf->st_mtime = mswindows_convert_time (wfd.ftLastWriteTime);
|
|
1656 buf->st_atime = mswindows_convert_time (wfd.ftLastAccessTime);
|
428
|
1657 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
|
771
|
1658 buf->st_ctime = mswindows_convert_time (wfd.ftCreationTime);
|
428
|
1659 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
|
|
1660
|
|
1661 /* determine rwx permissions */
|
|
1662 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
1663 permission = _S_IREAD;
|
|
1664 else
|
|
1665 permission = _S_IREAD | _S_IWRITE;
|
|
1666
|
|
1667 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1668 permission |= _S_IEXEC;
|
771
|
1669 else if (is_exec (name))
|
|
1670 permission |= _S_IEXEC;
|
428
|
1671
|
|
1672 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
|
|
1673
|
|
1674 return 0;
|
|
1675 }
|
|
1676
|
|
1677 int
|
771
|
1678 mswindows_utime (Lisp_Object path, struct utimbuf *times)
|
428
|
1679 {
|
771
|
1680 /* #### Supposedly we're providing this because standard utime()
|
|
1681 might not work; or at the very least to get consistent results
|
|
1682 since we replace other time-handling routines in stat. But out
|
|
1683 replacement doesn't seem to work, probably due to some subtle bug
|
|
1684 in this routine, which should be investigated eventually. So for
|
|
1685 the moment, we just use utime(), which conceivably might be
|
|
1686 slightly off in comparison with our own routines? Seems strange,
|
|
1687 and so far no problems seen. --ben */
|
428
|
1688
|
771
|
1689 struct utimbuf deftime;
|
|
1690 #if 0
|
|
1691 HANDLE fh;
|
|
1692 #endif
|
|
1693 static FILETIME mtime;
|
|
1694 static FILETIME atime;
|
|
1695 Extbyte *filename;
|
428
|
1696
|
771
|
1697 if (times == NULL)
|
428
|
1698 {
|
771
|
1699 deftime.modtime = deftime.actime = time (NULL);
|
|
1700 times = &deftime;
|
428
|
1701 }
|
|
1702
|
771
|
1703 LISP_STRING_TO_TSTR (path, filename);
|
|
1704 /* APA: SetFileTime fails to set mtime correctly (always 1-Jan-1970) */
|
|
1705 #if 0
|
|
1706 /* Need write access to set times. */
|
|
1707 fh = qxeCreateFile (filename, GENERIC_WRITE,
|
|
1708 FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
1709 0, OPEN_EXISTING, 0, NULL);
|
|
1710 if (fh)
|
|
1711 {
|
|
1712 convert_from_time_t (times->actime, &atime);
|
|
1713 convert_from_time_t (times->modtime, &mtime);
|
|
1714 if (!SetFileTime (fh, NULL, &atime, &mtime))
|
|
1715 {
|
|
1716 CloseHandle (fh);
|
|
1717 errno = EACCES;
|
|
1718 return -1;
|
|
1719 }
|
|
1720 CloseHandle (fh);
|
|
1721 }
|
|
1722 else
|
|
1723 {
|
|
1724 errno = EINVAL;
|
|
1725 return -1;
|
|
1726 }
|
|
1727 return 0;
|
|
1728 #else
|
|
1729 {
|
|
1730 struct _utimbuf newtimes;
|
|
1731
|
|
1732 newtimes.actime = times->actime;
|
|
1733 newtimes.modtime = times->modtime;
|
|
1734
|
|
1735 if (XEUNICODE_P)
|
|
1736 return _wutime ((const wchar_t *) filename, &newtimes);
|
|
1737 else
|
|
1738 return _utime (filename, &newtimes);
|
|
1739 }
|
|
1740 #endif
|
|
1741 }
|
|
1742
|
867
|
1743 Ibyte *
|
771
|
1744 mswindows_getdcwd (int drivelet)
|
|
1745 {
|
|
1746 Extbyte *cwdext;
|
867
|
1747 Ibyte *cwd;
|
771
|
1748
|
|
1749 if (XEUNICODE_P)
|
|
1750 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0);
|
|
1751 else
|
|
1752 cwdext = _getdcwd (drivelet, NULL, 0);
|
|
1753 TSTR_TO_C_STRING_MALLOC (cwdext, cwd);
|
|
1754 xfree (cwdext);
|
|
1755 return cwd;
|
428
|
1756 }
|
|
1757
|
442
|
1758
|
|
1759 /*--------------------------------------------------------------------*/
|
|
1760 /* Memory-mapped files */
|
|
1761 /*--------------------------------------------------------------------*/
|
|
1762
|
428
|
1763 int
|
867
|
1764 open_input_file (file_data *p_file, const Ibyte *filename)
|
428
|
1765 {
|
442
|
1766 /* Synched with FSF 20.6. We fixed some warnings. */
|
428
|
1767 HANDLE file;
|
|
1768 HANDLE file_mapping;
|
771
|
1769 void *file_base;
|
428
|
1770 DWORD size, upper_size;
|
771
|
1771 Extbyte *fileext;
|
428
|
1772
|
771
|
1773 C_STRING_TO_TSTR (filename, fileext);
|
|
1774
|
|
1775 file = qxeCreateFile (fileext, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
1776 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
428
|
1777 if (file == INVALID_HANDLE_VALUE)
|
|
1778 return FALSE;
|
|
1779
|
|
1780 size = GetFileSize (file, &upper_size);
|
771
|
1781 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_READONLY,
|
|
1782 0, size, NULL);
|
428
|
1783 if (!file_mapping)
|
|
1784 return FALSE;
|
|
1785
|
|
1786 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
|
|
1787 if (file_base == 0)
|
|
1788 return FALSE;
|
|
1789
|
771
|
1790 p_file->name = filename;
|
442
|
1791 p_file->size = size;
|
|
1792 p_file->file = file;
|
|
1793 p_file->file_mapping = file_mapping;
|
771
|
1794 p_file->file_base = file_base;
|
442
|
1795
|
|
1796 return TRUE;
|
|
1797 }
|
|
1798
|
|
1799 int
|
867
|
1800 open_output_file (file_data *p_file, const Ibyte *filename,
|
771
|
1801 unsigned long size)
|
442
|
1802 {
|
|
1803 /* Synched with FSF 20.6. We fixed some warnings. */
|
|
1804 HANDLE file;
|
|
1805 HANDLE file_mapping;
|
771
|
1806 void *file_base;
|
|
1807 Extbyte *fileext;
|
442
|
1808
|
771
|
1809 C_STRING_TO_TSTR (filename, fileext);
|
|
1810
|
|
1811 file = qxeCreateFile (fileext, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
1812 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
442
|
1813 if (file == INVALID_HANDLE_VALUE)
|
|
1814 return FALSE;
|
|
1815
|
771
|
1816 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_READWRITE,
|
|
1817 0, size, NULL);
|
442
|
1818 if (!file_mapping)
|
|
1819 return FALSE;
|
|
1820
|
|
1821 file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
|
|
1822 if (file_base == NULL)
|
|
1823 return FALSE;
|
|
1824
|
|
1825 p_file->name = filename;
|
428
|
1826 p_file->size = size;
|
|
1827 p_file->file = file;
|
|
1828 p_file->file_mapping = file_mapping;
|
771
|
1829 p_file->file_base = file_base;
|
428
|
1830
|
|
1831 return TRUE;
|
|
1832 }
|
|
1833
|
442
|
1834 #if 1 /* !defined(MINGW) */
|
|
1835 /* Return pointer to section header for section containing the given
|
|
1836 relative virtual address. */
|
|
1837 static IMAGE_SECTION_HEADER *
|
771
|
1838 rva_to_section (DWORD rva, IMAGE_NT_HEADERS *nt_header)
|
442
|
1839 {
|
|
1840 /* Synched with FSF 20.6. We added MINGW stuff. */
|
|
1841 PIMAGE_SECTION_HEADER section;
|
|
1842 int i;
|
|
1843
|
|
1844 section = IMAGE_FIRST_SECTION (nt_header);
|
|
1845
|
|
1846 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
|
|
1847 {
|
|
1848 /* Some linkers (eg. the NT SDK linker I believe) swapped the
|
|
1849 meaning of these two values - or rather, they ignored
|
|
1850 VirtualSize entirely and always set it to zero. This affects
|
|
1851 some very old exes (eg. gzip dated Dec 1993). Since
|
|
1852 mswindows_executable_type relies on this function to work reliably,
|
|
1853 we need to cope with this. */
|
|
1854 DWORD real_size = max (section->SizeOfRawData,
|
|
1855 section->Misc.VirtualSize);
|
|
1856 if (rva >= section->VirtualAddress
|
|
1857 && rva < section->VirtualAddress + real_size)
|
|
1858 return section;
|
|
1859 section++;
|
|
1860 }
|
|
1861 return NULL;
|
|
1862 }
|
|
1863 #endif
|
|
1864
|
|
1865 void
|
867
|
1866 mswindows_executable_type (const Ibyte *filename, int *is_dos_app,
|
771
|
1867 int *is_cygnus_app)
|
442
|
1868 {
|
|
1869 /* Synched with FSF 20.6. We added MINGW stuff and casts. */
|
|
1870 file_data executable;
|
867
|
1871 Ibyte *p;
|
442
|
1872
|
|
1873 /* Default values in case we can't tell for sure. */
|
|
1874 *is_dos_app = FALSE;
|
|
1875 *is_cygnus_app = FALSE;
|
|
1876
|
|
1877 if (!open_input_file (&executable, filename))
|
|
1878 return;
|
|
1879
|
771
|
1880 p = qxestrrchr (filename, '.');
|
442
|
1881
|
|
1882 /* We can only identify DOS .com programs from the extension. */
|
771
|
1883 if (p && qxestrcasecmp (p, ".com") == 0)
|
442
|
1884 *is_dos_app = TRUE;
|
771
|
1885 else if (p && (qxestrcasecmp (p, ".bat") == 0 ||
|
|
1886 qxestrcasecmp (p, ".cmd") == 0))
|
442
|
1887 {
|
|
1888 /* A DOS shell script - it appears that CreateProcess is happy to
|
|
1889 accept this (somewhat surprisingly); presumably it looks at
|
|
1890 COMSPEC to determine what executable to actually invoke.
|
|
1891 Therefore, we have to do the same here as well. */
|
|
1892 /* Actually, I think it uses the program association for that
|
|
1893 extension, which is defined in the registry. */
|
|
1894 p = egetenv ("COMSPEC");
|
|
1895 if (p)
|
|
1896 mswindows_executable_type (p, is_dos_app, is_cygnus_app);
|
|
1897 }
|
|
1898 else
|
|
1899 {
|
|
1900 /* Look for DOS .exe signature - if found, we must also check that
|
|
1901 it isn't really a 16- or 32-bit Windows exe, since both formats
|
|
1902 start with a DOS program stub. Note that 16-bit Windows
|
|
1903 executables use the OS/2 1.x format. */
|
|
1904
|
|
1905 #if 0 /* defined( MINGW ) */
|
771
|
1906 /* mingw doesn't have enough headers to detect cygwin
|
442
|
1907 apps, just do what we can. */
|
771
|
1908 FILHDR *exe_header;
|
442
|
1909
|
771
|
1910 exe_header = (FILHDR *) executable.file_base;
|
442
|
1911 if (exe_header->e_magic != DOSMAGIC)
|
|
1912 goto unwind;
|
|
1913
|
771
|
1914 if ((char *) exe_header->e_lfanew > (char *) executable.size)
|
442
|
1915 {
|
|
1916 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
|
|
1917 *is_dos_app = TRUE;
|
|
1918 }
|
|
1919 else if (exe_header->nt_signature != NT_SIGNATURE)
|
|
1920 {
|
|
1921 *is_dos_app = TRUE;
|
|
1922 }
|
|
1923 #else
|
771
|
1924 IMAGE_DOS_HEADER *dos_header;
|
|
1925 IMAGE_NT_HEADERS *nt_header;
|
442
|
1926
|
|
1927 dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
|
|
1928 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
|
|
1929 goto unwind;
|
|
1930
|
771
|
1931 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header +
|
|
1932 dos_header->e_lfanew);
|
442
|
1933
|
771
|
1934 if ((char *) nt_header > (char *) dos_header + executable.size)
|
442
|
1935 {
|
|
1936 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
|
|
1937 *is_dos_app = TRUE;
|
|
1938 }
|
|
1939 else if (nt_header->Signature != IMAGE_NT_SIGNATURE &&
|
|
1940 LOWORD (nt_header->Signature) != IMAGE_OS2_SIGNATURE)
|
|
1941 {
|
|
1942 *is_dos_app = TRUE;
|
|
1943 }
|
|
1944 else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
|
|
1945 {
|
|
1946 /* Look for cygwin.dll in DLL import list. */
|
|
1947 IMAGE_DATA_DIRECTORY import_dir =
|
771
|
1948 nt_header->OptionalHeader.
|
|
1949 DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
|
|
1950 IMAGE_IMPORT_DESCRIPTOR *imports;
|
|
1951 IMAGE_SECTION_HEADER *section;
|
442
|
1952
|
|
1953 section = rva_to_section (import_dir.VirtualAddress, nt_header);
|
771
|
1954 imports =
|
|
1955 (IMAGE_IMPORT_DESCRIPTOR *) RVA_TO_PTR (import_dir.VirtualAddress,
|
|
1956 section, executable);
|
|
1957
|
442
|
1958 for ( ; imports->Name; imports++)
|
|
1959 {
|
771
|
1960 Extbyte *dllname_ext =
|
|
1961 (Extbyte *) RVA_TO_PTR (imports->Name, section, executable);
|
867
|
1962 Ibyte *dllname;
|
771
|
1963
|
|
1964 EXTERNAL_TO_C_STRING (dllname_ext, dllname, Qbinary);
|
442
|
1965
|
|
1966 /* The exact name of the cygwin dll has changed with
|
|
1967 various releases, but hopefully this will be reasonably
|
|
1968 future proof. */
|
867
|
1969 if (qxestrncasecmp (dllname, (Ibyte *) "cygwin", 6) == 0)
|
442
|
1970 {
|
|
1971 *is_cygnus_app = TRUE;
|
|
1972 break;
|
|
1973 }
|
|
1974 }
|
|
1975 }
|
|
1976 #endif
|
|
1977 }
|
|
1978
|
|
1979 unwind:
|
|
1980 close_file_data (&executable);
|
|
1981 }
|
|
1982
|
428
|
1983 /* Close the system structures associated with the given file. */
|
|
1984 void
|
|
1985 close_file_data (file_data *p_file)
|
|
1986 {
|
611
|
1987 UnmapViewOfFile (p_file->file_base);
|
|
1988 CloseHandle (p_file->file_mapping);
|
|
1989 CloseHandle (p_file->file);
|
428
|
1990 }
|
|
1991
|
771
|
1992
|
|
1993 /* Some miscellaneous functions that are Windows specific, but not GUI
|
|
1994 specific (ie. are applicable in terminal or batch mode as well). */
|
|
1995
|
|
1996 DEFUN ("mswindows-short-file-name", Fmswindows_short_file_name, 1, 1, "", /*
|
|
1997 Return the short file name version (8.3) of the full path of FILENAME.
|
|
1998 If FILENAME does not exist, return nil.
|
|
1999 All path elements in FILENAME are converted to their short names.
|
|
2000 */
|
|
2001 (filename))
|
|
2002 {
|
|
2003 Extbyte shortname[MAX_PATH * MAX_XETCHAR_SIZE];
|
|
2004 Extbyte *fileext;
|
867
|
2005 Ibyte *shortint;
|
771
|
2006
|
|
2007 CHECK_STRING (filename);
|
|
2008
|
|
2009 /* first expand it. */
|
|
2010 filename = Fexpand_file_name (filename, Qnil);
|
|
2011
|
|
2012 LISP_STRING_TO_TSTR (filename, fileext);
|
|
2013 /* luckily, this returns the short version of each element in the path. */
|
|
2014 if (qxeGetShortPathName (fileext, shortname,
|
|
2015 sizeof (shortname) / XETCHAR_SIZE) == 0)
|
|
2016 return Qnil;
|
|
2017
|
|
2018 TSTR_TO_C_STRING (shortname, shortint);
|
|
2019 MSWINDOWS_NORMALIZE_FILENAME (shortint);
|
|
2020
|
|
2021 return build_string (shortint);
|
|
2022 }
|
|
2023
|
|
2024
|
|
2025 DEFUN ("mswindows-long-file-name", Fmswindows_long_file_name, 1, 1, "", /*
|
|
2026 Return the long file name version of the full path of FILENAME.
|
|
2027 If FILENAME does not exist, return nil.
|
|
2028 All path elements in FILENAME are converted to their long names.
|
|
2029 */
|
|
2030 (filename))
|
|
2031 {
|
867
|
2032 Ibyte *longname, *canon;
|
771
|
2033 Lisp_Object ret;
|
|
2034
|
|
2035 CHECK_STRING (filename);
|
|
2036
|
|
2037 /* first expand it. */
|
|
2038 filename = Fexpand_file_name (filename, Qnil);
|
|
2039
|
|
2040 if (!(longname = mswindows_get_long_filename (XSTRING_DATA (filename))))
|
|
2041 return Qnil;
|
|
2042
|
|
2043 canon = mswindows_canonicalize_filename (longname);
|
|
2044 ret = build_string (canon);
|
|
2045 xfree (canon);
|
|
2046 xfree (longname);
|
|
2047 return ret;
|
|
2048 }
|
|
2049
|
814
|
2050
|
|
2051 void
|
|
2052 init_nt (void)
|
|
2053 {
|
|
2054 /* Initial preparation for subprocess support: replace our standard
|
|
2055 handles with non-inheritable versions.
|
|
2056
|
|
2057 #### Do we still need this? This is left over from the old process
|
|
2058 support. */
|
|
2059 {
|
|
2060 HANDLE parent;
|
|
2061 HANDLE stdin_save = INVALID_HANDLE_VALUE;
|
|
2062 HANDLE stdout_save = INVALID_HANDLE_VALUE;
|
|
2063 HANDLE stderr_save = INVALID_HANDLE_VALUE;
|
|
2064
|
|
2065 parent = GetCurrentProcess ();
|
|
2066
|
|
2067 /* ignore errors when duplicating and closing; typically the
|
|
2068 handles will be invalid when running as a gui program. */
|
|
2069 DuplicateHandle (parent,
|
|
2070 GetStdHandle (STD_INPUT_HANDLE),
|
|
2071 parent,
|
|
2072 &stdin_save,
|
|
2073 0,
|
|
2074 FALSE,
|
|
2075 DUPLICATE_SAME_ACCESS);
|
|
2076
|
|
2077 DuplicateHandle (parent,
|
|
2078 GetStdHandle (STD_OUTPUT_HANDLE),
|
|
2079 parent,
|
|
2080 &stdout_save,
|
|
2081 0,
|
|
2082 FALSE,
|
|
2083 DUPLICATE_SAME_ACCESS);
|
|
2084
|
|
2085 DuplicateHandle (parent,
|
|
2086 GetStdHandle (STD_ERROR_HANDLE),
|
|
2087 parent,
|
|
2088 &stderr_save,
|
|
2089 0,
|
|
2090 FALSE,
|
|
2091 DUPLICATE_SAME_ACCESS);
|
|
2092
|
|
2093 retry_fclose (stdin);
|
|
2094 retry_fclose (stdout);
|
|
2095 retry_fclose (stderr);
|
|
2096
|
|
2097 if (stdin_save != INVALID_HANDLE_VALUE)
|
|
2098 _open_osfhandle ((long) stdin_save, O_TEXT);
|
|
2099 else
|
|
2100 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
|
|
2101 _fdopen (0, "r");
|
|
2102
|
|
2103 if (stdout_save != INVALID_HANDLE_VALUE)
|
|
2104 _open_osfhandle ((long) stdout_save, O_TEXT);
|
|
2105 else
|
|
2106 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
|
|
2107 _fdopen (1, "w");
|
|
2108
|
|
2109 if (stderr_save != INVALID_HANDLE_VALUE)
|
|
2110 _open_osfhandle ((long) stderr_save, O_TEXT);
|
|
2111 else
|
|
2112 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
|
|
2113 _fdopen (2, "w");
|
|
2114 }
|
|
2115
|
|
2116 /* determine which drives are fixed, for get_cached_volume_information */
|
|
2117 {
|
|
2118 /* GetDriveType must have trailing backslash. */
|
867
|
2119 Ibyte drive[] = "A:\\";
|
814
|
2120
|
|
2121 /* Loop over all possible drive letters */
|
|
2122 while (*drive <= 'Z')
|
|
2123 {
|
|
2124 Extbyte *driveext;
|
|
2125
|
|
2126 C_STRING_TO_TSTR (drive, driveext);
|
|
2127
|
|
2128 /* Record if this drive letter refers to a fixed drive. */
|
|
2129 fixed_drives[DRIVE_INDEX (*drive)] =
|
|
2130 (qxeGetDriveType (driveext) == DRIVE_FIXED);
|
|
2131
|
|
2132 (*drive)++;
|
|
2133 }
|
|
2134
|
|
2135 /* Reset the volume info cache. */
|
|
2136 volume_cache = NULL;
|
|
2137 }
|
|
2138 }
|
|
2139
|
771
|
2140 void
|
|
2141 syms_of_nt (void)
|
|
2142 {
|
|
2143 DEFSUBR (Fmswindows_short_file_name);
|
|
2144 DEFSUBR (Fmswindows_long_file_name);
|
|
2145 }
|
|
2146
|
440
|
2147 void
|
|
2148 vars_of_nt (void)
|
|
2149 {
|
771
|
2150 DEFVAR_INT ("mswindows-fake-unix-uid", &mswindows_fake_unix_uid /*
|
440
|
2151 *Set uid returned by `user-uid' and `user-real-uid'.
|
771
|
2152 Under NT and 9x, there are no uids, and even no almighty user called root.
|
|
2153 By setting this variable, you can have any uid of choice. Default is 0.
|
440
|
2154 Changes to this variable take effect immediately.
|
|
2155 */ );
|
771
|
2156 mswindows_fake_unix_uid = 0;
|
|
2157
|
|
2158 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
|
|
2159 Non-nil means determine accurate link count in file-attributes.
|
|
2160 This option slows down file-attributes noticeably, so is disabled by
|
|
2161 default. Note that it is only useful for files on NTFS volumes,
|
|
2162 where hard links are supported.
|
|
2163 */ );
|
|
2164 Vmswindows_get_true_file_attributes = Qnil;
|
440
|
2165 }
|
|
2166
|
428
|
2167 /* end of nt.c */
|