Avoid a warning on FreeBSD.
[wine/hacks.git] / dlls / ntdll / directory.c
blobead68208ff224caece55d03acaba55fd3d583bb5
1 /*
2 * NTDLL directory functions
4 * Copyright 1993 Erik Bos
5 * Copyright 2003 Eric Pouech
6 * Copyright 1996, 2004 Alexandre Julliard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <sys/types.h>
27 #include <dirent.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #ifdef HAVE_MNTENT_H
35 #include <mntent.h>
36 #endif
37 #include <sys/stat.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 #include <sys/ioctl.h>
40 #endif
41 #ifdef HAVE_LINUX_IOCTL_H
42 #include <linux/ioctl.h>
43 #endif
44 #ifdef HAVE_SYS_PARAM_H
45 #include <sys/param.h>
46 #endif
47 #ifdef HAVE_SYS_MOUNT_H
48 #include <sys/mount.h>
49 #endif
50 #include <time.h>
51 #ifdef HAVE_UNISTD_H
52 # include <unistd.h>
53 #endif
55 #define NONAMELESSUNION
56 #define NONAMELESSSTRUCT
57 #include "windef.h"
58 #include "winbase.h"
59 #include "winnt.h"
60 #include "winreg.h"
61 #include "ntstatus.h"
62 #include "winternl.h"
63 #include "ntdll_misc.h"
64 #include "wine/unicode.h"
65 #include "wine/server.h"
66 #include "wine/library.h"
67 #include "wine/debug.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(file);
71 /* just in case... */
72 #undef VFAT_IOCTL_READDIR_BOTH
73 #undef USE_GETDENTS
75 #ifdef linux
77 /* We want the real kernel dirent structure, not the libc one */
78 typedef struct
80 long d_ino;
81 long d_off;
82 unsigned short d_reclen;
83 char d_name[256];
84 } KERNEL_DIRENT;
86 /* Define the VFAT ioctl to get both short and long file names */
87 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, KERNEL_DIRENT [2] )
89 #ifndef O_DIRECTORY
90 # define O_DIRECTORY 0200000 /* must be directory */
91 #endif
93 #ifdef __i386__
95 typedef struct
97 ULONG64 d_ino;
98 LONG64 d_off;
99 unsigned short d_reclen;
100 unsigned char d_type;
101 char d_name[256];
102 } KERNEL_DIRENT64;
104 static inline int getdents64( int fd, KERNEL_DIRENT64 *de, unsigned int size )
106 int ret;
107 __asm__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
108 : "=a" (ret)
109 : "0" (220 /*NR_getdents64*/), "r" (fd), "c" (de), "d" (size)
110 : "memory" );
111 if (ret < 0)
113 errno = -ret;
114 ret = -1;
116 return ret;
118 #define USE_GETDENTS
120 #endif /* i386 */
122 #endif /* linux */
124 #define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
125 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
127 #define INVALID_NT_CHARS '*','?','<','>','|','"'
128 #define INVALID_DOS_CHARS INVALID_NT_CHARS,'+','=',',',';','[',']',' ','\345'
130 #define MAX_DIR_ENTRY_LEN 255 /* max length of a directory entry in chars */
132 static int show_dir_symlinks = -1;
133 static int show_dot_files;
135 /* at some point we may want to allow Winelib apps to set this */
136 static const int is_case_sensitive = FALSE;
138 static CRITICAL_SECTION dir_section;
139 static CRITICAL_SECTION_DEBUG critsect_debug =
141 0, 0, &dir_section,
142 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
143 0, 0, { 0, (DWORD)(__FILE__ ": dir_section") }
145 static CRITICAL_SECTION dir_section = { &critsect_debug, -1, 0, 0, 0, 0 };
148 /***********************************************************************
149 * get_default_com_device
151 * Return the default device to use for serial ports.
153 static char *get_default_com_device( int num )
155 char *ret = NULL;
157 if (!num || num > 9) return ret;
158 #ifdef linux
159 ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof("/dev/ttyS0") );
160 if (ret)
162 strcpy( ret, "/dev/ttyS0" );
163 ret[strlen(ret) - 1] = '0' + num - 1;
165 #else
166 FIXME( "no known default for device com%d\n", num );
167 #endif
168 return ret;
172 /***********************************************************************
173 * get_default_lpt_device
175 * Return the default device to use for parallel ports.
177 static char *get_default_lpt_device( int num )
179 char *ret = NULL;
181 if (!num || num > 9) return ret;
182 #ifdef linux
183 ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof("/dev/lp0") );
184 if (ret)
186 strcpy( ret, "/dev/lp0" );
187 ret[strlen(ret) - 1] = '0' + num - 1;
189 #else
190 FIXME( "no known default for device lpt%d\n", num );
191 #endif
192 return ret;
196 /***********************************************************************
197 * parse_mount_entries
199 * Parse mount entries looking for a given device. Helper for get_default_drive_device.
201 #ifdef linux
202 static char *parse_mount_entries( FILE *f, dev_t dev, ino_t ino )
204 struct mntent *entry;
205 struct stat st;
206 char *device;
208 while ((entry = getmntent( f )))
210 /* don't even bother stat'ing network mounts, there's no meaningful device anyway */
211 if (!strcmp( entry->mnt_type, "nfs" ) ||
212 !strcmp( entry->mnt_type, "smbfs" ) ||
213 !strcmp( entry->mnt_type, "ncpfs" )) continue;
215 if (stat( entry->mnt_dir, &st ) == -1) continue;
216 if (st.st_dev != dev || st.st_ino != ino) continue;
217 if (!strcmp( entry->mnt_type, "supermount" ))
219 if ((device = strstr( entry->mnt_opts, "dev=" )))
221 char *p = strchr( device + 4, ',' );
222 if (p) *p = 0;
223 return device + 4;
226 else
227 return entry->mnt_fsname;
229 return NULL;
231 #endif
233 /***********************************************************************
234 * get_default_drive_device
236 * Return the default device to use for a given drive mount point.
238 static char *get_default_drive_device( const char *root )
240 char *ret = NULL;
242 #ifdef linux
243 FILE *f;
244 char *device = NULL;
245 int fd, res = -1;
246 struct stat st;
248 /* try to open it first to force it to get mounted */
249 if ((fd = open( root, O_RDONLY | O_DIRECTORY )) != -1)
251 res = fstat( fd, &st );
252 close( fd );
254 /* now try normal stat just in case */
255 if (res == -1) res = stat( root, &st );
256 if (res == -1) return NULL;
258 RtlEnterCriticalSection( &dir_section );
260 if ((f = fopen( "/etc/mtab", "r" )))
262 device = parse_mount_entries( f, st.st_dev, st.st_ino );
263 endmntent( f );
265 /* look through fstab too in case it's not mounted (for instance if it's an audio CD) */
266 if (!device && (f = fopen( "/etc/fstab", "r" )))
268 device = parse_mount_entries( f, st.st_dev, st.st_ino );
269 endmntent( f );
271 if (device)
273 ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(device) + 1 );
274 if (ret) strcpy( ret, device );
276 RtlLeaveCriticalSection( &dir_section );
277 #elif defined(__APPLE__)
278 struct statfs *mntStat;
279 struct stat st;
280 int i;
281 int mntSize;
282 dev_t dev;
283 ino_t ino;
284 static const char path_bsd_device[] = "/dev/disk";
285 int res;
287 res = stat( root, &st );
288 if (res == -1) return NULL;
290 dev = st.st_dev;
291 ino = st.st_ino;
293 RtlEnterCriticalSection( &dir_section );
295 mntSize = getmntinfo(&mntStat, MNT_NOWAIT);
297 for (i = 0; i < mntSize && !ret; i++)
299 if (stat(mntStat[i].f_mntonname, &st ) == -1) continue;
300 if (st.st_dev != dev || st.st_ino != ino) continue;
302 /* FIXME add support for mounted network drive */
303 if ( strncmp(mntStat[i].f_mntfromname, path_bsd_device, strlen(path_bsd_device)) == 0)
305 /* set return value to the corresponding raw BSD node */
306 ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(mntStat[i].f_mntfromname) + 2 /* 2 : r and \0 */ );
307 if (ret)
309 strcpy(ret, "/dev/r");
310 strcat(ret, mntStat[i].f_mntfromname+sizeof("/dev/")-1);
314 RtlLeaveCriticalSection( &dir_section );
315 #else
316 static int warned;
317 if (!warned++) FIXME( "auto detection of DOS devices not supported on this platform\n" );
318 #endif
319 return ret;
323 /***********************************************************************
324 * init_options
326 * Initialize the show_dir_symlinks and show_dot_files options.
328 static void init_options(void)
330 static const WCHAR WineW[] = {'M','a','c','h','i','n','e','\\',
331 'S','o','f','t','w','a','r','e','\\',
332 'W','i','n','e','\\','W','i','n','e','\\',
333 'C','o','n','f','i','g','\\','W','i','n','e',0};
334 static const WCHAR ShowDotFilesW[] = {'S','h','o','w','D','o','t','F','i','l','e','s',0};
335 static const WCHAR ShowDirSymlinksW[] = {'S','h','o','w','D','i','r','S','y','m','l','i','n','k','s',0};
336 char tmp[80];
337 HKEY hkey;
338 DWORD dummy;
339 OBJECT_ATTRIBUTES attr;
340 UNICODE_STRING nameW;
342 show_dot_files = show_dir_symlinks = 0;
344 attr.Length = sizeof(attr);
345 attr.RootDirectory = 0;
346 attr.ObjectName = &nameW;
347 attr.Attributes = 0;
348 attr.SecurityDescriptor = NULL;
349 attr.SecurityQualityOfService = NULL;
350 RtlInitUnicodeString( &nameW, WineW );
352 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
354 RtlInitUnicodeString( &nameW, ShowDotFilesW );
355 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
357 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
358 show_dot_files = IS_OPTION_TRUE( str[0] );
360 RtlInitUnicodeString( &nameW, ShowDirSymlinksW );
361 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
363 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
364 show_dir_symlinks = IS_OPTION_TRUE( str[0] );
366 NtClose( hkey );
371 /***********************************************************************
372 * DIR_is_hidden_file
374 * Check if the specified file should be hidden based on its name and the show dot files option.
376 BOOL DIR_is_hidden_file( const UNICODE_STRING *name )
378 WCHAR *p, *end;
380 if (show_dir_symlinks == -1) init_options();
381 if (show_dot_files) return FALSE;
383 end = p = name->Buffer + name->Length/sizeof(WCHAR);
384 while (p > name->Buffer && IS_SEPARATOR(p[-1])) p--;
385 while (p > name->Buffer && !IS_SEPARATOR(p[-1])) p--;
386 if (p == end || *p != '.') return FALSE;
387 /* make sure it isn't '.' or '..' */
388 if (p + 1 == end) return FALSE;
389 if (p[1] == '.' && p + 2 == end) return FALSE;
390 return TRUE;
394 /***********************************************************************
395 * hash_short_file_name
397 * Transform a Unix file name into a hashed DOS name. If the name is a valid
398 * DOS name, it is converted to upper-case; otherwise it is replaced by a
399 * hashed version that fits in 8.3 format.
400 * 'buffer' must be at least 12 characters long.
401 * Returns length of short name in bytes; short name is NOT null-terminated.
403 static ULONG hash_short_file_name( const UNICODE_STRING *name, LPWSTR buffer )
405 static const WCHAR invalid_chars[] = { INVALID_DOS_CHARS,'~','.',0 };
406 static const char hash_chars[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
408 LPCWSTR p, ext, end = name->Buffer + name->Length / sizeof(WCHAR);
409 LPWSTR dst;
410 unsigned short hash;
411 int i;
413 /* Compute the hash code of the file name */
414 /* If you know something about hash functions, feel free to */
415 /* insert a better algorithm here... */
416 if (!is_case_sensitive)
418 for (p = name->Buffer, hash = 0xbeef; p < end - 1; p++)
419 hash = (hash<<3) ^ (hash>>5) ^ tolowerW(*p) ^ (tolowerW(p[1]) << 8);
420 hash = (hash<<3) ^ (hash>>5) ^ tolowerW(*p); /* Last character */
422 else
424 for (p = name->Buffer, hash = 0xbeef; p < end - 1; p++)
425 hash = (hash << 3) ^ (hash >> 5) ^ *p ^ (p[1] << 8);
426 hash = (hash << 3) ^ (hash >> 5) ^ *p; /* Last character */
429 /* Find last dot for start of the extension */
430 for (p = name->Buffer + 1, ext = NULL; p < end - 1; p++) if (*p == '.') ext = p;
432 /* Copy first 4 chars, replacing invalid chars with '_' */
433 for (i = 4, p = name->Buffer, dst = buffer; i > 0; i--, p++)
435 if (p == end || p == ext) break;
436 *dst++ = strchrW( invalid_chars, *p ) ? '_' : toupperW(*p);
438 /* Pad to 5 chars with '~' */
439 while (i-- >= 0) *dst++ = '~';
441 /* Insert hash code converted to 3 ASCII chars */
442 *dst++ = hash_chars[(hash >> 10) & 0x1f];
443 *dst++ = hash_chars[(hash >> 5) & 0x1f];
444 *dst++ = hash_chars[hash & 0x1f];
446 /* Copy the first 3 chars of the extension (if any) */
447 if (ext)
449 *dst++ = '.';
450 for (i = 3, ext++; (i > 0) && ext < end; i--, ext++)
451 *dst++ = strchrW( invalid_chars, *ext ) ? '_' : toupperW(*ext);
453 return dst - buffer;
457 /***********************************************************************
458 * match_filename
460 * Check a long file name against a mask.
462 * Tests (done in W95 DOS shell - case insensitive):
463 * *.txt test1.test.txt *
464 * *st1* test1.txt *
465 * *.t??????.t* test1.ta.tornado.txt *
466 * *tornado* test1.ta.tornado.txt *
467 * t*t test1.ta.tornado.txt *
468 * ?est* test1.txt *
469 * ?est??? test1.txt -
470 * *test1.txt* test1.txt *
471 * h?l?o*t.dat hellothisisatest.dat *
473 static BOOLEAN match_filename( const UNICODE_STRING *name_str, const UNICODE_STRING *mask_str )
475 int mismatch;
476 const WCHAR *name = name_str->Buffer;
477 const WCHAR *mask = mask_str->Buffer;
478 const WCHAR *name_end = name + name_str->Length / sizeof(WCHAR);
479 const WCHAR *mask_end = mask + mask_str->Length / sizeof(WCHAR);
480 const WCHAR *lastjoker = NULL;
481 const WCHAR *next_to_retry = NULL;
483 TRACE("(%s, %s)\n", debugstr_us(name_str), debugstr_us(mask_str));
485 while (name < name_end && mask < mask_end)
487 switch(*mask)
489 case '*':
490 mask++;
491 while (mask < mask_end && *mask == '*') mask++; /* Skip consecutive '*' */
492 if (mask == mask_end) return TRUE; /* end of mask is all '*', so match */
493 lastjoker = mask;
495 /* skip to the next match after the joker(s) */
496 if (is_case_sensitive)
497 while (name < name_end && (*name != *mask)) name++;
498 else
499 while (name < name_end && (toupperW(*name) != toupperW(*mask))) name++;
500 next_to_retry = name;
501 break;
502 case '?':
503 mask++;
504 name++;
505 break;
506 default:
507 if (is_case_sensitive) mismatch = (*mask != *name);
508 else mismatch = (toupperW(*mask) != toupperW(*name));
510 if (!mismatch)
512 mask++;
513 name++;
514 if (mask == mask_end)
516 if (name == name_end) return TRUE;
517 if (lastjoker) mask = lastjoker;
520 else /* mismatch ! */
522 if (lastjoker) /* we had an '*', so we can try unlimitedly */
524 mask = lastjoker;
526 /* this scan sequence was a mismatch, so restart
527 * 1 char after the first char we checked last time */
528 next_to_retry++;
529 name = next_to_retry;
531 else return FALSE; /* bad luck */
533 break;
536 while (mask < mask_end && ((*mask == '.') || (*mask == '*')))
537 mask++; /* Ignore trailing '.' or '*' in mask */
538 return (name == name_end && mask == mask_end);
542 /***********************************************************************
543 * append_entry
545 * helper for NtQueryDirectoryFile
547 static FILE_BOTH_DIR_INFORMATION *append_entry( void *info_ptr, ULONG *pos, ULONG max_length,
548 const char *long_name, const char *short_name,
549 const UNICODE_STRING *mask )
551 FILE_BOTH_DIR_INFORMATION *info;
552 int i, long_len, short_len, total_len;
553 struct stat st;
554 WCHAR long_nameW[MAX_DIR_ENTRY_LEN];
555 WCHAR short_nameW[12];
556 UNICODE_STRING str;
558 long_len = ntdll_umbstowcs( 0, long_name, strlen(long_name), long_nameW, MAX_DIR_ENTRY_LEN );
559 if (long_len == -1) return NULL;
561 str.Buffer = long_nameW;
562 str.Length = long_len * sizeof(WCHAR);
563 str.MaximumLength = sizeof(long_nameW);
565 if (short_name)
567 short_len = ntdll_umbstowcs( 0, short_name, strlen(short_name),
568 short_nameW, sizeof(short_nameW) / sizeof(WCHAR) );
569 if (short_len == -1) short_len = sizeof(short_nameW) / sizeof(WCHAR);
571 else /* generate a short name if necessary */
573 BOOLEAN spaces;
575 short_len = 0;
576 if (!RtlIsNameLegalDOS8Dot3( &str, NULL, &spaces ) || spaces)
577 short_len = hash_short_file_name( &str, short_nameW );
580 TRACE( "long %s short %s mask %s\n",
581 debugstr_us(&str), debugstr_wn(short_nameW, short_len), debugstr_us(mask) );
583 if (mask && !match_filename( &str, mask ))
585 if (!short_len) return NULL; /* no short name to match */
586 str.Buffer = short_nameW;
587 str.Length = short_len * sizeof(WCHAR);
588 str.MaximumLength = sizeof(short_nameW);
589 if (!match_filename( &str, mask )) return NULL;
592 total_len = (sizeof(*info) - sizeof(info->FileName) + long_len*sizeof(WCHAR) + 3) & ~3;
593 info = (FILE_BOTH_DIR_INFORMATION *)((char *)info_ptr + *pos);
595 if (*pos + total_len > max_length) total_len = max_length - *pos;
597 if (lstat( long_name, &st ) == -1) return NULL;
598 if (S_ISLNK( st.st_mode ))
600 if (stat( long_name, &st ) == -1) return NULL;
601 if (S_ISDIR( st.st_mode ) && !show_dir_symlinks) return NULL;
604 info->NextEntryOffset = total_len;
605 info->FileIndex = 0; /* NTFS always has 0 here, so let's not bother with it */
607 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime );
608 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime );
609 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime );
610 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime );
612 if (S_ISDIR(st.st_mode))
614 info->EndOfFile.QuadPart = info->AllocationSize.QuadPart = 0;
615 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
617 else
619 info->EndOfFile.QuadPart = st.st_size;
620 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
621 info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
624 if (!(st.st_mode & S_IWUSR))
625 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
627 if (!show_dot_files && long_name[0] == '.' && long_name[1] && (long_name[1] != '.' || long_name[2]))
628 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
630 info->EaSize = 0; /* FIXME */
631 info->ShortNameLength = short_len * sizeof(WCHAR);
632 for (i = 0; i < short_len; i++) info->ShortName[i] = toupperW(short_nameW[i]);
633 info->FileNameLength = long_len * sizeof(WCHAR);
634 memcpy( info->FileName, long_nameW,
635 min( info->FileNameLength, total_len-sizeof(*info)+sizeof(info->FileName) ));
637 *pos += total_len;
638 return info;
642 /***********************************************************************
643 * read_directory_vfat
645 * Read a directory using the VFAT ioctl; helper for NtQueryDirectoryFile.
647 #ifdef VFAT_IOCTL_READDIR_BOTH
648 static int read_directory_vfat( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
649 BOOLEAN single_entry, const UNICODE_STRING *mask,
650 BOOLEAN restart_scan )
653 int res;
654 KERNEL_DIRENT de[2];
655 FILE_BOTH_DIR_INFORMATION *info, *last_info = NULL;
656 static const unsigned int max_dir_info_size = sizeof(*info) + (MAX_DIR_ENTRY_LEN-1) * sizeof(WCHAR);
658 io->u.Status = STATUS_SUCCESS;
660 if (restart_scan) lseek( fd, 0, SEEK_SET );
662 if (length < max_dir_info_size) /* we may have to return a partial entry here */
664 off_t old_pos = lseek( fd, 0, SEEK_CUR );
666 res = ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de );
667 if (res == -1 && errno != ENOENT) return -1; /* VFAT ioctl probably not supported */
669 while (res != -1)
671 if (!de[0].d_reclen) break;
672 if (de[1].d_name[0])
673 info = append_entry( buffer, &io->Information, length,
674 de[1].d_name, de[0].d_name, mask );
675 else
676 info = append_entry( buffer, &io->Information, length,
677 de[0].d_name, NULL, mask );
678 if (info)
680 last_info = info;
681 if ((char *)info->FileName + info->FileNameLength > (char *)buffer + length)
683 io->u.Status = STATUS_BUFFER_OVERFLOW;
684 lseek( fd, old_pos, SEEK_SET ); /* restore pos to previous entry */
686 break;
688 old_pos = lseek( fd, 0, SEEK_CUR );
689 res = ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de );
692 else /* we'll only return full entries, no need to worry about overflow */
694 res = ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de );
695 if (res == -1 && errno != ENOENT) return -1; /* VFAT ioctl probably not supported */
697 while (res != -1)
699 if (!de[0].d_reclen) break;
700 if (de[1].d_name[0])
701 info = append_entry( buffer, &io->Information, length,
702 de[1].d_name, de[0].d_name, mask );
703 else
704 info = append_entry( buffer, &io->Information, length,
705 de[0].d_name, NULL, mask );
706 if (info)
708 last_info = info;
709 if (single_entry) break;
710 /* check if we still have enough space for the largest possible entry */
711 if (io->Information + max_dir_info_size > length) break;
713 res = ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de );
717 if (last_info) last_info->NextEntryOffset = 0;
718 else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
719 return 0;
721 #endif /* VFAT_IOCTL_READDIR_BOTH */
724 /***********************************************************************
725 * read_directory_getdents
727 * Read a directory using the Linux getdents64 system call; helper for NtQueryDirectoryFile.
729 #ifdef USE_GETDENTS
730 static int read_directory_getdents( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
731 BOOLEAN single_entry, const UNICODE_STRING *mask,
732 BOOLEAN restart_scan )
734 off_t old_pos = 0;
735 size_t size = length;
736 int res;
737 char local_buffer[8192];
738 KERNEL_DIRENT64 *data, *de;
739 FILE_BOTH_DIR_INFORMATION *info, *last_info = NULL;
740 static const unsigned int max_dir_info_size = sizeof(*info) + (MAX_DIR_ENTRY_LEN-1) * sizeof(WCHAR);
742 if (size <= sizeof(local_buffer) || !(data = RtlAllocateHeap( GetProcessHeap(), 0, size )))
744 size = sizeof(local_buffer);
745 data = (KERNEL_DIRENT64 *)local_buffer;
748 if (restart_scan) lseek( fd, 0, SEEK_SET );
749 else if (length < max_dir_info_size) /* we may have to return a partial entry here */
751 old_pos = lseek( fd, 0, SEEK_CUR );
752 if (old_pos == -1 && errno == ENOENT)
754 io->u.Status = STATUS_NO_MORE_FILES;
755 res = 0;
756 goto done;
760 io->u.Status = STATUS_SUCCESS;
762 res = getdents64( fd, data, size );
763 if (res == -1)
765 if (errno != ENOSYS)
767 io->u.Status = FILE_GetNtStatus();
768 res = 0;
770 goto done;
773 de = data;
775 while (res > 0)
777 res -= de->d_reclen;
778 info = append_entry( buffer, &io->Information, length, de->d_name, NULL, mask );
779 if (info)
781 last_info = info;
782 if ((char *)info->FileName + info->FileNameLength > (char *)buffer + length)
784 io->u.Status = STATUS_BUFFER_OVERFLOW;
785 lseek( fd, old_pos, SEEK_SET ); /* restore pos to previous entry */
786 break;
788 /* check if we still have enough space for the largest possible entry */
789 if (single_entry || io->Information + max_dir_info_size > length)
791 if (res > 0) lseek( fd, de->d_off, SEEK_SET ); /* set pos to next entry */
792 break;
795 old_pos = de->d_off;
796 /* move on to the next entry */
797 de = (KERNEL_DIRENT64 *)((char *)de + de->d_reclen);
800 if (last_info) last_info->NextEntryOffset = 0;
801 else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
802 res = 0;
803 done:
804 if ((char *)data != local_buffer) RtlFreeHeap( GetProcessHeap(), 0, data );
805 return res;
807 #endif /* USE_GETDENTS */
810 /***********************************************************************
811 * read_directory_readdir
813 * Read a directory using the POSIX readdir interface; helper for NtQueryDirectoryFile.
815 static void read_directory_readdir( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
816 BOOLEAN single_entry, const UNICODE_STRING *mask,
817 BOOLEAN restart_scan )
819 DIR *dir;
820 off_t i, old_pos = 0;
821 struct dirent *de;
822 FILE_BOTH_DIR_INFORMATION *info, *last_info = NULL;
823 static const unsigned int max_dir_info_size = sizeof(*info) + (MAX_DIR_ENTRY_LEN-1) * sizeof(WCHAR);
825 if (!(dir = opendir( "." )))
827 io->u.Status = FILE_GetNtStatus();
828 return;
831 if (!restart_scan)
833 old_pos = lseek( fd, 0, SEEK_CUR );
834 /* skip the right number of entries */
835 for (i = 0; i < old_pos; i++)
837 if (!readdir( dir ))
839 closedir( dir );
840 io->u.Status = STATUS_NO_MORE_FILES;
841 return;
845 io->u.Status = STATUS_SUCCESS;
847 while ((de = readdir( dir )))
849 old_pos++;
850 info = append_entry( buffer, &io->Information, length, de->d_name, NULL, mask );
851 if (info)
853 last_info = info;
854 if ((char *)info->FileName + info->FileNameLength > (char *)buffer + length)
856 io->u.Status = STATUS_BUFFER_OVERFLOW;
857 old_pos--; /* restore pos to previous entry */
858 break;
860 if (single_entry) break;
861 /* check if we still have enough space for the largest possible entry */
862 if (io->Information + max_dir_info_size > length) break;
866 lseek( fd, old_pos, SEEK_SET ); /* store dir offset as filepos for fd */
867 closedir( dir );
869 if (last_info) last_info->NextEntryOffset = 0;
870 else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
874 /******************************************************************************
875 * NtQueryDirectoryFile [NTDLL.@]
876 * ZwQueryDirectoryFile [NTDLL.@]
878 NTSTATUS WINAPI NtQueryDirectoryFile( HANDLE handle, HANDLE event,
879 PIO_APC_ROUTINE apc_routine, PVOID apc_context,
880 PIO_STATUS_BLOCK io,
881 PVOID buffer, ULONG length,
882 FILE_INFORMATION_CLASS info_class,
883 BOOLEAN single_entry,
884 PUNICODE_STRING mask,
885 BOOLEAN restart_scan )
887 int cwd, fd;
889 TRACE("(%p %p %p %p %p %p 0x%08lx 0x%08x 0x%08x %s 0x%08x\n",
890 handle, event, apc_routine, apc_context, io, buffer,
891 length, info_class, single_entry, debugstr_us(mask),
892 restart_scan);
894 if (length < sizeof(FILE_BOTH_DIR_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH;
896 if (event || apc_routine)
898 FIXME( "Unsupported yet option\n" );
899 return io->u.Status = STATUS_NOT_IMPLEMENTED;
901 if (info_class != FileBothDirectoryInformation)
903 FIXME( "Unsupported file info class %d\n", info_class );
904 return io->u.Status = STATUS_NOT_IMPLEMENTED;
907 if ((io->u.Status = wine_server_handle_to_fd( handle, GENERIC_READ, &fd, NULL )) != STATUS_SUCCESS)
908 return io->u.Status;
910 io->Information = 0;
912 RtlEnterCriticalSection( &dir_section );
914 if (show_dir_symlinks == -1) init_options();
916 if ((cwd = open(".", O_RDONLY)) != -1 && fchdir( fd ) != -1)
918 #ifdef VFAT_IOCTL_READDIR_BOTH
919 if ((read_directory_vfat( fd, io, buffer, length, single_entry, mask, restart_scan )) == -1)
920 #endif
921 #ifdef USE_GETDENTS
922 if ((read_directory_getdents( fd, io, buffer, length, single_entry, mask, restart_scan )) == -1)
923 #endif
924 read_directory_readdir( fd, io, buffer, length, single_entry, mask, restart_scan );
926 if (fchdir( cwd ) == -1) chdir( "/" );
928 else io->u.Status = FILE_GetNtStatus();
930 RtlLeaveCriticalSection( &dir_section );
932 wine_server_release_fd( handle, fd );
933 if (cwd != -1) close( cwd );
934 TRACE( "=> %lx (%ld)\n", io->u.Status, io->Information );
935 return io->u.Status;
939 /***********************************************************************
940 * find_file_in_dir
942 * Find a file in a directory the hard way, by doing a case-insensitive search.
943 * The file found is appended to unix_name at pos.
944 * There must be at least MAX_DIR_ENTRY_LEN+2 chars available at pos.
946 static NTSTATUS find_file_in_dir( char *unix_name, int pos, const WCHAR *name, int length,
947 int check_case )
949 WCHAR buffer[MAX_DIR_ENTRY_LEN];
950 UNICODE_STRING str;
951 BOOLEAN spaces;
952 DIR *dir;
953 struct dirent *de;
954 struct stat st;
955 int ret, used_default, is_name_8_dot_3;
957 /* try a shortcut for this directory */
959 unix_name[pos++] = '/';
960 ret = ntdll_wcstoumbs( 0, name, length, unix_name + pos, MAX_DIR_ENTRY_LEN,
961 NULL, &used_default );
962 /* if we used the default char, the Unix name won't round trip properly back to Unicode */
963 /* so it cannot match the file we are looking for */
964 if (ret >= 0 && !used_default)
966 unix_name[pos + ret] = 0;
967 if (!stat( unix_name, &st )) return STATUS_SUCCESS;
969 if (check_case) goto not_found; /* we want an exact match */
971 if (pos > 1) unix_name[pos - 1] = 0;
972 else unix_name[1] = 0; /* keep the initial slash */
974 /* check if it fits in 8.3 so that we don't look for short names if we won't need them */
976 str.Buffer = (WCHAR *)name;
977 str.Length = length * sizeof(WCHAR);
978 str.MaximumLength = str.Length;
979 is_name_8_dot_3 = RtlIsNameLegalDOS8Dot3( &str, NULL, &spaces ) && !spaces;
981 /* now look for it through the directory */
983 #ifdef VFAT_IOCTL_READDIR_BOTH
984 if (is_name_8_dot_3)
986 int fd = open( unix_name, O_RDONLY | O_DIRECTORY );
987 if (fd != -1)
989 KERNEL_DIRENT de[2];
991 if (ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de ) != -1)
993 unix_name[pos - 1] = '/';
994 for (;;)
996 if (!de[0].d_reclen) break;
998 if (de[1].d_name[0])
1000 ret = ntdll_umbstowcs( 0, de[1].d_name, strlen(de[1].d_name),
1001 buffer, MAX_DIR_ENTRY_LEN );
1002 if (ret == length && !memicmpW( buffer, name, length))
1004 strcpy( unix_name + pos, de[1].d_name );
1005 close( fd );
1006 return STATUS_SUCCESS;
1009 ret = ntdll_umbstowcs( 0, de[0].d_name, strlen(de[0].d_name),
1010 buffer, MAX_DIR_ENTRY_LEN );
1011 if (ret == length && !memicmpW( buffer, name, length))
1013 strcpy( unix_name + pos,
1014 de[1].d_name[0] ? de[1].d_name : de[0].d_name );
1015 close( fd );
1016 return STATUS_SUCCESS;
1018 if (ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de ) == -1)
1020 close( fd );
1021 goto not_found;
1025 close( fd );
1027 /* fall through to normal handling */
1029 #endif /* VFAT_IOCTL_READDIR_BOTH */
1031 if (!(dir = opendir( unix_name )))
1033 if (errno == ENOENT) return STATUS_OBJECT_PATH_NOT_FOUND;
1034 else return FILE_GetNtStatus();
1036 unix_name[pos - 1] = '/';
1037 str.Buffer = buffer;
1038 str.MaximumLength = sizeof(buffer);
1039 while ((de = readdir( dir )))
1041 ret = ntdll_umbstowcs( 0, de->d_name, strlen(de->d_name), buffer, MAX_DIR_ENTRY_LEN );
1042 if (ret == length && !memicmpW( buffer, name, length ))
1044 strcpy( unix_name + pos, de->d_name );
1045 closedir( dir );
1046 return STATUS_SUCCESS;
1049 if (!is_name_8_dot_3) continue;
1051 str.Length = ret * sizeof(WCHAR);
1052 if (!RtlIsNameLegalDOS8Dot3( &str, NULL, &spaces ) || spaces)
1054 WCHAR short_nameW[12];
1055 ret = hash_short_file_name( &str, short_nameW );
1056 if (ret == length && !memicmpW( short_nameW, name, length ))
1058 strcpy( unix_name + pos, de->d_name );
1059 closedir( dir );
1060 return STATUS_SUCCESS;
1064 closedir( dir );
1065 goto not_found; /* avoid warning */
1067 not_found:
1068 unix_name[pos - 1] = 0;
1069 return STATUS_OBJECT_PATH_NOT_FOUND;
1073 /******************************************************************************
1074 * get_dos_device
1076 * Get the Unix path of a DOS device.
1078 static NTSTATUS get_dos_device( const WCHAR *name, UINT name_len, ANSI_STRING *unix_name_ret )
1080 const char *config_dir = wine_get_config_dir();
1081 struct stat st;
1082 char *unix_name, *new_name, *dev;
1083 unsigned int i;
1084 int unix_len;
1086 /* make sure the device name is ASCII */
1087 for (i = 0; i < name_len; i++)
1088 if (name[i] <= 32 || name[i] >= 127) return STATUS_OBJECT_NAME_NOT_FOUND;
1090 unix_len = strlen(config_dir) + sizeof("/dosdevices/") + name_len + 1;
1092 if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len )))
1093 return STATUS_NO_MEMORY;
1095 strcpy( unix_name, config_dir );
1096 strcat( unix_name, "/dosdevices/" );
1097 dev = unix_name + strlen(unix_name);
1099 for (i = 0; i < name_len; i++) dev[i] = (char)tolowerW(name[i]);
1100 dev[i] = 0;
1102 /* special case for drive devices */
1103 if (name_len == 2 && dev[1] == ':')
1105 dev[i++] = ':';
1106 dev[i] = 0;
1109 for (;;)
1111 if (!stat( unix_name, &st ))
1113 TRACE( "%s -> %s\n", debugstr_wn(name,name_len), debugstr_a(unix_name) );
1114 unix_name_ret->Buffer = unix_name;
1115 unix_name_ret->Length = strlen(unix_name);
1116 unix_name_ret->MaximumLength = unix_len;
1117 return STATUS_SUCCESS;
1119 if (!dev) break;
1121 /* now try some defaults for it */
1122 if (!strcmp( dev, "aux" ))
1124 strcpy( dev, "com1" );
1125 continue;
1127 if (!strcmp( dev, "prn" ))
1129 strcpy( dev, "lpt1" );
1130 continue;
1132 if (!strcmp( dev, "nul" ))
1134 strcpy( unix_name, "/dev/null" );
1135 dev = NULL; /* last try */
1136 continue;
1139 new_name = NULL;
1140 if (dev[1] == ':' && dev[2] == ':') /* drive device */
1142 dev[2] = 0; /* remove last ':' to get the drive mount point symlink */
1143 new_name = get_default_drive_device( unix_name );
1145 else if (!strncmp( dev, "com", 3 )) new_name = get_default_com_device( dev[3] - '0' );
1146 else if (!strncmp( dev, "lpt", 3 )) new_name = get_default_lpt_device( dev[3] - '0' );
1148 if (!new_name) break;
1150 RtlFreeHeap( GetProcessHeap(), 0, unix_name );
1151 unix_name = new_name;
1152 unix_len = strlen(unix_name) + 1;
1153 dev = NULL; /* last try */
1155 RtlFreeHeap( GetProcessHeap(), 0, unix_name );
1156 return STATUS_OBJECT_NAME_NOT_FOUND;
1160 /* return the length of the DOS namespace prefix if any */
1161 static inline int get_dos_prefix_len( const UNICODE_STRING *name )
1163 static const WCHAR nt_prefixW[] = {'\\','?','?','\\'};
1164 static const WCHAR dosdev_prefixW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\'};
1166 if (name->Length > sizeof(nt_prefixW) &&
1167 !memcmp( name->Buffer, nt_prefixW, sizeof(nt_prefixW) ))
1168 return sizeof(nt_prefixW) / sizeof(WCHAR);
1170 if (name->Length > sizeof(dosdev_prefixW) &&
1171 !memicmpW( name->Buffer, dosdev_prefixW, sizeof(dosdev_prefixW)/sizeof(WCHAR) ))
1172 return sizeof(dosdev_prefixW) / sizeof(WCHAR);
1174 return 0;
1178 /******************************************************************************
1179 * wine_nt_to_unix_file_name (NTDLL.@) Not a Windows API
1181 * Convert a file name from NT namespace to Unix namespace.
1183 * If disposition is not FILE_OPEN or FILE_OVERWRITTE, the last path
1184 * element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
1185 * returned, but the unix name is still filled in properly.
1187 NTSTATUS wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
1188 UINT disposition, BOOLEAN check_case )
1190 static const WCHAR uncW[] = {'U','N','C','\\'};
1191 static const WCHAR invalid_charsW[] = { INVALID_NT_CHARS, 0 };
1193 NTSTATUS status = STATUS_SUCCESS;
1194 const char *config_dir = wine_get_config_dir();
1195 const WCHAR *name, *p;
1196 struct stat st;
1197 char *unix_name;
1198 int pos, ret, name_len, unix_len, used_default;
1200 name = nameW->Buffer;
1201 name_len = nameW->Length / sizeof(WCHAR);
1203 if (!name_len || !IS_SEPARATOR(name[0])) return STATUS_OBJECT_PATH_SYNTAX_BAD;
1205 if ((pos = get_dos_prefix_len( nameW )))
1207 BOOLEAN is_unc = FALSE;
1209 name += pos;
1210 name_len -= pos;
1212 /* check for UNC prefix */
1213 if (name_len > 4 && !memicmpW( name, uncW, 4 ))
1215 name += 3;
1216 name_len -= 3;
1217 is_unc = TRUE;
1219 else
1221 /* check for a drive letter with path */
1222 if (name_len < 3 || !isalphaW(name[0]) || name[1] != ':' || !IS_SEPARATOR(name[2]))
1224 /* not a drive with path, try other DOS devices */
1225 return get_dos_device( name, name_len, unix_name_ret );
1227 name += 2; /* skip drive letter */
1228 name_len -= 2;
1231 /* check for invalid characters */
1232 for (p = name; p < name + name_len; p++)
1233 if (*p < 32 || strchrW( invalid_charsW, *p )) return STATUS_OBJECT_NAME_INVALID;
1235 unix_len = ntdll_wcstoumbs( 0, name, name_len, NULL, 0, NULL, NULL );
1236 unix_len += MAX_DIR_ENTRY_LEN + 3;
1237 unix_len += strlen(config_dir) + sizeof("/dosdevices/") + 3;
1238 if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len )))
1239 return STATUS_NO_MEMORY;
1240 strcpy( unix_name, config_dir );
1241 strcat( unix_name, "/dosdevices/" );
1242 pos = strlen(unix_name);
1243 if (is_unc)
1245 strcpy( unix_name + pos, "unc" );
1246 pos += 3;
1248 else
1250 unix_name[pos++] = tolowerW( name[-2] );
1251 unix_name[pos++] = ':';
1252 unix_name[pos] = 0;
1255 else /* no DOS prefix, assume NT native name, map directly to Unix */
1257 if (!name_len || !IS_SEPARATOR(name[0])) return STATUS_OBJECT_NAME_INVALID;
1258 unix_len = ntdll_wcstoumbs( 0, name, name_len, NULL, 0, NULL, NULL );
1259 unix_len += MAX_DIR_ENTRY_LEN + 3;
1260 if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len )))
1261 return STATUS_NO_MEMORY;
1262 pos = 0;
1265 /* try a shortcut first */
1267 ret = ntdll_wcstoumbs( 0, name, name_len, unix_name + pos, unix_len - pos - 1,
1268 NULL, &used_default );
1270 while (name_len && IS_SEPARATOR(*name))
1272 name++;
1273 name_len--;
1276 if (ret > 0 && !used_default) /* if we used the default char the name didn't convert properly */
1278 char *p;
1279 unix_name[pos + ret] = 0;
1280 for (p = unix_name + pos ; *p; p++) if (*p == '\\') *p = '/';
1281 if (!stat( unix_name, &st ))
1283 /* creation fails with STATUS_ACCESS_DENIED for the root of the drive */
1284 if (disposition == FILE_CREATE)
1285 return name_len ? STATUS_OBJECT_NAME_COLLISION : STATUS_ACCESS_DENIED;
1286 goto done;
1290 if (!name_len) /* empty name -> drive root doesn't exist */
1292 RtlFreeHeap( GetProcessHeap(), 0, unix_name );
1293 return STATUS_OBJECT_PATH_NOT_FOUND;
1295 if (check_case && (disposition == FILE_OPEN || disposition == FILE_OVERWRITE))
1297 RtlFreeHeap( GetProcessHeap(), 0, unix_name );
1298 return STATUS_OBJECT_NAME_NOT_FOUND;
1301 /* now do it component by component */
1303 while (name_len)
1305 const WCHAR *end, *next;
1307 end = name;
1308 while (end < name + name_len && !IS_SEPARATOR(*end)) end++;
1309 next = end;
1310 while (next < name + name_len && IS_SEPARATOR(*next)) next++;
1311 name_len -= next - name;
1313 /* grow the buffer if needed */
1315 if (unix_len - pos < MAX_DIR_ENTRY_LEN + 2)
1317 char *new_name;
1318 unix_len += 2 * MAX_DIR_ENTRY_LEN;
1319 if (!(new_name = RtlReAllocateHeap( GetProcessHeap(), 0, unix_name, unix_len )))
1321 RtlFreeHeap( GetProcessHeap(), 0, unix_name );
1322 return STATUS_NO_MEMORY;
1324 unix_name = new_name;
1327 status = find_file_in_dir( unix_name, pos, name, end - name, check_case );
1329 /* if this is the last element, not finding it is not necessarily fatal */
1330 if (!name_len)
1332 if (status == STATUS_OBJECT_PATH_NOT_FOUND)
1334 status = STATUS_OBJECT_NAME_NOT_FOUND;
1335 if (disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
1337 ret = ntdll_wcstoumbs( 0, name, end - name, unix_name + pos + 1,
1338 MAX_DIR_ENTRY_LEN, NULL, &used_default );
1339 if (ret > 0 && !used_default)
1341 unix_name[pos] = '/';
1342 unix_name[pos + 1 + ret] = 0;
1343 status = STATUS_NO_SUCH_FILE;
1344 break;
1348 else if (status == STATUS_SUCCESS && disposition == FILE_CREATE)
1350 status = STATUS_OBJECT_NAME_COLLISION;
1354 if (status != STATUS_SUCCESS)
1356 /* couldn't find it at all, fail */
1357 WARN( "%s not found in %s\n", debugstr_w(name), unix_name );
1358 RtlFreeHeap( GetProcessHeap(), 0, unix_name );
1359 return status;
1362 pos += strlen( unix_name + pos );
1363 name = next;
1366 WARN( "%s -> %s required a case-insensitive search\n",
1367 debugstr_us(nameW), debugstr_a(unix_name) );
1369 done:
1370 TRACE( "%s -> %s\n", debugstr_us(nameW), debugstr_a(unix_name) );
1371 unix_name_ret->Buffer = unix_name;
1372 unix_name_ret->Length = strlen(unix_name);
1373 unix_name_ret->MaximumLength = unix_len;
1374 return status;
1378 /******************************************************************
1379 * RtlDoesFileExists_U (NTDLL.@)
1381 BOOLEAN WINAPI RtlDoesFileExists_U(LPCWSTR file_name)
1383 UNICODE_STRING nt_name;
1384 ANSI_STRING unix_name;
1385 BOOLEAN ret;
1387 if (!RtlDosPathNameToNtPathName_U( file_name, &nt_name, NULL, NULL )) return FALSE;
1388 ret = (wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, FALSE ) == STATUS_SUCCESS);
1389 if (ret) RtlFreeAnsiString( &unix_name );
1390 RtlFreeUnicodeString( &nt_name );
1391 return ret;