2004-03-09 02:03:03 +01:00
|
|
|
/*
|
|
|
|
* Volume management functions
|
|
|
|
*
|
|
|
|
* Copyright 1993 Erik Bos
|
|
|
|
* Copyright 1996, 2004 Alexandre Julliard
|
|
|
|
* Copyright 1999 Petr Tomasek
|
|
|
|
* Copyright 2000 Andreas Mohr
|
|
|
|
* Copyright 2003 Eric Pouech
|
|
|
|
*
|
|
|
|
* 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-09 02:03:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
2004-03-20 03:28:51 +01:00
|
|
|
#include <stdio.h>
|
2004-03-09 02:03:03 +01:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2004-03-09 02:03:03 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winioctl.h"
|
|
|
|
#include "ntddcdrm.h"
|
2008-11-10 16:28:37 +01:00
|
|
|
#define WINE_MOUNTMGR_EXTENSIONS
|
2008-01-04 14:31:40 +01:00
|
|
|
#include "ddk/mountmgr.h"
|
2004-03-20 03:28:51 +01:00
|
|
|
#include "kernel_private.h"
|
|
|
|
#include "wine/library.h"
|
2004-03-09 02:03:03 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(volume);
|
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
#define BLOCK_SIZE 2048
|
|
|
|
#define SUPERBLOCK_SIZE BLOCK_SIZE
|
2008-10-23 20:24:49 +02:00
|
|
|
#define SYMBOLIC_LINK_QUERY 0x0001
|
2004-03-09 02:03:03 +01:00
|
|
|
|
|
|
|
#define CDFRAMES_PERSEC 75
|
|
|
|
#define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
|
|
|
|
#define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
|
|
|
|
#define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc)->TrackData[(idx) - (toc)->FirstTrack].Address)
|
|
|
|
|
|
|
|
#define GETWORD(buf,off) MAKEWORD(buf[(off)],buf[(off+1)])
|
|
|
|
#define GETLONG(buf,off) MAKELONG(GETWORD(buf,off),GETWORD(buf,off+2))
|
|
|
|
|
|
|
|
enum fs_type
|
|
|
|
{
|
|
|
|
FS_ERROR, /* error accessing the device */
|
|
|
|
FS_UNKNOWN, /* unknown file system */
|
|
|
|
FS_FAT1216,
|
|
|
|
FS_FAT32,
|
2011-09-01 16:30:15 +02:00
|
|
|
FS_ISO9660,
|
|
|
|
FS_UDF /* For reference [E] = Ecma-167.pdf, [U] = udf260.pdf */
|
2004-03-09 02:03:03 +01:00
|
|
|
};
|
|
|
|
|
2004-03-20 03:28:51 +01:00
|
|
|
/* read a Unix symlink; returned buffer must be freed by caller */
|
|
|
|
static char *read_symlink( const char *path )
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
int ret, size = 128;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = readlink( path, buffer, size );
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
FILE_SetDosError();
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
return 0;
|
|
|
|
}
|
2004-03-30 23:00:07 +02:00
|
|
|
if (ret != size)
|
2004-03-20 03:28:51 +01:00
|
|
|
{
|
|
|
|
buffer[ret] = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the path of a dos device symlink in the $WINEPREFIX/dosdevices directory */
|
|
|
|
static char *get_dos_device_path( LPCWSTR name )
|
|
|
|
{
|
|
|
|
const char *config_dir = wine_get_config_dir();
|
|
|
|
char *buffer, *dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
strlen(config_dir) + sizeof("/dosdevices/") + 5 )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
strcpy( buffer, config_dir );
|
|
|
|
strcat( buffer, "/dosdevices/" );
|
|
|
|
dev = buffer + strlen(buffer);
|
|
|
|
/* no codepage conversion, DOS device names are ASCII anyway */
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
if (!(dev[i] = (char)tolowerW(name[i]))) break;
|
|
|
|
dev[5] = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2008-10-23 20:24:49 +02:00
|
|
|
/* read the contents of an NT symlink object */
|
|
|
|
static NTSTATUS read_nt_symlink( const WCHAR *name, WCHAR *target, DWORD size )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
|
|
|
|
if (!(status = NtOpenSymbolicLinkObject( &handle, SYMBOLIC_LINK_QUERY, &attr )))
|
|
|
|
{
|
|
|
|
UNICODE_STRING targetW;
|
|
|
|
targetW.Buffer = target;
|
|
|
|
targetW.MaximumLength = (size - 1) * sizeof(WCHAR);
|
|
|
|
status = NtQuerySymbolicLinkObject( handle, &targetW, NULL );
|
|
|
|
if (!status) target[targetW.Length / sizeof(WCHAR)] = 0;
|
|
|
|
NtClose( handle );
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2004-04-17 02:30:09 +02:00
|
|
|
/* open a handle to a device root */
|
|
|
|
static BOOL open_device_root( LPCWSTR root, HANDLE *handle )
|
|
|
|
{
|
|
|
|
static const WCHAR default_rootW[] = {'\\',0};
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!root) root = default_rootW;
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( root, &nt_name, NULL, NULL ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
status = NtOpenFile( handle, 0, &attr, &io, 0,
|
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-10 16:28:37 +01:00
|
|
|
/* query the type of a drive from the mount manager */
|
|
|
|
static DWORD get_mountmgr_drive_type( LPCWSTR root )
|
|
|
|
{
|
|
|
|
HANDLE mgr;
|
|
|
|
struct mountmgr_unix_drive data;
|
2014-07-19 20:53:10 +02:00
|
|
|
DWORD br;
|
2008-11-10 16:28:37 +01:00
|
|
|
|
|
|
|
memset( &data, 0, sizeof(data) );
|
|
|
|
if (root) data.letter = root[0];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR curdir[MAX_PATH];
|
|
|
|
GetCurrentDirectoryW( MAX_PATH, curdir );
|
|
|
|
if (curdir[1] != ':' || curdir[2] != '\\') return DRIVE_UNKNOWN;
|
|
|
|
data.letter = curdir[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
if (mgr == INVALID_HANDLE_VALUE) return DRIVE_UNKNOWN;
|
|
|
|
|
|
|
|
if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE, &data, sizeof(data), &data,
|
2014-07-19 20:53:10 +02:00
|
|
|
sizeof(data), &br, NULL ) && GetLastError() != ERROR_MORE_DATA)
|
2008-11-10 16:28:37 +01:00
|
|
|
data.type = DRIVE_UNKNOWN;
|
|
|
|
|
|
|
|
CloseHandle( mgr );
|
|
|
|
return data.type;
|
|
|
|
}
|
|
|
|
|
2007-12-08 19:53:24 +01:00
|
|
|
/* get the label by reading it from a file at the root of the filesystem */
|
2010-10-20 12:26:54 +02:00
|
|
|
static void get_filesystem_label( const UNICODE_STRING *device, WCHAR *label, DWORD len )
|
2007-12-08 19:53:24 +01:00
|
|
|
{
|
2010-10-20 12:26:54 +02:00
|
|
|
static const WCHAR labelW[] = {'.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
|
2007-12-08 19:53:24 +01:00
|
|
|
HANDLE handle;
|
2010-10-20 12:26:54 +02:00
|
|
|
UNICODE_STRING name;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
|
|
|
|
label[0] = 0;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &name;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
name.MaximumLength = device->Length + sizeof(labelW);
|
|
|
|
name.Length = name.MaximumLength - sizeof(WCHAR);
|
|
|
|
if (!(name.Buffer = HeapAlloc( GetProcessHeap(), 0, name.MaximumLength ))) return;
|
2007-12-08 19:53:24 +01:00
|
|
|
|
2010-10-20 12:26:54 +02:00
|
|
|
memcpy( name.Buffer, device->Buffer, device->Length );
|
|
|
|
memcpy( name.Buffer + device->Length / sizeof(WCHAR), labelW, sizeof(labelW) );
|
|
|
|
if (!NtOpenFile( &handle, GENERIC_READ, &attr, &io, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ))
|
2007-12-08 19:53:24 +01:00
|
|
|
{
|
|
|
|
char buffer[256], *p;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!ReadFile( handle, buffer, sizeof(buffer)-1, &size, NULL )) size = 0;
|
|
|
|
CloseHandle( handle );
|
|
|
|
p = buffer + size;
|
|
|
|
while (p > buffer && (p[-1] == ' ' || p[-1] == '\r' || p[-1] == '\n')) p--;
|
|
|
|
*p = 0;
|
|
|
|
if (!MultiByteToWideChar( CP_UNIXCP, 0, buffer, -1, label, len ))
|
|
|
|
label[len-1] = 0;
|
|
|
|
}
|
2010-10-20 12:26:54 +02:00
|
|
|
RtlFreeUnicodeString( &name );
|
2007-12-08 19:53:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get the serial number by reading it from a file at the root of the filesystem */
|
2010-10-20 12:26:54 +02:00
|
|
|
static DWORD get_filesystem_serial( const UNICODE_STRING *device )
|
2007-12-08 19:53:24 +01:00
|
|
|
{
|
2010-10-20 12:26:54 +02:00
|
|
|
static const WCHAR serialW[] = {'.','w','i','n','d','o','w','s','-','s','e','r','i','a','l',0};
|
2007-12-08 19:53:24 +01:00
|
|
|
HANDLE handle;
|
2010-10-20 12:26:54 +02:00
|
|
|
UNICODE_STRING name;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &name;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
name.MaximumLength = device->Length + sizeof(serialW);
|
|
|
|
name.Length = name.MaximumLength - sizeof(WCHAR);
|
|
|
|
if (!(name.Buffer = HeapAlloc( GetProcessHeap(), 0, name.MaximumLength ))) return 0;
|
2007-12-08 19:53:24 +01:00
|
|
|
|
2010-10-20 12:26:54 +02:00
|
|
|
memcpy( name.Buffer, device->Buffer, device->Length );
|
|
|
|
memcpy( name.Buffer + device->Length / sizeof(WCHAR), serialW, sizeof(serialW) );
|
|
|
|
if (!NtOpenFile( &handle, GENERIC_READ, &attr, &io, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT ))
|
2007-12-08 19:53:24 +01:00
|
|
|
{
|
|
|
|
char buffer[32];
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!ReadFile( handle, buffer, sizeof(buffer)-1, &size, NULL )) size = 0;
|
|
|
|
CloseHandle( handle );
|
|
|
|
buffer[size] = 0;
|
2010-10-20 12:26:54 +02:00
|
|
|
ret = strtoul( buffer, NULL, 16 );
|
2007-12-08 19:53:24 +01:00
|
|
|
}
|
2010-10-20 12:26:54 +02:00
|
|
|
RtlFreeUnicodeString( &name );
|
|
|
|
return ret;
|
2007-12-08 19:53:24 +01:00
|
|
|
}
|
2004-04-17 02:30:09 +02:00
|
|
|
|
2004-04-24 01:31:58 +02:00
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
* VOLUME_FindCdRomDataBestVoldesc
|
|
|
|
*/
|
|
|
|
static DWORD VOLUME_FindCdRomDataBestVoldesc( HANDLE handle )
|
|
|
|
{
|
|
|
|
BYTE cur_vd_type, max_vd_type = 0;
|
2006-12-05 23:33:40 +01:00
|
|
|
BYTE buffer[0x800];
|
2004-03-09 02:03:03 +01:00
|
|
|
DWORD size, offs, best_offs = 0, extra_offs = 0;
|
|
|
|
|
|
|
|
for (offs = 0x8000; offs <= 0x9800; offs += 0x800)
|
|
|
|
{
|
|
|
|
/* if 'CDROM' occurs at position 8, this is a pre-iso9660 cd, and
|
|
|
|
* the volume label is displaced forward by 8
|
|
|
|
*/
|
|
|
|
if (SetFilePointer( handle, offs, NULL, FILE_BEGIN ) != offs) break;
|
|
|
|
if (!ReadFile( handle, buffer, sizeof(buffer), &size, NULL )) break;
|
|
|
|
if (size != sizeof(buffer)) break;
|
|
|
|
/* check for non-ISO9660 signature */
|
|
|
|
if (!memcmp( buffer + 11, "ROM", 3 )) extra_offs = 8;
|
|
|
|
cur_vd_type = buffer[extra_offs];
|
|
|
|
if (cur_vd_type == 0xff) /* voldesc set terminator */
|
|
|
|
break;
|
|
|
|
if (cur_vd_type > max_vd_type)
|
|
|
|
{
|
|
|
|
max_vd_type = cur_vd_type;
|
|
|
|
best_offs = offs + extra_offs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return best_offs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VOLUME_ReadFATSuperblock
|
|
|
|
*/
|
|
|
|
static enum fs_type VOLUME_ReadFATSuperblock( HANDLE handle, BYTE *buff )
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
/* try a fixed disk, with a FAT partition */
|
|
|
|
if (SetFilePointer( handle, 0, NULL, FILE_BEGIN ) != 0 ||
|
2007-12-08 19:53:24 +01:00
|
|
|
!ReadFile( handle, buff, SUPERBLOCK_SIZE, &size, NULL ))
|
2008-01-07 23:17:42 +01:00
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_BAD_DEV_TYPE) return FS_UNKNOWN; /* not a real device */
|
2004-03-09 02:03:03 +01:00
|
|
|
return FS_ERROR;
|
2008-01-07 23:17:42 +01:00
|
|
|
}
|
2004-03-09 02:03:03 +01:00
|
|
|
|
2007-12-08 19:53:24 +01:00
|
|
|
if (size < SUPERBLOCK_SIZE) return FS_UNKNOWN;
|
|
|
|
|
2004-10-28 23:00:36 +02:00
|
|
|
/* FIXME: do really all FAT have their name beginning with
|
|
|
|
* "FAT" ? (At least FAT12, FAT16 and FAT32 have :)
|
|
|
|
*/
|
|
|
|
if (!memcmp(buff+0x36, "FAT", 3) || !memcmp(buff+0x52, "FAT", 3))
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
|
|
|
/* guess which type of FAT we have */
|
2004-10-28 23:00:36 +02:00
|
|
|
int reasonable;
|
|
|
|
unsigned int sectors,
|
|
|
|
sect_per_fat,
|
|
|
|
total_sectors,
|
|
|
|
num_boot_sectors,
|
|
|
|
num_fats,
|
|
|
|
num_root_dir_ents,
|
|
|
|
bytes_per_sector,
|
|
|
|
sectors_per_cluster,
|
|
|
|
nclust;
|
|
|
|
sect_per_fat = GETWORD(buff, 0x16);
|
|
|
|
if (!sect_per_fat) sect_per_fat = GETLONG(buff, 0x24);
|
|
|
|
total_sectors = GETWORD(buff, 0x13);
|
|
|
|
if (!total_sectors)
|
|
|
|
total_sectors = GETLONG(buff, 0x20);
|
|
|
|
num_boot_sectors = GETWORD(buff, 0x0e);
|
|
|
|
num_fats = buff[0x10];
|
|
|
|
num_root_dir_ents = GETWORD(buff, 0x11);
|
|
|
|
bytes_per_sector = GETWORD(buff, 0x0b);
|
|
|
|
sectors_per_cluster = buff[0x0d];
|
|
|
|
/* check if the parameters are reasonable and will not cause
|
|
|
|
* arithmetic errors in the calculation */
|
2008-03-01 00:12:09 +01:00
|
|
|
reasonable = num_boot_sectors < total_sectors &&
|
2004-10-28 23:00:36 +02:00
|
|
|
num_fats < 16 &&
|
|
|
|
bytes_per_sector >= 512 && bytes_per_sector % 512 == 0 &&
|
2010-10-25 12:40:54 +02:00
|
|
|
sectors_per_cluster >= 1;
|
2004-10-28 23:00:36 +02:00
|
|
|
if (!reasonable) return FS_UNKNOWN;
|
|
|
|
sectors = total_sectors - num_boot_sectors - num_fats * sect_per_fat -
|
|
|
|
(num_root_dir_ents * 32 + bytes_per_sector - 1) / bytes_per_sector;
|
|
|
|
nclust = sectors / sectors_per_cluster;
|
|
|
|
if ((buff[0x42] == 0x28 || buff[0x42] == 0x29) &&
|
|
|
|
!memcmp(buff+0x52, "FAT", 3)) return FS_FAT32;
|
2004-03-09 02:03:03 +01:00
|
|
|
if (nclust < 65525)
|
|
|
|
{
|
2004-10-28 23:00:36 +02:00
|
|
|
if ((buff[0x26] == 0x28 || buff[0x26] == 0x29) &&
|
|
|
|
!memcmp(buff+0x36, "FAT", 3))
|
2004-03-09 02:03:03 +01:00
|
|
|
return FS_FAT1216;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* VOLUME_ReadCDBlock
|
|
|
|
*/
|
|
|
|
static BOOL VOLUME_ReadCDBlock( HANDLE handle, BYTE *buff, INT offs )
|
|
|
|
{
|
|
|
|
DWORD size, whence = offs >= 0 ? FILE_BEGIN : FILE_END;
|
|
|
|
|
|
|
|
if (SetFilePointer( handle, offs, NULL, whence ) != offs ||
|
|
|
|
!ReadFile( handle, buff, SUPERBLOCK_SIZE, &size, NULL ) ||
|
|
|
|
size != SUPERBLOCK_SIZE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* VOLUME_ReadCDSuperblock
|
|
|
|
*/
|
|
|
|
static enum fs_type VOLUME_ReadCDSuperblock( HANDLE handle, BYTE *buff )
|
|
|
|
{
|
2011-09-01 16:30:15 +02:00
|
|
|
int i;
|
|
|
|
DWORD offs;
|
|
|
|
|
|
|
|
/* Check UDF first as UDF and ISO9660 structures can coexist on the same medium
|
|
|
|
* Starting from sector 16, we may find :
|
|
|
|
* - a CD-ROM Volume Descriptor Set (ISO9660) containing one or more Volume Descriptors
|
|
|
|
* - an Extented Area (UDF) -- [E] 2/8.3.1 and [U] 2.1.7
|
|
|
|
* There is no explicit end so read 16 sectors and then give up */
|
|
|
|
for( i=16; i<16+16; i++)
|
|
|
|
{
|
|
|
|
if (!VOLUME_ReadCDBlock(handle, buff, i*BLOCK_SIZE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We are supposed to check "BEA01", "NSR0x" and "TEA01" IDs + verify tag checksum
|
|
|
|
* but we assume the volume is well-formatted */
|
|
|
|
if (!memcmp(&buff[1], "BEA01", 5)) return FS_UDF;
|
|
|
|
}
|
2004-03-09 02:03:03 +01:00
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
offs = VOLUME_FindCdRomDataBestVoldesc( handle );
|
2004-03-09 02:03:03 +01:00
|
|
|
if (!offs) return FS_UNKNOWN;
|
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
if (!VOLUME_ReadCDBlock(handle, buff, offs))
|
2004-03-09 02:03:03 +01:00
|
|
|
return FS_ERROR;
|
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
/* check for the iso9660 identifier */
|
2004-03-09 02:03:03 +01:00
|
|
|
if (!memcmp(&buff[1], "CD001", 5)) return FS_ISO9660;
|
|
|
|
return FS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* UDF_Find_PVD
|
|
|
|
* Find the Primary Volume Descriptor
|
|
|
|
*/
|
|
|
|
static BOOL UDF_Find_PVD( HANDLE handle, BYTE pvd[] )
|
|
|
|
{
|
2013-02-11 23:44:12 +01:00
|
|
|
unsigned int i;
|
2011-09-01 16:30:15 +02:00
|
|
|
DWORD offset;
|
|
|
|
INT locations[] = { 256, -1, -257, 512 };
|
|
|
|
|
|
|
|
for(i=0; i<sizeof(locations)/sizeof(locations[0]); i++)
|
|
|
|
{
|
|
|
|
if (!VOLUME_ReadCDBlock(handle, pvd, locations[i]*BLOCK_SIZE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Tag Identifier of Anchor Volume Descriptor Pointer is 2 -- [E] 3/10.2.1 */
|
|
|
|
if (pvd[0]==2 && pvd[1]==0)
|
|
|
|
{
|
|
|
|
/* Tag location (Uint32) at offset 12, little-endian */
|
|
|
|
offset = pvd[20 + 0];
|
|
|
|
offset |= pvd[20 + 1] << 8;
|
|
|
|
offset |= pvd[20 + 2] << 16;
|
|
|
|
offset |= pvd[20 + 3] << 24;
|
|
|
|
offset *= BLOCK_SIZE;
|
|
|
|
|
|
|
|
if (!VOLUME_ReadCDBlock(handle, pvd, offset))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Check for the Primary Volume Descriptor Tag Id -- [E] 3/10.1.1 */
|
|
|
|
if (pvd[0]!=1 || pvd[1]!=0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* 8 or 16 bits per character -- [U] 2.1.1 */
|
|
|
|
if (!(pvd[24]==8 || pvd[24]==16))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* VOLUME_GetSuperblockLabel
|
|
|
|
*/
|
2011-09-01 16:30:15 +02:00
|
|
|
static void VOLUME_GetSuperblockLabel( const UNICODE_STRING *device, HANDLE handle,
|
|
|
|
enum fs_type type, const BYTE *superblock,
|
|
|
|
WCHAR *label, DWORD len )
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
|
|
|
const BYTE *label_ptr = NULL;
|
|
|
|
DWORD label_len;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FS_ERROR:
|
|
|
|
label_len = 0;
|
|
|
|
break;
|
2007-12-08 19:53:24 +01:00
|
|
|
case FS_UNKNOWN:
|
|
|
|
get_filesystem_label( device, label, len );
|
|
|
|
return;
|
2004-03-09 02:03:03 +01:00
|
|
|
case FS_FAT1216:
|
|
|
|
label_ptr = superblock + 0x2b;
|
|
|
|
label_len = 11;
|
|
|
|
break;
|
|
|
|
case FS_FAT32:
|
|
|
|
label_ptr = superblock + 0x47;
|
|
|
|
label_len = 11;
|
|
|
|
break;
|
|
|
|
case FS_ISO9660:
|
|
|
|
{
|
|
|
|
BYTE ver = superblock[0x5a];
|
|
|
|
|
|
|
|
if (superblock[0x58] == 0x25 && superblock[0x59] == 0x2f && /* Unicode ID */
|
|
|
|
((ver == 0x40) || (ver == 0x43) || (ver == 0x45)))
|
|
|
|
{ /* yippee, unicode */
|
2004-08-11 01:43:21 +02:00
|
|
|
unsigned int i;
|
2004-03-09 02:03:03 +01:00
|
|
|
|
|
|
|
if (len > 17) len = 17;
|
|
|
|
for (i = 0; i < len-1; i++)
|
|
|
|
label[i] = (superblock[40+2*i] << 8) | superblock[41+2*i];
|
|
|
|
label[i] = 0;
|
|
|
|
while (i && label[i-1] == ' ') label[--i] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
label_ptr = superblock + 40;
|
|
|
|
label_len = 32;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-01 16:30:15 +02:00
|
|
|
case FS_UDF:
|
|
|
|
{
|
|
|
|
BYTE pvd[BLOCK_SIZE];
|
|
|
|
|
|
|
|
if(!UDF_Find_PVD(handle, pvd))
|
|
|
|
{
|
|
|
|
label_len = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [E] 3/10.1.4 and [U] 2.1.1 */
|
|
|
|
if(pvd[24]==8)
|
|
|
|
{
|
|
|
|
label_ptr = pvd + 24 + 1;
|
|
|
|
label_len = pvd[24+32-1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 23:44:12 +01:00
|
|
|
unsigned int i;
|
2011-09-01 16:30:15 +02:00
|
|
|
|
|
|
|
label_len = 1 + pvd[24+32-1];
|
|
|
|
for(i=0; i<label_len && i<len; i+=2)
|
|
|
|
label[i/2] = (pvd[24+1 +i] << 8) | pvd[24+1 +i+1];
|
|
|
|
label[label_len] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
|
|
|
if (label_len) RtlMultiByteToUnicodeN( label, (len-1) * sizeof(WCHAR),
|
2006-09-14 18:39:53 +02:00
|
|
|
&label_len, (LPCSTR)label_ptr, label_len );
|
2004-03-09 02:03:03 +01:00
|
|
|
label_len /= sizeof(WCHAR);
|
|
|
|
label[label_len] = 0;
|
|
|
|
while (label_len && label[label_len-1] == ' ') label[--label_len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-08 10:55:19 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* UDF_Find_FSD_Sector
|
|
|
|
* Find the File Set Descriptor used to compute the serial of a UDF volume
|
|
|
|
*/
|
|
|
|
static int UDF_Find_FSD_Sector( HANDLE handle, BYTE block[] )
|
|
|
|
{
|
|
|
|
int i, PVD_sector, PD_sector, PD_length;
|
|
|
|
|
|
|
|
if(!UDF_Find_PVD(handle,block))
|
|
|
|
goto default_sector;
|
|
|
|
|
|
|
|
/* Retrieve the tag location of the PVD -- [E] 3/7.2 */
|
|
|
|
PVD_sector = block[12 + 0];
|
|
|
|
PVD_sector |= block[12 + 1] << 8;
|
|
|
|
PVD_sector |= block[12 + 2] << 16;
|
|
|
|
PVD_sector |= block[12 + 3] << 24;
|
|
|
|
|
|
|
|
/* Find the Partition Descriptor */
|
|
|
|
for(i=PVD_sector+1; ; i++)
|
|
|
|
{
|
|
|
|
if(!VOLUME_ReadCDBlock(handle, block, i*BLOCK_SIZE))
|
|
|
|
goto default_sector;
|
|
|
|
|
|
|
|
/* Partition Descriptor Tag Id -- [E] 3/10.5.1 */
|
|
|
|
if(block[0]==5 && block[1]==0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Terminating Descriptor Tag Id -- [E] 3/10.9.1 */
|
|
|
|
if(block[0]==8 && block[1]==0)
|
|
|
|
goto default_sector;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the partition starting location -- [E] 3/10.5.8 */
|
|
|
|
PD_sector = block[188 + 0];
|
|
|
|
PD_sector |= block[188 + 1] << 8;
|
|
|
|
PD_sector |= block[188 + 2] << 16;
|
|
|
|
PD_sector |= block[188 + 3] << 24;
|
|
|
|
|
|
|
|
/* Find the partition length -- [E] 3/10.5.9 */
|
|
|
|
PD_length = block[192 + 0];
|
|
|
|
PD_length |= block[192 + 1] << 8;
|
|
|
|
PD_length |= block[192 + 2] << 16;
|
|
|
|
PD_length |= block[192 + 3] << 24;
|
|
|
|
|
|
|
|
for(i=PD_sector; i<PD_sector+PD_length; i++)
|
|
|
|
{
|
|
|
|
if(!VOLUME_ReadCDBlock(handle, block, i*BLOCK_SIZE))
|
|
|
|
goto default_sector;
|
|
|
|
|
|
|
|
/* File Set Descriptor Tag Id -- [E] 3/14.1.1 */
|
|
|
|
if(block[0]==0 && block[1]==1)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
default_sector:
|
|
|
|
WARN("FSD sector not found, serial may be incorrect\n");
|
|
|
|
return 257;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* VOLUME_GetSuperblockSerial
|
|
|
|
*/
|
2011-09-01 16:30:15 +02:00
|
|
|
static DWORD VOLUME_GetSuperblockSerial( const UNICODE_STRING *device, HANDLE handle,
|
|
|
|
enum fs_type type, const BYTE *superblock )
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
2012-12-08 10:55:19 +01:00
|
|
|
int FSD_sector;
|
2011-11-02 11:53:40 +01:00
|
|
|
BYTE block[BLOCK_SIZE];
|
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FS_ERROR:
|
|
|
|
break;
|
2007-12-08 19:53:24 +01:00
|
|
|
case FS_UNKNOWN:
|
|
|
|
return get_filesystem_serial( device );
|
2004-03-09 02:03:03 +01:00
|
|
|
case FS_FAT1216:
|
|
|
|
return GETLONG( superblock, 0x27 );
|
|
|
|
case FS_FAT32:
|
|
|
|
return GETLONG( superblock, 0x33 );
|
2011-09-01 16:30:15 +02:00
|
|
|
case FS_UDF:
|
2012-12-08 10:55:19 +01:00
|
|
|
FSD_sector = UDF_Find_FSD_Sector(handle, block);
|
|
|
|
if (!VOLUME_ReadCDBlock(handle, block, FSD_sector*BLOCK_SIZE))
|
2011-11-05 21:53:46 +01:00
|
|
|
break;
|
|
|
|
superblock = block;
|
|
|
|
/* fallthrough */
|
2004-03-09 02:03:03 +01:00
|
|
|
case FS_ISO9660:
|
|
|
|
{
|
|
|
|
BYTE sum[4];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sum[0] = sum[1] = sum[2] = sum[3] = 0;
|
|
|
|
for (i = 0; i < 2048; i += 4)
|
|
|
|
{
|
|
|
|
/* DON'T optimize this into DWORD !! (breaks overflow) */
|
|
|
|
sum[0] += superblock[i+0];
|
|
|
|
sum[1] += superblock[i+1];
|
|
|
|
sum[2] += superblock[i+2];
|
|
|
|
sum[3] += superblock[i+3];
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* OK, another braindead one... argh. Just believe it.
|
|
|
|
* Me$$ysoft chose to reverse the serial number in NT4/W2K.
|
|
|
|
* It's true and nobody will ever be able to change it.
|
|
|
|
*/
|
2011-09-09 01:45:30 +02:00
|
|
|
if ((GetVersion() & 0x80000000) || type == FS_UDF)
|
2004-03-09 02:03:03 +01:00
|
|
|
return (sum[3] << 24) | (sum[2] << 16) | (sum[1] << 8) | sum[0];
|
|
|
|
else
|
|
|
|
return (sum[0] << 24) | (sum[1] << 16) | (sum[2] << 8) | sum[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* VOLUME_GetAudioCDSerial
|
|
|
|
*/
|
|
|
|
static DWORD VOLUME_GetAudioCDSerial( const CDROM_TOC *toc )
|
|
|
|
{
|
|
|
|
DWORD serial = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i <= toc->LastTrack - toc->FirstTrack; i++)
|
|
|
|
serial += ((toc->TrackData[i].Address[1] << 16) |
|
|
|
|
(toc->TrackData[i].Address[2] << 8) |
|
|
|
|
toc->TrackData[i].Address[3]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dwStart, dwEnd collect the beginning and end of the disc respectively, in
|
|
|
|
* frames.
|
|
|
|
* There it is collected for correcting the serial when there are less than
|
|
|
|
* 3 tracks.
|
|
|
|
*/
|
|
|
|
if (toc->LastTrack - toc->FirstTrack + 1 < 3)
|
|
|
|
{
|
|
|
|
DWORD dwStart = FRAME_OF_TOC(toc, toc->FirstTrack);
|
|
|
|
DWORD dwEnd = FRAME_OF_TOC(toc, toc->LastTrack + 1);
|
|
|
|
serial += dwEnd - dwStart;
|
|
|
|
}
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumeInformationW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumeInformationW( LPCWSTR root, LPWSTR label, DWORD label_len,
|
|
|
|
DWORD *serial, DWORD *filename_len, DWORD *flags,
|
|
|
|
LPWSTR fsname, DWORD fsname_len )
|
|
|
|
{
|
|
|
|
static const WCHAR audiocdW[] = {'A','u','d','i','o',' ','C','D',0};
|
|
|
|
static const WCHAR fatW[] = {'F','A','T',0};
|
2008-03-01 00:12:09 +01:00
|
|
|
static const WCHAR fat32W[] = {'F','A','T','3','2',0};
|
2009-04-27 13:25:53 +02:00
|
|
|
static const WCHAR ntfsW[] = {'N','T','F','S',0};
|
2004-03-09 02:03:03 +01:00
|
|
|
static const WCHAR cdfsW[] = {'C','D','F','S',0};
|
2011-09-01 16:30:15 +02:00
|
|
|
static const WCHAR udfW[] = {'U','D','F',0};
|
2010-10-20 12:17:35 +02:00
|
|
|
static const WCHAR default_rootW[] = {'\\',0};
|
2004-03-09 02:03:03 +01:00
|
|
|
|
|
|
|
HANDLE handle;
|
2010-10-20 12:23:00 +02:00
|
|
|
NTSTATUS status;
|
2010-10-20 12:17:35 +02:00
|
|
|
UNICODE_STRING nt_name;
|
2010-10-20 12:23:00 +02:00
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2010-10-20 12:25:32 +02:00
|
|
|
FILE_FS_DEVICE_INFORMATION info;
|
2010-10-20 12:17:35 +02:00
|
|
|
WCHAR *p;
|
2004-03-09 02:03:03 +01:00
|
|
|
enum fs_type type = FS_UNKNOWN;
|
2010-10-20 12:17:35 +02:00
|
|
|
BOOL ret = FALSE;
|
2004-03-09 02:03:03 +01:00
|
|
|
|
2010-10-20 12:17:35 +02:00
|
|
|
if (!root) root = default_rootW;
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( root, &nt_name, NULL, NULL ))
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
2010-10-20 12:17:35 +02:00
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return FALSE;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
2010-10-20 12:17:35 +02:00
|
|
|
/* there must be exactly one backslash in the name, at the end */
|
|
|
|
p = memchrW( nt_name.Buffer + 4, '\\', (nt_name.Length - 4) / sizeof(WCHAR) );
|
|
|
|
if (p != nt_name.Buffer + nt_name.Length / sizeof(WCHAR) - 1)
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
2010-10-20 12:29:45 +02:00
|
|
|
/* check if root contains an explicit subdir */
|
|
|
|
if (root[0] && root[1] == ':') root += 2;
|
|
|
|
while (*root == '\\') root++;
|
|
|
|
if (strchrW( root, '\\' ))
|
|
|
|
SetLastError( ERROR_DIR_NOT_ROOT );
|
|
|
|
else
|
|
|
|
SetLastError( ERROR_INVALID_NAME );
|
2010-10-20 12:17:35 +02:00
|
|
|
goto done;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* try to open the device */
|
|
|
|
|
2010-10-20 12:23:00 +02:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
nt_name.Length -= sizeof(WCHAR); /* without trailing slash */
|
|
|
|
status = NtOpenFile( &handle, GENERIC_READ, &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
nt_name.Length += sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS)
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
|
|
|
BYTE superblock[SUPERBLOCK_SIZE];
|
|
|
|
CDROM_TOC toc;
|
|
|
|
DWORD br;
|
|
|
|
|
|
|
|
/* check for audio CD */
|
|
|
|
/* FIXME: we only check the first track for now */
|
|
|
|
if (DeviceIoControl( handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, 0 ))
|
|
|
|
{
|
|
|
|
if (!(toc.TrackData[0].Control & 0x04)) /* audio track */
|
|
|
|
{
|
2010-10-20 12:23:00 +02:00
|
|
|
TRACE( "%s: found audio CD\n", debugstr_w(nt_name.Buffer) );
|
2004-03-09 02:03:03 +01:00
|
|
|
if (label) lstrcpynW( label, audiocdW, label_len );
|
|
|
|
if (serial) *serial = VOLUME_GetAudioCDSerial( &toc );
|
|
|
|
CloseHandle( handle );
|
|
|
|
type = FS_ISO9660;
|
|
|
|
goto fill_fs_info;
|
|
|
|
}
|
|
|
|
type = VOLUME_ReadCDSuperblock( handle, superblock );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = VOLUME_ReadFATSuperblock( handle, superblock );
|
|
|
|
if (type == FS_UNKNOWN) type = VOLUME_ReadCDSuperblock( handle, superblock );
|
|
|
|
}
|
2010-10-20 12:23:00 +02:00
|
|
|
TRACE( "%s: found fs type %d\n", debugstr_w(nt_name.Buffer), type );
|
2011-09-01 16:30:15 +02:00
|
|
|
if (type == FS_ERROR)
|
|
|
|
{
|
|
|
|
CloseHandle( handle );
|
|
|
|
goto done;
|
|
|
|
}
|
2004-03-09 02:03:03 +01:00
|
|
|
|
2011-09-01 16:30:15 +02:00
|
|
|
if (label && label_len) VOLUME_GetSuperblockLabel( &nt_name, handle, type, superblock, label, label_len );
|
|
|
|
if (serial) *serial = VOLUME_GetSuperblockSerial( &nt_name, handle, type, superblock );
|
|
|
|
CloseHandle( handle );
|
2004-03-09 02:03:03 +01:00
|
|
|
goto fill_fs_info;
|
|
|
|
}
|
2010-11-04 16:43:21 +01:00
|
|
|
else TRACE( "cannot open device %s: %x\n", debugstr_w(nt_name.Buffer), status );
|
2004-03-09 02:03:03 +01:00
|
|
|
|
|
|
|
/* we couldn't open the device, fallback to default strategy */
|
|
|
|
|
2010-10-20 12:25:32 +02:00
|
|
|
status = NtOpenFile( &handle, 0, &attr, &io, 0, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
2010-10-20 12:25:32 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsDeviceInformation );
|
|
|
|
NtClose( handle );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2010-10-20 12:17:35 +02:00
|
|
|
goto done;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
2010-10-20 12:25:32 +02:00
|
|
|
if (info.DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) type = FS_ISO9660;
|
2004-03-09 02:03:03 +01:00
|
|
|
|
2010-10-20 12:26:54 +02:00
|
|
|
if (label && label_len) get_filesystem_label( &nt_name, label, label_len );
|
|
|
|
if (serial) *serial = get_filesystem_serial( &nt_name );
|
2004-03-09 02:03:03 +01:00
|
|
|
|
|
|
|
fill_fs_info: /* now fill in the information that depends on the file system type */
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FS_ISO9660:
|
|
|
|
if (fsname) lstrcpynW( fsname, cdfsW, fsname_len );
|
|
|
|
if (filename_len) *filename_len = 221;
|
|
|
|
if (flags) *flags = FILE_READ_ONLY_VOLUME;
|
|
|
|
break;
|
2011-09-01 16:30:15 +02:00
|
|
|
case FS_UDF:
|
|
|
|
if (fsname) lstrcpynW( fsname, udfW, fsname_len );
|
|
|
|
if (filename_len) *filename_len = 255;
|
|
|
|
if (flags)
|
|
|
|
*flags = FILE_READ_ONLY_VOLUME | FILE_UNICODE_ON_DISK | FILE_CASE_SENSITIVE_SEARCH;
|
|
|
|
break;
|
2004-03-09 02:03:03 +01:00
|
|
|
case FS_FAT1216:
|
|
|
|
if (fsname) lstrcpynW( fsname, fatW, fsname_len );
|
2008-03-01 00:12:09 +01:00
|
|
|
case FS_FAT32:
|
|
|
|
if (type == FS_FAT32 && fsname) lstrcpynW( fsname, fat32W, fsname_len );
|
2004-03-09 02:03:03 +01:00
|
|
|
if (filename_len) *filename_len = 255;
|
|
|
|
if (flags) *flags = FILE_CASE_PRESERVED_NAMES; /* FIXME */
|
|
|
|
break;
|
2004-05-03 22:22:07 +02:00
|
|
|
default:
|
2009-04-27 13:25:53 +02:00
|
|
|
if (fsname) lstrcpynW( fsname, ntfsW, fsname_len );
|
2004-05-03 22:22:07 +02:00
|
|
|
if (filename_len) *filename_len = 255;
|
2012-09-19 16:03:46 +02:00
|
|
|
if (flags) *flags = FILE_CASE_PRESERVED_NAMES | FILE_PERSISTENT_ACLS;
|
2004-05-03 22:22:07 +02:00
|
|
|
break;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
2010-10-20 12:17:35 +02:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
return ret;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumeInformationA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumeInformationA( LPCSTR root, LPSTR label,
|
2004-05-13 22:21:25 +02:00
|
|
|
DWORD label_len, DWORD *serial,
|
|
|
|
DWORD *filename_len, DWORD *flags,
|
|
|
|
LPSTR fsname, DWORD fsname_len )
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *rootW = NULL;
|
2004-03-09 02:03:03 +01:00
|
|
|
LPWSTR labelW, fsnameW;
|
|
|
|
BOOL ret;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
|
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
labelW = label ? HeapAlloc(GetProcessHeap(), 0, label_len * sizeof(WCHAR)) : NULL;
|
|
|
|
fsnameW = fsname ? HeapAlloc(GetProcessHeap(), 0, fsname_len * sizeof(WCHAR)) : NULL;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if ((ret = GetVolumeInformationW(rootW, labelW, label_len, serial,
|
2004-03-09 02:03:03 +01:00
|
|
|
filename_len, flags, fsnameW, fsname_len)))
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
if (label) FILE_name_WtoA( labelW, -1, label, label_len );
|
|
|
|
if (fsname) FILE_name_WtoA( fsnameW, -1, fsname, fsname_len );
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, labelW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, fsnameW );
|
2004-03-09 02:03:03 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetVolumeLabelW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label )
|
|
|
|
{
|
|
|
|
WCHAR device[] = {'\\','\\','.','\\','A',':',0};
|
|
|
|
HANDLE handle;
|
|
|
|
enum fs_type type = FS_UNKNOWN;
|
|
|
|
|
|
|
|
if (!root)
|
|
|
|
{
|
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
GetCurrentDirectoryW( MAX_PATH, path );
|
|
|
|
device[4] = path[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!root[0] || root[1] != ':')
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_NAME );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
device[4] = root[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to open the device */
|
|
|
|
|
2005-11-22 16:03:27 +01:00
|
|
|
handle = CreateFileW( device, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
2004-03-09 02:03:03 +01:00
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
if (handle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
BYTE superblock[SUPERBLOCK_SIZE];
|
|
|
|
|
|
|
|
type = VOLUME_ReadFATSuperblock( handle, superblock );
|
2005-11-22 16:03:27 +01:00
|
|
|
if (type == FS_UNKNOWN) type = VOLUME_ReadCDSuperblock( handle, superblock );
|
2004-03-09 02:03:03 +01:00
|
|
|
CloseHandle( handle );
|
2005-11-22 16:03:27 +01:00
|
|
|
if (type != FS_UNKNOWN)
|
|
|
|
{
|
|
|
|
/* we can't set the label on FAT or CDROM file systems */
|
|
|
|
TRACE( "cannot set label on device %s type %d\n", debugstr_w(device), type );
|
|
|
|
SetLastError( ERROR_ACCESS_DENIED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE( "cannot open device %s: err %d\n", debugstr_w(device), GetLastError() );
|
2005-02-15 16:47:58 +01:00
|
|
|
if (GetLastError() == ERROR_ACCESS_DENIED) return FALSE;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we couldn't open the device, fallback to default strategy */
|
|
|
|
|
|
|
|
switch(GetDriveTypeW( root ))
|
|
|
|
{
|
|
|
|
case DRIVE_UNKNOWN:
|
|
|
|
case DRIVE_NO_ROOT_DIR:
|
|
|
|
SetLastError( ERROR_NOT_READY );
|
|
|
|
break;
|
|
|
|
case DRIVE_REMOVABLE:
|
|
|
|
case DRIVE_FIXED:
|
|
|
|
{
|
|
|
|
WCHAR labelW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
|
|
|
|
|
|
|
|
labelW[0] = device[4];
|
2008-10-17 14:12:19 +02:00
|
|
|
|
|
|
|
if (!label[0]) /* delete label file when setting an empty label */
|
|
|
|
return DeleteFileW( labelW ) || GetLastError() == ERROR_FILE_NOT_FOUND;
|
|
|
|
|
2004-03-09 02:03:03 +01:00
|
|
|
handle = CreateFileW( labelW, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
|
|
|
CREATE_ALWAYS, 0, 0 );
|
|
|
|
if (handle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
char buffer[64];
|
|
|
|
DWORD size;
|
|
|
|
|
2008-10-17 14:12:19 +02:00
|
|
|
if (!WideCharToMultiByte( CP_UNIXCP, 0, label, -1, buffer, sizeof(buffer)-1, NULL, NULL ))
|
|
|
|
buffer[sizeof(buffer)-2] = 0;
|
|
|
|
strcat( buffer, "\n" );
|
2004-03-09 02:03:03 +01:00
|
|
|
WriteFile( handle, buffer, strlen(buffer), &size, NULL );
|
|
|
|
CloseHandle( handle );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DRIVE_REMOTE:
|
|
|
|
case DRIVE_RAMDISK:
|
|
|
|
case DRIVE_CDROM:
|
|
|
|
SetLastError( ERROR_ACCESS_DENIED );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetVolumeLabelA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetVolumeLabelA(LPCSTR root, LPCSTR volname)
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *rootW = NULL, *volnameW = NULL;
|
2004-03-09 02:03:03 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
|
|
|
|
if (volname && !(volnameW = FILE_name_AtoW( volname, TRUE ))) return FALSE;
|
|
|
|
ret = SetVolumeLabelW( rootW, volnameW );
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, volnameW );
|
2004-03-09 02:03:03 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2007-01-07 13:08:31 +01:00
|
|
|
* GetVolumeNameForVolumeMountPointA (KERNEL32.@)
|
2004-03-09 02:03:03 +01:00
|
|
|
*/
|
2007-01-07 13:08:31 +01:00
|
|
|
BOOL WINAPI GetVolumeNameForVolumeMountPointA( LPCSTR path, LPSTR volume, DWORD size )
|
2004-03-09 02:03:03 +01:00
|
|
|
{
|
2007-01-07 13:08:31 +01:00
|
|
|
BOOL ret;
|
|
|
|
WCHAR volumeW[50], *pathW = NULL;
|
|
|
|
DWORD len = min( sizeof(volumeW) / sizeof(WCHAR), size );
|
|
|
|
|
|
|
|
TRACE("(%s, %p, %x)\n", debugstr_a(path), volume, size);
|
|
|
|
|
|
|
|
if (!path || !(pathW = FILE_name_AtoW( path, TRUE )))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((ret = GetVolumeNameForVolumeMountPointW( pathW, volumeW, len )))
|
|
|
|
FILE_name_WtoA( volumeW, -1, volume, len );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, pathW );
|
|
|
|
return ret;
|
2004-03-09 02:03:03 +01:00
|
|
|
}
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2007-01-07 13:08:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumeNameForVolumeMountPointW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumeNameForVolumeMountPointW( LPCWSTR path, LPWSTR volume, DWORD size )
|
|
|
|
{
|
2009-05-24 05:45:07 +02:00
|
|
|
static const WCHAR prefixW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
|
2013-08-28 06:36:48 +02:00
|
|
|
static const WCHAR volumeW[] = {'\\','?','?','\\','V','o','l','u','m','e','{'};
|
2009-05-24 05:45:07 +02:00
|
|
|
static const WCHAR trailingW[] = {'\\',0};
|
|
|
|
|
|
|
|
MOUNTMGR_MOUNT_POINT *input = NULL, *o1;
|
|
|
|
MOUNTMGR_MOUNT_POINTS *output = NULL;
|
|
|
|
WCHAR *p;
|
|
|
|
char *r;
|
|
|
|
DWORD i, i_size = 1024, o_size = 1024;
|
2009-10-22 14:57:24 +02:00
|
|
|
WCHAR *nonpersist_name;
|
2009-05-24 05:45:07 +02:00
|
|
|
WCHAR symlink_name[MAX_PATH];
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE mgr = INVALID_HANDLE_VALUE;
|
2007-01-07 13:08:31 +01:00
|
|
|
BOOL ret = FALSE;
|
2014-07-19 20:53:10 +02:00
|
|
|
DWORD br;
|
2007-01-07 13:08:31 +01:00
|
|
|
|
|
|
|
TRACE("(%s, %p, %x)\n", debugstr_w(path), volume, size);
|
2009-05-24 05:45:07 +02:00
|
|
|
if (path[lstrlenW(path)-1] != '\\')
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_NAME );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < 50)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* if length of input is > 3 then it must be a mounted folder */
|
|
|
|
if (lstrlenW(path) > 3)
|
|
|
|
{
|
|
|
|
FIXME("Mounted Folders are not yet supported\n");
|
|
|
|
SetLastError( ERROR_NOT_A_REPARSE_POINT );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
if (mgr == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
|
|
|
if (!(input = HeapAlloc( GetProcessHeap(), 0, i_size )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
goto err_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(output = HeapAlloc( GetProcessHeap(), 0, o_size )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
goto err_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the symlink name as "\DosDevices\C:" */
|
|
|
|
lstrcpyW( symlink_name, prefixW );
|
|
|
|
lstrcatW( symlink_name, path );
|
|
|
|
symlink_name[lstrlenW(symlink_name)-1] = 0;
|
|
|
|
|
|
|
|
/* Take the mount point and get the "nonpersistent name" */
|
|
|
|
/* We will then take that and get the volume name */
|
2009-10-22 14:57:24 +02:00
|
|
|
nonpersist_name = (WCHAR *)(input + 1);
|
|
|
|
status = read_nt_symlink( symlink_name, nonpersist_name, i_size - sizeof(*input) );
|
2009-05-24 05:45:07 +02:00
|
|
|
TRACE("read_nt_symlink got stat=%x, for %s, got <%s>\n", status,
|
|
|
|
debugstr_w(symlink_name), debugstr_w(nonpersist_name));
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
|
|
|
goto err_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now take the "nonpersistent name" and ask the mountmgr */
|
|
|
|
/* to give us all the mount points. One of them will be */
|
|
|
|
/* the volume name (format of \??\Volume{). */
|
|
|
|
memset( input, 0, sizeof(*input) ); /* clear all input parameters */
|
|
|
|
input->DeviceNameOffset = sizeof(*input);
|
|
|
|
input->DeviceNameLength = lstrlenW( nonpersist_name) * sizeof(WCHAR);
|
2009-10-22 14:57:24 +02:00
|
|
|
i_size = input->DeviceNameOffset + input->DeviceNameLength;
|
2009-05-24 05:45:07 +02:00
|
|
|
|
|
|
|
output->Size = o_size;
|
|
|
|
|
|
|
|
/* now get the true volume name from the mountmgr */
|
|
|
|
if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_POINTS, input, i_size,
|
2014-07-19 20:53:10 +02:00
|
|
|
output, o_size, &br, NULL ))
|
2009-05-24 05:45:07 +02:00
|
|
|
goto err_ret;
|
2007-01-07 13:08:31 +01:00
|
|
|
|
2009-05-24 05:45:07 +02:00
|
|
|
/* Verify and return the data, note string is not null terminated */
|
|
|
|
TRACE("found %d matching mount points\n", output->NumberOfMountPoints);
|
|
|
|
if (output->NumberOfMountPoints < 1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NO_VOLUME_ID );
|
|
|
|
goto err_ret;
|
|
|
|
}
|
|
|
|
o1 = &output->MountPoints[0];
|
2007-01-07 13:08:31 +01:00
|
|
|
|
2009-05-24 05:45:07 +02:00
|
|
|
/* look for the volume name in returned values */
|
|
|
|
for(i=0;i<output->NumberOfMountPoints;i++)
|
2007-01-07 13:08:31 +01:00
|
|
|
{
|
2009-05-24 05:45:07 +02:00
|
|
|
p = (WCHAR*)((char *)output + o1->SymbolicLinkNameOffset);
|
|
|
|
r = (char *)output + o1->UniqueIdOffset;
|
|
|
|
TRACE("found symlink=%s, unique=%s, devname=%s\n",
|
|
|
|
debugstr_wn(p, o1->SymbolicLinkNameLength/sizeof(WCHAR)),
|
|
|
|
debugstr_an(r, o1->UniqueIdLength),
|
|
|
|
debugstr_wn((WCHAR*)((char *)output + o1->DeviceNameOffset),
|
|
|
|
o1->DeviceNameLength/sizeof(WCHAR)));
|
|
|
|
|
2013-08-28 06:36:48 +02:00
|
|
|
if (!strncmpW( p, volumeW, sizeof(volumeW)/sizeof(WCHAR) ))
|
2009-05-24 05:45:07 +02:00
|
|
|
{
|
|
|
|
/* is there space in the return variable ?? */
|
|
|
|
if ((o1->SymbolicLinkNameLength/sizeof(WCHAR))+2 > size)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
goto err_ret;
|
|
|
|
}
|
|
|
|
memcpy( volume, p, o1->SymbolicLinkNameLength );
|
|
|
|
volume[o1->SymbolicLinkNameLength / sizeof(WCHAR)] = 0;
|
|
|
|
lstrcatW( volume, trailingW );
|
|
|
|
/* change second char from '?' to '\' */
|
|
|
|
volume[1] = '\\';
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
o1++;
|
2007-01-07 13:08:31 +01:00
|
|
|
}
|
2009-05-24 05:45:07 +02:00
|
|
|
|
|
|
|
err_ret:
|
|
|
|
HeapFree( GetProcessHeap(), 0, input );
|
|
|
|
HeapFree( GetProcessHeap(), 0, output );
|
|
|
|
CloseHandle( mgr );
|
2007-01-07 13:08:31 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2004-03-20 03:28:51 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DefineDosDeviceW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DefineDosDeviceW( DWORD flags, LPCWSTR devname, LPCWSTR targetpath )
|
|
|
|
{
|
2004-03-30 23:00:07 +02:00
|
|
|
DWORD len, dosdev;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
char *path = NULL, *target, *p;
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%x, %s, %s\n", flags, debugstr_w(devname), debugstr_w(targetpath));
|
2005-10-10 12:44:35 +02:00
|
|
|
|
2004-04-27 04:43:40 +02:00
|
|
|
if (!(flags & DDD_REMOVE_DEFINITION))
|
2004-03-20 03:28:51 +01:00
|
|
|
{
|
2004-04-27 04:43:40 +02:00
|
|
|
if (!(flags & DDD_RAW_TARGET_PATH))
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME( "(0x%08x,%s,%s) DDD_RAW_TARGET_PATH flag not set, not supported yet\n",
|
2004-04-27 04:43:40 +02:00
|
|
|
flags, debugstr_w(devname), debugstr_w(targetpath) );
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2004-04-27 04:43:40 +02:00
|
|
|
len = WideCharToMultiByte( CP_UNIXCP, 0, targetpath, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((target = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, targetpath, -1, target, len, NULL, NULL );
|
|
|
|
for (p = target; *p; p++) if (*p == '\\') *p = '/';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-30 23:00:07 +02:00
|
|
|
}
|
2004-04-27 04:43:40 +02:00
|
|
|
else target = NULL;
|
2004-03-30 23:00:07 +02:00
|
|
|
|
2004-03-20 03:28:51 +01:00
|
|
|
/* first check for a DOS device */
|
|
|
|
|
|
|
|
if ((dosdev = RtlIsDosDeviceName_U( devname )))
|
|
|
|
{
|
|
|
|
WCHAR name[5];
|
|
|
|
|
|
|
|
memcpy( name, devname + HIWORD(dosdev)/sizeof(WCHAR), LOWORD(dosdev) );
|
|
|
|
name[LOWORD(dosdev)/sizeof(WCHAR)] = 0;
|
2004-03-30 23:00:07 +02:00
|
|
|
path = get_dos_device_path( name );
|
|
|
|
}
|
|
|
|
else if (isalphaW(devname[0]) && devname[1] == ':' && !devname[2]) /* drive mapping */
|
|
|
|
{
|
|
|
|
path = get_dos_device_path( devname );
|
|
|
|
}
|
|
|
|
else SetLastError( ERROR_FILE_NOT_FOUND );
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2004-03-30 23:00:07 +02:00
|
|
|
if (path)
|
|
|
|
{
|
2004-04-27 04:43:40 +02:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
TRACE( "creating symlink %s -> %s\n", path, target );
|
|
|
|
unlink( path );
|
|
|
|
if (!symlink( target, path )) ret = TRUE;
|
|
|
|
else FILE_SetDosError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "removing symlink %s\n", path );
|
|
|
|
if (!unlink( path )) ret = TRUE;
|
|
|
|
else FILE_SetDosError();
|
|
|
|
}
|
2004-03-20 03:28:51 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, path );
|
|
|
|
}
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, target );
|
2004-03-30 23:00:07 +02:00
|
|
|
return ret;
|
2004-03-20 03:28:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DefineDosDeviceA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DefineDosDeviceA(DWORD flags, LPCSTR devname, LPCSTR targetpath)
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *devW, *targetW = NULL;
|
2004-03-20 03:28:51 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (!(devW = FILE_name_AtoW( devname, FALSE ))) return FALSE;
|
|
|
|
if (targetpath && !(targetW = FILE_name_AtoW( targetpath, TRUE ))) return FALSE;
|
|
|
|
ret = DefineDosDeviceW(flags, devW, targetW);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, targetW );
|
2004-03-20 03:28:51 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QueryDosDeviceW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* returns array of strings terminated by \0, terminated by \0
|
|
|
|
*/
|
|
|
|
DWORD WINAPI QueryDosDeviceW( LPCWSTR devname, LPWSTR target, DWORD bufsize )
|
|
|
|
{
|
|
|
|
static const WCHAR auxW[] = {'A','U','X',0};
|
|
|
|
static const WCHAR nulW[] = {'N','U','L',0};
|
|
|
|
static const WCHAR prnW[] = {'P','R','N',0};
|
|
|
|
static const WCHAR comW[] = {'C','O','M',0};
|
|
|
|
static const WCHAR lptW[] = {'L','P','T',0};
|
2004-04-23 05:22:34 +02:00
|
|
|
static const WCHAR com0W[] = {'\\','?','?','\\','C','O','M','0',0};
|
2004-03-20 03:28:51 +01:00
|
|
|
static const WCHAR com1W[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','C','O','M','1',0,0};
|
|
|
|
static const WCHAR lpt1W[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','L','P','T','1',0,0};
|
2009-07-24 11:01:41 +02:00
|
|
|
static const WCHAR dosdevW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2004-04-23 05:22:34 +02:00
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
WCHAR nt_buffer[10];
|
|
|
|
NTSTATUS status;
|
2004-03-20 03:28:51 +01:00
|
|
|
|
|
|
|
if (!bufsize)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (devname)
|
|
|
|
{
|
|
|
|
WCHAR *p, name[5];
|
|
|
|
char *path, *link;
|
|
|
|
DWORD dosdev, ret = 0;
|
|
|
|
|
2004-03-30 23:00:07 +02:00
|
|
|
if ((dosdev = RtlIsDosDeviceName_U( devname )))
|
|
|
|
{
|
|
|
|
memcpy( name, devname + HIWORD(dosdev)/sizeof(WCHAR), LOWORD(dosdev) );
|
|
|
|
name[LOWORD(dosdev)/sizeof(WCHAR)] = 0;
|
|
|
|
}
|
2009-07-24 11:01:41 +02:00
|
|
|
else
|
2004-03-30 23:00:07 +02:00
|
|
|
{
|
2009-07-24 11:01:41 +02:00
|
|
|
WCHAR *buffer;
|
2008-10-23 20:24:49 +02:00
|
|
|
|
2009-07-24 11:01:41 +02:00
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(dosdevW) + strlenW(devname)*sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memcpy( buffer, dosdevW, sizeof(dosdevW) );
|
|
|
|
strcatW( buffer, devname );
|
|
|
|
status = read_nt_symlink( buffer, target, bufsize );
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
if (status)
|
2008-10-23 20:24:49 +02:00
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = strlenW( target ) + 1;
|
|
|
|
goto done;
|
2004-03-30 23:00:07 +02:00
|
|
|
}
|
2009-07-24 11:01:41 +02:00
|
|
|
|
|
|
|
/* FIXME: should read NT symlink for all devices */
|
2004-03-30 23:00:07 +02:00
|
|
|
|
2004-03-20 03:28:51 +01:00
|
|
|
if (!(path = get_dos_device_path( name ))) return 0;
|
|
|
|
link = read_symlink( path );
|
|
|
|
HeapFree( GetProcessHeap(), 0, path );
|
|
|
|
|
|
|
|
if (link)
|
|
|
|
{
|
|
|
|
ret = MultiByteToWideChar( CP_UNIXCP, 0, link, -1, target, bufsize );
|
|
|
|
HeapFree( GetProcessHeap(), 0, link );
|
|
|
|
}
|
2004-03-30 23:00:07 +02:00
|
|
|
else if (dosdev) /* look for device defaults */
|
2004-03-20 03:28:51 +01:00
|
|
|
{
|
|
|
|
if (!strcmpiW( name, auxW ))
|
|
|
|
{
|
|
|
|
if (bufsize >= sizeof(com1W)/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
memcpy( target, com1W, sizeof(com1W) );
|
|
|
|
ret = sizeof(com1W)/sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (!strcmpiW( name, prnW ))
|
|
|
|
{
|
|
|
|
if (bufsize >= sizeof(lpt1W)/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
memcpy( target, lpt1W, sizeof(lpt1W) );
|
|
|
|
ret = sizeof(lpt1W)/sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-23 05:22:34 +02:00
|
|
|
nt_buffer[0] = '\\';
|
|
|
|
nt_buffer[1] = '?';
|
|
|
|
nt_buffer[2] = '?';
|
|
|
|
nt_buffer[3] = '\\';
|
|
|
|
strcpyW( nt_buffer + 4, name );
|
|
|
|
RtlInitUnicodeString( &nt_name, nt_buffer );
|
2004-04-27 04:15:52 +02:00
|
|
|
status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE );
|
2004-04-23 05:22:34 +02:00
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
2004-03-20 03:28:51 +01:00
|
|
|
else
|
2004-04-23 05:22:34 +02:00
|
|
|
{
|
|
|
|
ret = MultiByteToWideChar( CP_UNIXCP, 0, unix_name.Buffer, -1, target, bufsize );
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
}
|
2004-03-20 03:28:51 +01:00
|
|
|
}
|
2008-10-23 20:24:49 +02:00
|
|
|
done:
|
2004-03-20 03:28:51 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret < bufsize) target[ret++] = 0; /* add an extra null */
|
|
|
|
for (p = target; *p; p++) if (*p == '/') *p = '\\';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else /* return a list of all devices */
|
|
|
|
{
|
2009-07-24 11:01:41 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
HANDLE handle;
|
2004-03-20 03:28:51 +01:00
|
|
|
WCHAR *p = target;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (bufsize <= (sizeof(auxW)+sizeof(nulW)+sizeof(prnW))/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-24 11:01:41 +02:00
|
|
|
/* FIXME: these should be NT symlinks too */
|
|
|
|
|
2004-03-20 03:28:51 +01:00
|
|
|
memcpy( p, auxW, sizeof(auxW) );
|
|
|
|
p += sizeof(auxW) / sizeof(WCHAR);
|
|
|
|
memcpy( p, nulW, sizeof(nulW) );
|
|
|
|
p += sizeof(nulW) / sizeof(WCHAR);
|
|
|
|
memcpy( p, prnW, sizeof(prnW) );
|
|
|
|
p += sizeof(prnW) / sizeof(WCHAR);
|
|
|
|
|
2004-04-23 05:22:34 +02:00
|
|
|
strcpyW( nt_buffer, com0W );
|
|
|
|
RtlInitUnicodeString( &nt_name, nt_buffer );
|
2004-03-20 03:28:51 +01:00
|
|
|
|
|
|
|
for (i = 1; i <= 9; i++)
|
|
|
|
{
|
2004-04-23 05:22:34 +02:00
|
|
|
nt_buffer[7] = '0' + i;
|
2004-04-27 04:15:52 +02:00
|
|
|
if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
|
2004-03-20 03:28:51 +01:00
|
|
|
{
|
2004-04-23 05:22:34 +02:00
|
|
|
RtlFreeAnsiString( &unix_name );
|
2004-03-20 03:28:51 +01:00
|
|
|
if (p + 5 >= target + bufsize)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpyW( p, comW );
|
|
|
|
p[3] = '0' + i;
|
|
|
|
p[4] = 0;
|
|
|
|
p += 5;
|
|
|
|
}
|
|
|
|
}
|
2004-04-23 05:22:34 +02:00
|
|
|
strcpyW( nt_buffer + 4, lptW );
|
2004-03-20 03:28:51 +01:00
|
|
|
for (i = 1; i <= 9; i++)
|
|
|
|
{
|
2004-04-23 05:22:34 +02:00
|
|
|
nt_buffer[7] = '0' + i;
|
2004-04-27 04:15:52 +02:00
|
|
|
if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
|
2004-03-20 03:28:51 +01:00
|
|
|
{
|
2004-04-23 05:22:34 +02:00
|
|
|
RtlFreeAnsiString( &unix_name );
|
2004-03-20 03:28:51 +01:00
|
|
|
if (p + 5 >= target + bufsize)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpyW( p, lptW );
|
|
|
|
p[3] = '0' + i;
|
|
|
|
p[4] = 0;
|
|
|
|
p += 5;
|
|
|
|
}
|
|
|
|
}
|
2004-04-23 05:22:34 +02:00
|
|
|
|
2009-07-24 11:01:41 +02:00
|
|
|
RtlInitUnicodeString( &nt_name, dosdevW );
|
|
|
|
nt_name.Length -= sizeof(WCHAR); /* without trailing slash */
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
status = NtOpenDirectoryObject( &handle, FILE_LIST_DIRECTORY, &attr );
|
|
|
|
if (!status)
|
2004-03-30 23:00:07 +02:00
|
|
|
{
|
2009-07-24 11:01:41 +02:00
|
|
|
char data[1024];
|
|
|
|
DIRECTORY_BASIC_INFORMATION *info = (DIRECTORY_BASIC_INFORMATION *)data;
|
|
|
|
ULONG ctx = 0, len;
|
2008-10-23 20:24:49 +02:00
|
|
|
|
2009-07-24 11:01:41 +02:00
|
|
|
while (!NtQueryDirectoryObject( handle, info, sizeof(data), 1, 0, &ctx, &len ))
|
2004-03-30 23:00:07 +02:00
|
|
|
{
|
2009-07-24 11:01:41 +02:00
|
|
|
if (p + info->ObjectName.Length/sizeof(WCHAR) + 1 >= target + bufsize)
|
2004-03-30 23:00:07 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2009-07-24 11:01:41 +02:00
|
|
|
NtClose( handle );
|
2004-03-30 23:00:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-07-24 11:01:41 +02:00
|
|
|
memcpy( p, info->ObjectName.Buffer, info->ObjectName.Length );
|
|
|
|
p += info->ObjectName.Length/sizeof(WCHAR);
|
2004-03-30 23:00:07 +02:00
|
|
|
*p++ = 0;
|
|
|
|
}
|
2009-07-24 11:01:41 +02:00
|
|
|
NtClose( handle );
|
2004-03-30 23:00:07 +02:00
|
|
|
}
|
2009-07-24 11:01:41 +02:00
|
|
|
|
2004-03-20 03:28:51 +01:00
|
|
|
*p++ = 0; /* terminating null */
|
|
|
|
return p - target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QueryDosDeviceA (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* returns array of strings terminated by \0, terminated by \0
|
|
|
|
*/
|
|
|
|
DWORD WINAPI QueryDosDeviceA( LPCSTR devname, LPSTR target, DWORD bufsize )
|
|
|
|
{
|
|
|
|
DWORD ret = 0, retW;
|
2005-02-26 18:46:34 +01:00
|
|
|
WCHAR *devnameW = NULL;
|
2004-05-13 22:21:25 +02:00
|
|
|
LPWSTR targetW;
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2005-02-26 18:46:34 +01:00
|
|
|
if (devname && !(devnameW = FILE_name_AtoW( devname, FALSE ))) return 0;
|
2004-05-13 22:21:25 +02:00
|
|
|
|
|
|
|
targetW = HeapAlloc( GetProcessHeap(),0, bufsize * sizeof(WCHAR) );
|
2004-03-20 03:28:51 +01:00
|
|
|
if (!targetW)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
retW = QueryDosDeviceW(devnameW, targetW, bufsize);
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
ret = FILE_name_WtoA( targetW, retW, target, bufsize );
|
2004-03-20 03:28:51 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, targetW);
|
|
|
|
return ret;
|
|
|
|
}
|
2004-04-17 02:30:09 +02:00
|
|
|
|
|
|
|
|
2004-04-24 01:31:58 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetLogicalDrives (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetLogicalDrives(void)
|
|
|
|
{
|
2012-07-28 16:14:15 +02:00
|
|
|
static const WCHAR dosdevW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
DWORD bitmask = 0;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle;
|
2004-04-24 01:31:58 +02:00
|
|
|
|
2012-07-28 16:14:15 +02:00
|
|
|
RtlInitUnicodeString( &nt_name, dosdevW );
|
|
|
|
nt_name.Length -= sizeof(WCHAR); /* without trailing slash */
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
status = NtOpenDirectoryObject( &handle, FILE_LIST_DIRECTORY, &attr );
|
|
|
|
if (!status)
|
2004-04-24 01:31:58 +02:00
|
|
|
{
|
2012-07-28 16:14:15 +02:00
|
|
|
char data[1024];
|
|
|
|
DIRECTORY_BASIC_INFORMATION *info = (DIRECTORY_BASIC_INFORMATION *)data;
|
|
|
|
ULONG ctx = 0, len;
|
2004-04-24 01:31:58 +02:00
|
|
|
|
2012-07-28 16:14:15 +02:00
|
|
|
while (!NtQueryDirectoryObject( handle, info, sizeof(data), 1, 0, &ctx, &len ))
|
|
|
|
if(info->ObjectName.Length == 2*sizeof(WCHAR) && info->ObjectName.Buffer[1] == ':')
|
|
|
|
bitmask |= 1 << (info->ObjectName.Buffer[0] - 'A');
|
|
|
|
|
|
|
|
NtClose( handle );
|
2004-04-24 01:31:58 +02:00
|
|
|
}
|
2012-07-28 16:14:15 +02:00
|
|
|
|
|
|
|
return bitmask;
|
2004-04-24 01:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetLogicalDriveStringsA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
UINT WINAPI GetLogicalDriveStringsA( UINT len, LPSTR buffer )
|
|
|
|
{
|
|
|
|
DWORD drives = GetLogicalDrives();
|
|
|
|
UINT drive, count;
|
|
|
|
|
|
|
|
for (drive = count = 0; drive < 26; drive++) if (drives & (1 << drive)) count++;
|
|
|
|
if ((count * 4) + 1 > len) return count * 4 + 1;
|
|
|
|
|
|
|
|
for (drive = 0; drive < 26; drive++)
|
|
|
|
{
|
|
|
|
if (drives & (1 << drive))
|
|
|
|
{
|
2008-10-15 17:24:13 +02:00
|
|
|
*buffer++ = 'A' + drive;
|
2004-04-24 01:31:58 +02:00
|
|
|
*buffer++ = ':';
|
|
|
|
*buffer++ = '\\';
|
|
|
|
*buffer++ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buffer = 0;
|
|
|
|
return count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetLogicalDriveStringsW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
UINT WINAPI GetLogicalDriveStringsW( UINT len, LPWSTR buffer )
|
|
|
|
{
|
|
|
|
DWORD drives = GetLogicalDrives();
|
|
|
|
UINT drive, count;
|
|
|
|
|
|
|
|
for (drive = count = 0; drive < 26; drive++) if (drives & (1 << drive)) count++;
|
|
|
|
if ((count * 4) + 1 > len) return count * 4 + 1;
|
|
|
|
|
|
|
|
for (drive = 0; drive < 26; drive++)
|
|
|
|
{
|
|
|
|
if (drives & (1 << drive))
|
|
|
|
{
|
2008-10-15 17:24:13 +02:00
|
|
|
*buffer++ = 'A' + drive;
|
2004-04-24 01:31:58 +02:00
|
|
|
*buffer++ = ':';
|
|
|
|
*buffer++ = '\\';
|
|
|
|
*buffer++ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buffer = 0;
|
|
|
|
return count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetDriveTypeW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Returns the type of the disk drive specified. If root is NULL the
|
|
|
|
* root of the current directory is used.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* Type of drive (from Win32 SDK):
|
|
|
|
*
|
|
|
|
* DRIVE_UNKNOWN unable to find out anything about the drive
|
|
|
|
* DRIVE_NO_ROOT_DIR nonexistent root dir
|
|
|
|
* DRIVE_REMOVABLE the disk can be removed from the machine
|
2005-05-06 17:44:31 +02:00
|
|
|
* DRIVE_FIXED the disk cannot be removed from the machine
|
2004-04-24 01:31:58 +02:00
|
|
|
* DRIVE_REMOTE network disk
|
|
|
|
* DRIVE_CDROM CDROM drive
|
|
|
|
* DRIVE_RAMDISK virtual disk in RAM
|
|
|
|
*/
|
|
|
|
UINT WINAPI GetDriveTypeW(LPCWSTR root) /* [in] String describing drive */
|
|
|
|
{
|
|
|
|
FILE_FS_DEVICE_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle;
|
|
|
|
UINT ret;
|
|
|
|
|
2015-03-30 03:03:03 +02:00
|
|
|
if (!open_device_root( root, &handle ))
|
|
|
|
{
|
|
|
|
/* CD ROM devices do not necessarily have a volume, but a drive type */
|
|
|
|
ret = get_mountmgr_drive_type( root );
|
|
|
|
if (ret == DRIVE_CDROM || ret == DRIVE_REMOVABLE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return DRIVE_NO_ROOT_DIR;
|
|
|
|
}
|
2004-04-24 01:31:58 +02:00
|
|
|
|
|
|
|
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsDeviceInformation );
|
|
|
|
NtClose( handle );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
ret = DRIVE_UNKNOWN;
|
|
|
|
}
|
2008-11-10 16:28:37 +01:00
|
|
|
else
|
2004-04-24 01:31:58 +02:00
|
|
|
{
|
|
|
|
switch (info.DeviceType)
|
|
|
|
{
|
|
|
|
case FILE_DEVICE_CD_ROM_FILE_SYSTEM: ret = DRIVE_CDROM; break;
|
|
|
|
case FILE_DEVICE_VIRTUAL_DISK: ret = DRIVE_RAMDISK; break;
|
|
|
|
case FILE_DEVICE_NETWORK_FILE_SYSTEM: ret = DRIVE_REMOTE; break;
|
|
|
|
case FILE_DEVICE_DISK_FILE_SYSTEM:
|
|
|
|
if (info.Characteristics & FILE_REMOTE_DEVICE) ret = DRIVE_REMOTE;
|
|
|
|
else if (info.Characteristics & FILE_REMOVABLE_MEDIA) ret = DRIVE_REMOVABLE;
|
2008-11-10 16:28:37 +01:00
|
|
|
else if ((ret = get_mountmgr_drive_type( root )) == DRIVE_UNKNOWN) ret = DRIVE_FIXED;
|
2004-04-24 01:31:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = DRIVE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE( "%s -> %d\n", debugstr_w(root), ret );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetDriveTypeA (KERNEL32.@)
|
2005-11-08 12:01:03 +01:00
|
|
|
*
|
|
|
|
* See GetDriveTypeW.
|
2004-04-24 01:31:58 +02:00
|
|
|
*/
|
|
|
|
UINT WINAPI GetDriveTypeA( LPCSTR root )
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *rootW = NULL;
|
2004-04-24 01:31:58 +02:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return DRIVE_NO_ROOT_DIR;
|
|
|
|
return GetDriveTypeW( rootW );
|
2004-04-24 01:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-17 02:30:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetDiskFreeSpaceExW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* This function is used to acquire the size of the available and
|
|
|
|
* total space on a logical volume.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* Zero on failure, nonzero upon success. Use GetLastError to obtain
|
|
|
|
* detailed error information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetDiskFreeSpaceExW( LPCWSTR root, PULARGE_INTEGER avail,
|
|
|
|
PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
|
|
|
|
{
|
|
|
|
FILE_FS_SIZE_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle;
|
|
|
|
UINT units;
|
|
|
|
|
|
|
|
TRACE( "%s,%p,%p,%p\n", debugstr_w(root), avail, total, totalfree );
|
|
|
|
|
|
|
|
if (!open_device_root( root, &handle )) return FALSE;
|
|
|
|
|
|
|
|
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
|
|
|
|
NtClose( handle );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
units = info.SectorsPerAllocationUnit * info.BytesPerSector;
|
|
|
|
if (total) total->QuadPart = info.TotalAllocationUnits.QuadPart * units;
|
|
|
|
if (totalfree) totalfree->QuadPart = info.AvailableAllocationUnits.QuadPart * units;
|
|
|
|
/* FIXME: this one should take quotas into account */
|
|
|
|
if (avail) avail->QuadPart = info.AvailableAllocationUnits.QuadPart * units;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetDiskFreeSpaceExA (KERNEL32.@)
|
2005-11-08 12:01:03 +01:00
|
|
|
*
|
|
|
|
* See GetDiskFreeSpaceExW.
|
2004-04-17 02:30:09 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetDiskFreeSpaceExA( LPCSTR root, PULARGE_INTEGER avail,
|
|
|
|
PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *rootW = NULL;
|
2004-04-17 02:30:09 +02:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
|
|
|
|
return GetDiskFreeSpaceExW( rootW, avail, total, totalfree );
|
2004-04-17 02:30:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetDiskFreeSpaceW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetDiskFreeSpaceW( LPCWSTR root, LPDWORD cluster_sectors,
|
|
|
|
LPDWORD sector_bytes, LPDWORD free_clusters,
|
|
|
|
LPDWORD total_clusters )
|
|
|
|
{
|
|
|
|
FILE_FS_SIZE_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle;
|
|
|
|
UINT units;
|
|
|
|
|
|
|
|
TRACE( "%s,%p,%p,%p,%p\n", debugstr_w(root),
|
|
|
|
cluster_sectors, sector_bytes, free_clusters, total_clusters );
|
|
|
|
|
|
|
|
if (!open_device_root( root, &handle )) return FALSE;
|
|
|
|
|
|
|
|
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
|
|
|
|
NtClose( handle );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
units = info.SectorsPerAllocationUnit * info.BytesPerSector;
|
|
|
|
|
2005-10-20 13:36:40 +02:00
|
|
|
if( GetVersion() & 0x80000000) { /* win3.x, 9x, ME */
|
|
|
|
/* cap the size and available at 2GB as per specs */
|
|
|
|
if (info.TotalAllocationUnits.QuadPart * units > 0x7fffffff) {
|
|
|
|
info.TotalAllocationUnits.QuadPart = 0x7fffffff / units;
|
|
|
|
if (info.AvailableAllocationUnits.QuadPart * units > 0x7fffffff)
|
|
|
|
info.AvailableAllocationUnits.QuadPart = 0x7fffffff / units;
|
|
|
|
}
|
|
|
|
/* nr. of clusters is always <= 65335 */
|
|
|
|
while( info.TotalAllocationUnits.QuadPart > 65535 ) {
|
|
|
|
info.TotalAllocationUnits.QuadPart /= 2;
|
|
|
|
info.AvailableAllocationUnits.QuadPart /= 2;
|
|
|
|
info.SectorsPerAllocationUnit *= 2;
|
|
|
|
}
|
|
|
|
}
|
2004-04-17 02:30:09 +02:00
|
|
|
|
|
|
|
if (cluster_sectors) *cluster_sectors = info.SectorsPerAllocationUnit;
|
|
|
|
if (sector_bytes) *sector_bytes = info.BytesPerSector;
|
|
|
|
if (free_clusters) *free_clusters = info.AvailableAllocationUnits.u.LowPart;
|
|
|
|
if (total_clusters) *total_clusters = info.TotalAllocationUnits.u.LowPart;
|
2012-06-25 08:03:37 +02:00
|
|
|
TRACE("%#08x, %#08x, %#08x, %#08x\n", info.SectorsPerAllocationUnit, info.BytesPerSector,
|
|
|
|
info.AvailableAllocationUnits.u.LowPart, info.TotalAllocationUnits.u.LowPart);
|
2004-04-17 02:30:09 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetDiskFreeSpaceA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors,
|
|
|
|
LPDWORD sector_bytes, LPDWORD free_clusters,
|
|
|
|
LPDWORD total_clusters )
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *rootW = NULL;
|
2004-04-17 02:30:09 +02:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
|
|
|
|
return GetDiskFreeSpaceW( rootW, cluster_sectors, sector_bytes, free_clusters, total_clusters );
|
2004-04-17 02:30:09 +02:00
|
|
|
}
|
2005-06-02 12:30:44 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumePathNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumePathNameA(LPCSTR filename, LPSTR volumepathname, DWORD buflen)
|
|
|
|
{
|
2009-04-22 12:47:06 +02:00
|
|
|
BOOL ret;
|
2013-09-06 17:19:34 +02:00
|
|
|
WCHAR *filenameW = NULL, *volumeW = NULL;
|
2009-04-22 12:47:06 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME("(%s, %p, %d), stub!\n", debugstr_a(filename), volumepathname, buflen);
|
2009-04-22 12:47:06 +02:00
|
|
|
|
2013-09-06 17:19:34 +02:00
|
|
|
if (filename && !(filenameW = FILE_name_AtoW( filename, FALSE )))
|
|
|
|
return FALSE;
|
|
|
|
if (volumepathname && !(volumeW = HeapAlloc( GetProcessHeap(), 0, buflen * sizeof(WCHAR) )))
|
|
|
|
return FALSE;
|
2009-04-22 12:47:06 +02:00
|
|
|
|
|
|
|
if ((ret = GetVolumePathNameW( filenameW, volumeW, buflen )))
|
|
|
|
FILE_name_WtoA( volumeW, -1, volumepathname, buflen );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, volumeW );
|
|
|
|
return ret;
|
2005-06-02 12:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumePathNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD buflen)
|
|
|
|
{
|
2009-04-22 12:47:06 +02:00
|
|
|
const WCHAR *p = filename;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME("(%s, %p, %d), stub!\n", debugstr_w(filename), volumepathname, buflen);
|
2009-04-22 12:47:06 +02:00
|
|
|
|
2013-09-06 17:19:34 +02:00
|
|
|
if (!filename || !volumepathname || !buflen)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p && tolowerW(p[0]) >= 'a' && tolowerW(p[0]) <= 'z' && p[1] ==':' && p[2] == '\\')
|
2009-04-22 12:47:06 +02:00
|
|
|
{
|
2013-09-06 17:19:34 +02:00
|
|
|
if (buflen < 4)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-04-22 12:47:06 +02:00
|
|
|
volumepathname[0] = p[0];
|
|
|
|
volumepathname[1] = ':';
|
|
|
|
volumepathname[2] = '\\';
|
|
|
|
volumepathname[3] = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-09-06 17:19:34 +02:00
|
|
|
|
|
|
|
SetLastError(ERROR_INVALID_NAME);
|
2005-06-02 12:30:44 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-02-18 19:37:29 +01:00
|
|
|
|
2011-03-09 15:11:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumePathNamesForVolumeNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumePathNamesForVolumeNameA(LPCSTR volumename, LPSTR volumepathname, DWORD buflen, PDWORD returnlen)
|
|
|
|
{
|
2011-03-29 13:03:42 +02:00
|
|
|
BOOL ret;
|
|
|
|
WCHAR *volumenameW = NULL, *volumepathnameW;
|
|
|
|
|
|
|
|
if (volumename && !(volumenameW = FILE_name_AtoW( volumename, TRUE ))) return FALSE;
|
|
|
|
if (!(volumepathnameW = HeapAlloc( GetProcessHeap(), 0, buflen * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, volumenameW );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = GetVolumePathNamesForVolumeNameW( volumenameW, volumepathnameW, buflen, returnlen )))
|
|
|
|
{
|
|
|
|
char *path = volumepathname;
|
|
|
|
const WCHAR *pathW = volumepathnameW;
|
|
|
|
|
|
|
|
while (*pathW)
|
|
|
|
{
|
|
|
|
int len = strlenW( pathW ) + 1;
|
|
|
|
FILE_name_WtoA( pathW, len, path, buflen );
|
|
|
|
buflen -= len;
|
|
|
|
pathW += len;
|
|
|
|
path += len;
|
|
|
|
}
|
|
|
|
path[0] = 0;
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, volumenameW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, volumepathnameW );
|
|
|
|
return ret;
|
2011-03-09 15:11:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-29 13:03:42 +02:00
|
|
|
static MOUNTMGR_MOUNT_POINTS *query_mount_points( HANDLE mgr, MOUNTMGR_MOUNT_POINT *input, DWORD insize )
|
|
|
|
{
|
|
|
|
MOUNTMGR_MOUNT_POINTS *output;
|
|
|
|
DWORD outsize = 1024;
|
2014-07-19 20:53:10 +02:00
|
|
|
DWORD br;
|
2011-03-29 13:03:42 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(output = HeapAlloc( GetProcessHeap(), 0, outsize )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-07-19 20:53:10 +02:00
|
|
|
if (DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_POINTS, input, insize, output, outsize, &br, NULL )) break;
|
2011-03-29 13:03:42 +02:00
|
|
|
outsize = output->Size;
|
|
|
|
HeapFree( GetProcessHeap(), 0, output );
|
|
|
|
if (GetLastError() != ERROR_MORE_DATA) return NULL;
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2009-10-23 11:56:22 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetVolumePathNamesForVolumeNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetVolumePathNamesForVolumeNameW(LPCWSTR volumename, LPWSTR volumepathname, DWORD buflen, PDWORD returnlen)
|
|
|
|
{
|
2011-03-29 13:03:42 +02:00
|
|
|
static const WCHAR dosdevicesW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\'};
|
|
|
|
HANDLE mgr;
|
|
|
|
DWORD len, size;
|
|
|
|
MOUNTMGR_MOUNT_POINT *spec;
|
|
|
|
MOUNTMGR_MOUNT_POINTS *link, *target = NULL;
|
|
|
|
WCHAR *name, *path;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
UINT i, j;
|
|
|
|
|
|
|
|
TRACE("%s, %p, %u, %p\n", debugstr_w(volumename), volumepathname, buflen, returnlen);
|
|
|
|
|
|
|
|
if (!volumename || (len = strlenW( volumename )) != 49)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_NAME );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
if (mgr == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
|
|
|
size = sizeof(*spec) + sizeof(WCHAR) * (len - 1); /* remove trailing backslash */
|
|
|
|
if (!(spec = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) goto done;
|
|
|
|
spec->SymbolicLinkNameOffset = sizeof(*spec);
|
|
|
|
spec->SymbolicLinkNameLength = size - sizeof(*spec);
|
|
|
|
name = (WCHAR *)((char *)spec + spec->SymbolicLinkNameOffset);
|
|
|
|
memcpy( name, volumename, size - sizeof(*spec) );
|
|
|
|
name[1] = '?'; /* map \\?\ to \??\ */
|
|
|
|
|
|
|
|
target = query_mount_points( mgr, spec, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, spec );
|
|
|
|
if (!target)
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (!target->NumberOfMountPoints)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
len = 0;
|
|
|
|
path = volumepathname;
|
|
|
|
for (i = 0; i < target->NumberOfMountPoints; i++)
|
|
|
|
{
|
|
|
|
link = NULL;
|
|
|
|
if (target->MountPoints[i].DeviceNameOffset)
|
|
|
|
{
|
|
|
|
const WCHAR *device = (const WCHAR *)((const char *)target + target->MountPoints[i].DeviceNameOffset);
|
|
|
|
USHORT device_len = target->MountPoints[i].DeviceNameLength;
|
|
|
|
|
|
|
|
size = sizeof(*spec) + device_len;
|
|
|
|
if (!(spec = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) goto done;
|
|
|
|
spec->DeviceNameOffset = sizeof(*spec);
|
|
|
|
spec->DeviceNameLength = device_len;
|
|
|
|
memcpy( (char *)spec + spec->DeviceNameOffset, device, device_len );
|
|
|
|
|
|
|
|
link = query_mount_points( mgr, spec, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, spec );
|
|
|
|
}
|
|
|
|
else if (target->MountPoints[i].UniqueIdOffset)
|
|
|
|
{
|
|
|
|
const WCHAR *id = (const WCHAR *)((const char *)target + target->MountPoints[i].UniqueIdOffset);
|
|
|
|
USHORT id_len = target->MountPoints[i].UniqueIdLength;
|
|
|
|
|
|
|
|
size = sizeof(*spec) + id_len;
|
|
|
|
if (!(spec = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) goto done;
|
|
|
|
spec->UniqueIdOffset = sizeof(*spec);
|
|
|
|
spec->UniqueIdLength = id_len;
|
|
|
|
memcpy( (char *)spec + spec->UniqueIdOffset, id, id_len );
|
|
|
|
|
|
|
|
link = query_mount_points( mgr, spec, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, spec );
|
|
|
|
}
|
|
|
|
if (!link) continue;
|
|
|
|
for (j = 0; j < link->NumberOfMountPoints; j++)
|
|
|
|
{
|
|
|
|
const WCHAR *linkname;
|
|
|
|
|
|
|
|
if (!link->MountPoints[j].SymbolicLinkNameOffset) continue;
|
|
|
|
linkname = (const WCHAR *)((const char *)link + link->MountPoints[j].SymbolicLinkNameOffset);
|
|
|
|
|
|
|
|
if (link->MountPoints[j].SymbolicLinkNameLength == sizeof(dosdevicesW) + 2 * sizeof(WCHAR) &&
|
|
|
|
!memicmpW( linkname, dosdevicesW, sizeof(dosdevicesW) / sizeof(WCHAR) ))
|
|
|
|
{
|
|
|
|
len += 4;
|
|
|
|
if (volumepathname && len < buflen)
|
|
|
|
{
|
|
|
|
path[0] = linkname[sizeof(dosdevicesW) / sizeof(WCHAR)];
|
|
|
|
path[1] = ':';
|
|
|
|
path[2] = '\\';
|
|
|
|
path[3] = 0;
|
|
|
|
path += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, link );
|
|
|
|
}
|
|
|
|
if (buflen <= len) SetLastError( ERROR_MORE_DATA );
|
|
|
|
else if (volumepathname)
|
|
|
|
{
|
|
|
|
volumepathname[len] = 0;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
if (returnlen) *returnlen = len + 1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, target );
|
|
|
|
CloseHandle( mgr );
|
|
|
|
return ret;
|
2009-10-23 11:56:22 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 21:44:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FindFirstVolumeA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI FindFirstVolumeA(LPSTR volume, DWORD len)
|
|
|
|
{
|
2008-01-04 14:31:40 +01:00
|
|
|
WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
HANDLE handle = FindFirstVolumeW( buffer, len );
|
|
|
|
|
|
|
|
if (handle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (!WideCharToMultiByte( CP_ACP, 0, buffer, -1, volume, len, NULL, NULL ))
|
|
|
|
{
|
|
|
|
FindVolumeClose( handle );
|
|
|
|
handle = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
return handle;
|
2007-11-18 21:44:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindFirstVolumeW (KERNEL32.@)
|
|
|
|
*/
|
2008-01-04 14:31:40 +01:00
|
|
|
HANDLE WINAPI FindFirstVolumeW( LPWSTR volume, DWORD len )
|
2007-11-18 21:44:25 +01:00
|
|
|
{
|
2008-01-04 14:31:40 +01:00
|
|
|
DWORD size = 1024;
|
2014-07-19 20:53:10 +02:00
|
|
|
DWORD br;
|
2008-01-04 14:31:40 +01:00
|
|
|
HANDLE mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
if (mgr == INVALID_HANDLE_VALUE) return INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
MOUNTMGR_MOUNT_POINT input;
|
|
|
|
MOUNTMGR_MOUNT_POINTS *output;
|
|
|
|
|
|
|
|
if (!(output = HeapAlloc( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset( &input, 0, sizeof(input) );
|
|
|
|
|
|
|
|
if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_POINTS, &input, sizeof(input),
|
2014-07-19 20:53:10 +02:00
|
|
|
output, size, &br, NULL ))
|
2008-01-04 14:31:40 +01:00
|
|
|
{
|
|
|
|
if (GetLastError() != ERROR_MORE_DATA) break;
|
|
|
|
size = output->Size;
|
|
|
|
HeapFree( GetProcessHeap(), 0, output );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CloseHandle( mgr );
|
|
|
|
/* abuse the Size field to store the current index */
|
|
|
|
output->Size = 0;
|
|
|
|
if (!FindNextVolumeW( output, volume, len ))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, output );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2009-03-11 09:39:16 +01:00
|
|
|
return output;
|
2008-01-04 14:31:40 +01:00
|
|
|
}
|
|
|
|
CloseHandle( mgr );
|
2007-11-18 21:44:25 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2008-01-04 14:31:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FindNextVolumeA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FindNextVolumeA( HANDLE handle, LPSTR volume, DWORD len )
|
|
|
|
{
|
|
|
|
WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if ((ret = FindNextVolumeW( handle, buffer, len )))
|
|
|
|
{
|
|
|
|
if (!WideCharToMultiByte( CP_ACP, 0, buffer, -1, volume, len, NULL, NULL )) ret = FALSE;
|
|
|
|
}
|
2008-01-07 22:12:54 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
2008-01-04 14:31:40 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindNextVolumeW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FindNextVolumeW( HANDLE handle, LPWSTR volume, DWORD len )
|
|
|
|
{
|
|
|
|
MOUNTMGR_MOUNT_POINTS *data = handle;
|
|
|
|
|
|
|
|
while (data->Size < data->NumberOfMountPoints)
|
|
|
|
{
|
|
|
|
static const WCHAR volumeW[] = {'\\','?','?','\\','V','o','l','u','m','e','{',};
|
|
|
|
WCHAR *link = (WCHAR *)((char *)data + data->MountPoints[data->Size].SymbolicLinkNameOffset);
|
|
|
|
DWORD size = data->MountPoints[data->Size].SymbolicLinkNameLength;
|
|
|
|
data->Size++;
|
|
|
|
/* skip non-volumes */
|
|
|
|
if (size < sizeof(volumeW) || memcmp( link, volumeW, sizeof(volumeW) )) continue;
|
|
|
|
if (size + sizeof(WCHAR) >= len * sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
memcpy( volume, link, size );
|
|
|
|
volume[1] = '\\'; /* map \??\ to \\?\ */
|
|
|
|
volume[size / sizeof(WCHAR)] = '\\'; /* Windows appends a backslash */
|
|
|
|
volume[size / sizeof(WCHAR) + 1] = 0;
|
|
|
|
TRACE( "returning entry %u %s\n", data->Size - 1, debugstr_w(volume) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
SetLastError( ERROR_NO_MORE_FILES );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindVolumeClose (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FindVolumeClose(HANDLE handle)
|
|
|
|
{
|
|
|
|
return HeapFree( GetProcessHeap(), 0, handle );
|
|
|
|
}
|
|
|
|
|
2007-02-18 19:37:29 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FindFirstVolumeMountPointA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI FindFirstVolumeMountPointA(LPCSTR root, LPSTR mount_point, DWORD len)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %p, %d), stub!\n", debugstr_a(root), mount_point, len);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindFirstVolumeMountPointW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI FindFirstVolumeMountPointW(LPCWSTR root, LPWSTR mount_point, DWORD len)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %p, %d), stub!\n", debugstr_w(root), mount_point, len);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2007-10-31 01:02:26 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindVolumeMountPointClose (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FindVolumeMountPointClose(HANDLE h)
|
|
|
|
{
|
|
|
|
FIXME("(%p), stub!\n", h);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-13 01:16:20 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteVolumeMountPointA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteVolumeMountPointA(LPCSTR mountpoint)
|
|
|
|
{
|
|
|
|
FIXME("(%s), stub!\n", debugstr_a(mountpoint));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteVolumeMountPointW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteVolumeMountPointW(LPCWSTR mountpoint)
|
|
|
|
{
|
|
|
|
FIXME("(%s), stub!\n", debugstr_w(mountpoint));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-11 09:38:03 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetVolumeMountPointA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetVolumeMountPointA(LPCSTR path, LPCSTR volume)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %s), stub!\n", debugstr_a(path), debugstr_a(volume));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetVolumeMountPointW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetVolumeMountPointW(LPCWSTR path, LPCWSTR volume)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %s), stub!\n", debugstr_w(path), debugstr_w(volume));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|