2004-03-16 02:32:02 +01:00
|
|
|
/*
|
|
|
|
* NTDLL directory functions
|
|
|
|
*
|
|
|
|
* Copyright 1993 Erik Bos
|
|
|
|
* Copyright 2003 Eric Pouech
|
|
|
|
* Copyright 1996, 2004 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-03-16 02:32:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2008-10-28 13:55:24 +01:00
|
|
|
#include <assert.h>
|
2004-03-16 02:32:02 +01:00
|
|
|
#include <sys/types.h>
|
2008-10-19 18:55:13 +02:00
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
# include <dirent.h>
|
|
|
|
#endif
|
2004-03-16 02:32:02 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-04-29 22:04:48 +02:00
|
|
|
#include <stdio.h>
|
2006-06-19 22:36:30 +02:00
|
|
|
#include <limits.h>
|
2004-05-24 21:07:12 +02:00
|
|
|
#ifdef HAVE_MNTENT_H
|
|
|
|
#include <mntent.h>
|
|
|
|
#endif
|
2005-05-06 18:22:54 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2010-12-27 12:01:43 +01:00
|
|
|
#ifdef HAVE_SYS_SYSCALL_H
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
#endif
|
2011-01-18 21:09:44 +01:00
|
|
|
#ifdef HAVE_SYS_ATTR_H
|
|
|
|
#include <sys/attr.h>
|
|
|
|
#endif
|
2015-05-20 21:59:39 +02:00
|
|
|
#ifdef HAVE_SYS_VNODE_H
|
2015-10-05 10:01:56 +02:00
|
|
|
/* Work around a conflict with Solaris' system list defined in sys/list.h. */
|
|
|
|
#define list SYSLIST
|
|
|
|
#define list_next SYSLIST_NEXT
|
|
|
|
#define list_prev SYSLIST_PREV
|
|
|
|
#define list_head SYSLIST_HEAD
|
|
|
|
#define list_tail SYSLIST_TAIL
|
|
|
|
#define list_move_tail SYSLIST_MOVE_TAIL
|
|
|
|
#define list_remove SYSLIST_REMOVE
|
2015-05-20 21:59:39 +02:00
|
|
|
#include <sys/vnode.h>
|
2015-10-05 10:01:56 +02:00
|
|
|
#undef list
|
|
|
|
#undef list_next
|
|
|
|
#undef list_prev
|
|
|
|
#undef list_head
|
|
|
|
#undef list_tail
|
|
|
|
#undef list_move_tail
|
|
|
|
#undef list_remove
|
2015-05-20 21:59:39 +02:00
|
|
|
#endif
|
2004-03-16 02:32:02 +01:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LINUX_IOCTL_H
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
#endif
|
2005-10-28 18:45:24 +02:00
|
|
|
#ifdef HAVE_LINUX_MAJOR_H
|
|
|
|
# include <linux/major.h>
|
|
|
|
#endif
|
2004-07-07 02:47:10 +02:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MOUNT_H
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#endif
|
2011-01-18 21:09:44 +01:00
|
|
|
#ifdef HAVE_SYS_STATFS_H
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
#endif
|
2004-03-16 02:32:02 +01:00
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2015-03-14 03:38:17 +01:00
|
|
|
#define NONAMELESSUNION
|
2004-03-16 02:32:02 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "winternl.h"
|
2011-06-16 12:27:01 +02:00
|
|
|
#include "ddk/wdm.h"
|
2004-03-16 02:32:02 +01:00
|
|
|
#include "ntdll_misc.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/server.h"
|
2009-12-09 23:34:45 +01:00
|
|
|
#include "wine/list.h"
|
2004-04-13 01:31:09 +02:00
|
|
|
#include "wine/library.h"
|
2004-03-16 02:32:02 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(file);
|
|
|
|
|
2004-12-06 17:48:16 +01:00
|
|
|
/* just in case... */
|
|
|
|
#undef VFAT_IOCTL_READDIR_BOTH
|
|
|
|
#undef USE_GETDENTS
|
|
|
|
|
2004-03-16 02:32:02 +01:00
|
|
|
#ifdef linux
|
2004-12-06 17:48:16 +01:00
|
|
|
|
2004-03-16 02:32:02 +01:00
|
|
|
/* We want the real kernel dirent structure, not the libc one */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long d_ino;
|
|
|
|
long d_off;
|
|
|
|
unsigned short d_reclen;
|
|
|
|
char d_name[256];
|
|
|
|
} KERNEL_DIRENT;
|
|
|
|
|
2004-12-06 17:48:16 +01:00
|
|
|
/* Define the VFAT ioctl to get both short and long file names */
|
2004-03-16 02:32:02 +01:00
|
|
|
#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, KERNEL_DIRENT [2] )
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
#ifndef O_DIRECTORY
|
|
|
|
# define O_DIRECTORY 0200000 /* must be directory */
|
|
|
|
#endif
|
|
|
|
|
2013-01-21 21:37:02 +01:00
|
|
|
#ifdef __NR_getdents64
|
2004-12-06 17:48:16 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ULONG64 d_ino;
|
|
|
|
LONG64 d_off;
|
|
|
|
unsigned short d_reclen;
|
|
|
|
unsigned char d_type;
|
|
|
|
char d_name[256];
|
|
|
|
} KERNEL_DIRENT64;
|
|
|
|
|
2014-08-23 17:02:58 +02:00
|
|
|
#undef getdents64
|
2006-12-01 13:11:38 +01:00
|
|
|
static inline int getdents64( int fd, char *de, unsigned int size )
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2013-01-21 21:37:02 +01:00
|
|
|
return syscall( __NR_getdents64, fd, de, size );
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
|
|
|
#define USE_GETDENTS
|
2010-12-27 12:01:43 +01:00
|
|
|
#endif
|
2004-04-14 06:36:21 +02:00
|
|
|
|
2004-03-16 02:32:02 +01:00
|
|
|
#endif /* linux */
|
|
|
|
|
|
|
|
#define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
|
2004-04-13 01:31:09 +02:00
|
|
|
#define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2004-04-14 06:36:21 +02:00
|
|
|
#define INVALID_NT_CHARS '*','?','<','>','|','"'
|
|
|
|
#define INVALID_DOS_CHARS INVALID_NT_CHARS,'+','=',',',';','[',']',' ','\345'
|
2004-03-16 02:32:02 +01:00
|
|
|
|
|
|
|
#define MAX_DIR_ENTRY_LEN 255 /* max length of a directory entry in chars */
|
|
|
|
|
2008-10-28 13:55:24 +01:00
|
|
|
#define MAX_IGNORED_FILES 4
|
|
|
|
|
2009-10-22 19:59:04 +02:00
|
|
|
struct file_identity
|
2008-10-28 13:55:24 +01:00
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
ino_t ino;
|
2009-10-22 19:59:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct file_identity ignored_files[MAX_IGNORED_FILES];
|
2013-02-20 22:25:56 +01:00
|
|
|
static unsigned int ignored_files_count;
|
2008-10-28 13:55:24 +01:00
|
|
|
|
2009-11-18 17:42:51 +01:00
|
|
|
union file_directory_info
|
|
|
|
{
|
|
|
|
ULONG next;
|
2009-11-18 18:07:30 +01:00
|
|
|
FILE_DIRECTORY_INFORMATION dir;
|
2009-11-18 17:42:51 +01:00
|
|
|
FILE_BOTH_DIRECTORY_INFORMATION both;
|
2009-11-18 18:07:30 +01:00
|
|
|
FILE_FULL_DIRECTORY_INFORMATION full;
|
|
|
|
FILE_ID_BOTH_DIRECTORY_INFORMATION id_both;
|
|
|
|
FILE_ID_FULL_DIRECTORY_INFORMATION id_full;
|
2009-11-18 17:42:51 +01:00
|
|
|
};
|
|
|
|
|
2013-08-29 16:48:23 +02:00
|
|
|
static BOOL show_dot_files;
|
|
|
|
static RTL_RUN_ONCE init_once = RTL_RUN_ONCE_INIT;
|
2004-03-16 02:32:02 +01:00
|
|
|
|
|
|
|
/* at some point we may want to allow Winelib apps to set this */
|
2013-10-29 21:54:12 +01:00
|
|
|
static const BOOL is_case_sensitive = FALSE;
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2009-10-22 19:55:02 +02:00
|
|
|
UNICODE_STRING system_dir = { 0, 0, NULL }; /* system directory */
|
|
|
|
|
2009-12-02 17:33:28 +01:00
|
|
|
static struct file_identity curdir;
|
2009-10-22 20:06:06 +02:00
|
|
|
static struct file_identity windir;
|
|
|
|
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION dir_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
2004-03-16 02:32:02 +01:00
|
|
|
{
|
2004-04-29 22:04:48 +02:00
|
|
|
0, 0, &dir_section,
|
2004-03-16 02:32:02 +01:00
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": dir_section") }
|
2004-03-16 02:32:02 +01:00
|
|
|
};
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION dir_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2004-03-16 02:32:02 +01:00
|
|
|
|
|
|
|
|
2005-02-09 14:32:12 +01:00
|
|
|
/* check if a given Unicode char is OK in a DOS short name */
|
|
|
|
static inline BOOL is_invalid_dos_char( WCHAR ch )
|
|
|
|
{
|
|
|
|
static const WCHAR invalid_chars[] = { INVALID_DOS_CHARS,'~','.',0 };
|
|
|
|
if (ch > 0x7f) return TRUE;
|
|
|
|
return strchrW( invalid_chars, ch ) != NULL;
|
|
|
|
}
|
|
|
|
|
2006-10-03 14:54:21 +02:00
|
|
|
/* check if the device can be a mounted volume */
|
2013-10-29 21:54:12 +01:00
|
|
|
static inline BOOL is_valid_mounted_device( const struct stat *st )
|
2006-10-03 14:54:21 +02:00
|
|
|
{
|
|
|
|
#if defined(linux) || defined(__sun__)
|
|
|
|
return S_ISBLK( st->st_mode );
|
|
|
|
#else
|
|
|
|
/* disks are char devices on *BSD */
|
|
|
|
return S_ISCHR( st->st_mode );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-10-28 13:55:24 +01:00
|
|
|
static inline void ignore_file( const char *name )
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
assert( ignored_files_count < MAX_IGNORED_FILES );
|
|
|
|
if (!stat( name, &st ))
|
|
|
|
{
|
|
|
|
ignored_files[ignored_files_count].dev = st.st_dev;
|
|
|
|
ignored_files[ignored_files_count].ino = st.st_ino;
|
|
|
|
ignored_files_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-22 19:59:04 +02:00
|
|
|
static inline BOOL is_same_file( const struct file_identity *file, const struct stat *st )
|
|
|
|
{
|
|
|
|
return st->st_dev == file->dev && st->st_ino == file->ino;
|
|
|
|
}
|
|
|
|
|
2008-10-28 13:55:24 +01:00
|
|
|
static inline BOOL is_ignored_file( const struct stat *st )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ignored_files_count; i++)
|
2009-10-22 19:59:04 +02:00
|
|
|
if (is_same_file( &ignored_files[i], st )) return TRUE;
|
2008-10-28 13:55:24 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:54:06 +01:00
|
|
|
static inline unsigned int dir_info_size( FILE_INFORMATION_CLASS class, unsigned int len )
|
|
|
|
{
|
|
|
|
switch (class)
|
|
|
|
{
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileDirectoryInformation:
|
2014-05-15 14:25:05 +02:00
|
|
|
return (FIELD_OFFSET( FILE_DIRECTORY_INFORMATION, FileName[len] ) + 7) & ~7;
|
2009-11-18 17:54:06 +01:00
|
|
|
case FileBothDirectoryInformation:
|
2014-05-15 14:25:05 +02:00
|
|
|
return (FIELD_OFFSET( FILE_BOTH_DIRECTORY_INFORMATION, FileName[len] ) + 7) & ~7;
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileFullDirectoryInformation:
|
2014-05-15 14:25:05 +02:00
|
|
|
return (FIELD_OFFSET( FILE_FULL_DIRECTORY_INFORMATION, FileName[len] ) + 7) & ~7;
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileIdBothDirectoryInformation:
|
2014-05-15 14:25:05 +02:00
|
|
|
return (FIELD_OFFSET( FILE_ID_BOTH_DIRECTORY_INFORMATION, FileName[len] ) + 7) & ~7;
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileIdFullDirectoryInformation:
|
2014-05-15 14:25:05 +02:00
|
|
|
return (FIELD_OFFSET( FILE_ID_FULL_DIRECTORY_INFORMATION, FileName[len] ) + 7) & ~7;
|
2009-11-18 17:54:06 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
2009-12-25 11:14:07 +01:00
|
|
|
return 0;
|
2009-11-18 17:54:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int max_dir_info_size( FILE_INFORMATION_CLASS class )
|
|
|
|
{
|
|
|
|
return dir_info_size( class, MAX_DIR_ENTRY_LEN );
|
|
|
|
}
|
|
|
|
|
2013-07-01 19:49:46 +02:00
|
|
|
static inline BOOL has_wildcard( const UNICODE_STRING *mask )
|
|
|
|
{
|
|
|
|
return (!mask ||
|
|
|
|
memchrW( mask->Buffer, '*', mask->Length / sizeof(WCHAR) ) ||
|
|
|
|
memchrW( mask->Buffer, '?', mask->Length / sizeof(WCHAR) ));
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:54:06 +01:00
|
|
|
|
2009-12-09 23:34:45 +01:00
|
|
|
/* support for a directory queue for filesystem searches */
|
|
|
|
|
|
|
|
struct dir_name
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
char name[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list dir_queue = LIST_INIT( dir_queue );
|
|
|
|
|
|
|
|
static NTSTATUS add_dir_to_queue( const char *name )
|
|
|
|
{
|
|
|
|
int len = strlen( name ) + 1;
|
|
|
|
struct dir_name *dir = RtlAllocateHeap( GetProcessHeap(), 0,
|
|
|
|
FIELD_OFFSET( struct dir_name, name[len] ));
|
|
|
|
if (!dir) return STATUS_NO_MEMORY;
|
|
|
|
strcpy( dir->name, name );
|
|
|
|
list_add_tail( &dir_queue, &dir->entry );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS next_dir_in_queue( char *name )
|
|
|
|
{
|
|
|
|
struct list *head = list_head( &dir_queue );
|
|
|
|
if (head)
|
|
|
|
{
|
|
|
|
struct dir_name *dir = LIST_ENTRY( head, struct dir_name, entry );
|
|
|
|
strcpy( name, dir->name );
|
|
|
|
list_remove( &dir->entry );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, dir );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_dir_queue(void)
|
|
|
|
{
|
|
|
|
struct list *head;
|
|
|
|
|
|
|
|
while ((head = list_head( &dir_queue )))
|
|
|
|
{
|
|
|
|
struct dir_name *dir = LIST_ENTRY( head, struct dir_name, entry );
|
|
|
|
list_remove( &dir->entry );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, dir );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-23 05:22:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_default_com_device
|
|
|
|
*
|
|
|
|
* Return the default device to use for serial ports.
|
|
|
|
*/
|
|
|
|
static char *get_default_com_device( int num )
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
|
2015-12-24 05:58:43 +01:00
|
|
|
if (num < 1 || num > 256) return NULL;
|
2004-04-23 05:22:34 +02:00
|
|
|
#ifdef linux
|
2015-12-24 05:58:43 +01:00
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof("/dev/ttyS256") );
|
|
|
|
if (!ret) return NULL;
|
|
|
|
sprintf( ret, "/dev/ttyS%d", num - 1 );
|
2006-08-05 23:12:22 +02:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2015-12-24 05:58:43 +01:00
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof("/dev/cuau256") );
|
|
|
|
if (!ret) return NULL;
|
|
|
|
sprintf( ret, "/dev/cuau%d", num - 1 );
|
2012-06-02 18:54:10 +02:00
|
|
|
#elif defined(__DragonFly__)
|
2015-12-24 05:58:43 +01:00
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof("/dev/cuaa256") );
|
|
|
|
if (!ret) return NULL;
|
|
|
|
sprintf( ret, "/dev/cuaa%d", num - 1 );
|
2004-04-23 05:22:34 +02:00
|
|
|
#else
|
|
|
|
FIXME( "no known default for device com%d\n", num );
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_default_lpt_device
|
|
|
|
*
|
|
|
|
* Return the default device to use for parallel ports.
|
|
|
|
*/
|
|
|
|
static char *get_default_lpt_device( int num )
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
|
2015-12-24 05:58:43 +01:00
|
|
|
if (num < 1 || num > 256) return NULL;
|
2004-04-23 05:22:34 +02:00
|
|
|
#ifdef linux
|
2015-12-24 05:58:43 +01:00
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof("/dev/lp256") );
|
|
|
|
if (!ret) return NULL;
|
|
|
|
sprintf( ret, "/dev/lp%d", num - 1 );
|
2004-04-23 05:22:34 +02:00
|
|
|
#else
|
|
|
|
FIXME( "no known default for device lpt%d\n", num );
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-07 14:22:10 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
|
|
|
|
static char *unescape_field( char *str )
|
|
|
|
{
|
|
|
|
char *in, *out;
|
|
|
|
|
|
|
|
for (in = out = str; *in; in++, out++)
|
|
|
|
{
|
|
|
|
*out = *in;
|
|
|
|
if (in[0] == '\\')
|
|
|
|
{
|
|
|
|
if (in[1] == '\\')
|
|
|
|
{
|
|
|
|
out[0] = '\\';
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
else if (in[1] == '0' && in[2] == '4' && in[3] == '0')
|
|
|
|
{
|
|
|
|
out[0] = ' ';
|
|
|
|
in += 3;
|
|
|
|
}
|
|
|
|
else if (in[1] == '0' && in[2] == '1' && in[3] == '1')
|
|
|
|
{
|
|
|
|
out[0] = '\t';
|
|
|
|
in += 3;
|
|
|
|
}
|
|
|
|
else if (in[1] == '0' && in[2] == '1' && in[3] == '2')
|
|
|
|
{
|
|
|
|
out[0] = '\n';
|
|
|
|
in += 3;
|
|
|
|
}
|
|
|
|
else if (in[1] == '1' && in[2] == '3' && in[3] == '4')
|
|
|
|
{
|
|
|
|
out[0] = '\\';
|
|
|
|
in += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *get_field( char **str )
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
ret = strsep( str, " \t" );
|
|
|
|
if (*str) *str += strspn( *str, " \t" );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/************************************************************************
|
|
|
|
* getmntent_replacement
|
|
|
|
*
|
|
|
|
* getmntent replacement for Android.
|
|
|
|
*
|
|
|
|
* NB returned static buffer is not thread safe; protect with dir_section.
|
|
|
|
*/
|
|
|
|
static struct mntent *getmntent_replacement( FILE *f )
|
|
|
|
{
|
|
|
|
static struct mntent entry;
|
|
|
|
static char buf[4096];
|
|
|
|
char *p, *start;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!fgets( buf, sizeof(buf), f )) return NULL;
|
|
|
|
p = strchr( buf, '\n' );
|
|
|
|
if (p) *p = '\0';
|
|
|
|
else /* Partially unread line, move file ptr to end */
|
|
|
|
{
|
|
|
|
char tmp[1024];
|
|
|
|
while (fgets( tmp, sizeof(tmp), f ))
|
|
|
|
if (strchr( tmp, '\n' )) break;
|
|
|
|
}
|
|
|
|
start = buf + strspn( buf, " \t" );
|
|
|
|
} while (start[0] == '\0' || start[0] == '#');
|
|
|
|
|
|
|
|
p = get_field( &start );
|
|
|
|
entry.mnt_fsname = p ? unescape_field( p ) : (char *)"";
|
|
|
|
|
|
|
|
p = get_field( &start );
|
|
|
|
entry.mnt_dir = p ? unescape_field( p ) : (char *)"";
|
|
|
|
|
|
|
|
p = get_field( &start );
|
|
|
|
entry.mnt_type = p ? unescape_field( p ) : (char *)"";
|
|
|
|
|
|
|
|
p = get_field( &start );
|
|
|
|
entry.mnt_opts = p ? unescape_field( p ) : (char *)"";
|
|
|
|
|
|
|
|
p = get_field( &start );
|
|
|
|
entry.mnt_freq = p ? atoi(p) : 0;
|
|
|
|
|
|
|
|
p = get_field( &start );
|
|
|
|
entry.mnt_passno = p ? atoi(p) : 0;
|
|
|
|
|
|
|
|
return &entry;
|
|
|
|
}
|
|
|
|
#define getmntent getmntent_replacement
|
|
|
|
#endif
|
2004-04-23 05:22:34 +02:00
|
|
|
|
2007-10-18 15:16:07 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DIR_get_drives_info
|
|
|
|
*
|
|
|
|
* Retrieve device/inode number for all the drives. Helper for find_drive_root.
|
|
|
|
*/
|
|
|
|
unsigned int DIR_get_drives_info( struct drive_info info[MAX_DOS_DRIVES] )
|
|
|
|
{
|
|
|
|
static struct drive_info cache[MAX_DOS_DRIVES];
|
|
|
|
static time_t last_update;
|
|
|
|
static unsigned int nb_drives;
|
|
|
|
unsigned int ret;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
if (now != last_update)
|
|
|
|
{
|
|
|
|
const char *config_dir = wine_get_config_dir();
|
|
|
|
char *buffer, *p;
|
|
|
|
struct stat st;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if ((buffer = RtlAllocateHeap( GetProcessHeap(), 0,
|
|
|
|
strlen(config_dir) + sizeof("/dosdevices/a:") )))
|
|
|
|
{
|
|
|
|
strcpy( buffer, config_dir );
|
|
|
|
strcat( buffer, "/dosdevices/a:" );
|
|
|
|
p = buffer + strlen(buffer) - 2;
|
|
|
|
|
|
|
|
for (i = nb_drives = 0; i < MAX_DOS_DRIVES; i++)
|
|
|
|
{
|
|
|
|
*p = 'a' + i;
|
|
|
|
if (!stat( buffer, &st ))
|
|
|
|
{
|
|
|
|
cache[i].dev = st.st_dev;
|
|
|
|
cache[i].ino = st.st_ino;
|
|
|
|
nb_drives++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cache[i].dev = 0;
|
|
|
|
cache[i].ino = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, buffer );
|
|
|
|
}
|
|
|
|
last_update = now;
|
|
|
|
}
|
|
|
|
memcpy( info, cache, sizeof(cache) );
|
|
|
|
ret = nb_drives;
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 22:04:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* parse_mount_entries
|
|
|
|
*
|
|
|
|
* Parse mount entries looking for a given device. Helper for get_default_drive_device.
|
|
|
|
*/
|
2005-05-14 20:48:18 +02:00
|
|
|
|
|
|
|
#ifdef sun
|
|
|
|
#include <sys/vfstab.h>
|
|
|
|
static char *parse_vfstab_entries( FILE *f, dev_t dev, ino_t ino)
|
|
|
|
{
|
2007-03-17 20:07:10 +01:00
|
|
|
struct vfstab entry;
|
2005-05-14 20:48:18 +02:00
|
|
|
struct stat st;
|
|
|
|
char *device;
|
|
|
|
|
2007-03-17 20:07:10 +01:00
|
|
|
while (! getvfsent( f, &entry ))
|
2005-05-14 20:48:18 +02:00
|
|
|
{
|
|
|
|
/* don't even bother stat'ing network mounts, there's no meaningful device anyway */
|
2007-03-17 20:07:10 +01:00
|
|
|
if (!strcmp( entry.vfs_fstype, "nfs" ) ||
|
|
|
|
!strcmp( entry.vfs_fstype, "smbfs" ) ||
|
|
|
|
!strcmp( entry.vfs_fstype, "ncpfs" )) continue;
|
2005-05-14 20:48:18 +02:00
|
|
|
|
2007-03-17 20:07:10 +01:00
|
|
|
if (stat( entry.vfs_mountp, &st ) == -1) continue;
|
2005-05-14 20:48:18 +02:00
|
|
|
if (st.st_dev != dev || st.st_ino != ino) continue;
|
2007-03-17 20:07:10 +01:00
|
|
|
if (!strcmp( entry.vfs_fstype, "fd" ))
|
2005-05-14 20:48:18 +02:00
|
|
|
{
|
2007-03-17 20:07:10 +01:00
|
|
|
if ((device = strstr( entry.vfs_mntopts, "dev=" )))
|
2005-05-14 20:48:18 +02:00
|
|
|
{
|
|
|
|
char *p = strchr( device + 4, ',' );
|
|
|
|
if (p) *p = 0;
|
|
|
|
return device + 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-03-17 20:07:10 +01:00
|
|
|
return entry.vfs_special;
|
2005-05-14 20:48:18 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-04-29 22:04:48 +02:00
|
|
|
#ifdef linux
|
|
|
|
static char *parse_mount_entries( FILE *f, dev_t dev, ino_t ino )
|
|
|
|
{
|
|
|
|
struct mntent *entry;
|
|
|
|
struct stat st;
|
|
|
|
char *device;
|
|
|
|
|
|
|
|
while ((entry = getmntent( f )))
|
|
|
|
{
|
2004-09-13 20:14:15 +02:00
|
|
|
/* don't even bother stat'ing network mounts, there's no meaningful device anyway */
|
|
|
|
if (!strcmp( entry->mnt_type, "nfs" ) ||
|
|
|
|
!strcmp( entry->mnt_type, "smbfs" ) ||
|
|
|
|
!strcmp( entry->mnt_type, "ncpfs" )) continue;
|
|
|
|
|
2004-04-29 22:04:48 +02:00
|
|
|
if (stat( entry->mnt_dir, &st ) == -1) continue;
|
|
|
|
if (st.st_dev != dev || st.st_ino != ino) continue;
|
|
|
|
if (!strcmp( entry->mnt_type, "supermount" ))
|
|
|
|
{
|
|
|
|
if ((device = strstr( entry->mnt_opts, "dev=" )))
|
|
|
|
{
|
|
|
|
char *p = strchr( device + 4, ',' );
|
|
|
|
if (p) *p = 0;
|
|
|
|
return device + 4;
|
|
|
|
}
|
|
|
|
}
|
2005-10-13 16:32:22 +02:00
|
|
|
else if (!stat( entry->mnt_fsname, &st ) && S_ISREG(st.st_mode))
|
|
|
|
{
|
|
|
|
/* if device is a regular file check for a loop mount */
|
|
|
|
if ((device = strstr( entry->mnt_opts, "loop=" )))
|
|
|
|
{
|
|
|
|
char *p = strchr( device + 5, ',' );
|
|
|
|
if (p) *p = 0;
|
|
|
|
return device + 5;
|
|
|
|
}
|
|
|
|
}
|
2004-04-29 22:04:48 +02:00
|
|
|
else
|
|
|
|
return entry->mnt_fsname;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-02 18:53:57 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
2005-05-19 13:12:27 +02:00
|
|
|
#include <fstab.h>
|
|
|
|
static char *parse_mount_entries( FILE *f, dev_t dev, ino_t ino )
|
|
|
|
{
|
|
|
|
struct fstab *entry;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
while ((entry = getfsent()))
|
|
|
|
{
|
|
|
|
/* don't even bother stat'ing network mounts, there's no meaningful device anyway */
|
|
|
|
if (!strcmp( entry->fs_vfstype, "nfs" ) ||
|
|
|
|
!strcmp( entry->fs_vfstype, "smbfs" ) ||
|
|
|
|
!strcmp( entry->fs_vfstype, "ncpfs" )) continue;
|
|
|
|
|
|
|
|
if (stat( entry->fs_file, &st ) == -1) continue;
|
|
|
|
if (st.st_dev != dev || st.st_ino != ino) continue;
|
|
|
|
return entry->fs_spec;
|
|
|
|
}
|
2005-05-20 21:24:07 +02:00
|
|
|
return NULL;
|
2005-05-19 13:12:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-05-14 20:48:18 +02:00
|
|
|
#ifdef sun
|
|
|
|
#include <sys/mnttab.h>
|
|
|
|
static char *parse_mount_entries( FILE *f, dev_t dev, ino_t ino )
|
|
|
|
{
|
2007-03-17 20:07:10 +01:00
|
|
|
struct mnttab entry;
|
2005-05-14 20:48:18 +02:00
|
|
|
struct stat st;
|
|
|
|
char *device;
|
|
|
|
|
|
|
|
|
2007-03-17 20:07:10 +01:00
|
|
|
while (( ! getmntent( f, &entry) ))
|
2005-05-14 20:48:18 +02:00
|
|
|
{
|
|
|
|
/* don't even bother stat'ing network mounts, there's no meaningful device anyway */
|
2007-03-17 20:07:10 +01:00
|
|
|
if (!strcmp( entry.mnt_fstype, "nfs" ) ||
|
|
|
|
!strcmp( entry.mnt_fstype, "smbfs" ) ||
|
|
|
|
!strcmp( entry.mnt_fstype, "ncpfs" )) continue;
|
2005-05-14 20:48:18 +02:00
|
|
|
|
2007-03-17 20:07:10 +01:00
|
|
|
if (stat( entry.mnt_mountp, &st ) == -1) continue;
|
2005-05-14 20:48:18 +02:00
|
|
|
if (st.st_dev != dev || st.st_ino != ino) continue;
|
2007-03-17 20:07:10 +01:00
|
|
|
if (!strcmp( entry.mnt_fstype, "fd" ))
|
2005-05-14 20:48:18 +02:00
|
|
|
{
|
2007-03-17 20:07:10 +01:00
|
|
|
if ((device = strstr( entry.mnt_mntopts, "dev=" )))
|
2005-05-14 20:48:18 +02:00
|
|
|
{
|
|
|
|
char *p = strchr( device + 4, ',' );
|
|
|
|
if (p) *p = 0;
|
|
|
|
return device + 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-03-17 20:07:10 +01:00
|
|
|
return entry.mnt_special;
|
2005-05-14 20:48:18 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-04-29 22:04:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_default_drive_device
|
|
|
|
*
|
|
|
|
* Return the default device to use for a given drive mount point.
|
|
|
|
*/
|
|
|
|
static char *get_default_drive_device( const char *root )
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
#ifdef linux
|
|
|
|
FILE *f;
|
|
|
|
char *device = NULL;
|
|
|
|
int fd, res = -1;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
/* try to open it first to force it to get mounted */
|
|
|
|
if ((fd = open( root, O_RDONLY | O_DIRECTORY )) != -1)
|
|
|
|
{
|
|
|
|
res = fstat( fd, &st );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
/* now try normal stat just in case */
|
|
|
|
if (res == -1) res = stat( root, &st );
|
|
|
|
if (res == -1) return NULL;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
2014-04-07 14:22:11 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
if ((f = fopen( "/proc/mounts", "r" )))
|
|
|
|
{
|
|
|
|
device = parse_mount_entries( f, st.st_dev, st.st_ino );
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
#else
|
2004-04-29 22:04:48 +02:00
|
|
|
if ((f = fopen( "/etc/mtab", "r" )))
|
|
|
|
{
|
|
|
|
device = parse_mount_entries( f, st.st_dev, st.st_ino );
|
2013-07-29 21:07:12 +02:00
|
|
|
fclose( f );
|
2004-04-29 22:04:48 +02:00
|
|
|
}
|
|
|
|
/* look through fstab too in case it's not mounted (for instance if it's an audio CD) */
|
|
|
|
if (!device && (f = fopen( "/etc/fstab", "r" )))
|
|
|
|
{
|
|
|
|
device = parse_mount_entries( f, st.st_dev, st.st_ino );
|
2013-07-29 21:07:12 +02:00
|
|
|
fclose( f );
|
2004-04-29 22:04:48 +02:00
|
|
|
}
|
2014-04-07 14:22:11 +02:00
|
|
|
#endif
|
2004-04-29 22:04:48 +02:00
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(device) + 1 );
|
|
|
|
if (ret) strcpy( ret, device );
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2005-05-14 20:48:18 +02:00
|
|
|
|
2012-06-02 18:53:57 +02:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__ ) || defined(__DragonFly__)
|
2005-05-19 13:12:27 +02:00
|
|
|
char *device = NULL;
|
|
|
|
int fd, res = -1;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
/* try to open it first to force it to get mounted */
|
|
|
|
if ((fd = open( root, O_RDONLY )) != -1)
|
|
|
|
{
|
|
|
|
res = fstat( fd, &st );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
/* now try normal stat just in case */
|
|
|
|
if (res == -1) res = stat( root, &st );
|
|
|
|
if (res == -1) return NULL;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
|
|
|
/* The FreeBSD parse_mount_entries doesn't require a file argument, so just
|
|
|
|
* pass NULL. Leave the argument in for symmetry.
|
|
|
|
*/
|
|
|
|
device = parse_mount_entries( NULL, st.st_dev, st.st_ino );
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(device) + 1 );
|
|
|
|
if (ret) strcpy( ret, device );
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
|
|
|
|
2005-05-14 20:48:18 +02:00
|
|
|
#elif defined( sun )
|
|
|
|
FILE *f;
|
|
|
|
char *device = NULL;
|
|
|
|
int fd, res = -1;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
/* try to open it first to force it to get mounted */
|
|
|
|
if ((fd = open( root, O_RDONLY )) != -1)
|
|
|
|
{
|
|
|
|
res = fstat( fd, &st );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
/* now try normal stat just in case */
|
|
|
|
if (res == -1) res = stat( root, &st );
|
|
|
|
if (res == -1) return NULL;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
|
|
|
if ((f = fopen( "/etc/mnttab", "r" )))
|
|
|
|
{
|
|
|
|
device = parse_mount_entries( f, st.st_dev, st.st_ino);
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
/* look through fstab too in case it's not mounted (for instance if it's an audio CD) */
|
|
|
|
if (!device && (f = fopen( "/etc/vfstab", "r" )))
|
|
|
|
{
|
|
|
|
device = parse_vfstab_entries( f, st.st_dev, st.st_ino );
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(device) + 1 );
|
|
|
|
if (ret) strcpy( ret, device );
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
|
|
|
|
2004-07-07 02:47:10 +02:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
struct statfs *mntStat;
|
|
|
|
struct stat st;
|
|
|
|
int i;
|
|
|
|
int mntSize;
|
|
|
|
dev_t dev;
|
|
|
|
ino_t ino;
|
|
|
|
static const char path_bsd_device[] = "/dev/disk";
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = stat( root, &st );
|
|
|
|
if (res == -1) return NULL;
|
|
|
|
|
|
|
|
dev = st.st_dev;
|
|
|
|
ino = st.st_ino;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
|
|
|
mntSize = getmntinfo(&mntStat, MNT_NOWAIT);
|
|
|
|
|
|
|
|
for (i = 0; i < mntSize && !ret; i++)
|
|
|
|
{
|
|
|
|
if (stat(mntStat[i].f_mntonname, &st ) == -1) continue;
|
|
|
|
if (st.st_dev != dev || st.st_ino != ino) continue;
|
|
|
|
|
|
|
|
/* FIXME add support for mounted network drive */
|
|
|
|
if ( strncmp(mntStat[i].f_mntfromname, path_bsd_device, strlen(path_bsd_device)) == 0)
|
|
|
|
{
|
|
|
|
/* set return value to the corresponding raw BSD node */
|
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(mntStat[i].f_mntfromname) + 2 /* 2 : r and \0 */ );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
strcpy(ret, "/dev/r");
|
|
|
|
strcat(ret, mntStat[i].f_mntfromname+sizeof("/dev/")-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2004-04-29 22:04:48 +02:00
|
|
|
#else
|
|
|
|
static int warned;
|
|
|
|
if (!warned++) FIXME( "auto detection of DOS devices not supported on this platform\n" );
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-28 18:45:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_device_mount_point
|
|
|
|
*
|
|
|
|
* Return the current mount point for a device.
|
|
|
|
*/
|
|
|
|
static char *get_device_mount_point( dev_t dev )
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
#ifdef linux
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
2014-04-07 14:22:11 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
if ((f = fopen( "/proc/mounts", "r" )))
|
|
|
|
#else
|
2005-10-28 18:45:24 +02:00
|
|
|
if ((f = fopen( "/etc/mtab", "r" )))
|
2014-04-07 14:22:11 +02:00
|
|
|
#endif
|
2005-10-28 18:45:24 +02:00
|
|
|
{
|
|
|
|
struct mntent *entry;
|
|
|
|
struct stat st;
|
|
|
|
char *p, *device;
|
|
|
|
|
|
|
|
while ((entry = getmntent( f )))
|
|
|
|
{
|
|
|
|
/* don't even bother stat'ing network mounts, there's no meaningful device anyway */
|
|
|
|
if (!strcmp( entry->mnt_type, "nfs" ) ||
|
|
|
|
!strcmp( entry->mnt_type, "smbfs" ) ||
|
|
|
|
!strcmp( entry->mnt_type, "ncpfs" )) continue;
|
|
|
|
|
|
|
|
if (!strcmp( entry->mnt_type, "supermount" ))
|
|
|
|
{
|
|
|
|
if ((device = strstr( entry->mnt_opts, "dev=" )))
|
|
|
|
{
|
|
|
|
device += 4;
|
|
|
|
if ((p = strchr( device, ',' ))) *p = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!stat( entry->mnt_fsname, &st ) && S_ISREG(st.st_mode))
|
|
|
|
{
|
|
|
|
/* if device is a regular file check for a loop mount */
|
|
|
|
if ((device = strstr( entry->mnt_opts, "loop=" )))
|
|
|
|
{
|
|
|
|
device += 5;
|
|
|
|
if ((p = strchr( device, ',' ))) *p = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else device = entry->mnt_fsname;
|
|
|
|
|
|
|
|
if (device && !stat( device, &st ) && S_ISBLK(st.st_mode) && st.st_rdev == dev)
|
|
|
|
{
|
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(entry->mnt_dir) + 1 );
|
|
|
|
if (ret) strcpy( ret, entry->mnt_dir );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-29 21:07:12 +02:00
|
|
|
fclose( f );
|
2005-10-28 18:45:24 +02:00
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2006-10-03 14:54:21 +02:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
struct statfs *entry;
|
|
|
|
struct stat st;
|
|
|
|
int i, size;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
|
|
|
size = getmntinfo( &entry, MNT_NOWAIT );
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
if (stat( entry[i].f_mntfromname, &st ) == -1) continue;
|
|
|
|
if (S_ISBLK(st.st_mode) && st.st_rdev == dev)
|
|
|
|
{
|
2013-09-04 16:28:10 +02:00
|
|
|
ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(entry[i].f_mntonname) + 1 );
|
|
|
|
if (ret) strcpy( ret, entry[i].f_mntonname );
|
2006-10-03 14:54:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2005-10-28 18:45:24 +02:00
|
|
|
#else
|
|
|
|
static int warned;
|
|
|
|
if (!warned++) FIXME( "unmounting devices not supported on this platform\n" );
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-18 21:09:44 +01:00
|
|
|
#if defined(HAVE_GETATTRLIST) && defined(ATTR_VOL_CAPABILITIES) && \
|
|
|
|
defined(VOL_CAPABILITIES_FORMAT) && defined(VOL_CAP_FMT_CASE_SENSITIVE)
|
|
|
|
|
|
|
|
struct get_fsid
|
|
|
|
{
|
|
|
|
ULONG size;
|
|
|
|
dev_t dev;
|
|
|
|
fsid_t fsid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fs_cache
|
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
fsid_t fsid;
|
|
|
|
BOOLEAN case_sensitive;
|
|
|
|
} fs_cache[64];
|
|
|
|
|
|
|
|
struct vol_caps
|
|
|
|
{
|
|
|
|
ULONG size;
|
|
|
|
vol_capabilities_attr_t caps;
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* look_up_fs_cache
|
|
|
|
*
|
|
|
|
* Checks if the specified file system is in the cache.
|
|
|
|
*/
|
|
|
|
static struct fs_cache *look_up_fs_cache( dev_t dev )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < sizeof(fs_cache)/sizeof(fs_cache[0]); i++)
|
|
|
|
if (fs_cache[i].dev == dev)
|
|
|
|
return fs_cache+i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* add_fs_cache
|
|
|
|
*
|
|
|
|
* Adds the specified file system to the cache.
|
|
|
|
*/
|
|
|
|
static void add_fs_cache( dev_t dev, fsid_t fsid, BOOLEAN case_sensitive )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct fs_cache *entry = look_up_fs_cache( dev );
|
|
|
|
static int once = 0;
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
/* Update the cache */
|
|
|
|
entry->fsid = fsid;
|
|
|
|
entry->case_sensitive = case_sensitive;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a new entry */
|
|
|
|
for (i = 0; i < sizeof(fs_cache)/sizeof(fs_cache[0]); i++)
|
|
|
|
if (fs_cache[i].dev == 0)
|
|
|
|
{
|
|
|
|
/* This entry is empty, use it */
|
|
|
|
fs_cache[i].dev = dev;
|
|
|
|
fs_cache[i].fsid = fsid;
|
|
|
|
fs_cache[i].case_sensitive = case_sensitive;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cache is out of space, warn */
|
2011-02-01 11:33:47 +01:00
|
|
|
if (!once++)
|
2011-01-18 21:09:44 +01:00
|
|
|
WARN( "FS cache is out of space, expect performance problems\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2015-06-11 23:04:04 +02:00
|
|
|
* get_dir_case_sensitivity_attr
|
2011-01-18 21:09:44 +01:00
|
|
|
*
|
2015-06-11 23:04:04 +02:00
|
|
|
* Checks if the volume containing the specified directory is case
|
|
|
|
* sensitive or not. Uses getattrlist(2).
|
2011-01-18 21:09:44 +01:00
|
|
|
*/
|
2015-06-11 23:04:04 +02:00
|
|
|
static int get_dir_case_sensitivity_attr( const char *dir )
|
2011-01-18 21:09:44 +01:00
|
|
|
{
|
2015-12-30 06:37:58 +01:00
|
|
|
char *mntpoint;
|
2011-01-18 21:09:44 +01:00
|
|
|
struct attrlist attr;
|
|
|
|
struct vol_caps caps;
|
2015-06-11 23:04:04 +02:00
|
|
|
struct get_fsid get_fsid;
|
2011-01-18 21:09:44 +01:00
|
|
|
struct fs_cache *entry;
|
|
|
|
|
2015-06-11 23:04:04 +02:00
|
|
|
/* First get the FS ID of the volume */
|
|
|
|
attr.bitmapcount = ATTR_BIT_MAP_COUNT;
|
|
|
|
attr.reserved = 0;
|
|
|
|
attr.commonattr = ATTR_CMN_DEVID|ATTR_CMN_FSID;
|
|
|
|
attr.volattr = attr.dirattr = attr.fileattr = attr.forkattr = 0;
|
|
|
|
get_fsid.size = 0;
|
|
|
|
if (getattrlist( dir, &attr, &get_fsid, sizeof(get_fsid), 0 ) != 0 ||
|
|
|
|
get_fsid.size != sizeof(get_fsid))
|
|
|
|
return -1;
|
2011-01-18 21:09:44 +01:00
|
|
|
/* Try to look it up in the cache */
|
2015-06-11 23:04:04 +02:00
|
|
|
entry = look_up_fs_cache( get_fsid.dev );
|
|
|
|
if (entry && !memcmp( &entry->fsid, &get_fsid.fsid, sizeof(fsid_t) ))
|
2011-01-18 21:09:44 +01:00
|
|
|
/* Cache lookup succeeded */
|
|
|
|
return entry->case_sensitive;
|
|
|
|
/* Cache is stale at this point, we have to update it */
|
|
|
|
|
2015-06-11 23:04:04 +02:00
|
|
|
mntpoint = get_device_mount_point( get_fsid.dev );
|
2011-01-18 21:09:44 +01:00
|
|
|
/* Now look up the case-sensitivity */
|
2015-06-11 23:04:04 +02:00
|
|
|
attr.commonattr = 0;
|
2011-01-18 21:09:44 +01:00
|
|
|
attr.volattr = ATTR_VOL_INFO|ATTR_VOL_CAPABILITIES;
|
|
|
|
if (getattrlist( mntpoint, &attr, &caps, sizeof(caps), 0 ) < 0)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mntpoint );
|
2015-06-11 23:04:04 +02:00
|
|
|
add_fs_cache( get_fsid.dev, get_fsid.fsid, TRUE );
|
2011-01-18 21:09:44 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mntpoint );
|
|
|
|
if (caps.size == sizeof(caps) &&
|
|
|
|
(caps.caps.valid[VOL_CAPABILITIES_FORMAT] &
|
|
|
|
(VOL_CAP_FMT_CASE_SENSITIVE | VOL_CAP_FMT_CASE_PRESERVING)) ==
|
|
|
|
(VOL_CAP_FMT_CASE_SENSITIVE | VOL_CAP_FMT_CASE_PRESERVING))
|
|
|
|
{
|
|
|
|
BOOLEAN ret;
|
|
|
|
|
|
|
|
if ((caps.caps.capabilities[VOL_CAPABILITIES_FORMAT] &
|
|
|
|
VOL_CAP_FMT_CASE_SENSITIVE) != VOL_CAP_FMT_CASE_SENSITIVE)
|
|
|
|
ret = FALSE;
|
|
|
|
else
|
|
|
|
ret = TRUE;
|
|
|
|
/* Update the cache */
|
2015-06-11 23:04:04 +02:00
|
|
|
add_fs_cache( get_fsid.dev, get_fsid.fsid, ret );
|
2011-01-18 21:09:44 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_dir_case_sensitivity_stat
|
|
|
|
*
|
|
|
|
* Checks if the volume containing the specified directory is case
|
|
|
|
* sensitive or not. Uses statfs(2) or statvfs(2).
|
|
|
|
*/
|
|
|
|
static BOOLEAN get_dir_case_sensitivity_stat( const char *dir )
|
|
|
|
{
|
|
|
|
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
|
|
struct statfs stfs;
|
|
|
|
|
2011-03-30 20:50:12 +02:00
|
|
|
if (statfs( dir, &stfs ) == -1) return FALSE;
|
2011-01-18 21:09:44 +01:00
|
|
|
/* Assume these file systems are always case insensitive on Mac OS.
|
|
|
|
* For FreeBSD, only assume CIOPFS is case insensitive (AFAIK, Mac OS
|
|
|
|
* is the only UNIX that supports case-insensitive lookup).
|
|
|
|
*/
|
|
|
|
if (!strcmp( stfs.f_fstypename, "fusefs" ) &&
|
|
|
|
!strncmp( stfs.f_mntfromname, "ciopfs", 5 ))
|
|
|
|
return FALSE;
|
|
|
|
#ifdef __APPLE__
|
|
|
|
if (!strcmp( stfs.f_fstypename, "msdos" ) ||
|
|
|
|
!strcmp( stfs.f_fstypename, "cd9660" ) ||
|
|
|
|
!strcmp( stfs.f_fstypename, "udf" ) ||
|
|
|
|
!strcmp( stfs.f_fstypename, "ntfs" ) ||
|
|
|
|
!strcmp( stfs.f_fstypename, "smbfs" ))
|
|
|
|
return FALSE;
|
|
|
|
#ifdef _DARWIN_FEATURE_64_BIT_INODE
|
|
|
|
if (!strcmp( stfs.f_fstypename, "hfs" ) && (stfs.f_fssubtype == 0 ||
|
|
|
|
stfs.f_fssubtype == 1 ||
|
|
|
|
stfs.f_fssubtype == 128))
|
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
/* The field says "reserved", but a quick look at the kernel source
|
|
|
|
* tells us that this "reserved" field is really the same as the
|
|
|
|
* "fssubtype" field from the inode64 structure (see munge_statfs()
|
|
|
|
* in <xnu-source>/bsd/vfs/vfs_syscalls.c).
|
|
|
|
*/
|
|
|
|
if (!strcmp( stfs.f_fstypename, "hfs" ) && (stfs.f_reserved1 == 0 ||
|
|
|
|
stfs.f_reserved1 == 1 ||
|
|
|
|
stfs.f_reserved1 == 128))
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
struct statvfs stfs;
|
|
|
|
|
2011-03-30 20:50:12 +02:00
|
|
|
if (statvfs( dir, &stfs ) == -1) return FALSE;
|
2011-01-18 21:09:44 +01:00
|
|
|
/* Only assume CIOPFS is case insensitive. */
|
|
|
|
if (strcmp( stfs.f_fstypename, "fusefs" ) ||
|
|
|
|
strncmp( stfs.f_mntfromname, "ciopfs", 5 ))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
struct statfs stfs;
|
|
|
|
struct stat st;
|
|
|
|
char *cifile;
|
|
|
|
|
|
|
|
/* Only assume CIOPFS is case insensitive. */
|
2011-03-30 20:50:12 +02:00
|
|
|
if (statfs( dir, &stfs ) == -1) return FALSE;
|
2011-01-18 21:09:44 +01:00
|
|
|
if (stfs.f_type != 0x65735546 /* FUSE_SUPER_MAGIC */)
|
|
|
|
return TRUE;
|
|
|
|
/* Normally, we'd have to parse the mtab to find out exactly what
|
|
|
|
* kind of FUSE FS this is. But, someone on wine-devel suggested
|
|
|
|
* a shortcut. We'll stat a special file in the directory. If it's
|
|
|
|
* there, we'll assume it's a CIOPFS, else not.
|
|
|
|
* This will break if somebody puts a file named ".ciopfs" in a non-
|
|
|
|
* CIOPFS directory.
|
|
|
|
*/
|
|
|
|
cifile = RtlAllocateHeap( GetProcessHeap(), 0, strlen( dir )+sizeof("/.ciopfs") );
|
|
|
|
if (!cifile) return TRUE;
|
|
|
|
strcpy( cifile, dir );
|
|
|
|
strcat( cifile, "/.ciopfs" );
|
|
|
|
if (stat( cifile, &st ) == 0)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, cifile );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, cifile );
|
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_dir_case_sensitivity
|
|
|
|
*
|
|
|
|
* Checks if the volume containing the specified directory is case
|
|
|
|
* sensitive or not. Uses statfs(2) or statvfs(2).
|
|
|
|
*/
|
|
|
|
static BOOLEAN get_dir_case_sensitivity( const char *dir )
|
|
|
|
{
|
|
|
|
#if defined(HAVE_GETATTRLIST) && defined(ATTR_VOL_CAPABILITIES) && \
|
|
|
|
defined(VOL_CAPABILITIES_FORMAT) && defined(VOL_CAP_FMT_CASE_SENSITIVE)
|
|
|
|
int case_sensitive = get_dir_case_sensitivity_attr( dir );
|
|
|
|
if (case_sensitive != -1) return case_sensitive;
|
|
|
|
#endif
|
|
|
|
return get_dir_case_sensitivity_stat( dir );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-16 02:32:02 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* init_options
|
|
|
|
*
|
2005-10-27 13:22:47 +02:00
|
|
|
* Initialize the show_dot_files options.
|
2004-03-16 02:32:02 +01:00
|
|
|
*/
|
2013-08-29 16:48:23 +02:00
|
|
|
static DWORD WINAPI init_options( RTL_RUN_ONCE *once, void *param, void **context )
|
2004-03-16 02:32:02 +01:00
|
|
|
{
|
2005-06-17 23:07:44 +02:00
|
|
|
static const WCHAR WineW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
|
2004-03-16 02:32:02 +01:00
|
|
|
static const WCHAR ShowDotFilesW[] = {'S','h','o','w','D','o','t','F','i','l','e','s',0};
|
|
|
|
char tmp[80];
|
2005-06-17 23:07:44 +02:00
|
|
|
HANDLE root, hkey;
|
2004-03-16 02:32:02 +01:00
|
|
|
DWORD dummy;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
|
2005-06-17 23:07:44 +02:00
|
|
|
RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
|
2004-03-16 02:32:02 +01:00
|
|
|
attr.Length = sizeof(attr);
|
2005-06-17 23:07:44 +02:00
|
|
|
attr.RootDirectory = root;
|
2004-03-16 02:32:02 +01:00
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, WineW );
|
|
|
|
|
2005-06-17 23:07:44 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine */
|
2004-03-16 02:32:02 +01:00
|
|
|
if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
|
|
|
|
{
|
|
|
|
RtlInitUnicodeString( &nameW, ShowDotFilesW );
|
|
|
|
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
|
|
|
|
{
|
|
|
|
WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
|
|
|
|
show_dot_files = IS_OPTION_TRUE( str[0] );
|
|
|
|
}
|
|
|
|
NtClose( hkey );
|
|
|
|
}
|
2005-06-17 23:07:44 +02:00
|
|
|
NtClose( root );
|
2008-10-28 13:55:24 +01:00
|
|
|
|
|
|
|
/* a couple of directories that we don't want to return in directory searches */
|
|
|
|
ignore_file( wine_get_config_dir() );
|
|
|
|
ignore_file( "/dev" );
|
|
|
|
ignore_file( "/proc" );
|
|
|
|
#ifdef linux
|
|
|
|
ignore_file( "/sys" );
|
|
|
|
#endif
|
2013-08-29 16:48:23 +02:00
|
|
|
return TRUE;
|
2004-03-16 02:32:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-20 02:36:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DIR_is_hidden_file
|
|
|
|
*
|
|
|
|
* Check if the specified file should be hidden based on its name and the show dot files option.
|
|
|
|
*/
|
|
|
|
BOOL DIR_is_hidden_file( const UNICODE_STRING *name )
|
|
|
|
{
|
|
|
|
WCHAR *p, *end;
|
|
|
|
|
2013-08-29 16:48:23 +02:00
|
|
|
RtlRunOnceExecuteOnce( &init_once, init_options, NULL, NULL );
|
|
|
|
|
2004-04-20 02:36:29 +02:00
|
|
|
if (show_dot_files) return FALSE;
|
|
|
|
|
|
|
|
end = p = name->Buffer + name->Length/sizeof(WCHAR);
|
|
|
|
while (p > name->Buffer && IS_SEPARATOR(p[-1])) p--;
|
|
|
|
while (p > name->Buffer && !IS_SEPARATOR(p[-1])) p--;
|
|
|
|
if (p == end || *p != '.') return FALSE;
|
|
|
|
/* make sure it isn't '.' or '..' */
|
|
|
|
if (p + 1 == end) return FALSE;
|
|
|
|
if (p[1] == '.' && p + 2 == end) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-16 02:32:02 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* hash_short_file_name
|
|
|
|
*
|
|
|
|
* Transform a Unix file name into a hashed DOS name. If the name is a valid
|
|
|
|
* DOS name, it is converted to upper-case; otherwise it is replaced by a
|
|
|
|
* hashed version that fits in 8.3 format.
|
|
|
|
* 'buffer' must be at least 12 characters long.
|
|
|
|
* Returns length of short name in bytes; short name is NOT null-terminated.
|
|
|
|
*/
|
|
|
|
static ULONG hash_short_file_name( const UNICODE_STRING *name, LPWSTR buffer )
|
|
|
|
{
|
|
|
|
static const char hash_chars[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
|
|
|
|
|
|
|
|
LPCWSTR p, ext, end = name->Buffer + name->Length / sizeof(WCHAR);
|
|
|
|
LPWSTR dst;
|
|
|
|
unsigned short hash;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Compute the hash code of the file name */
|
|
|
|
/* If you know something about hash functions, feel free to */
|
|
|
|
/* insert a better algorithm here... */
|
|
|
|
if (!is_case_sensitive)
|
|
|
|
{
|
|
|
|
for (p = name->Buffer, hash = 0xbeef; p < end - 1; p++)
|
|
|
|
hash = (hash<<3) ^ (hash>>5) ^ tolowerW(*p) ^ (tolowerW(p[1]) << 8);
|
|
|
|
hash = (hash<<3) ^ (hash>>5) ^ tolowerW(*p); /* Last character */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (p = name->Buffer, hash = 0xbeef; p < end - 1; p++)
|
|
|
|
hash = (hash << 3) ^ (hash >> 5) ^ *p ^ (p[1] << 8);
|
|
|
|
hash = (hash << 3) ^ (hash >> 5) ^ *p; /* Last character */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find last dot for start of the extension */
|
|
|
|
for (p = name->Buffer + 1, ext = NULL; p < end - 1; p++) if (*p == '.') ext = p;
|
|
|
|
|
|
|
|
/* Copy first 4 chars, replacing invalid chars with '_' */
|
|
|
|
for (i = 4, p = name->Buffer, dst = buffer; i > 0; i--, p++)
|
|
|
|
{
|
|
|
|
if (p == end || p == ext) break;
|
2005-02-09 14:32:12 +01:00
|
|
|
*dst++ = is_invalid_dos_char(*p) ? '_' : toupperW(*p);
|
2004-03-16 02:32:02 +01:00
|
|
|
}
|
|
|
|
/* Pad to 5 chars with '~' */
|
|
|
|
while (i-- >= 0) *dst++ = '~';
|
|
|
|
|
|
|
|
/* Insert hash code converted to 3 ASCII chars */
|
|
|
|
*dst++ = hash_chars[(hash >> 10) & 0x1f];
|
|
|
|
*dst++ = hash_chars[(hash >> 5) & 0x1f];
|
|
|
|
*dst++ = hash_chars[hash & 0x1f];
|
|
|
|
|
|
|
|
/* Copy the first 3 chars of the extension (if any) */
|
|
|
|
if (ext)
|
|
|
|
{
|
|
|
|
*dst++ = '.';
|
|
|
|
for (i = 3, ext++; (i > 0) && ext < end; i--, ext++)
|
2005-02-09 14:32:12 +01:00
|
|
|
*dst++ = is_invalid_dos_char(*ext) ? '_' : toupperW(*ext);
|
2004-03-16 02:32:02 +01:00
|
|
|
}
|
|
|
|
return dst - buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* match_filename
|
|
|
|
*
|
|
|
|
* Check a long file name against a mask.
|
|
|
|
*
|
|
|
|
* Tests (done in W95 DOS shell - case insensitive):
|
|
|
|
* *.txt test1.test.txt *
|
|
|
|
* *st1* test1.txt *
|
|
|
|
* *.t??????.t* test1.ta.tornado.txt *
|
|
|
|
* *tornado* test1.ta.tornado.txt *
|
|
|
|
* t*t test1.ta.tornado.txt *
|
|
|
|
* ?est* test1.txt *
|
|
|
|
* ?est??? test1.txt -
|
|
|
|
* *test1.txt* test1.txt *
|
|
|
|
* h?l?o*t.dat hellothisisatest.dat *
|
|
|
|
*/
|
|
|
|
static BOOLEAN match_filename( const UNICODE_STRING *name_str, const UNICODE_STRING *mask_str )
|
|
|
|
{
|
2013-10-29 21:54:12 +01:00
|
|
|
BOOL mismatch;
|
2004-03-16 02:32:02 +01:00
|
|
|
const WCHAR *name = name_str->Buffer;
|
|
|
|
const WCHAR *mask = mask_str->Buffer;
|
|
|
|
const WCHAR *name_end = name + name_str->Length / sizeof(WCHAR);
|
|
|
|
const WCHAR *mask_end = mask + mask_str->Length / sizeof(WCHAR);
|
|
|
|
const WCHAR *lastjoker = NULL;
|
|
|
|
const WCHAR *next_to_retry = NULL;
|
|
|
|
|
|
|
|
TRACE("(%s, %s)\n", debugstr_us(name_str), debugstr_us(mask_str));
|
|
|
|
|
|
|
|
while (name < name_end && mask < mask_end)
|
|
|
|
{
|
|
|
|
switch(*mask)
|
|
|
|
{
|
|
|
|
case '*':
|
|
|
|
mask++;
|
|
|
|
while (mask < mask_end && *mask == '*') mask++; /* Skip consecutive '*' */
|
|
|
|
if (mask == mask_end) return TRUE; /* end of mask is all '*', so match */
|
|
|
|
lastjoker = mask;
|
|
|
|
|
|
|
|
/* skip to the next match after the joker(s) */
|
|
|
|
if (is_case_sensitive)
|
|
|
|
while (name < name_end && (*name != *mask)) name++;
|
|
|
|
else
|
|
|
|
while (name < name_end && (toupperW(*name) != toupperW(*mask))) name++;
|
|
|
|
next_to_retry = name;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
mask++;
|
|
|
|
name++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (is_case_sensitive) mismatch = (*mask != *name);
|
|
|
|
else mismatch = (toupperW(*mask) != toupperW(*name));
|
|
|
|
|
|
|
|
if (!mismatch)
|
|
|
|
{
|
|
|
|
mask++;
|
|
|
|
name++;
|
|
|
|
if (mask == mask_end)
|
|
|
|
{
|
|
|
|
if (name == name_end) return TRUE;
|
|
|
|
if (lastjoker) mask = lastjoker;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* mismatch ! */
|
|
|
|
{
|
|
|
|
if (lastjoker) /* we had an '*', so we can try unlimitedly */
|
|
|
|
{
|
|
|
|
mask = lastjoker;
|
|
|
|
|
|
|
|
/* this scan sequence was a mismatch, so restart
|
|
|
|
* 1 char after the first char we checked last time */
|
|
|
|
next_to_retry++;
|
|
|
|
name = next_to_retry;
|
|
|
|
}
|
|
|
|
else return FALSE; /* bad luck */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (mask < mask_end && ((*mask == '.') || (*mask == '*')))
|
|
|
|
mask++; /* Ignore trailing '.' or '*' in mask */
|
|
|
|
return (name == name_end && mask == mask_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* append_entry
|
|
|
|
*
|
|
|
|
* helper for NtQueryDirectoryFile
|
|
|
|
*/
|
2009-11-18 17:42:51 +01:00
|
|
|
static union file_directory_info *append_entry( void *info_ptr, IO_STATUS_BLOCK *io, ULONG max_length,
|
2004-03-16 02:32:02 +01:00
|
|
|
const char *long_name, const char *short_name,
|
2009-11-18 17:47:37 +01:00
|
|
|
const UNICODE_STRING *mask, FILE_INFORMATION_CLASS class )
|
2004-03-16 02:32:02 +01:00
|
|
|
{
|
2009-11-18 17:42:51 +01:00
|
|
|
union file_directory_info *info;
|
2004-03-16 02:32:02 +01:00
|
|
|
int i, long_len, short_len, total_len;
|
|
|
|
struct stat st;
|
|
|
|
WCHAR long_nameW[MAX_DIR_ENTRY_LEN];
|
|
|
|
WCHAR short_nameW[12];
|
2009-11-18 18:07:30 +01:00
|
|
|
WCHAR *filename;
|
2004-03-16 02:32:02 +01:00
|
|
|
UNICODE_STRING str;
|
2014-08-20 04:31:00 +02:00
|
|
|
ULONG attributes;
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2009-11-18 17:37:15 +01:00
|
|
|
io->u.Status = STATUS_SUCCESS;
|
2004-03-16 02:32:02 +01:00
|
|
|
long_len = ntdll_umbstowcs( 0, long_name, strlen(long_name), long_nameW, MAX_DIR_ENTRY_LEN );
|
|
|
|
if (long_len == -1) return NULL;
|
|
|
|
|
|
|
|
str.Buffer = long_nameW;
|
|
|
|
str.Length = long_len * sizeof(WCHAR);
|
|
|
|
str.MaximumLength = sizeof(long_nameW);
|
|
|
|
|
|
|
|
if (short_name)
|
|
|
|
{
|
|
|
|
short_len = ntdll_umbstowcs( 0, short_name, strlen(short_name),
|
|
|
|
short_nameW, sizeof(short_nameW) / sizeof(WCHAR) );
|
|
|
|
if (short_len == -1) short_len = sizeof(short_nameW) / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else /* generate a short name if necessary */
|
|
|
|
{
|
|
|
|
BOOLEAN spaces;
|
|
|
|
|
|
|
|
short_len = 0;
|
|
|
|
if (!RtlIsNameLegalDOS8Dot3( &str, NULL, &spaces ) || spaces)
|
|
|
|
short_len = hash_short_file_name( &str, short_nameW );
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "long %s short %s mask %s\n",
|
|
|
|
debugstr_us(&str), debugstr_wn(short_nameW, short_len), debugstr_us(mask) );
|
|
|
|
|
|
|
|
if (mask && !match_filename( &str, mask ))
|
|
|
|
{
|
|
|
|
if (!short_len) return NULL; /* no short name to match */
|
|
|
|
str.Buffer = short_nameW;
|
|
|
|
str.Length = short_len * sizeof(WCHAR);
|
|
|
|
str.MaximumLength = sizeof(short_nameW);
|
|
|
|
if (!match_filename( &str, mask )) return NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
if (get_file_info( long_name, &st, &attributes ) == -1) return NULL;
|
2008-10-28 13:55:24 +01:00
|
|
|
if (is_ignored_file( &st ))
|
|
|
|
{
|
|
|
|
TRACE( "ignoring file %s\n", long_name );
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-11-18 17:23:55 +01:00
|
|
|
if (!show_dot_files && long_name[0] == '.' && long_name[1] && (long_name[1] != '.' || long_name[2]))
|
|
|
|
attributes |= FILE_ATTRIBUTE_HIDDEN;
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2009-11-18 17:54:06 +01:00
|
|
|
total_len = dir_info_size( class, long_len );
|
2009-11-18 17:37:15 +01:00
|
|
|
if (io->Information + total_len > max_length)
|
|
|
|
{
|
|
|
|
total_len = max_length - io->Information;
|
|
|
|
io->u.Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2009-11-18 17:42:51 +01:00
|
|
|
info = (union file_directory_info *)((char *)info_ptr + io->Information);
|
2009-12-02 17:33:28 +01:00
|
|
|
if (st.st_dev != curdir.dev) st.st_ino = 0; /* ignore inode if on a different device */
|
2009-11-18 18:07:30 +01:00
|
|
|
/* all the structures start with a FileDirectoryInformation layout */
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( &st, attributes, info, class );
|
2009-11-18 18:07:30 +01:00
|
|
|
info->dir.NextEntryOffset = total_len;
|
|
|
|
info->dir.FileIndex = 0; /* NTFS always has 0 here, so let's not bother with it */
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2009-11-18 17:47:37 +01:00
|
|
|
switch (class)
|
|
|
|
{
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileDirectoryInformation:
|
|
|
|
info->dir.FileNameLength = long_len * sizeof(WCHAR);
|
|
|
|
filename = info->dir.FileName;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFullDirectoryInformation:
|
|
|
|
info->full.EaSize = 0; /* FIXME */
|
|
|
|
info->full.FileNameLength = long_len * sizeof(WCHAR);
|
|
|
|
filename = info->full.FileName;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileIdFullDirectoryInformation:
|
|
|
|
info->id_full.EaSize = 0; /* FIXME */
|
|
|
|
info->id_full.FileNameLength = long_len * sizeof(WCHAR);
|
|
|
|
filename = info->id_full.FileName;
|
|
|
|
break;
|
|
|
|
|
2009-11-18 17:47:37 +01:00
|
|
|
case FileBothDirectoryInformation:
|
|
|
|
info->both.EaSize = 0; /* FIXME */
|
|
|
|
info->both.ShortNameLength = short_len * sizeof(WCHAR);
|
|
|
|
for (i = 0; i < short_len; i++) info->both.ShortName[i] = toupperW(short_nameW[i]);
|
|
|
|
info->both.FileNameLength = long_len * sizeof(WCHAR);
|
2009-11-18 18:07:30 +01:00
|
|
|
filename = info->both.FileName;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileIdBothDirectoryInformation:
|
|
|
|
info->id_both.EaSize = 0; /* FIXME */
|
|
|
|
info->id_both.ShortNameLength = short_len * sizeof(WCHAR);
|
|
|
|
for (i = 0; i < short_len; i++) info->id_both.ShortName[i] = toupperW(short_nameW[i]);
|
|
|
|
info->id_both.FileNameLength = long_len * sizeof(WCHAR);
|
|
|
|
filename = info->id_both.FileName;
|
2009-11-18 17:47:37 +01:00
|
|
|
break;
|
2009-11-18 18:07:30 +01:00
|
|
|
|
2009-11-18 17:47:37 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
2010-03-06 22:39:37 +01:00
|
|
|
return NULL;
|
2009-11-18 17:47:37 +01:00
|
|
|
}
|
2014-05-15 14:25:04 +02:00
|
|
|
memcpy( filename, long_nameW, long_len * sizeof(WCHAR) );
|
2009-11-18 17:37:15 +01:00
|
|
|
io->Information += total_len;
|
2004-03-16 02:32:02 +01:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-14 20:24:07 +02:00
|
|
|
#ifdef VFAT_IOCTL_READDIR_BOTH
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* start_vfat_ioctl
|
|
|
|
*
|
|
|
|
* Wrapper for the VFAT ioctl to work around various kernel bugs.
|
|
|
|
* dir_section must be held by caller.
|
|
|
|
*/
|
|
|
|
static KERNEL_DIRENT *start_vfat_ioctl( int fd )
|
|
|
|
{
|
|
|
|
static KERNEL_DIRENT *de;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (!de)
|
|
|
|
{
|
|
|
|
SIZE_T size = 2 * sizeof(*de) + page_size;
|
|
|
|
void *addr = NULL;
|
|
|
|
|
|
|
|
if (NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 1, &size, MEM_RESERVE, PAGE_READWRITE ))
|
|
|
|
return NULL;
|
|
|
|
/* commit only the size needed for the dir entries */
|
|
|
|
/* this leaves an extra unaccessible page, which should make the kernel */
|
|
|
|
/* fail with -EFAULT before it stomps all over our memory */
|
|
|
|
de = addr;
|
|
|
|
size = 2 * sizeof(*de);
|
|
|
|
NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 1, &size, MEM_COMMIT, PAGE_READWRITE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set d_reclen to 65535 to work around an AFS kernel bug */
|
|
|
|
de[0].d_reclen = 65535;
|
|
|
|
res = ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de );
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
if (errno != ENOENT) return NULL; /* VFAT ioctl probably not supported */
|
|
|
|
de[0].d_reclen = 0; /* eof */
|
|
|
|
}
|
|
|
|
else if (!res && de[0].d_reclen == 65535) return NULL; /* AFS bug */
|
|
|
|
|
|
|
|
return de;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-06 17:48:16 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* read_directory_vfat
|
|
|
|
*
|
|
|
|
* Read a directory using the VFAT ioctl; helper for NtQueryDirectoryFile.
|
|
|
|
*/
|
|
|
|
static int read_directory_vfat( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, const UNICODE_STRING *mask,
|
2009-11-18 17:47:37 +01:00
|
|
|
BOOLEAN restart_scan, FILE_INFORMATION_CLASS class )
|
2004-12-06 17:48:16 +01:00
|
|
|
|
|
|
|
{
|
2006-10-14 20:24:07 +02:00
|
|
|
size_t len;
|
|
|
|
KERNEL_DIRENT *de;
|
2009-11-18 17:42:51 +01:00
|
|
|
union file_directory_info *info, *last_info = NULL;
|
2004-12-06 17:48:16 +01:00
|
|
|
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if (restart_scan) lseek( fd, 0, SEEK_SET );
|
|
|
|
|
2009-11-18 17:54:06 +01:00
|
|
|
if (length < max_dir_info_size(class)) /* we may have to return a partial entry here */
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
off_t old_pos = lseek( fd, 0, SEEK_CUR );
|
|
|
|
|
2006-10-14 20:24:07 +02:00
|
|
|
if (!(de = start_vfat_ioctl( fd ))) return -1; /* not supported */
|
2004-12-06 17:48:16 +01:00
|
|
|
|
2006-10-14 20:24:07 +02:00
|
|
|
while (de[0].d_reclen)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2006-07-19 20:04:45 +02:00
|
|
|
/* make sure names are null-terminated to work around an x86-64 kernel bug */
|
2006-10-14 20:24:07 +02:00
|
|
|
len = min(de[0].d_reclen, sizeof(de[0].d_name) - 1 );
|
|
|
|
de[0].d_name[len] = 0;
|
|
|
|
len = min(de[1].d_reclen, sizeof(de[1].d_name) - 1 );
|
|
|
|
de[1].d_name[len] = 0;
|
|
|
|
|
2004-12-06 17:48:16 +01:00
|
|
|
if (de[1].d_name[0])
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, de[1].d_name, de[0].d_name, mask, class );
|
2004-12-06 17:48:16 +01:00
|
|
|
else
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, de[0].d_name, NULL, mask, class );
|
2004-12-06 17:48:16 +01:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
last_info = info;
|
2009-11-18 17:37:15 +01:00
|
|
|
if (io->u.Status == STATUS_BUFFER_OVERFLOW)
|
2004-12-06 17:48:16 +01:00
|
|
|
lseek( fd, old_pos, SEEK_SET ); /* restore pos to previous entry */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
old_pos = lseek( fd, 0, SEEK_CUR );
|
2006-10-14 20:24:07 +02:00
|
|
|
if (ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de ) == -1) break;
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* we'll only return full entries, no need to worry about overflow */
|
|
|
|
{
|
2006-10-14 20:24:07 +02:00
|
|
|
if (!(de = start_vfat_ioctl( fd ))) return -1; /* not supported */
|
2004-12-06 17:48:16 +01:00
|
|
|
|
2006-10-14 20:24:07 +02:00
|
|
|
while (de[0].d_reclen)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2006-07-19 20:04:45 +02:00
|
|
|
/* make sure names are null-terminated to work around an x86-64 kernel bug */
|
2006-10-14 20:24:07 +02:00
|
|
|
len = min(de[0].d_reclen, sizeof(de[0].d_name) - 1 );
|
|
|
|
de[0].d_name[len] = 0;
|
|
|
|
len = min(de[1].d_reclen, sizeof(de[1].d_name) - 1 );
|
|
|
|
de[1].d_name[len] = 0;
|
|
|
|
|
2004-12-06 17:48:16 +01:00
|
|
|
if (de[1].d_name[0])
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, de[1].d_name, de[0].d_name, mask, class );
|
2004-12-06 17:48:16 +01:00
|
|
|
else
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, de[0].d_name, NULL, mask, class );
|
2004-12-06 17:48:16 +01:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
last_info = info;
|
|
|
|
if (single_entry) break;
|
|
|
|
/* check if we still have enough space for the largest possible entry */
|
2009-11-18 17:54:06 +01:00
|
|
|
if (io->Information + max_dir_info_size(class) > length) break;
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
2006-10-14 20:24:07 +02:00
|
|
|
if (ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)de ) == -1) break;
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:42:51 +01:00
|
|
|
if (last_info) last_info->next = 0;
|
2004-12-06 17:48:16 +01:00
|
|
|
else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* VFAT_IOCTL_READDIR_BOTH */
|
|
|
|
|
|
|
|
|
2011-08-04 22:24:49 +02:00
|
|
|
#ifdef USE_GETDENTS
|
|
|
|
/***********************************************************************
|
|
|
|
* read_first_dent_name
|
|
|
|
*
|
|
|
|
* reads name of first or second dentry (if they have inodes).
|
|
|
|
*/
|
|
|
|
static char *read_first_dent_name( int which, int fd, off_t second_offs, KERNEL_DIRENT64 *de_first_two,
|
|
|
|
char *buffer, size_t size, BOOL *buffer_changed )
|
|
|
|
{
|
|
|
|
KERNEL_DIRENT64 *de;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
de = de_first_two;
|
|
|
|
if (de != NULL)
|
|
|
|
{
|
|
|
|
if (which == 1)
|
|
|
|
de = (KERNEL_DIRENT64 *)((char *)de + de->d_reclen);
|
|
|
|
|
|
|
|
return de->d_ino ? de->d_name : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*buffer_changed = TRUE;
|
|
|
|
lseek( fd, which == 1 ? second_offs : 0, SEEK_SET );
|
|
|
|
res = getdents64( fd, buffer, size );
|
|
|
|
if (res <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
de = (KERNEL_DIRENT64 *)buffer;
|
|
|
|
return de->d_ino ? de->d_name : NULL;
|
|
|
|
}
|
|
|
|
|
2004-12-06 17:48:16 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* read_directory_getdents
|
|
|
|
*
|
|
|
|
* Read a directory using the Linux getdents64 system call; helper for NtQueryDirectoryFile.
|
|
|
|
*/
|
|
|
|
static int read_directory_getdents( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, const UNICODE_STRING *mask,
|
2009-11-18 17:47:37 +01:00
|
|
|
BOOLEAN restart_scan, FILE_INFORMATION_CLASS class )
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2011-08-04 22:24:49 +02:00
|
|
|
static off_t second_entry_pos;
|
|
|
|
static struct file_identity last_dir_id;
|
|
|
|
off_t old_pos = 0, next_pos;
|
2004-12-06 17:48:16 +01:00
|
|
|
size_t size = length;
|
2006-12-01 13:11:38 +01:00
|
|
|
char *data, local_buffer[8192];
|
2011-08-04 22:24:49 +02:00
|
|
|
KERNEL_DIRENT64 *de, *de_first_two = NULL;
|
2009-11-18 17:42:51 +01:00
|
|
|
union file_directory_info *info, *last_info = NULL;
|
2011-08-04 22:24:49 +02:00
|
|
|
const char *filename;
|
|
|
|
BOOL data_buffer_changed;
|
|
|
|
int res, swap_to;
|
2004-12-06 17:48:16 +01:00
|
|
|
|
|
|
|
if (size <= sizeof(local_buffer) || !(data = RtlAllocateHeap( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
size = sizeof(local_buffer);
|
2006-12-01 13:11:38 +01:00
|
|
|
data = local_buffer;
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (restart_scan) lseek( fd, 0, SEEK_SET );
|
2011-08-04 22:24:49 +02:00
|
|
|
else
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
old_pos = lseek( fd, 0, SEEK_CUR );
|
2011-08-30 16:41:29 +02:00
|
|
|
if (old_pos == -1)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2011-08-30 16:41:29 +02:00
|
|
|
io->u.Status = (errno == ENOENT) ? STATUS_NO_MORE_FILES : FILE_GetNtStatus();
|
2004-12-06 17:48:16 +01:00
|
|
|
res = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
2011-08-04 22:24:49 +02:00
|
|
|
de = (KERNEL_DIRENT64 *)data;
|
|
|
|
|
|
|
|
/* if old_pos is not 0 we don't know how many entries have been returned already,
|
|
|
|
* so maintain second_entry_pos to know when to return '..' */
|
|
|
|
if (old_pos != 0 && (last_dir_id.dev != curdir.dev || last_dir_id.ino != curdir.ino))
|
|
|
|
{
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
res = getdents64( fd, data, size );
|
|
|
|
if (res > 0)
|
|
|
|
{
|
|
|
|
second_entry_pos = de->d_off;
|
|
|
|
last_dir_id = curdir;
|
|
|
|
}
|
|
|
|
lseek( fd, old_pos, SEEK_SET );
|
|
|
|
}
|
2004-12-06 17:48:16 +01:00
|
|
|
|
|
|
|
res = getdents64( fd, data, size );
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
if (errno != ENOSYS)
|
|
|
|
{
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-08-04 22:24:49 +02:00
|
|
|
if (old_pos == 0 && res > 0)
|
2006-12-01 13:11:38 +01:00
|
|
|
{
|
2011-08-04 22:24:49 +02:00
|
|
|
second_entry_pos = de->d_off;
|
|
|
|
last_dir_id = curdir;
|
|
|
|
if (res > de->d_reclen)
|
|
|
|
de_first_two = de;
|
|
|
|
}
|
2006-12-01 13:11:38 +01:00
|
|
|
|
2011-08-04 22:24:49 +02:00
|
|
|
while (res > 0)
|
|
|
|
{
|
|
|
|
res -= de->d_reclen;
|
|
|
|
next_pos = de->d_off;
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
/* we must return first 2 entries as "." and "..", but getdents64()
|
|
|
|
* can return them anywhere, so swap first entries with "." and ".." */
|
|
|
|
if (old_pos == 0)
|
|
|
|
filename = ".";
|
|
|
|
else if (old_pos == second_entry_pos)
|
|
|
|
filename = "..";
|
|
|
|
else if (!strcmp( de->d_name, "." ) || !strcmp( de->d_name, ".." ))
|
2006-12-01 13:11:38 +01:00
|
|
|
{
|
2011-08-04 22:24:49 +02:00
|
|
|
swap_to = !strcmp( de->d_name, "." ) ? 0 : 1;
|
|
|
|
data_buffer_changed = FALSE;
|
|
|
|
|
|
|
|
filename = read_first_dent_name( swap_to, fd, second_entry_pos, de_first_two,
|
|
|
|
data, size, &data_buffer_changed );
|
|
|
|
if (filename != NULL && (!strcmp( filename, "." ) || !strcmp( filename, ".." )))
|
|
|
|
filename = read_first_dent_name( swap_to ^ 1, fd, second_entry_pos, NULL,
|
|
|
|
data, size, &data_buffer_changed );
|
|
|
|
if (data_buffer_changed)
|
2006-12-01 13:11:38 +01:00
|
|
|
{
|
2011-08-04 22:24:49 +02:00
|
|
|
lseek( fd, next_pos, SEEK_SET );
|
2006-12-01 13:11:38 +01:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 22:24:49 +02:00
|
|
|
else if (de->d_ino)
|
|
|
|
filename = de->d_name;
|
2004-12-06 17:48:16 +01:00
|
|
|
|
2011-08-04 22:24:49 +02:00
|
|
|
if (filename && (info = append_entry( buffer, io, length, filename, NULL, mask, class )))
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
last_info = info;
|
2009-11-18 17:37:15 +01:00
|
|
|
if (io->u.Status == STATUS_BUFFER_OVERFLOW)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
lseek( fd, old_pos, SEEK_SET ); /* restore pos to previous entry */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* check if we still have enough space for the largest possible entry */
|
2009-11-18 17:54:06 +01:00
|
|
|
if (single_entry || io->Information + max_dir_info_size(class) > length)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2011-08-04 22:24:49 +02:00
|
|
|
if (res > 0) lseek( fd, next_pos, SEEK_SET ); /* set pos to next entry */
|
2004-12-06 17:48:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 22:24:49 +02:00
|
|
|
old_pos = next_pos;
|
2004-12-06 17:48:16 +01:00
|
|
|
/* move on to the next entry */
|
2004-12-09 17:54:20 +01:00
|
|
|
if (res > 0) de = (KERNEL_DIRENT64 *)((char *)de + de->d_reclen);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = getdents64( fd, data, size );
|
2006-12-01 13:11:38 +01:00
|
|
|
de = (KERNEL_DIRENT64 *)data;
|
2011-08-04 22:24:49 +02:00
|
|
|
de_first_two = NULL;
|
2004-12-09 17:54:20 +01:00
|
|
|
}
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
|
|
|
|
2009-11-18 17:42:51 +01:00
|
|
|
if (last_info) last_info->next = 0;
|
2004-12-06 17:48:16 +01:00
|
|
|
else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
|
|
|
|
res = 0;
|
|
|
|
done:
|
2006-12-01 13:11:38 +01:00
|
|
|
if (data != local_buffer) RtlFreeHeap( GetProcessHeap(), 0, data );
|
2004-12-06 17:48:16 +01:00
|
|
|
return res;
|
|
|
|
}
|
2006-11-13 15:42:48 +01:00
|
|
|
|
|
|
|
#elif defined HAVE_GETDIRENTRIES
|
|
|
|
|
2009-12-25 11:08:53 +01:00
|
|
|
#ifdef _DARWIN_FEATURE_64_BIT_INODE
|
2009-07-31 23:25:48 +02:00
|
|
|
|
|
|
|
/* Darwin doesn't provide a version of getdirentries with support for 64-bit
|
|
|
|
* inodes. When 64-bit inodes are enabled, the getdirentries symbol is mapped
|
|
|
|
* to _getdirentries_is_not_available_when_64_bit_inodes_are_in_effect so that
|
|
|
|
* we get link errors if we try to use it. We still need getdirentries, but we
|
|
|
|
* don't need it to support 64-bit inodes. So, we use the legacy getdirentries
|
|
|
|
* with 32-bit inodes. We have to be careful to use a corresponding dirent
|
|
|
|
* structure, too.
|
|
|
|
*/
|
|
|
|
int darwin_legacy_getdirentries(int, char *, int, long *) __asm("_getdirentries");
|
|
|
|
#define getdirentries darwin_legacy_getdirentries
|
|
|
|
|
|
|
|
struct darwin_legacy_dirent {
|
|
|
|
__uint32_t d_ino;
|
|
|
|
__uint16_t d_reclen;
|
|
|
|
__uint8_t d_type;
|
|
|
|
__uint8_t d_namlen;
|
|
|
|
char d_name[__DARWIN_MAXNAMLEN + 1];
|
|
|
|
};
|
|
|
|
#define dirent darwin_legacy_dirent
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-10-05 17:48:55 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wine_getdirentries
|
|
|
|
*
|
|
|
|
* Wrapper for the BSD getdirentries system call to fix a bug in the
|
|
|
|
* Mac OS X version. For some file systems (at least Apple Filing
|
|
|
|
* Protocol a.k.a. AFP), getdirentries resets the file position to 0
|
|
|
|
* when it's about to return 0 (no more entries). So, a subsequent
|
|
|
|
* getdirentries call starts over at the beginning again, causing an
|
|
|
|
* infinite loop.
|
|
|
|
*/
|
|
|
|
static inline int wine_getdirentries(int fd, char *buf, int nbytes, long *basep)
|
|
|
|
{
|
|
|
|
int res = getdirentries(fd, buf, nbytes, basep);
|
|
|
|
#ifdef __APPLE__
|
|
|
|
if (res == 0)
|
|
|
|
lseek(fd, *basep, SEEK_SET);
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:05:30 +02:00
|
|
|
static inline int dir_reclen(struct dirent *de)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_STRUCT_DIRENT_D_RECLEN
|
|
|
|
return de->d_reclen;
|
|
|
|
#else
|
|
|
|
return _DIRENT_RECLEN(de->d_namlen);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-11-13 15:42:48 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* read_directory_getdirentries
|
|
|
|
*
|
|
|
|
* Read a directory using the BSD getdirentries system call; helper for NtQueryDirectoryFile.
|
|
|
|
*/
|
|
|
|
static int read_directory_getdirentries( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, const UNICODE_STRING *mask,
|
2009-11-18 17:47:37 +01:00
|
|
|
BOOLEAN restart_scan, FILE_INFORMATION_CLASS class )
|
2006-11-13 15:42:48 +01:00
|
|
|
{
|
|
|
|
long restart_pos;
|
|
|
|
ULONG_PTR restart_info_pos = 0;
|
|
|
|
size_t size, initial_size = length;
|
2006-12-01 13:11:38 +01:00
|
|
|
int res, fake_dot_dot = 1;
|
2006-11-13 15:42:48 +01:00
|
|
|
char *data, local_buffer[8192];
|
|
|
|
struct dirent *de;
|
2009-11-18 17:42:51 +01:00
|
|
|
union file_directory_info *info, *last_info = NULL, *restart_last_info = NULL;
|
2006-11-13 15:42:48 +01:00
|
|
|
|
|
|
|
size = initial_size;
|
|
|
|
data = local_buffer;
|
|
|
|
if (size > sizeof(local_buffer) && !(data = RtlAllocateHeap( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_NO_MEMORY;
|
|
|
|
return io->u.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restart_scan) lseek( fd, 0, SEEK_SET );
|
|
|
|
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* FIXME: should make sure size is larger than filesystem block size */
|
2007-10-05 17:48:55 +02:00
|
|
|
res = wine_getdirentries( fd, data, size, &restart_pos );
|
2006-11-13 15:42:48 +01:00
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
res = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
de = (struct dirent *)data;
|
|
|
|
|
2006-12-01 13:11:38 +01:00
|
|
|
if (restart_scan)
|
|
|
|
{
|
|
|
|
/* check if we got . and .. from getdirentries */
|
|
|
|
if (res > 0)
|
|
|
|
{
|
2012-06-02 19:05:30 +02:00
|
|
|
if (!strcmp( de->d_name, "." ) && res > dir_reclen(de))
|
2006-12-01 13:11:38 +01:00
|
|
|
{
|
2012-06-02 19:05:30 +02:00
|
|
|
struct dirent *next_de = (struct dirent *)(data + dir_reclen(de));
|
2006-12-01 13:11:38 +01:00
|
|
|
if (!strcmp( next_de->d_name, ".." )) fake_dot_dot = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* make sure we have enough room for both entries */
|
|
|
|
if (fake_dot_dot)
|
|
|
|
{
|
2009-11-18 17:54:06 +01:00
|
|
|
const ULONG min_info_size = dir_info_size( class, 1 ) + dir_info_size( class, 2 );
|
2006-12-01 13:11:38 +01:00
|
|
|
if (length < min_info_size || single_entry)
|
|
|
|
{
|
|
|
|
FIXME( "not enough room %u/%u for fake . and .. entries\n", length, single_entry );
|
|
|
|
fake_dot_dot = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fake_dot_dot)
|
|
|
|
{
|
2009-11-18 17:47:37 +01:00
|
|
|
if ((info = append_entry( buffer, io, length, ".", NULL, mask, class )))
|
2006-12-01 13:11:38 +01:00
|
|
|
last_info = info;
|
2009-11-18 17:47:37 +01:00
|
|
|
if ((info = append_entry( buffer, io, length, "..", NULL, mask, class )))
|
2006-12-01 13:11:38 +01:00
|
|
|
last_info = info;
|
|
|
|
|
|
|
|
restart_last_info = last_info;
|
|
|
|
restart_info_pos = io->Information;
|
|
|
|
|
|
|
|
/* check if we still have enough space for the largest possible entry */
|
2009-11-18 17:54:06 +01:00
|
|
|
if (last_info && io->Information + max_dir_info_size(class) > length)
|
2006-12-01 13:11:38 +01:00
|
|
|
{
|
|
|
|
lseek( fd, 0, SEEK_SET ); /* reset pos to first entry */
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-13 15:42:48 +01:00
|
|
|
while (res > 0)
|
|
|
|
{
|
2012-06-02 19:05:30 +02:00
|
|
|
res -= dir_reclen(de);
|
2006-11-13 15:42:48 +01:00
|
|
|
if (de->d_fileno &&
|
2006-12-01 13:11:38 +01:00
|
|
|
!(fake_dot_dot && (!strcmp( de->d_name, "." ) || !strcmp( de->d_name, ".." ))) &&
|
2009-11-18 17:47:37 +01:00
|
|
|
((info = append_entry( buffer, io, length, de->d_name, NULL, mask, class ))))
|
2006-11-13 15:42:48 +01:00
|
|
|
{
|
|
|
|
last_info = info;
|
2009-11-18 17:37:15 +01:00
|
|
|
if (io->u.Status == STATUS_BUFFER_OVERFLOW)
|
2006-11-13 15:42:48 +01:00
|
|
|
{
|
|
|
|
lseek( fd, (unsigned long)restart_pos, SEEK_SET );
|
|
|
|
if (restart_info_pos) /* if we have a complete read already, return it */
|
|
|
|
{
|
2009-11-18 17:37:15 +01:00
|
|
|
io->u.Status = STATUS_SUCCESS;
|
2006-11-13 15:42:48 +01:00
|
|
|
io->Information = restart_info_pos;
|
|
|
|
last_info = restart_last_info;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* otherwise restart from the start with a smaller size */
|
|
|
|
size = (char *)de - data;
|
2009-11-18 17:37:15 +01:00
|
|
|
if (!size) break;
|
2006-11-13 15:42:48 +01:00
|
|
|
io->Information = 0;
|
|
|
|
last_info = NULL;
|
|
|
|
goto restart;
|
|
|
|
}
|
2013-07-01 19:49:46 +02:00
|
|
|
if (!has_wildcard( mask )) break;
|
2006-11-13 15:42:48 +01:00
|
|
|
/* if we have to return but the buffer contains more data, restart with a smaller size */
|
2009-11-18 17:54:06 +01:00
|
|
|
if (res > 0 && (single_entry || io->Information + max_dir_info_size(class) > length))
|
2006-11-13 15:42:48 +01:00
|
|
|
{
|
|
|
|
lseek( fd, (unsigned long)restart_pos, SEEK_SET );
|
2012-06-02 19:05:30 +02:00
|
|
|
size = (char *)de + dir_reclen(de) - data;
|
2006-11-13 15:42:48 +01:00
|
|
|
io->Information = restart_info_pos;
|
|
|
|
last_info = restart_last_info;
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* move on to the next entry */
|
|
|
|
if (res > 0)
|
|
|
|
{
|
2012-06-02 19:05:30 +02:00
|
|
|
de = (struct dirent *)((char *)de + dir_reclen(de));
|
2006-11-13 15:42:48 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (size < initial_size) break; /* already restarted once, give up now */
|
|
|
|
restart_last_info = last_info;
|
|
|
|
restart_info_pos = io->Information;
|
|
|
|
restart:
|
2007-10-05 17:48:55 +02:00
|
|
|
res = wine_getdirentries( fd, data, size, &restart_pos );
|
2006-11-13 15:42:48 +01:00
|
|
|
de = (struct dirent *)data;
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:42:51 +01:00
|
|
|
if (last_info) last_info->next = 0;
|
2006-11-13 15:42:48 +01:00
|
|
|
else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
|
|
|
|
res = 0;
|
|
|
|
done:
|
|
|
|
if (data != local_buffer) RtlFreeHeap( GetProcessHeap(), 0, data );
|
|
|
|
return res;
|
|
|
|
}
|
2009-07-31 23:25:48 +02:00
|
|
|
|
2009-12-25 11:08:53 +01:00
|
|
|
#ifdef _DARWIN_FEATURE_64_BIT_INODE
|
2009-07-31 23:25:48 +02:00
|
|
|
#undef getdirentries
|
|
|
|
#undef dirent
|
|
|
|
#endif
|
|
|
|
|
2006-11-13 15:42:48 +01:00
|
|
|
#endif /* HAVE_GETDIRENTRIES */
|
2004-12-06 17:48:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* read_directory_readdir
|
|
|
|
*
|
|
|
|
* Read a directory using the POSIX readdir interface; helper for NtQueryDirectoryFile.
|
|
|
|
*/
|
|
|
|
static void read_directory_readdir( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, const UNICODE_STRING *mask,
|
2009-11-18 17:47:37 +01:00
|
|
|
BOOLEAN restart_scan, FILE_INFORMATION_CLASS class )
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
off_t i, old_pos = 0;
|
|
|
|
struct dirent *de;
|
2009-11-18 17:42:51 +01:00
|
|
|
union file_directory_info *info, *last_info = NULL;
|
2004-12-06 17:48:16 +01:00
|
|
|
|
|
|
|
if (!(dir = opendir( "." )))
|
|
|
|
{
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!restart_scan)
|
|
|
|
{
|
|
|
|
old_pos = lseek( fd, 0, SEEK_CUR );
|
|
|
|
/* skip the right number of entries */
|
2006-12-01 13:11:38 +01:00
|
|
|
for (i = 0; i < old_pos - 2; i++)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
if (!readdir( dir ))
|
|
|
|
{
|
|
|
|
closedir( dir );
|
|
|
|
io->u.Status = STATUS_NO_MORE_FILES;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
|
|
|
|
2006-12-01 13:11:38 +01:00
|
|
|
for (;;)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
2006-12-01 13:11:38 +01:00
|
|
|
if (old_pos == 0)
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, ".", NULL, mask, class );
|
2006-12-01 13:11:38 +01:00
|
|
|
else if (old_pos == 1)
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, "..", NULL, mask, class );
|
2006-12-01 13:11:38 +01:00
|
|
|
else if ((de = readdir( dir )))
|
|
|
|
{
|
|
|
|
if (strcmp( de->d_name, "." ) && strcmp( de->d_name, ".." ))
|
2009-11-18 17:47:37 +01:00
|
|
|
info = append_entry( buffer, io, length, de->d_name, NULL, mask, class );
|
2006-12-01 13:11:38 +01:00
|
|
|
else
|
|
|
|
info = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
2004-12-06 17:48:16 +01:00
|
|
|
old_pos++;
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
last_info = info;
|
2009-11-18 17:37:15 +01:00
|
|
|
if (io->u.Status == STATUS_BUFFER_OVERFLOW)
|
2004-12-06 17:48:16 +01:00
|
|
|
{
|
|
|
|
old_pos--; /* restore pos to previous entry */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (single_entry) break;
|
|
|
|
/* check if we still have enough space for the largest possible entry */
|
2009-11-18 17:54:06 +01:00
|
|
|
if (io->Information + max_dir_info_size(class) > length) break;
|
2004-12-06 17:48:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lseek( fd, old_pos, SEEK_SET ); /* store dir offset as filepos for fd */
|
|
|
|
closedir( dir );
|
|
|
|
|
2009-11-18 17:42:51 +01:00
|
|
|
if (last_info) last_info->next = 0;
|
2004-12-06 17:48:16 +01:00
|
|
|
else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
|
|
|
|
}
|
|
|
|
|
2006-08-03 21:25:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* read_directory_stat
|
|
|
|
*
|
|
|
|
* Read a single file from a directory by determining whether the file
|
|
|
|
* identified by mask exists using stat.
|
|
|
|
*/
|
|
|
|
static int read_directory_stat( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, const UNICODE_STRING *mask,
|
2009-11-18 17:47:37 +01:00
|
|
|
BOOLEAN restart_scan, FILE_INFORMATION_CLASS class )
|
2006-08-03 21:25:28 +02:00
|
|
|
{
|
|
|
|
int unix_len, ret, used_default;
|
|
|
|
char *unix_name;
|
|
|
|
struct stat st;
|
2015-05-19 23:32:34 +02:00
|
|
|
BOOL case_sensitive = get_dir_case_sensitivity(".");
|
2006-08-03 21:25:28 +02:00
|
|
|
|
2015-05-19 23:32:34 +02:00
|
|
|
TRACE("looking up file %s\n", debugstr_us( mask ));
|
2006-08-03 21:25:28 +02:00
|
|
|
|
|
|
|
unix_len = ntdll_wcstoumbs( 0, mask->Buffer, mask->Length / sizeof(WCHAR), NULL, 0, NULL, NULL );
|
2006-08-07 13:53:31 +02:00
|
|
|
if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len + 1)))
|
2006-08-03 21:25:28 +02:00
|
|
|
{
|
|
|
|
io->u.Status = STATUS_NO_MEMORY;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = ntdll_wcstoumbs( 0, mask->Buffer, mask->Length / sizeof(WCHAR), unix_name, unix_len,
|
|
|
|
NULL, &used_default );
|
|
|
|
if (ret > 0 && !used_default)
|
|
|
|
{
|
2006-08-07 13:53:31 +02:00
|
|
|
unix_name[ret] = 0;
|
2006-08-03 21:25:28 +02:00
|
|
|
if (restart_scan)
|
|
|
|
{
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
}
|
|
|
|
else if (lseek( fd, 0, SEEK_CUR ) != 0)
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_NO_MORE_FILES;
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = stat( unix_name, &st );
|
2015-05-19 23:32:34 +02:00
|
|
|
if (case_sensitive && !ret)
|
2006-08-03 21:25:28 +02:00
|
|
|
{
|
2009-11-18 17:47:37 +01:00
|
|
|
union file_directory_info *info = append_entry( buffer, io, length, unix_name, NULL, NULL, class );
|
2006-08-03 21:25:28 +02:00
|
|
|
if (info)
|
|
|
|
{
|
2009-11-18 17:42:51 +01:00
|
|
|
info->next = 0;
|
2009-11-18 17:37:15 +01:00
|
|
|
if (io->u.Status != STATUS_BUFFER_OVERFLOW) lseek( fd, 1, SEEK_CUR );
|
2006-08-03 21:25:28 +02:00
|
|
|
}
|
2015-06-11 23:04:14 +02:00
|
|
|
else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
|
2006-08-03 21:25:28 +02:00
|
|
|
}
|
2015-05-19 23:32:34 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
}
|
2006-08-03 21:25:28 +02:00
|
|
|
}
|
|
|
|
else ret = -1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-05-19 23:59:06 +02:00
|
|
|
#ifdef HAVE_GETATTRLIST
|
|
|
|
/***********************************************************************
|
|
|
|
* read_directory_getattrlist
|
|
|
|
*
|
|
|
|
* Read a single file from a directory by determining whether the file
|
|
|
|
* identified by mask exists using getattrlist.
|
|
|
|
*/
|
|
|
|
static int read_directory_getattrlist( int fd, IO_STATUS_BLOCK *io, void *buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, const UNICODE_STRING *mask,
|
|
|
|
BOOLEAN restart_scan, FILE_INFORMATION_CLASS class )
|
|
|
|
{
|
|
|
|
int unix_len, ret, used_default;
|
|
|
|
char *unix_name;
|
|
|
|
struct attrlist attrlist;
|
2015-05-20 21:59:39 +02:00
|
|
|
#include "pshpack4.h"
|
2015-05-19 23:59:06 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u_int32_t length;
|
|
|
|
struct attrreference name_reference;
|
2015-05-20 21:59:39 +02:00
|
|
|
fsobj_type_t type;
|
2015-05-20 21:58:52 +02:00
|
|
|
char name[NAME_MAX * 3 + 1];
|
2015-05-19 23:59:06 +02:00
|
|
|
} attrlist_buffer;
|
2015-05-20 21:59:39 +02:00
|
|
|
#include "poppack.h"
|
2015-05-19 23:59:06 +02:00
|
|
|
|
|
|
|
TRACE("looking up file %s\n", debugstr_us( mask ));
|
|
|
|
|
|
|
|
unix_len = ntdll_wcstoumbs( 0, mask->Buffer, mask->Length / sizeof(WCHAR), NULL, 0, NULL, NULL );
|
|
|
|
if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len + 1)))
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_NO_MEMORY;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = ntdll_wcstoumbs( 0, mask->Buffer, mask->Length / sizeof(WCHAR), unix_name, unix_len,
|
|
|
|
NULL, &used_default );
|
|
|
|
if (ret > 0 && !used_default)
|
|
|
|
{
|
|
|
|
unix_name[ret] = 0;
|
|
|
|
if (restart_scan)
|
|
|
|
{
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
}
|
|
|
|
else if (lseek( fd, 0, SEEK_CUR ) != 0)
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_NO_MORE_FILES;
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset( &attrlist, 0, sizeof(attrlist) );
|
|
|
|
attrlist.bitmapcount = ATTR_BIT_MAP_COUNT;
|
2015-06-11 23:04:04 +02:00
|
|
|
attrlist.commonattr = ATTR_CMN_NAME | ATTR_CMN_OBJTYPE;
|
2015-05-20 21:59:39 +02:00
|
|
|
ret = getattrlist( unix_name, &attrlist, &attrlist_buffer, sizeof(attrlist_buffer), FSOPT_NOFOLLOW );
|
|
|
|
/* If unix_name named a symlink, the above may have succeeded even if the symlink is broken.
|
|
|
|
Check that with another call without FSOPT_NOFOLLOW. We don't ask for any attributes. */
|
|
|
|
if (!ret && attrlist_buffer.type == VLNK)
|
|
|
|
{
|
|
|
|
u_int32_t dummy;
|
|
|
|
attrlist.commonattr = 0;
|
|
|
|
ret = getattrlist( unix_name, &attrlist, &dummy, sizeof(dummy), 0 );
|
|
|
|
}
|
2015-05-19 23:59:06 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
union file_directory_info *info = append_entry( buffer, io, length, attrlist_buffer.name, NULL, NULL, class );
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
info->next = 0;
|
|
|
|
if (io->u.Status != STATUS_BUFFER_OVERFLOW) lseek( fd, 1, SEEK_CUR );
|
|
|
|
}
|
2015-06-11 23:04:14 +02:00
|
|
|
else io->u.Status = restart_scan ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES;
|
2015-05-19 23:59:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else ret = -1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-08-03 21:25:28 +02:00
|
|
|
|
2004-03-16 02:32:02 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryDirectoryFile [NTDLL.@]
|
|
|
|
* ZwQueryDirectoryFile [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryDirectoryFile( HANDLE handle, HANDLE event,
|
|
|
|
PIO_APC_ROUTINE apc_routine, PVOID apc_context,
|
|
|
|
PIO_STATUS_BLOCK io,
|
|
|
|
PVOID buffer, ULONG length,
|
|
|
|
FILE_INFORMATION_CLASS info_class,
|
|
|
|
BOOLEAN single_entry,
|
|
|
|
PUNICODE_STRING mask,
|
|
|
|
BOOLEAN restart_scan )
|
|
|
|
{
|
2006-11-03 11:38:44 +01:00
|
|
|
int cwd, fd, needs_close;
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p %p %p %p %p %p 0x%08x 0x%08x 0x%08x %s 0x%08x\n",
|
2004-03-16 02:32:02 +01:00
|
|
|
handle, event, apc_routine, apc_context, io, buffer,
|
|
|
|
length, info_class, single_entry, debugstr_us(mask),
|
|
|
|
restart_scan);
|
|
|
|
|
|
|
|
if (event || apc_routine)
|
|
|
|
{
|
|
|
|
FIXME( "Unsupported yet option\n" );
|
|
|
|
return io->u.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-11-18 17:47:37 +01:00
|
|
|
switch (info_class)
|
2004-03-16 02:32:02 +01:00
|
|
|
{
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileDirectoryInformation:
|
2009-11-18 17:47:37 +01:00
|
|
|
case FileBothDirectoryInformation:
|
2009-11-18 18:07:30 +01:00
|
|
|
case FileFullDirectoryInformation:
|
|
|
|
case FileIdBothDirectoryInformation:
|
|
|
|
case FileIdFullDirectoryInformation:
|
2009-11-18 17:54:06 +01:00
|
|
|
if (length < dir_info_size( info_class, 1 )) return io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
|
2012-10-10 18:37:57 +02:00
|
|
|
if (!buffer) return io->u.Status = STATUS_ACCESS_VIOLATION;
|
2009-11-18 17:47:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2004-03-16 02:32:02 +01:00
|
|
|
FIXME( "Unsupported file info class %d\n", info_class );
|
|
|
|
return io->u.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2006-11-20 14:15:06 +01:00
|
|
|
if ((io->u.Status = server_get_unix_fd( handle, FILE_LIST_DIRECTORY, &fd, &needs_close, NULL, NULL )) != STATUS_SUCCESS)
|
2004-03-16 02:32:02 +01:00
|
|
|
return io->u.Status;
|
|
|
|
|
|
|
|
io->Information = 0;
|
|
|
|
|
2013-08-29 16:48:23 +02:00
|
|
|
RtlRunOnceExecuteOnce( &init_once, init_options, NULL, NULL );
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2013-08-29 16:48:23 +02:00
|
|
|
RtlEnterCriticalSection( &dir_section );
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2007-03-29 21:02:59 +02:00
|
|
|
cwd = open( ".", O_RDONLY );
|
|
|
|
if (fchdir( fd ) != -1)
|
2004-03-16 02:32:02 +01:00
|
|
|
{
|
2009-12-02 17:33:28 +01:00
|
|
|
struct stat st;
|
|
|
|
fstat( fd, &st );
|
|
|
|
curdir.dev = st.st_dev;
|
|
|
|
curdir.ino = st.st_ino;
|
2004-03-16 02:32:02 +01:00
|
|
|
#ifdef VFAT_IOCTL_READDIR_BOTH
|
2009-11-18 17:47:37 +01:00
|
|
|
if ((read_directory_vfat( fd, io, buffer, length, single_entry,
|
|
|
|
mask, restart_scan, info_class )) != -1) goto done;
|
2004-12-06 17:48:16 +01:00
|
|
|
#endif
|
2015-05-19 23:59:06 +02:00
|
|
|
if (!has_wildcard( mask ))
|
|
|
|
{
|
|
|
|
#ifdef HAVE_GETATTRLIST
|
|
|
|
if (read_directory_getattrlist( fd, io, buffer, length, single_entry,
|
2009-11-18 17:47:37 +01:00
|
|
|
mask, restart_scan, info_class ) != -1) goto done;
|
2015-05-19 23:59:06 +02:00
|
|
|
#endif
|
|
|
|
if (read_directory_stat( fd, io, buffer, length, single_entry,
|
|
|
|
mask, restart_scan, info_class ) != -1) goto done;
|
|
|
|
}
|
2004-12-06 17:48:16 +01:00
|
|
|
#ifdef USE_GETDENTS
|
2009-11-18 17:47:37 +01:00
|
|
|
if ((read_directory_getdents( fd, io, buffer, length, single_entry,
|
|
|
|
mask, restart_scan, info_class )) != -1) goto done;
|
2006-11-13 15:42:48 +01:00
|
|
|
#elif defined HAVE_GETDIRENTRIES
|
2009-11-18 17:47:37 +01:00
|
|
|
if ((read_directory_getdirentries( fd, io, buffer, length, single_entry,
|
|
|
|
mask, restart_scan, info_class )) != -1) goto done;
|
2004-12-06 17:48:16 +01:00
|
|
|
#endif
|
2009-11-18 17:47:37 +01:00
|
|
|
read_directory_readdir( fd, io, buffer, length, single_entry, mask, restart_scan, info_class );
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2006-08-03 21:25:28 +02:00
|
|
|
done:
|
2007-03-29 21:02:59 +02:00
|
|
|
if (cwd == -1 || fchdir( cwd ) == -1) chdir( "/" );
|
2004-03-16 02:32:02 +01:00
|
|
|
}
|
|
|
|
else io->u.Status = FILE_GetNtStatus();
|
|
|
|
|
2004-04-29 22:04:48 +02:00
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2004-03-16 02:32:02 +01:00
|
|
|
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( fd );
|
2004-03-16 02:32:02 +01:00
|
|
|
if (cwd != -1) close( cwd );
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "=> %x (%ld)\n", io->u.Status, io->Information );
|
2004-03-16 02:32:02 +01:00
|
|
|
return io->u.Status;
|
|
|
|
}
|
2004-04-13 01:31:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* find_file_in_dir
|
|
|
|
*
|
|
|
|
* Find a file in a directory the hard way, by doing a case-insensitive search.
|
|
|
|
* The file found is appended to unix_name at pos.
|
|
|
|
* There must be at least MAX_DIR_ENTRY_LEN+2 chars available at pos.
|
|
|
|
*/
|
|
|
|
static NTSTATUS find_file_in_dir( char *unix_name, int pos, const WCHAR *name, int length,
|
2013-12-09 10:34:53 +01:00
|
|
|
BOOLEAN check_case, BOOLEAN *is_win_dir )
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_DIR_ENTRY_LEN];
|
|
|
|
UNICODE_STRING str;
|
2013-12-09 10:34:53 +01:00
|
|
|
BOOLEAN spaces, is_name_8_dot_3;
|
2004-04-13 01:31:09 +02:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
struct stat st;
|
2013-12-09 10:34:53 +01:00
|
|
|
int ret, used_default;
|
2004-04-13 01:31:09 +02:00
|
|
|
|
|
|
|
/* try a shortcut for this directory */
|
|
|
|
|
|
|
|
unix_name[pos++] = '/';
|
|
|
|
ret = ntdll_wcstoumbs( 0, name, length, unix_name + pos, MAX_DIR_ENTRY_LEN,
|
|
|
|
NULL, &used_default );
|
|
|
|
/* if we used the default char, the Unix name won't round trip properly back to Unicode */
|
|
|
|
/* so it cannot match the file we are looking for */
|
|
|
|
if (ret >= 0 && !used_default)
|
|
|
|
{
|
|
|
|
unix_name[pos + ret] = 0;
|
2009-10-22 20:06:06 +02:00
|
|
|
if (!stat( unix_name, &st ))
|
|
|
|
{
|
|
|
|
if (is_win_dir) *is_win_dir = is_same_file( &windir, &st );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
if (check_case) goto not_found; /* we want an exact match */
|
|
|
|
|
|
|
|
if (pos > 1) unix_name[pos - 1] = 0;
|
|
|
|
else unix_name[1] = 0; /* keep the initial slash */
|
|
|
|
|
|
|
|
/* check if it fits in 8.3 so that we don't look for short names if we won't need them */
|
|
|
|
|
|
|
|
str.Buffer = (WCHAR *)name;
|
|
|
|
str.Length = length * sizeof(WCHAR);
|
|
|
|
str.MaximumLength = str.Length;
|
|
|
|
is_name_8_dot_3 = RtlIsNameLegalDOS8Dot3( &str, NULL, &spaces ) && !spaces;
|
2014-07-28 19:58:23 +02:00
|
|
|
#ifndef VFAT_IOCTL_READDIR_BOTH
|
|
|
|
is_name_8_dot_3 = is_name_8_dot_3 && length >= 8 && name[4] == '~';
|
|
|
|
#endif
|
2004-04-13 01:31:09 +02:00
|
|
|
|
2011-01-18 21:09:44 +01:00
|
|
|
if (!is_name_8_dot_3 && !get_dir_case_sensitivity( unix_name )) goto not_found;
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
/* now look for it through the directory */
|
|
|
|
|
|
|
|
#ifdef VFAT_IOCTL_READDIR_BOTH
|
|
|
|
if (is_name_8_dot_3)
|
|
|
|
{
|
|
|
|
int fd = open( unix_name, O_RDONLY | O_DIRECTORY );
|
|
|
|
if (fd != -1)
|
|
|
|
{
|
2011-10-20 01:53:19 +02:00
|
|
|
KERNEL_DIRENT *kde;
|
2004-04-13 01:31:09 +02:00
|
|
|
|
2006-10-14 20:24:07 +02:00
|
|
|
RtlEnterCriticalSection( &dir_section );
|
2011-10-20 01:53:19 +02:00
|
|
|
if ((kde = start_vfat_ioctl( fd )))
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
|
|
|
unix_name[pos - 1] = '/';
|
2011-10-20 01:53:19 +02:00
|
|
|
while (kde[0].d_reclen)
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2006-07-19 20:04:45 +02:00
|
|
|
/* make sure names are null-terminated to work around an x86-64 kernel bug */
|
2011-10-20 01:53:19 +02:00
|
|
|
size_t len = min(kde[0].d_reclen, sizeof(kde[0].d_name) - 1 );
|
|
|
|
kde[0].d_name[len] = 0;
|
|
|
|
len = min(kde[1].d_reclen, sizeof(kde[1].d_name) - 1 );
|
|
|
|
kde[1].d_name[len] = 0;
|
2004-04-13 01:31:09 +02:00
|
|
|
|
2011-10-20 01:53:19 +02:00
|
|
|
if (kde[1].d_name[0])
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2011-10-20 01:53:19 +02:00
|
|
|
ret = ntdll_umbstowcs( 0, kde[1].d_name, strlen(kde[1].d_name),
|
2004-04-13 01:31:09 +02:00
|
|
|
buffer, MAX_DIR_ENTRY_LEN );
|
|
|
|
if (ret == length && !memicmpW( buffer, name, length))
|
|
|
|
{
|
2011-10-20 01:53:19 +02:00
|
|
|
strcpy( unix_name + pos, kde[1].d_name );
|
2006-10-14 20:24:07 +02:00
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2004-04-13 01:31:09 +02:00
|
|
|
close( fd );
|
2009-10-22 20:06:06 +02:00
|
|
|
goto success;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-20 01:53:19 +02:00
|
|
|
ret = ntdll_umbstowcs( 0, kde[0].d_name, strlen(kde[0].d_name),
|
2004-04-13 01:31:09 +02:00
|
|
|
buffer, MAX_DIR_ENTRY_LEN );
|
|
|
|
if (ret == length && !memicmpW( buffer, name, length))
|
|
|
|
{
|
|
|
|
strcpy( unix_name + pos,
|
2011-10-20 01:53:19 +02:00
|
|
|
kde[1].d_name[0] ? kde[1].d_name : kde[0].d_name );
|
2006-10-14 20:24:07 +02:00
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2004-04-13 01:31:09 +02:00
|
|
|
close( fd );
|
2009-10-22 20:06:06 +02:00
|
|
|
goto success;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
2011-10-20 01:53:19 +02:00
|
|
|
if (ioctl( fd, VFAT_IOCTL_READDIR_BOTH, (long)kde ) == -1)
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2006-10-14 20:24:07 +02:00
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2004-04-13 01:31:09 +02:00
|
|
|
close( fd );
|
|
|
|
goto not_found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-10-14 20:24:07 +02:00
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2004-04-13 01:31:09 +02:00
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
/* fall through to normal handling */
|
|
|
|
}
|
|
|
|
#endif /* VFAT_IOCTL_READDIR_BOTH */
|
|
|
|
|
2004-04-17 01:32:40 +02:00
|
|
|
if (!(dir = opendir( unix_name )))
|
|
|
|
{
|
|
|
|
if (errno == ENOENT) return STATUS_OBJECT_PATH_NOT_FOUND;
|
|
|
|
else return FILE_GetNtStatus();
|
|
|
|
}
|
2004-04-13 01:31:09 +02:00
|
|
|
unix_name[pos - 1] = '/';
|
|
|
|
str.Buffer = buffer;
|
|
|
|
str.MaximumLength = sizeof(buffer);
|
|
|
|
while ((de = readdir( dir )))
|
|
|
|
{
|
|
|
|
ret = ntdll_umbstowcs( 0, de->d_name, strlen(de->d_name), buffer, MAX_DIR_ENTRY_LEN );
|
|
|
|
if (ret == length && !memicmpW( buffer, name, length ))
|
|
|
|
{
|
|
|
|
strcpy( unix_name + pos, de->d_name );
|
|
|
|
closedir( dir );
|
2009-10-22 20:06:06 +02:00
|
|
|
goto success;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_name_8_dot_3) continue;
|
|
|
|
|
|
|
|
str.Length = ret * sizeof(WCHAR);
|
|
|
|
if (!RtlIsNameLegalDOS8Dot3( &str, NULL, &spaces ) || spaces)
|
|
|
|
{
|
|
|
|
WCHAR short_nameW[12];
|
|
|
|
ret = hash_short_file_name( &str, short_nameW );
|
|
|
|
if (ret == length && !memicmpW( short_nameW, name, length ))
|
|
|
|
{
|
|
|
|
strcpy( unix_name + pos, de->d_name );
|
|
|
|
closedir( dir );
|
2009-10-22 20:06:06 +02:00
|
|
|
goto success;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir( dir );
|
|
|
|
|
|
|
|
not_found:
|
|
|
|
unix_name[pos - 1] = 0;
|
2004-04-22 00:26:44 +02:00
|
|
|
return STATUS_OBJECT_PATH_NOT_FOUND;
|
2009-10-22 20:06:06 +02:00
|
|
|
|
|
|
|
success:
|
|
|
|
if (is_win_dir && !stat( unix_name, &st )) *is_win_dir = is_same_file( &windir, &st );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN64
|
|
|
|
|
|
|
|
static const WCHAR catrootW[] = {'s','y','s','t','e','m','3','2','\\','c','a','t','r','o','o','t',0};
|
|
|
|
static const WCHAR catroot2W[] = {'s','y','s','t','e','m','3','2','\\','c','a','t','r','o','o','t','2',0};
|
|
|
|
static const WCHAR driversstoreW[] = {'s','y','s','t','e','m','3','2','\\','d','r','i','v','e','r','s','s','t','o','r','e',0};
|
|
|
|
static const WCHAR driversetcW[] = {'s','y','s','t','e','m','3','2','\\','d','r','i','v','e','r','s','\\','e','t','c',0};
|
|
|
|
static const WCHAR logfilesW[] = {'s','y','s','t','e','m','3','2','\\','l','o','g','f','i','l','e','s',0};
|
|
|
|
static const WCHAR spoolW[] = {'s','y','s','t','e','m','3','2','\\','s','p','o','o','l',0};
|
|
|
|
static const WCHAR system32W[] = {'s','y','s','t','e','m','3','2',0};
|
|
|
|
static const WCHAR syswow64W[] = {'s','y','s','w','o','w','6','4',0};
|
|
|
|
static const WCHAR sysnativeW[] = {'s','y','s','n','a','t','i','v','e',0};
|
|
|
|
static const WCHAR regeditW[] = {'r','e','g','e','d','i','t','.','e','x','e',0};
|
|
|
|
static const WCHAR wow_regeditW[] = {'s','y','s','w','o','w','6','4','\\','r','e','g','e','d','i','t','.','e','x','e',0};
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const WCHAR *source;
|
|
|
|
const WCHAR *dos_target;
|
|
|
|
const char *unix_target;
|
|
|
|
} redirects[] =
|
|
|
|
{
|
|
|
|
{ catrootW, NULL, NULL },
|
|
|
|
{ catroot2W, NULL, NULL },
|
|
|
|
{ driversstoreW, NULL, NULL },
|
|
|
|
{ driversetcW, NULL, NULL },
|
|
|
|
{ logfilesW, NULL, NULL },
|
|
|
|
{ spoolW, NULL, NULL },
|
|
|
|
{ system32W, syswow64W, NULL },
|
|
|
|
{ sysnativeW, system32W, NULL },
|
|
|
|
{ regeditW, wow_regeditW, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int nb_redirects;
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_redirect_target
|
|
|
|
*
|
|
|
|
* Find the target unix name for a redirected dir.
|
|
|
|
*/
|
|
|
|
static const char *get_redirect_target( const char *windows_dir, const WCHAR *name )
|
|
|
|
{
|
|
|
|
int used_default, len, pos, win_len = strlen( windows_dir );
|
|
|
|
char *unix_name, *unix_target = NULL;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, win_len + MAX_DIR_ENTRY_LEN + 2 )))
|
|
|
|
return NULL;
|
|
|
|
memcpy( unix_name, windows_dir, win_len );
|
|
|
|
pos = win_len;
|
|
|
|
|
|
|
|
while (*name)
|
|
|
|
{
|
|
|
|
const WCHAR *end, *next;
|
|
|
|
|
|
|
|
for (end = name; *end; end++) if (IS_SEPARATOR(*end)) break;
|
|
|
|
for (next = end; *next; next++) if (!IS_SEPARATOR(*next)) break;
|
|
|
|
|
|
|
|
status = find_file_in_dir( unix_name, pos, name, end - name, FALSE, NULL );
|
|
|
|
if (status == STATUS_OBJECT_PATH_NOT_FOUND && !*next) /* not finding last element is ok */
|
|
|
|
{
|
|
|
|
len = ntdll_wcstoumbs( 0, name, end - name, unix_name + pos + 1,
|
|
|
|
MAX_DIR_ENTRY_LEN - (pos - win_len), NULL, &used_default );
|
|
|
|
if (len > 0 && !used_default)
|
|
|
|
{
|
|
|
|
unix_name[pos] = '/';
|
|
|
|
pos += len + 1;
|
|
|
|
unix_name[pos] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (status) goto done;
|
|
|
|
pos += strlen( unix_name + pos );
|
|
|
|
name = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unix_target = RtlAllocateHeap( GetProcessHeap(), 0, pos - win_len )))
|
|
|
|
memcpy( unix_target, unix_name + win_len + 1, pos - win_len );
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
return unix_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* init_redirects
|
|
|
|
*/
|
|
|
|
static void init_redirects(void)
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
struct stat st;
|
|
|
|
unsigned int i;
|
|
|
|
|
2011-06-16 12:27:01 +02:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( user_shared_data->NtSystemRoot, &nt_name, NULL, NULL ))
|
2009-10-22 20:06:06 +02:00
|
|
|
{
|
2011-06-16 12:27:01 +02:00
|
|
|
ERR( "can't convert %s\n", debugstr_w(user_shared_data->NtSystemRoot) );
|
2009-10-22 20:06:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN_IF, FALSE );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
if (status)
|
|
|
|
{
|
2011-06-16 12:27:01 +02:00
|
|
|
ERR( "cannot open %s (%x)\n", debugstr_w(user_shared_data->NtSystemRoot), status );
|
2009-10-22 20:06:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!stat( unix_name.Buffer, &st ))
|
|
|
|
{
|
|
|
|
windir.dev = st.st_dev;
|
|
|
|
windir.ino = st.st_ino;
|
|
|
|
nb_redirects = sizeof(redirects) / sizeof(redirects[0]);
|
|
|
|
for (i = 0; i < nb_redirects; i++)
|
|
|
|
{
|
|
|
|
if (!redirects[i].dos_target) continue;
|
|
|
|
redirects[i].unix_target = get_redirect_target( unix_name.Buffer, redirects[i].dos_target );
|
|
|
|
TRACE( "%s -> %s\n", debugstr_w(redirects[i].source), redirects[i].unix_target );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* match_redirect
|
|
|
|
*
|
|
|
|
* Check if path matches a redirect name. If yes, return matched length.
|
|
|
|
*/
|
2013-12-09 10:34:53 +01:00
|
|
|
static int match_redirect( const WCHAR *path, int len, const WCHAR *redir, BOOLEAN check_case )
|
2009-10-22 20:06:06 +02:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i < len && *redir)
|
|
|
|
{
|
|
|
|
if (IS_SEPARATOR(path[i]))
|
|
|
|
{
|
|
|
|
if (*redir++ != '\\') return 0;
|
|
|
|
while (i < len && IS_SEPARATOR(path[i])) i++;
|
|
|
|
continue; /* move on to next path component */
|
|
|
|
}
|
|
|
|
else if (check_case)
|
|
|
|
{
|
|
|
|
if (path[i] != *redir) return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tolowerW(path[i]) != tolowerW(*redir)) return 0;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
redir++;
|
|
|
|
}
|
|
|
|
if (*redir) return 0;
|
|
|
|
if (i < len && !IS_SEPARATOR(path[i])) return 0;
|
|
|
|
while (i < len && IS_SEPARATOR(path[i])) i++;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_redirect_path
|
|
|
|
*
|
|
|
|
* Retrieve the Unix path corresponding to a redirected path if any.
|
|
|
|
*/
|
2013-12-09 10:34:53 +01:00
|
|
|
static int get_redirect_path( char *unix_name, int pos, const WCHAR *name, int length, BOOLEAN check_case )
|
2009-10-22 20:06:06 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_redirects; i++)
|
|
|
|
{
|
|
|
|
if ((len = match_redirect( name, length, redirects[i].source, check_case )))
|
|
|
|
{
|
|
|
|
if (!redirects[i].unix_target) break;
|
|
|
|
unix_name[pos++] = '/';
|
|
|
|
strcpy( unix_name + pos, redirects[i].unix_target );
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
|
2009-10-22 20:06:06 +02:00
|
|
|
#else /* _WIN64 */
|
|
|
|
|
|
|
|
/* there are no redirects on 64-bit */
|
|
|
|
|
|
|
|
static const unsigned int nb_redirects = 0;
|
|
|
|
|
2013-12-09 10:34:53 +01:00
|
|
|
static int get_redirect_path( char *unix_name, int pos, const WCHAR *name, int length, BOOLEAN check_case )
|
2009-10-22 20:06:06 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2004-04-13 01:31:09 +02:00
|
|
|
|
2009-10-22 19:55:02 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DIR_init_windows_dir
|
|
|
|
*/
|
|
|
|
void DIR_init_windows_dir( const WCHAR *win, const WCHAR *sys )
|
|
|
|
{
|
|
|
|
/* FIXME: should probably store paths as NT file names */
|
|
|
|
|
|
|
|
RtlCreateUnicodeString( &system_dir, sys );
|
2009-10-22 20:06:06 +02:00
|
|
|
|
|
|
|
#ifndef _WIN64
|
|
|
|
if (is_wow64) init_redirects();
|
|
|
|
#endif
|
2009-10-22 19:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-23 05:22:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* get_dos_device
|
|
|
|
*
|
|
|
|
* Get the Unix path of a DOS device.
|
|
|
|
*/
|
|
|
|
static NTSTATUS get_dos_device( const WCHAR *name, UINT name_len, ANSI_STRING *unix_name_ret )
|
|
|
|
{
|
|
|
|
const char *config_dir = wine_get_config_dir();
|
|
|
|
struct stat st;
|
2004-04-29 22:04:48 +02:00
|
|
|
char *unix_name, *new_name, *dev;
|
2004-08-14 01:53:44 +02:00
|
|
|
unsigned int i;
|
|
|
|
int unix_len;
|
2004-04-23 05:22:34 +02:00
|
|
|
|
|
|
|
/* make sure the device name is ASCII */
|
|
|
|
for (i = 0; i < name_len; i++)
|
2005-12-12 14:27:45 +01:00
|
|
|
if (name[i] <= 32 || name[i] >= 127) return STATUS_BAD_DEVICE_TYPE;
|
2004-04-23 05:22:34 +02:00
|
|
|
|
2004-04-29 02:27:57 +02:00
|
|
|
unix_len = strlen(config_dir) + sizeof("/dosdevices/") + name_len + 1;
|
2004-04-23 05:22:34 +02:00
|
|
|
|
|
|
|
if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len )))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
strcpy( unix_name, config_dir );
|
|
|
|
strcat( unix_name, "/dosdevices/" );
|
|
|
|
dev = unix_name + strlen(unix_name);
|
|
|
|
|
|
|
|
for (i = 0; i < name_len; i++) dev[i] = (char)tolowerW(name[i]);
|
|
|
|
dev[i] = 0;
|
|
|
|
|
|
|
|
/* special case for drive devices */
|
2004-04-29 02:27:57 +02:00
|
|
|
if (name_len == 2 && dev[1] == ':')
|
|
|
|
{
|
|
|
|
dev[i++] = ':';
|
|
|
|
dev[i] = 0;
|
|
|
|
}
|
2004-04-23 05:22:34 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!stat( unix_name, &st ))
|
|
|
|
{
|
|
|
|
TRACE( "%s -> %s\n", debugstr_wn(name,name_len), debugstr_a(unix_name) );
|
|
|
|
unix_name_ret->Buffer = unix_name;
|
|
|
|
unix_name_ret->Length = strlen(unix_name);
|
|
|
|
unix_name_ret->MaximumLength = unix_len;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
if (!dev) break;
|
|
|
|
|
|
|
|
/* now try some defaults for it */
|
|
|
|
if (!strcmp( dev, "aux" ))
|
|
|
|
{
|
|
|
|
strcpy( dev, "com1" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp( dev, "prn" ))
|
|
|
|
{
|
|
|
|
strcpy( dev, "lpt1" );
|
|
|
|
continue;
|
|
|
|
}
|
2004-04-29 22:04:48 +02:00
|
|
|
|
|
|
|
new_name = NULL;
|
|
|
|
if (dev[1] == ':' && dev[2] == ':') /* drive device */
|
2004-04-23 05:22:34 +02:00
|
|
|
{
|
2004-04-29 22:04:48 +02:00
|
|
|
dev[2] = 0; /* remove last ':' to get the drive mount point symlink */
|
|
|
|
new_name = get_default_drive_device( unix_name );
|
2004-04-23 05:22:34 +02:00
|
|
|
}
|
2008-11-19 15:58:59 +01:00
|
|
|
else if (!strncmp( dev, "com", 3 )) new_name = get_default_com_device( atoi(dev + 3 ));
|
|
|
|
else if (!strncmp( dev, "lpt", 3 )) new_name = get_default_lpt_device( atoi(dev + 3 ));
|
2004-04-29 22:04:48 +02:00
|
|
|
|
|
|
|
if (!new_name) break;
|
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
unix_name = new_name;
|
|
|
|
unix_len = strlen(unix_name) + 1;
|
|
|
|
dev = NULL; /* last try */
|
2004-04-23 05:22:34 +02:00
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
2005-12-12 14:27:45 +01:00
|
|
|
return STATUS_BAD_DEVICE_TYPE;
|
2004-04-23 05:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
/* return the length of the DOS namespace prefix if any */
|
|
|
|
static inline int get_dos_prefix_len( const UNICODE_STRING *name )
|
|
|
|
{
|
|
|
|
static const WCHAR nt_prefixW[] = {'\\','?','?','\\'};
|
|
|
|
static const WCHAR dosdev_prefixW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\'};
|
|
|
|
|
2015-09-25 13:35:58 +02:00
|
|
|
if (name->Length >= sizeof(nt_prefixW) &&
|
2004-04-13 01:31:09 +02:00
|
|
|
!memcmp( name->Buffer, nt_prefixW, sizeof(nt_prefixW) ))
|
|
|
|
return sizeof(nt_prefixW) / sizeof(WCHAR);
|
|
|
|
|
2015-09-25 13:35:58 +02:00
|
|
|
if (name->Length >= sizeof(dosdev_prefixW) &&
|
2004-04-13 01:31:09 +02:00
|
|
|
!memicmpW( name->Buffer, dosdev_prefixW, sizeof(dosdev_prefixW)/sizeof(WCHAR) ))
|
|
|
|
return sizeof(dosdev_prefixW) / sizeof(WCHAR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 23:34:45 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* find_file_id
|
|
|
|
*
|
|
|
|
* Recursively search directories from the dir queue for a given inode.
|
|
|
|
*/
|
|
|
|
static NTSTATUS find_file_id( ANSI_STRING *unix_name, ULONGLONG file_id, dev_t dev )
|
|
|
|
{
|
|
|
|
unsigned int pos;
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
NTSTATUS status;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
while (!(status = next_dir_in_queue( unix_name->Buffer )))
|
|
|
|
{
|
|
|
|
if (!(dir = opendir( unix_name->Buffer ))) continue;
|
|
|
|
TRACE( "searching %s for %s\n", unix_name->Buffer, wine_dbgstr_longlong(file_id) );
|
|
|
|
pos = strlen( unix_name->Buffer );
|
|
|
|
if (pos + MAX_DIR_ENTRY_LEN >= unix_name->MaximumLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
char *new = RtlReAllocateHeap( GetProcessHeap(), 0, unix_name->Buffer,
|
|
|
|
unix_name->MaximumLength * 2 );
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
closedir( dir );
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
unix_name->MaximumLength *= 2;
|
|
|
|
unix_name->Buffer = new;
|
|
|
|
}
|
|
|
|
unix_name->Buffer[pos++] = '/';
|
|
|
|
while ((de = readdir( dir )))
|
|
|
|
{
|
|
|
|
if (!strcmp( de->d_name, "." ) || !strcmp( de->d_name, ".." )) continue;
|
|
|
|
strcpy( unix_name->Buffer + pos, de->d_name );
|
|
|
|
if (lstat( unix_name->Buffer, &st ) == -1) continue;
|
|
|
|
if (st.st_dev != dev) continue;
|
|
|
|
if (st.st_ino == file_id)
|
|
|
|
{
|
|
|
|
closedir( dir );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
if (!S_ISDIR( st.st_mode )) continue;
|
|
|
|
if ((status = add_dir_to_queue( unix_name->Buffer )) != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
closedir( dir );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir( dir );
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 17:35:43 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* file_id_to_unix_file_name
|
|
|
|
*
|
|
|
|
* Lookup a file from its file id instead of its name.
|
|
|
|
*/
|
2009-12-09 23:34:45 +01:00
|
|
|
NTSTATUS file_id_to_unix_file_name( const OBJECT_ATTRIBUTES *attr, ANSI_STRING *unix_name )
|
2009-12-02 17:35:43 +01:00
|
|
|
{
|
|
|
|
enum server_fd_type type;
|
|
|
|
int old_cwd, root_fd, needs_close;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONGLONG file_id;
|
|
|
|
struct stat st, root_st;
|
|
|
|
|
|
|
|
if (attr->ObjectName->Length != sizeof(ULONGLONG)) return STATUS_OBJECT_PATH_SYNTAX_BAD;
|
|
|
|
if (!attr->RootDirectory) return STATUS_INVALID_PARAMETER;
|
|
|
|
memcpy( &file_id, attr->ObjectName->Buffer, sizeof(file_id) );
|
|
|
|
|
2009-12-09 23:34:45 +01:00
|
|
|
unix_name->MaximumLength = 2 * MAX_DIR_ENTRY_LEN + 4;
|
|
|
|
if (!(unix_name->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, unix_name->MaximumLength )))
|
2009-12-02 17:35:43 +01:00
|
|
|
return STATUS_NO_MEMORY;
|
2009-12-09 23:34:45 +01:00
|
|
|
strcpy( unix_name->Buffer, "." );
|
|
|
|
|
|
|
|
if ((status = server_get_unix_fd( attr->RootDirectory, 0, &root_fd, &needs_close, &type, NULL )))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (type != FD_TYPE_DIR)
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_TYPE_MISMATCH;
|
|
|
|
goto done;
|
|
|
|
}
|
2009-12-02 17:35:43 +01:00
|
|
|
|
2009-12-09 23:34:45 +01:00
|
|
|
fstat( root_fd, &root_st );
|
|
|
|
if (root_st.st_ino == file_id) /* shortcut for "." */
|
2009-12-02 17:35:43 +01:00
|
|
|
{
|
2009-12-09 23:34:45 +01:00
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
if ((old_cwd = open( ".", O_RDONLY )) != -1 && fchdir( root_fd ) != -1)
|
|
|
|
{
|
|
|
|
/* shortcut for ".." */
|
|
|
|
if (!stat( "..", &st ) && st.st_dev == root_st.st_dev && st.st_ino == file_id)
|
2009-12-02 17:35:43 +01:00
|
|
|
{
|
2009-12-09 23:34:45 +01:00
|
|
|
strcpy( unix_name->Buffer, ".." );
|
|
|
|
status = STATUS_SUCCESS;
|
2009-12-02 17:35:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 23:34:45 +01:00
|
|
|
status = add_dir_to_queue( "." );
|
|
|
|
if (!status)
|
|
|
|
status = find_file_id( unix_name, file_id, root_st.st_dev );
|
|
|
|
if (!status) /* get rid of "./" prefix */
|
|
|
|
memmove( unix_name->Buffer, unix_name->Buffer + 2, strlen(unix_name->Buffer) - 1 );
|
|
|
|
flush_dir_queue();
|
2009-12-02 17:35:43 +01:00
|
|
|
}
|
2009-12-09 23:34:45 +01:00
|
|
|
if (fchdir( old_cwd ) == -1) chdir( "/" );
|
2009-12-02 17:35:43 +01:00
|
|
|
}
|
2009-12-09 23:34:45 +01:00
|
|
|
else status = FILE_GetNtStatus();
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
|
|
|
if (old_cwd != -1) close( old_cwd );
|
2009-12-02 17:35:43 +01:00
|
|
|
|
2009-12-09 23:34:45 +01:00
|
|
|
done:
|
2009-12-02 17:35:43 +01:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
2009-12-09 23:34:45 +01:00
|
|
|
TRACE( "%s -> %s\n", wine_dbgstr_longlong(file_id), debugstr_a(unix_name->Buffer) );
|
|
|
|
unix_name->Length = strlen( unix_name->Buffer );
|
2009-12-02 17:35:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 23:34:45 +01:00
|
|
|
TRACE( "%s not found in dir %p\n", wine_dbgstr_longlong(file_id), attr->RootDirectory );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name->Buffer );
|
2009-12-02 17:35:43 +01:00
|
|
|
}
|
2009-12-09 23:34:45 +01:00
|
|
|
if (needs_close) close( root_fd );
|
2009-12-02 17:35:43 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-01 16:30:52 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* lookup_unix_name
|
|
|
|
*
|
|
|
|
* Helper for nt_to_unix_file_name
|
|
|
|
*/
|
|
|
|
static NTSTATUS lookup_unix_name( const WCHAR *name, int name_len, char **buffer, int unix_len, int pos,
|
|
|
|
UINT disposition, BOOLEAN check_case )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
int ret, used_default, len;
|
|
|
|
struct stat st;
|
|
|
|
char *unix_name = *buffer;
|
|
|
|
const BOOL redirect = nb_redirects && ntdll_get_thread_data()->wow64_redir;
|
|
|
|
|
|
|
|
/* try a shortcut first */
|
|
|
|
|
|
|
|
ret = ntdll_wcstoumbs( 0, name, name_len, unix_name + pos, unix_len - pos - 1,
|
|
|
|
NULL, &used_default );
|
|
|
|
|
|
|
|
while (name_len && IS_SEPARATOR(*name))
|
|
|
|
{
|
|
|
|
name++;
|
|
|
|
name_len--;
|
|
|
|
}
|
|
|
|
|
2009-12-01 17:07:55 +01:00
|
|
|
if (ret >= 0 && !used_default) /* if we used the default char the name didn't convert properly */
|
2009-12-01 16:30:52 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
unix_name[pos + ret] = 0;
|
|
|
|
for (p = unix_name + pos ; *p; p++) if (*p == '\\') *p = '/';
|
2009-12-01 17:07:55 +01:00
|
|
|
if (!redirect || (!strstr( unix_name, "/windows/") && strncmp( unix_name, "windows/", 8 )))
|
2009-12-01 16:30:52 +01:00
|
|
|
{
|
2009-12-01 17:07:55 +01:00
|
|
|
if (!stat( unix_name, &st ))
|
|
|
|
{
|
|
|
|
/* creation fails with STATUS_ACCESS_DENIED for the root of the drive */
|
|
|
|
if (disposition == FILE_CREATE)
|
|
|
|
return name_len ? STATUS_OBJECT_NAME_COLLISION : STATUS_ACCESS_DENIED;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2009-12-01 16:30:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name_len) /* empty name -> drive root doesn't exist */
|
|
|
|
return STATUS_OBJECT_PATH_NOT_FOUND;
|
|
|
|
if (check_case && !redirect && (disposition == FILE_OPEN || disposition == FILE_OVERWRITE))
|
|
|
|
return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
|
|
|
|
/* now do it component by component */
|
|
|
|
|
|
|
|
while (name_len)
|
|
|
|
{
|
|
|
|
const WCHAR *end, *next;
|
2013-12-09 10:34:53 +01:00
|
|
|
BOOLEAN is_win_dir = FALSE;
|
2009-12-01 16:30:52 +01:00
|
|
|
|
|
|
|
end = name;
|
|
|
|
while (end < name + name_len && !IS_SEPARATOR(*end)) end++;
|
|
|
|
next = end;
|
|
|
|
while (next < name + name_len && IS_SEPARATOR(*next)) next++;
|
|
|
|
name_len -= next - name;
|
|
|
|
|
|
|
|
/* grow the buffer if needed */
|
|
|
|
|
|
|
|
if (unix_len - pos < MAX_DIR_ENTRY_LEN + 2)
|
|
|
|
{
|
|
|
|
char *new_name;
|
|
|
|
unix_len += 2 * MAX_DIR_ENTRY_LEN;
|
|
|
|
if (!(new_name = RtlReAllocateHeap( GetProcessHeap(), 0, unix_name, unix_len )))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
unix_name = *buffer = new_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = find_file_in_dir( unix_name, pos, name, end - name,
|
|
|
|
check_case, redirect ? &is_win_dir : NULL );
|
|
|
|
|
|
|
|
/* if this is the last element, not finding it is not necessarily fatal */
|
|
|
|
if (!name_len)
|
|
|
|
{
|
|
|
|
if (status == STATUS_OBJECT_PATH_NOT_FOUND)
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
if (disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
|
|
|
|
{
|
|
|
|
ret = ntdll_wcstoumbs( 0, name, end - name, unix_name + pos + 1,
|
|
|
|
MAX_DIR_ENTRY_LEN, NULL, &used_default );
|
|
|
|
if (ret > 0 && !used_default)
|
|
|
|
{
|
|
|
|
unix_name[pos] = '/';
|
|
|
|
unix_name[pos + 1 + ret] = 0;
|
|
|
|
status = STATUS_NO_SUCH_FILE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (status == STATUS_SUCCESS && disposition == FILE_CREATE)
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_NAME_COLLISION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS) break;
|
|
|
|
|
|
|
|
pos += strlen( unix_name + pos );
|
|
|
|
name = next;
|
|
|
|
|
|
|
|
if (is_win_dir && (len = get_redirect_path( unix_name, pos, name, name_len, check_case )))
|
|
|
|
{
|
|
|
|
name += len;
|
|
|
|
name_len -= len;
|
|
|
|
pos += strlen( unix_name + pos );
|
|
|
|
TRACE( "redirecting -> %s + %s\n", debugstr_a(unix_name), debugstr_w(name) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-01 17:07:55 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* nt_to_unix_file_name_attr
|
|
|
|
*/
|
|
|
|
NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, ANSI_STRING *unix_name_ret,
|
|
|
|
UINT disposition )
|
|
|
|
{
|
|
|
|
static const WCHAR invalid_charsW[] = { INVALID_NT_CHARS, 0 };
|
|
|
|
enum server_fd_type type;
|
|
|
|
int old_cwd, root_fd, needs_close;
|
|
|
|
const WCHAR *name, *p;
|
|
|
|
char *unix_name;
|
|
|
|
int name_len, unix_len;
|
|
|
|
NTSTATUS status;
|
|
|
|
BOOLEAN check_case = !(attr->Attributes & OBJ_CASE_INSENSITIVE);
|
|
|
|
|
|
|
|
if (!attr->RootDirectory) /* without root dir fall back to normal lookup */
|
|
|
|
return wine_nt_to_unix_file_name( attr->ObjectName, unix_name_ret, disposition, check_case );
|
|
|
|
|
|
|
|
name = attr->ObjectName->Buffer;
|
|
|
|
name_len = attr->ObjectName->Length / sizeof(WCHAR);
|
|
|
|
|
2009-12-03 10:08:56 +01:00
|
|
|
if (name_len && IS_SEPARATOR(name[0])) return STATUS_INVALID_PARAMETER;
|
2009-12-01 17:07:55 +01:00
|
|
|
|
|
|
|
/* check for invalid characters */
|
|
|
|
for (p = name; p < name + name_len; p++)
|
|
|
|
if (*p < 32 || strchrW( invalid_charsW, *p )) return STATUS_OBJECT_NAME_INVALID;
|
|
|
|
|
|
|
|
unix_len = ntdll_wcstoumbs( 0, name, name_len, NULL, 0, NULL, NULL );
|
|
|
|
unix_len += MAX_DIR_ENTRY_LEN + 3;
|
|
|
|
if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len )))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
unix_name[0] = '.';
|
|
|
|
|
2010-01-08 15:54:20 +01:00
|
|
|
if (!(status = server_get_unix_fd( attr->RootDirectory, 0, &root_fd, &needs_close, &type, NULL )))
|
2009-12-01 17:07:55 +01:00
|
|
|
{
|
|
|
|
if (type != FD_TYPE_DIR)
|
|
|
|
{
|
|
|
|
if (needs_close) close( root_fd );
|
|
|
|
status = STATUS_BAD_DEVICE_TYPE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
if ((old_cwd = open( ".", O_RDONLY )) != -1 && fchdir( root_fd ) != -1)
|
|
|
|
{
|
|
|
|
status = lookup_unix_name( name, name_len, &unix_name, unix_len, 1,
|
|
|
|
disposition, check_case );
|
|
|
|
if (fchdir( old_cwd ) == -1) chdir( "/" );
|
|
|
|
}
|
|
|
|
else status = FILE_GetNtStatus();
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
|
|
|
if (old_cwd != -1) close( old_cwd );
|
|
|
|
if (needs_close) close( root_fd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (status == STATUS_OBJECT_TYPE_MISMATCH) status = STATUS_BAD_DEVICE_TYPE;
|
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS || status == STATUS_NO_SUCH_FILE)
|
|
|
|
{
|
|
|
|
TRACE( "%s -> %s\n", debugstr_us(attr->ObjectName), debugstr_a(unix_name) );
|
|
|
|
unix_name_ret->Buffer = unix_name;
|
|
|
|
unix_name_ret->Length = strlen(unix_name);
|
|
|
|
unix_name_ret->MaximumLength = unix_len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "%s not found in %s\n", debugstr_w(name), unix_name );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
/******************************************************************************
|
2004-04-23 04:46:18 +02:00
|
|
|
* wine_nt_to_unix_file_name (NTDLL.@) Not a Windows API
|
2004-04-13 01:31:09 +02:00
|
|
|
*
|
|
|
|
* Convert a file name from NT namespace to Unix namespace.
|
2004-04-22 00:26:44 +02:00
|
|
|
*
|
2008-04-08 23:22:43 +02:00
|
|
|
* If disposition is not FILE_OPEN or FILE_OVERWRITE, the last path
|
2004-04-27 04:15:52 +02:00
|
|
|
* element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
|
|
|
|
* returned, but the unix name is still filled in properly.
|
2004-04-13 01:31:09 +02:00
|
|
|
*/
|
2008-12-16 16:37:46 +01:00
|
|
|
NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
|
|
|
|
UINT disposition, BOOLEAN check_case )
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2007-03-22 16:35:51 +01:00
|
|
|
static const WCHAR unixW[] = {'u','n','i','x'};
|
2004-04-14 06:36:21 +02:00
|
|
|
static const WCHAR invalid_charsW[] = { INVALID_NT_CHARS, 0 };
|
|
|
|
|
2004-04-22 00:26:44 +02:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2004-04-13 01:31:09 +02:00
|
|
|
const char *config_dir = wine_get_config_dir();
|
2004-04-17 01:32:40 +02:00
|
|
|
const WCHAR *name, *p;
|
2004-04-13 01:31:09 +02:00
|
|
|
struct stat st;
|
|
|
|
char *unix_name;
|
2007-03-22 16:35:51 +01:00
|
|
|
int pos, ret, name_len, unix_len, prefix_len, used_default;
|
|
|
|
WCHAR prefix[MAX_DIR_ENTRY_LEN];
|
|
|
|
BOOLEAN is_unix = FALSE;
|
2004-04-13 01:31:09 +02:00
|
|
|
|
|
|
|
name = nameW->Buffer;
|
|
|
|
name_len = nameW->Length / sizeof(WCHAR);
|
|
|
|
|
2004-04-14 06:36:21 +02:00
|
|
|
if (!name_len || !IS_SEPARATOR(name[0])) return STATUS_OBJECT_PATH_SYNTAX_BAD;
|
|
|
|
|
2007-03-22 16:35:51 +01:00
|
|
|
if (!(pos = get_dos_prefix_len( nameW )))
|
|
|
|
return STATUS_BAD_DEVICE_TYPE; /* no DOS prefix, assume NT native name */
|
|
|
|
|
|
|
|
name += pos;
|
|
|
|
name_len -= pos;
|
|
|
|
|
2015-09-25 13:35:58 +02:00
|
|
|
if (!name_len) return STATUS_OBJECT_NAME_INVALID;
|
|
|
|
|
2007-03-22 16:35:51 +01:00
|
|
|
/* check for sub-directory */
|
|
|
|
for (pos = 0; pos < name_len; pos++)
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2007-03-22 16:35:51 +01:00
|
|
|
if (IS_SEPARATOR(name[pos])) break;
|
|
|
|
if (name[pos] < 32 || strchrW( invalid_charsW, name[pos] ))
|
|
|
|
return STATUS_OBJECT_NAME_INVALID;
|
|
|
|
}
|
|
|
|
if (pos > MAX_DIR_ENTRY_LEN)
|
|
|
|
return STATUS_OBJECT_NAME_INVALID;
|
2004-05-17 23:09:19 +02:00
|
|
|
|
2007-03-22 16:35:51 +01:00
|
|
|
if (pos == name_len) /* no subdir, plain DOS device */
|
|
|
|
return get_dos_device( name, name_len, unix_name_ret );
|
2004-04-14 06:36:21 +02:00
|
|
|
|
2007-03-22 16:35:51 +01:00
|
|
|
for (prefix_len = 0; prefix_len < pos; prefix_len++)
|
|
|
|
prefix[prefix_len] = tolowerW(name[prefix_len]);
|
|
|
|
|
|
|
|
name += prefix_len;
|
|
|
|
name_len -= prefix_len;
|
2004-04-23 05:22:34 +02:00
|
|
|
|
2007-03-22 16:35:51 +01:00
|
|
|
/* check for invalid characters (all chars except 0 are valid for unix) */
|
|
|
|
is_unix = (prefix_len == 4 && !memcmp( prefix, unixW, sizeof(unixW) ));
|
|
|
|
if (is_unix)
|
|
|
|
{
|
|
|
|
for (p = name; p < name + name_len; p++)
|
|
|
|
if (!*p) return STATUS_OBJECT_NAME_INVALID;
|
|
|
|
check_case = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-14 06:36:21 +02:00
|
|
|
for (p = name; p < name + name_len; p++)
|
|
|
|
if (*p < 32 || strchrW( invalid_charsW, *p )) return STATUS_OBJECT_NAME_INVALID;
|
2007-03-22 16:35:51 +01:00
|
|
|
}
|
2004-04-14 06:36:21 +02:00
|
|
|
|
2007-03-22 16:35:51 +01:00
|
|
|
unix_len = ntdll_wcstoumbs( 0, prefix, prefix_len, NULL, 0, NULL, NULL );
|
|
|
|
unix_len += ntdll_wcstoumbs( 0, name, name_len, NULL, 0, NULL, NULL );
|
|
|
|
unix_len += MAX_DIR_ENTRY_LEN + 3;
|
|
|
|
unix_len += strlen(config_dir) + sizeof("/dosdevices/");
|
|
|
|
if (!(unix_name = RtlAllocateHeap( GetProcessHeap(), 0, unix_len )))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
strcpy( unix_name, config_dir );
|
|
|
|
strcat( unix_name, "/dosdevices/" );
|
|
|
|
pos = strlen(unix_name);
|
|
|
|
|
|
|
|
ret = ntdll_wcstoumbs( 0, prefix, prefix_len, unix_name + pos, unix_len - pos - 1,
|
|
|
|
NULL, &used_default );
|
|
|
|
if (!ret || used_default)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
return STATUS_OBJECT_NAME_INVALID;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
2007-03-22 16:35:51 +01:00
|
|
|
pos += ret;
|
|
|
|
|
|
|
|
/* check if prefix exists (except for DOS drives to avoid extra stat calls) */
|
|
|
|
|
|
|
|
if (prefix_len != 2 || prefix[1] != ':')
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2007-03-22 16:35:51 +01:00
|
|
|
unix_name[pos] = 0;
|
|
|
|
if (lstat( unix_name, &st ) == -1 && errno == ENOENT)
|
|
|
|
{
|
|
|
|
if (!is_unix)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
return STATUS_BAD_DEVICE_TYPE;
|
|
|
|
}
|
|
|
|
pos = 0; /* fall back to unix root */
|
|
|
|
}
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
|
2009-12-01 16:30:52 +01:00
|
|
|
status = lookup_unix_name( name, name_len, &unix_name, unix_len, pos, disposition, check_case );
|
|
|
|
if (status == STATUS_SUCCESS || status == STATUS_NO_SUCH_FILE)
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2009-12-01 16:30:52 +01:00
|
|
|
TRACE( "%s -> %s\n", debugstr_us(nameW), debugstr_a(unix_name) );
|
|
|
|
unix_name_ret->Buffer = unix_name;
|
|
|
|
unix_name_ret->Length = strlen(unix_name);
|
|
|
|
unix_name_ret->MaximumLength = unix_len;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
2009-12-01 16:30:52 +01:00
|
|
|
else
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2009-12-01 16:30:52 +01:00
|
|
|
TRACE( "%s not found in %s\n", debugstr_w(name), unix_name );
|
2004-04-13 01:31:09 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
2009-10-22 20:06:06 +02:00
|
|
|
}
|
2004-04-22 00:26:44 +02:00
|
|
|
return status;
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 15:08:39 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlWow64EnableFsRedirection (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlWow64EnableFsRedirection( BOOLEAN enable )
|
|
|
|
{
|
|
|
|
if (!is_wow64) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
ntdll_get_thread_data()->wow64_redir = enable;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlWow64EnableFsRedirectionEx (NTDLL.@)
|
|
|
|
*/
|
2009-10-28 10:54:22 +01:00
|
|
|
NTSTATUS WINAPI RtlWow64EnableFsRedirectionEx( ULONG disable, ULONG *old_value )
|
2009-07-06 15:08:39 +02:00
|
|
|
{
|
|
|
|
if (!is_wow64) return STATUS_NOT_IMPLEMENTED;
|
2012-08-21 21:58:17 +02:00
|
|
|
if (((ULONG_PTR)old_value >> 16) == 0) return STATUS_ACCESS_VIOLATION;
|
|
|
|
|
2009-10-28 10:54:22 +01:00
|
|
|
*old_value = !ntdll_get_thread_data()->wow64_redir;
|
|
|
|
ntdll_get_thread_data()->wow64_redir = !disable;
|
2009-07-06 15:08:39 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlDoesFileExists_U (NTDLL.@)
|
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlDoesFileExists_U(LPCWSTR file_name)
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
2007-05-03 22:33:58 +02:00
|
|
|
FILE_BASIC_INFORMATION basic_info;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2004-04-13 01:31:09 +02:00
|
|
|
BOOLEAN ret;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( file_name, &nt_name, NULL, NULL )) return FALSE;
|
2007-05-03 22:33:58 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
ret = NtQueryAttributesFile(&attr, &basic_info) == STATUS_SUCCESS;
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
return ret;
|
|
|
|
}
|
2005-08-11 12:41:26 +02:00
|
|
|
|
|
|
|
|
2005-10-28 18:45:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DIR_unmount_device
|
|
|
|
*
|
|
|
|
* Unmount the specified device.
|
|
|
|
*/
|
|
|
|
NTSTATUS DIR_unmount_device( HANDLE handle )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2006-11-03 11:38:44 +01:00
|
|
|
int unix_fd, needs_close;
|
2005-10-28 18:45:24 +02:00
|
|
|
|
2006-11-20 14:15:06 +01:00
|
|
|
if (!(status = server_get_unix_fd( handle, 0, &unix_fd, &needs_close, NULL, NULL )))
|
2005-10-28 18:45:24 +02:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *mount_point = NULL;
|
|
|
|
|
2006-10-03 14:54:21 +02:00
|
|
|
if (fstat( unix_fd, &st ) == -1 || !is_valid_mounted_device( &st ))
|
2005-10-28 18:45:24 +02:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((mount_point = get_device_mount_point( st.st_rdev )))
|
|
|
|
{
|
2006-10-03 14:54:21 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
static const char umount[] = "diskutil unmount >/dev/null 2>&1 ";
|
|
|
|
#else
|
2005-10-28 18:45:24 +02:00
|
|
|
static const char umount[] = "umount >/dev/null 2>&1 ";
|
2006-10-03 14:54:21 +02:00
|
|
|
#endif
|
2005-10-28 18:45:24 +02:00
|
|
|
char *cmd = RtlAllocateHeap( GetProcessHeap(), 0, strlen(mount_point)+sizeof(umount));
|
|
|
|
if (cmd)
|
|
|
|
{
|
|
|
|
strcpy( cmd, umount );
|
|
|
|
strcat( cmd, mount_point );
|
|
|
|
system( cmd );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, cmd );
|
|
|
|
#ifdef linux
|
|
|
|
/* umount will fail to release the loop device since we still have
|
|
|
|
a handle to it, so we release it here */
|
|
|
|
if (major(st.st_rdev) == LOOP_MAJOR) ioctl( unix_fd, 0x4c01 /*LOOP_CLR_FD*/, 0 );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount_point );
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( unix_fd );
|
2005-10-28 18:45:24 +02:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-11 12:41:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DIR_get_unix_cwd
|
|
|
|
*
|
|
|
|
* Retrieve the Unix name of the current directory; helper for wine_unix_to_nt_file_name.
|
|
|
|
* Returned value must be freed by caller.
|
|
|
|
*/
|
|
|
|
NTSTATUS DIR_get_unix_cwd( char **cwd )
|
|
|
|
{
|
2006-11-03 11:38:44 +01:00
|
|
|
int old_cwd, unix_fd, needs_close;
|
2005-08-11 12:41:26 +02:00
|
|
|
CURDIR *curdir;
|
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
|
|
|
if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */
|
|
|
|
curdir = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir;
|
|
|
|
else
|
|
|
|
curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectory;
|
|
|
|
|
|
|
|
if (!(handle = curdir->Handle))
|
|
|
|
{
|
|
|
|
UNICODE_STRING dirW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( curdir->DosPath.Buffer, &dirW, NULL, NULL ))
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_NAME_INVALID;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &dirW;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2016-02-09 12:11:07 +01:00
|
|
|
status = NtOpenFile( &handle, SYNCHRONIZE, &attr, &io, 0,
|
2005-08-11 12:41:26 +02:00
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
RtlFreeUnicodeString( &dirW );
|
|
|
|
if (status != STATUS_SUCCESS) goto done;
|
|
|
|
}
|
|
|
|
|
2006-11-20 14:15:06 +01:00
|
|
|
if ((status = server_get_unix_fd( handle, 0, &unix_fd, &needs_close, NULL, NULL )) == STATUS_SUCCESS)
|
2005-08-11 12:41:26 +02:00
|
|
|
{
|
|
|
|
RtlEnterCriticalSection( &dir_section );
|
|
|
|
|
|
|
|
if ((old_cwd = open(".", O_RDONLY)) != -1 && fchdir( unix_fd ) != -1)
|
|
|
|
{
|
|
|
|
unsigned int size = 512;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(*cwd = RtlAllocateHeap( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (getcwd( *cwd, size )) break;
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, *cwd );
|
|
|
|
if (errno != ERANGE)
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_PATH_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
if (fchdir( old_cwd ) == -1) chdir( "/" );
|
|
|
|
}
|
|
|
|
else status = FILE_GetNtStatus();
|
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &dir_section );
|
2009-09-10 10:53:38 +02:00
|
|
|
if (old_cwd != -1) close( old_cwd );
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( unix_fd );
|
2005-08-11 12:41:26 +02:00
|
|
|
}
|
|
|
|
if (!curdir->Handle) NtClose( handle );
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlReleasePebLock();
|
|
|
|
return status;
|
|
|
|
}
|