From 53d4f6c6a30964687d3fc710f4233a3b1efe2b22 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 4 Aug 2013 17:32:38 +0000 Subject: [PATCH] [KERNEL32] [FORMATTING]: Separate volume.c into disk.c, volume.c, and mountpt.c. Format function headers appropriately. No code change. svn path=/trunk/; revision=59638 --- reactos/dll/win32/kernel32/CMakeLists.txt | 2 + reactos/dll/win32/kernel32/client/file/disk.c | 424 ++++++++ .../dll/win32/kernel32/client/file/mntpoint.c | 394 +++++++ .../dll/win32/kernel32/client/file/volume.c | 986 ++---------------- 4 files changed, 904 insertions(+), 902 deletions(-) create mode 100644 reactos/dll/win32/kernel32/client/file/disk.c create mode 100644 reactos/dll/win32/kernel32/client/file/mntpoint.c diff --git a/reactos/dll/win32/kernel32/CMakeLists.txt b/reactos/dll/win32/kernel32/CMakeLists.txt index caf39abae86..fc2cd0a6a2b 100644 --- a/reactos/dll/win32/kernel32/CMakeLists.txt +++ b/reactos/dll/win32/kernel32/CMakeLists.txt @@ -47,6 +47,7 @@ list(APPEND SOURCE client/file/delete.c client/file/deviceio.c client/file/dir.c + client/file/disk.c client/file/fileinfo.c client/file/filemap.c client/file/filename.c @@ -57,6 +58,7 @@ list(APPEND SOURCE client/file/lock.c client/file/mailslot.c client/file/move.c + client/file/mntpoint.c client/file/npipe.c client/file/rw.c client/file/tape.c diff --git a/reactos/dll/win32/kernel32/client/file/disk.c b/reactos/dll/win32/kernel32/client/file/disk.c new file mode 100644 index 00000000000..c54ebe97e67 --- /dev/null +++ b/reactos/dll/win32/kernel32/client/file/disk.c @@ -0,0 +1,424 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/disk.c + * PURPOSE: Disk and Drive functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * Erik Bos, Alexandre Julliard : + * GetLogicalDriveStringsA, + * GetLogicalDriveStringsW, GetLogicalDrives + * UPDATE HISTORY: + * Created 01/11/98 + */ +//WINE copyright notice: +/* + * DOS drives handling functions + * + * Copyright 1993 Erik Bos + * Copyright 1996 Alexandre Julliard + */ + +#include +#define NDEBUG +#include +DEBUG_CHANNEL(kernel32file); + +#define MAX_DOS_DRIVES 26 +HANDLE WINAPI InternalOpenDirW(IN LPCWSTR DirName, IN BOOLEAN Write); + +/* + * @implemented + */ +/* Synced to Wine-2008/12/28 */ +DWORD +WINAPI +GetLogicalDriveStringsA(IN DWORD nBufferLength, + IN LPSTR lpBuffer) +{ + DWORD drive, count; + DWORD dwDriveMap; + LPSTR p; + + dwDriveMap = GetLogicalDrives(); + + for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++) + { + if (dwDriveMap & (1< nBufferLength) return ((count * 4) + 1); + + p = lpBuffer; + + for (drive = 0; drive < MAX_DOS_DRIVES; drive++) + if (dwDriveMap & (1< nBufferLength) return ((count * 4) + 1); + + p = lpBuffer; + for (drive = 0; drive < MAX_DOS_DRIVES; drive++) + if (dwDriveMap & (1<QuadPart = + BytesPerCluster.QuadPart * FsInfo.FsFullSize.CallerAvailableAllocationUnits.QuadPart; + } + + if (lpTotalNumberOfBytes != NULL) + { + lpTotalNumberOfBytes->QuadPart = + BytesPerCluster.QuadPart * FsInfo.FsFullSize.TotalAllocationUnits.QuadPart; + } + + if (lpTotalNumberOfFreeBytes != NULL) + { + lpTotalNumberOfFreeBytes->QuadPart = + BytesPerCluster.QuadPart * FsInfo.FsFullSize.ActualAvailableAllocationUnits.QuadPart; + } + + return TRUE; + } + } + + Status = NtQueryVolumeInformationFile(hFile, + &IoStatusBlock, + &FsInfo.FsSize, + sizeof(FsInfo.FsSize), + FileFsSizeInformation); + + /* Close the handle before returning data + to avoid a handle leak in case of a fault! */ + CloseHandle(hFile); + + if (!NT_SUCCESS(Status)) + { + BaseSetLastNTError (Status); + return FALSE; + } + + BytesPerCluster.QuadPart = + FsInfo.FsSize.BytesPerSector * FsInfo.FsSize.SectorsPerAllocationUnit; + + if (lpFreeBytesAvailableToCaller) + { + lpFreeBytesAvailableToCaller->QuadPart = + BytesPerCluster.QuadPart * FsInfo.FsSize.AvailableAllocationUnits.QuadPart; + } + + if (lpTotalNumberOfBytes) + { + lpTotalNumberOfBytes->QuadPart = + BytesPerCluster.QuadPart * FsInfo.FsSize.TotalAllocationUnits.QuadPart; + } + + if (lpTotalNumberOfFreeBytes) + { + lpTotalNumberOfFreeBytes->QuadPart = + BytesPerCluster.QuadPart * FsInfo.FsSize.AvailableAllocationUnits.QuadPart; + } + + return TRUE; +} + +/* + * @implemented + */ +UINT +WINAPI +GetDriveTypeA(IN LPCSTR lpRootPathName) +{ + PWCHAR RootPathNameW; + + if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE))) + return DRIVE_UNKNOWN; + + return GetDriveTypeW(RootPathNameW); +} + +/* + * @implemented + */ +UINT +WINAPI +GetDriveTypeW(IN LPCWSTR lpRootPathName) +{ + FILE_FS_DEVICE_INFORMATION FileFsDevice; + IO_STATUS_BLOCK IoStatusBlock; + + HANDLE hFile; + NTSTATUS errCode; + + hFile = InternalOpenDirW(lpRootPathName, FALSE); + if (hFile == INVALID_HANDLE_VALUE) + { + return DRIVE_NO_ROOT_DIR; /* According to WINE regression tests */ + } + + errCode = NtQueryVolumeInformationFile (hFile, + &IoStatusBlock, + &FileFsDevice, + sizeof(FILE_FS_DEVICE_INFORMATION), + FileFsDeviceInformation); + if (!NT_SUCCESS(errCode)) + { + CloseHandle(hFile); + BaseSetLastNTError (errCode); + return 0; + } + CloseHandle(hFile); + + switch (FileFsDevice.DeviceType) + { + case FILE_DEVICE_CD_ROM: + case FILE_DEVICE_CD_ROM_FILE_SYSTEM: + return DRIVE_CDROM; + case FILE_DEVICE_VIRTUAL_DISK: + return DRIVE_RAMDISK; + case FILE_DEVICE_NETWORK_FILE_SYSTEM: + return DRIVE_REMOTE; + case FILE_DEVICE_DISK: + case FILE_DEVICE_DISK_FILE_SYSTEM: + if (FileFsDevice.Characteristics & FILE_REMOTE_DEVICE) + return DRIVE_REMOTE; + if (FileFsDevice.Characteristics & FILE_REMOVABLE_MEDIA) + return DRIVE_REMOVABLE; + return DRIVE_FIXED; + } + + ERR("Returning DRIVE_UNKNOWN for device type %d\n", FileFsDevice.DeviceType); + + return DRIVE_UNKNOWN; +} + +/* EOF */ diff --git a/reactos/dll/win32/kernel32/client/file/mntpoint.c b/reactos/dll/win32/kernel32/client/file/mntpoint.c new file mode 100644 index 00000000000..af0ae94df2f --- /dev/null +++ b/reactos/dll/win32/kernel32/client/file/mntpoint.c @@ -0,0 +1,394 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/mntpoint.c + * PURPOSE: File volume mount point functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * Erik Bos, Alexandre Julliard : + * GetLogicalDriveStringsA, + * GetLogicalDriveStringsW, GetLogicalDrives + * UPDATE HISTORY: + * Created 01/11/98 + */ +//WINE copyright notice: +/* + * DOS drives handling functions + * + * Copyright 1993 Erik Bos + * Copyright 1996 Alexandre Julliard + */ + +#include +#define NDEBUG +#include +DEBUG_CHANNEL(kernel32file); + +/** + * @name GetVolumeNameForVolumeMountPointW + * @implemented + * + * Return an unique volume name for a drive root or mount point. + * + * @param VolumeMountPoint + * Pointer to string that contains either root drive name or + * mount point name. + * @param VolumeName + * Pointer to buffer that is filled with resulting unique + * volume name on success. + * @param VolumeNameLength + * Size of VolumeName buffer in TCHARs. + * + * @return + * TRUE when the function succeeds and the VolumeName buffer is filled, + * FALSE otherwise. + */ +BOOL +WINAPI +GetVolumeNameForVolumeMountPointW(IN LPCWSTR VolumeMountPoint, + OUT LPWSTR VolumeName, + IN DWORD VolumeNameLength) +{ + UNICODE_STRING NtFileName; + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE FileHandle; + IO_STATUS_BLOCK Iosb; + ULONG BufferLength; + PMOUNTDEV_NAME MountDevName; + PMOUNTMGR_MOUNT_POINT MountPoint; + ULONG MountPointSize; + PMOUNTMGR_MOUNT_POINTS MountPoints; + ULONG Index; + PUCHAR SymbolicLinkName; + BOOL Result; + NTSTATUS Status; + + if (!VolumeMountPoint || !VolumeMountPoint[0]) + { + SetLastError(ERROR_PATH_NOT_FOUND); + return FALSE; + } + + /* + * First step is to convert the passed volume mount point name to + * an NT acceptable name. + */ + + if (!RtlDosPathNameToNtPathName_U(VolumeMountPoint, &NtFileName, NULL, NULL)) + { + SetLastError(ERROR_PATH_NOT_FOUND); + return FALSE; + } + + if (NtFileName.Length > sizeof(WCHAR) && + NtFileName.Buffer[(NtFileName.Length / sizeof(WCHAR)) - 1] == '\\') + { + NtFileName.Length -= sizeof(WCHAR); + } + + /* + * Query mount point device name which we will later use for determining + * the volume name. + */ + + InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL); + Status = NtOpenFile(&FileHandle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, + &ObjectAttributes, &Iosb, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SYNCHRONOUS_IO_NONALERT); + RtlFreeUnicodeString(&NtFileName); + if (!NT_SUCCESS(Status)) + { + BaseSetLastNTError(Status); + return FALSE; + } + + BufferLength = sizeof(MOUNTDEV_NAME) + 50 * sizeof(WCHAR); + do + { + MountDevName = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength); + if (MountDevName == NULL) + { + NtClose(FileHandle); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb, + IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, + NULL, 0, MountDevName, BufferLength); + if (!NT_SUCCESS(Status)) + { + RtlFreeHeap(GetProcessHeap(), 0, MountDevName); + if (Status == STATUS_BUFFER_OVERFLOW) + { + BufferLength = sizeof(MOUNTDEV_NAME) + MountDevName->NameLength; + continue; + } + else + { + NtClose(FileHandle); + BaseSetLastNTError(Status); + return FALSE; + } + } + } + while (!NT_SUCCESS(Status)); + + NtClose(FileHandle); + + /* + * Get the mount point information from mount manager. + */ + + MountPointSize = MountDevName->NameLength + sizeof(MOUNTMGR_MOUNT_POINT); + MountPoint = RtlAllocateHeap(GetProcessHeap(), 0, MountPointSize); + if (MountPoint == NULL) + { + RtlFreeHeap(GetProcessHeap(), 0, MountDevName); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + RtlZeroMemory(MountPoint, sizeof(MOUNTMGR_MOUNT_POINT)); + MountPoint->DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINT); + MountPoint->DeviceNameLength = MountDevName->NameLength; + RtlCopyMemory(MountPoint + 1, MountDevName->Name, MountDevName->NameLength); + RtlFreeHeap(RtlGetProcessHeap(), 0, MountDevName); + + RtlInitUnicodeString(&NtFileName, L"\\??\\MountPointManager"); + InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL); + Status = NtOpenFile(&FileHandle, FILE_GENERIC_READ, &ObjectAttributes, + &Iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SYNCHRONOUS_IO_NONALERT); + if (!NT_SUCCESS(Status)) + { + BaseSetLastNTError(Status); + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); + return FALSE; + } + + BufferLength = sizeof(MOUNTMGR_MOUNT_POINTS); + do + { + MountPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength); + if (MountPoints == NULL) + { + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); + NtClose(FileHandle); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb, + IOCTL_MOUNTMGR_QUERY_POINTS, + MountPoint, MountPointSize, + MountPoints, BufferLength); + if (!NT_SUCCESS(Status)) + { + if (Status == STATUS_BUFFER_OVERFLOW) + { + BufferLength = MountPoints->Size; + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); + continue; + } + else if (!NT_SUCCESS(Status)) + { + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); + NtClose(FileHandle); + BaseSetLastNTError(Status); + return FALSE; + } + } + } + while (!NT_SUCCESS(Status)); + + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); + NtClose(FileHandle); + + /* + * Now we've gathered info about all mount points mapped to our device, so + * select the correct one and copy it into the output buffer. + */ + + for (Index = 0; Index < MountPoints->NumberOfMountPoints; Index++) + { + MountPoint = MountPoints->MountPoints + Index; + SymbolicLinkName = (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset; + + /* + * Check for "\\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\" + * (with the last slash being optional) style symbolic links. + */ + + if (MountPoint->SymbolicLinkNameLength == 48 * sizeof(WCHAR) || + (MountPoint->SymbolicLinkNameLength == 49 * sizeof(WCHAR) && + SymbolicLinkName[48] == L'\\')) + { + if (RtlCompareMemory(SymbolicLinkName, L"\\??\\Volume{", + 11 * sizeof(WCHAR)) == 11 * sizeof(WCHAR) && + SymbolicLinkName[19] == L'-' && SymbolicLinkName[24] == L'-' && + SymbolicLinkName[29] == L'-' && SymbolicLinkName[34] == L'-' && + SymbolicLinkName[47] == L'}') + { + if (VolumeNameLength >= MountPoint->SymbolicLinkNameLength / sizeof(WCHAR)) + { + RtlCopyMemory(VolumeName, + (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset, + MountPoint->SymbolicLinkNameLength); + VolumeName[1] = L'\\'; + Result = TRUE; + } + else + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + Result = FALSE; + } + + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); + + return Result; + } + } + } + + RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); + SetLastError(ERROR_INVALID_PARAMETER); + + return FALSE; +} + +/* + * @implemented (Wine 13 sep 2008) + */ +BOOL +WINAPI +GetVolumeNameForVolumeMountPointA(IN LPCSTR lpszVolumeMountPoint, + IN LPSTR lpszVolumeName, + IN DWORD cchBufferLength) +{ + BOOL ret; + WCHAR volumeW[50], *pathW = NULL; + DWORD len = min( sizeof(volumeW) / sizeof(WCHAR), cchBufferLength ); + + TRACE("(%s, %p, %x)\n", debugstr_a(lpszVolumeMountPoint), lpszVolumeName, cchBufferLength); + + if (!lpszVolumeMountPoint || !(pathW = FilenameA2W( lpszVolumeMountPoint, TRUE ))) + return FALSE; + + if ((ret = GetVolumeNameForVolumeMountPointW( pathW, volumeW, len ))) + FilenameW2A_N( lpszVolumeName, len, volumeW, -1 ); + + RtlFreeHeap( RtlGetProcessHeap(), 0, pathW ); + return ret; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +SetVolumeMountPointW(IN LPCWSTR lpszVolumeMountPoint, + IN LPCWSTR lpszVolumeName) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +SetVolumeMountPointA(IN LPCSTR lpszVolumeMountPoint, + IN LPCSTR lpszVolumeName) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +DeleteVolumeMountPointA(IN LPCSTR lpszVolumeMountPoint) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +DeleteVolumeMountPointW(IN LPCWSTR lpszVolumeMountPoint) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +HANDLE +WINAPI +FindFirstVolumeMountPointW(IN LPCWSTR lpszRootPathName, + IN LPWSTR lpszVolumeMountPoint, + IN DWORD cchBufferLength) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +HANDLE +WINAPI +FindFirstVolumeMountPointA(IN LPCSTR lpszRootPathName, + IN LPSTR lpszVolumeMountPoint, + IN DWORD cchBufferLength) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +FindNextVolumeMountPointA(IN HANDLE hFindVolumeMountPoint, + IN LPSTR lpszVolumeMountPoint, + DWORD cchBufferLength) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +FindNextVolumeMountPointW(IN HANDLE hFindVolumeMountPoint, + IN LPWSTR lpszVolumeMountPoint, + DWORD cchBufferLength) +{ + STUB; + return 0; +} + +/* + * @unimplemented + */ +BOOL +WINAPI +FindVolumeMountPointClose(IN HANDLE hFindVolumeMountPoint) +{ + STUB; + return 0; +} + +/* EOF */ diff --git a/reactos/dll/win32/kernel32/client/file/volume.c b/reactos/dll/win32/kernel32/client/file/volume.c index 62cc81bbf89..dedfb1c05b1 100644 --- a/reactos/dll/win32/kernel32/client/file/volume.c +++ b/reactos/dll/win32/kernel32/client/file/volume.c @@ -23,477 +23,66 @@ #include DEBUG_CHANNEL(kernel32file); -#define MAX_DOS_DRIVES 26 - - -static HANDLE -InternalOpenDirW(LPCWSTR DirName, - BOOLEAN Write) +HANDLE +WINAPI +InternalOpenDirW(IN LPCWSTR DirName, + IN BOOLEAN Write) { - UNICODE_STRING NtPathU; - OBJECT_ATTRIBUTES ObjectAttributes; - NTSTATUS errCode; - IO_STATUS_BLOCK IoStatusBlock; - HANDLE hFile; + UNICODE_STRING NtPathU; + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS errCode; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE hFile; - if (!RtlDosPathNameToNtPathName_U(DirName, - &NtPathU, - NULL, - NULL)) + if (!RtlDosPathNameToNtPathName_U(DirName, &NtPathU, NULL, NULL)) { - WARN("Invalid path\n"); - SetLastError(ERROR_BAD_PATHNAME); - return INVALID_HANDLE_VALUE; + WARN("Invalid path\n"); + SetLastError(ERROR_BAD_PATHNAME); + return INVALID_HANDLE_VALUE; } InitializeObjectAttributes(&ObjectAttributes, - &NtPathU, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); + &NtPathU, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); - errCode = NtCreateFile (&hFile, - Write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ, - &ObjectAttributes, - &IoStatusBlock, - NULL, - 0, - FILE_SHARE_READ|FILE_SHARE_WRITE, - FILE_OPEN, - 0, - NULL, - 0); + errCode = NtCreateFile(&hFile, + Write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ, + &ObjectAttributes, + &IoStatusBlock, + NULL, + 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_OPEN, + 0, + NULL, + 0); - RtlFreeHeap(RtlGetProcessHeap(), - 0, - NtPathU.Buffer); + RtlFreeHeap(RtlGetProcessHeap(), 0, NtPathU.Buffer); if (!NT_SUCCESS(errCode)) { - BaseSetLastNTError (errCode); - return INVALID_HANDLE_VALUE; + BaseSetLastNTError(errCode); + return INVALID_HANDLE_VALUE; } + return hFile; } - /* * @implemented */ -/* Synced to Wine-2008/12/28 */ -DWORD WINAPI -GetLogicalDriveStringsA(DWORD nBufferLength, - LPSTR lpBuffer) -{ - DWORD drive, count; - DWORD dwDriveMap; - LPSTR p; - - dwDriveMap = GetLogicalDrives(); - - for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++) - { - if (dwDriveMap & (1< nBufferLength) return ((count * 4) + 1); - - p = lpBuffer; - - for (drive = 0; drive < MAX_DOS_DRIVES; drive++) - if (dwDriveMap & (1< nBufferLength) return ((count * 4) + 1); - - p = lpBuffer; - for (drive = 0; drive < MAX_DOS_DRIVES; drive++) - if (dwDriveMap & (1<QuadPart = - BytesPerCluster.QuadPart * FsInfo.FsFullSize.CallerAvailableAllocationUnits.QuadPart; - } - - if (lpTotalNumberOfBytes != NULL) - { - lpTotalNumberOfBytes->QuadPart = - BytesPerCluster.QuadPart * FsInfo.FsFullSize.TotalAllocationUnits.QuadPart; - } - - if (lpTotalNumberOfFreeBytes != NULL) - { - lpTotalNumberOfFreeBytes->QuadPart = - BytesPerCluster.QuadPart * FsInfo.FsFullSize.ActualAvailableAllocationUnits.QuadPart; - } - - return TRUE; - } - } - - Status = NtQueryVolumeInformationFile(hFile, - &IoStatusBlock, - &FsInfo.FsSize, - sizeof(FsInfo.FsSize), - FileFsSizeInformation); - - /* Close the handle before returning data - to avoid a handle leak in case of a fault! */ - CloseHandle(hFile); - - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError (Status); - return FALSE; - } - - BytesPerCluster.QuadPart = - FsInfo.FsSize.BytesPerSector * FsInfo.FsSize.SectorsPerAllocationUnit; - - if (lpFreeBytesAvailableToCaller) - { - lpFreeBytesAvailableToCaller->QuadPart = - BytesPerCluster.QuadPart * FsInfo.FsSize.AvailableAllocationUnits.QuadPart; - } - - if (lpTotalNumberOfBytes) - { - lpTotalNumberOfBytes->QuadPart = - BytesPerCluster.QuadPart * FsInfo.FsSize.TotalAllocationUnits.QuadPart; - } - - if (lpTotalNumberOfFreeBytes) - { - lpTotalNumberOfFreeBytes->QuadPart = - BytesPerCluster.QuadPart * FsInfo.FsSize.AvailableAllocationUnits.QuadPart; - } - - return TRUE; -} - - -/* - * @implemented - */ -UINT WINAPI -GetDriveTypeA(LPCSTR lpRootPathName) -{ - PWCHAR RootPathNameW; - - if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE))) - return DRIVE_UNKNOWN; - - return GetDriveTypeW(RootPathNameW); -} - - -/* - * @implemented - */ -UINT WINAPI -GetDriveTypeW(LPCWSTR lpRootPathName) -{ - FILE_FS_DEVICE_INFORMATION FileFsDevice; - IO_STATUS_BLOCK IoStatusBlock; - - HANDLE hFile; - NTSTATUS errCode; - - hFile = InternalOpenDirW(lpRootPathName, FALSE); - if (hFile == INVALID_HANDLE_VALUE) - { - return DRIVE_NO_ROOT_DIR; /* According to WINE regression tests */ - } - - errCode = NtQueryVolumeInformationFile (hFile, - &IoStatusBlock, - &FileFsDevice, - sizeof(FILE_FS_DEVICE_INFORMATION), - FileFsDeviceInformation); - if (!NT_SUCCESS(errCode)) - { - CloseHandle(hFile); - BaseSetLastNTError (errCode); - return 0; - } - CloseHandle(hFile); - - switch (FileFsDevice.DeviceType) - { - case FILE_DEVICE_CD_ROM: - case FILE_DEVICE_CD_ROM_FILE_SYSTEM: - return DRIVE_CDROM; - case FILE_DEVICE_VIRTUAL_DISK: - return DRIVE_RAMDISK; - case FILE_DEVICE_NETWORK_FILE_SYSTEM: - return DRIVE_REMOTE; - case FILE_DEVICE_DISK: - case FILE_DEVICE_DISK_FILE_SYSTEM: - if (FileFsDevice.Characteristics & FILE_REMOTE_DEVICE) - return DRIVE_REMOTE; - if (FileFsDevice.Characteristics & FILE_REMOVABLE_MEDIA) - return DRIVE_REMOVABLE; - return DRIVE_FIXED; - } - - ERR("Returning DRIVE_UNKNOWN for device type %d\n", FileFsDevice.DeviceType); - - return DRIVE_UNKNOWN; -} - - -/* - * @implemented - */ -BOOL WINAPI -GetVolumeInformationA( - LPCSTR lpRootPathName, - LPSTR lpVolumeNameBuffer, - DWORD nVolumeNameSize, - LPDWORD lpVolumeSerialNumber, - LPDWORD lpMaximumComponentLength, - LPDWORD lpFileSystemFlags, - LPSTR lpFileSystemNameBuffer, - DWORD nFileSystemNameSize - ) +BOOL +WINAPI +GetVolumeInformationA(IN LPCSTR lpRootPathName, + IN LPSTR lpVolumeNameBuffer, + IN DWORD nVolumeNameSize, + OUT LPDWORD lpVolumeSerialNumber OPTIONAL, + OUT LPDWORD lpMaximumComponentLength OPTIONAL, + OUT LPDWORD lpFileSystemFlags OPTIONAL, + OUT LPSTR lpFileSystemNameBuffer OPTIONAL, + IN DWORD nFileSystemNameSize) { UNICODE_STRING FileSystemNameU; UNICODE_STRING VolumeNameU = { 0, 0, NULL }; @@ -622,17 +211,16 @@ FailNoMem: /* * @implemented */ -BOOL WINAPI -GetVolumeInformationW( - LPCWSTR lpRootPathName, - LPWSTR lpVolumeNameBuffer, - DWORD nVolumeNameSize, - LPDWORD lpVolumeSerialNumber, - LPDWORD lpMaximumComponentLength, - LPDWORD lpFileSystemFlags, - LPWSTR lpFileSystemNameBuffer, - DWORD nFileSystemNameSize - ) +BOOL +WINAPI +GetVolumeInformationW(IN LPCWSTR lpRootPathName, + IN LPWSTR lpVolumeNameBuffer, + IN DWORD nVolumeNameSize, + OUT LPDWORD lpVolumeSerialNumber OPTIONAL, + OUT LPDWORD lpMaximumComponentLength OPTIONAL, + OUT LPDWORD lpFileSystemFlags OPTIONAL, + OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, + IN DWORD nFileSystemNameSize) { PFILE_FS_VOLUME_INFORMATION FileFsVolume; PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute; @@ -734,16 +322,13 @@ GetVolumeInformationW( return TRUE; } - /* * @implemented */ BOOL WINAPI -SetVolumeLabelA ( - LPCSTR lpRootPathName, - LPCSTR lpVolumeName /* NULL if deleting label */ - ) +SetVolumeLabelA(IN LPCSTR lpRootPathName, + IN LPCSTR lpVolumeName OPTIONAL) /* NULL if deleting label */ { PWCHAR RootPathNameW; PWCHAR VolumeNameW = NULL; @@ -771,15 +356,13 @@ SetVolumeLabelA ( return Result; } - /* * @implemented */ -BOOL WINAPI -SetVolumeLabelW( - LPCWSTR lpRootPathName, - LPCWSTR lpVolumeName /* NULL if deleting label */ - ) +BOOL +WINAPI +SetVolumeLabelW(IN LPCWSTR lpRootPathName, + IN LPCWSTR lpVolumeName OPTIONAL) /* NULL if deleting label */ { PFILE_FS_LABEL_INFORMATION LabelInfo; IO_STATUS_BLOCK IoStatusBlock; @@ -834,276 +417,13 @@ SetVolumeLabelW( return TRUE; } -/** - * @name GetVolumeNameForVolumeMountPointW - * - * Return an unique volume name for a drive root or mount point. - * - * @param VolumeMountPoint - * Pointer to string that contains either root drive name or - * mount point name. - * @param VolumeName - * Pointer to buffer that is filled with resulting unique - * volume name on success. - * @param VolumeNameLength - * Size of VolumeName buffer in TCHARs. - * - * @return - * TRUE when the function succeeds and the VolumeName buffer is filled, - * FALSE otherwise. - */ - -BOOL WINAPI -GetVolumeNameForVolumeMountPointW( - IN LPCWSTR VolumeMountPoint, - OUT LPWSTR VolumeName, - IN DWORD VolumeNameLength) -{ - UNICODE_STRING NtFileName; - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE FileHandle; - IO_STATUS_BLOCK Iosb; - ULONG BufferLength; - PMOUNTDEV_NAME MountDevName; - PMOUNTMGR_MOUNT_POINT MountPoint; - ULONG MountPointSize; - PMOUNTMGR_MOUNT_POINTS MountPoints; - ULONG Index; - PUCHAR SymbolicLinkName; - BOOL Result; - NTSTATUS Status; - - if (!VolumeMountPoint || !VolumeMountPoint[0]) - { - SetLastError(ERROR_PATH_NOT_FOUND); - return FALSE; - } - - /* - * First step is to convert the passed volume mount point name to - * an NT acceptable name. - */ - - if (!RtlDosPathNameToNtPathName_U(VolumeMountPoint, &NtFileName, NULL, NULL)) - { - SetLastError(ERROR_PATH_NOT_FOUND); - return FALSE; - } - - if (NtFileName.Length > sizeof(WCHAR) && - NtFileName.Buffer[(NtFileName.Length / sizeof(WCHAR)) - 1] == '\\') - { - NtFileName.Length -= sizeof(WCHAR); - } - - /* - * Query mount point device name which we will later use for determining - * the volume name. - */ - - InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL); - Status = NtOpenFile(&FileHandle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, - &ObjectAttributes, &Iosb, - FILE_SHARE_READ | FILE_SHARE_WRITE, - FILE_SYNCHRONOUS_IO_NONALERT); - RtlFreeUnicodeString(&NtFileName); - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); - return FALSE; - } - - BufferLength = sizeof(MOUNTDEV_NAME) + 50 * sizeof(WCHAR); - do - { - MountDevName = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength); - if (MountDevName == NULL) - { - NtClose(FileHandle); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb, - IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, - NULL, 0, MountDevName, BufferLength); - if (!NT_SUCCESS(Status)) - { - RtlFreeHeap(GetProcessHeap(), 0, MountDevName); - if (Status == STATUS_BUFFER_OVERFLOW) - { - BufferLength = sizeof(MOUNTDEV_NAME) + MountDevName->NameLength; - continue; - } - else - { - NtClose(FileHandle); - BaseSetLastNTError(Status); - return FALSE; - } - } - } - while (!NT_SUCCESS(Status)); - - NtClose(FileHandle); - - /* - * Get the mount point information from mount manager. - */ - - MountPointSize = MountDevName->NameLength + sizeof(MOUNTMGR_MOUNT_POINT); - MountPoint = RtlAllocateHeap(GetProcessHeap(), 0, MountPointSize); - if (MountPoint == NULL) - { - RtlFreeHeap(GetProcessHeap(), 0, MountDevName); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - RtlZeroMemory(MountPoint, sizeof(MOUNTMGR_MOUNT_POINT)); - MountPoint->DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINT); - MountPoint->DeviceNameLength = MountDevName->NameLength; - RtlCopyMemory(MountPoint + 1, MountDevName->Name, MountDevName->NameLength); - RtlFreeHeap(RtlGetProcessHeap(), 0, MountDevName); - - RtlInitUnicodeString(&NtFileName, L"\\??\\MountPointManager"); - InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL); - Status = NtOpenFile(&FileHandle, FILE_GENERIC_READ, &ObjectAttributes, - &Iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, - FILE_SYNCHRONOUS_IO_NONALERT); - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError(Status); - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); - return FALSE; - } - - BufferLength = sizeof(MOUNTMGR_MOUNT_POINTS); - do - { - MountPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength); - if (MountPoints == NULL) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); - NtClose(FileHandle); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb, - IOCTL_MOUNTMGR_QUERY_POINTS, - MountPoint, MountPointSize, - MountPoints, BufferLength); - if (!NT_SUCCESS(Status)) - { - if (Status == STATUS_BUFFER_OVERFLOW) - { - BufferLength = MountPoints->Size; - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); - continue; - } - else if (!NT_SUCCESS(Status)) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); - NtClose(FileHandle); - BaseSetLastNTError(Status); - return FALSE; - } - } - } - while (!NT_SUCCESS(Status)); - - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint); - NtClose(FileHandle); - - /* - * Now we've gathered info about all mount points mapped to our device, so - * select the correct one and copy it into the output buffer. - */ - - for (Index = 0; Index < MountPoints->NumberOfMountPoints; Index++) - { - MountPoint = MountPoints->MountPoints + Index; - SymbolicLinkName = (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset; - - /* - * Check for "\\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\" - * (with the last slash being optional) style symbolic links. - */ - - if (MountPoint->SymbolicLinkNameLength == 48 * sizeof(WCHAR) || - (MountPoint->SymbolicLinkNameLength == 49 * sizeof(WCHAR) && - SymbolicLinkName[48] == L'\\')) - { - if (RtlCompareMemory(SymbolicLinkName, L"\\??\\Volume{", - 11 * sizeof(WCHAR)) == 11 * sizeof(WCHAR) && - SymbolicLinkName[19] == L'-' && SymbolicLinkName[24] == L'-' && - SymbolicLinkName[29] == L'-' && SymbolicLinkName[34] == L'-' && - SymbolicLinkName[47] == L'}') - { - if (VolumeNameLength >= MountPoint->SymbolicLinkNameLength / sizeof(WCHAR)) - { - RtlCopyMemory(VolumeName, - (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset, - MountPoint->SymbolicLinkNameLength); - VolumeName[1] = L'\\'; - Result = TRUE; - } - else - { - SetLastError(ERROR_FILENAME_EXCED_RANGE); - Result = FALSE; - } - - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); - - return Result; - } - } - } - - RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints); - SetLastError(ERROR_INVALID_PARAMETER); - - return FALSE; -} - -/* - * @implemented (Wine 13 sep 2008) - */ -BOOL -WINAPI -GetVolumeNameForVolumeMountPointA( - LPCSTR lpszVolumeMountPoint, - LPSTR lpszVolumeName, - DWORD cchBufferLength - ) -{ - BOOL ret; - WCHAR volumeW[50], *pathW = NULL; - DWORD len = min( sizeof(volumeW) / sizeof(WCHAR), cchBufferLength ); - - TRACE("(%s, %p, %x)\n", debugstr_a(lpszVolumeMountPoint), lpszVolumeName, cchBufferLength); - - if (!lpszVolumeMountPoint || !(pathW = FilenameA2W( lpszVolumeMountPoint, TRUE ))) - return FALSE; - - if ((ret = GetVolumeNameForVolumeMountPointW( pathW, volumeW, len ))) - FilenameW2A_N( lpszVolumeName, len, volumeW, -1 ); - - RtlFreeHeap( RtlGetProcessHeap(), 0, pathW ); - return ret; -} - /* * @implemented (Wine 13 sep 2008) */ HANDLE WINAPI -FindFirstVolumeW( - LPWSTR volume, - DWORD len - ) +FindFirstVolumeW(IN LPWSTR volume, + IN DWORD len) { DWORD size = 1024; HANDLE mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, @@ -1149,10 +469,8 @@ FindFirstVolumeW( */ HANDLE WINAPI -FindFirstVolumeA( - LPSTR volume, - DWORD len - ) +FindFirstVolumeA(IN LPSTR volume, + IN DWORD len) { WCHAR *buffer = NULL; HANDLE handle; @@ -1184,9 +502,7 @@ FindFirstVolumeA( */ BOOL WINAPI -FindVolumeClose( - HANDLE hFindVolume - ) +FindVolumeClose(IN HANDLE hFindVolume) { return RtlFreeHeap(RtlGetProcessHeap(), 0, hFindVolume); } @@ -1196,9 +512,9 @@ FindVolumeClose( */ BOOL WINAPI -GetVolumePathNameA(LPCSTR lpszFileName, - LPSTR lpszVolumePathName, - DWORD cchBufferLength) +GetVolumePathNameA(IN LPCSTR lpszFileName, + IN LPSTR lpszVolumePathName, + IN DWORD cchBufferLength) { PWCHAR FileNameW = NULL; WCHAR VolumePathName[MAX_PATH]; @@ -1223,9 +539,9 @@ GetVolumePathNameA(LPCSTR lpszFileName, */ BOOL WINAPI -GetVolumePathNameW(LPCWSTR lpszFileName, - LPWSTR lpszVolumePathName, - DWORD cchBufferLength) +GetVolumePathNameW(IN LPCWSTR lpszFileName, + IN LPWSTR lpszVolumePathName, + IN DWORD cchBufferLength) { DWORD PathLength; UNICODE_STRING UnicodeFilePath; @@ -1329,57 +645,14 @@ Cleanup2: return Result; } - -/* - * @unimplemented - */ -BOOL -WINAPI -SetVolumeMountPointW( - LPCWSTR lpszVolumeMountPoint, - LPCWSTR lpszVolumeName - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -BOOL -WINAPI -DeleteVolumeMountPointA( - LPCSTR lpszVolumeMountPoint - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -HANDLE -WINAPI -FindFirstVolumeMountPointA( - LPCSTR lpszRootPathName, - LPSTR lpszVolumeMountPoint, - DWORD cchBufferLength - ) -{ - STUB; - return 0; -} - /* * @implemented */ BOOL WINAPI -FindNextVolumeA(HANDLE handle, - LPSTR volume, - DWORD len) +FindNextVolumeA(IN HANDLE handle, + IN LPSTR volume, + IN DWORD len) { WCHAR *buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, len * sizeof(WCHAR)); BOOL ret; @@ -1399,102 +672,14 @@ FindNextVolumeA(HANDLE handle, return ret; } -/* - * @unimplemented - */ -BOOL -WINAPI -FindNextVolumeMountPointA( - HANDLE hFindVolumeMountPoint, - LPSTR lpszVolumeMountPoint, - DWORD cchBufferLength - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -BOOL -WINAPI -GetVolumePathNamesForVolumeNameA( - LPCSTR lpszVolumeName, - LPSTR lpszVolumePathNames, - DWORD cchBufferLength, - PDWORD lpcchReturnLength - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -BOOL -WINAPI -SetVolumeMountPointA( - LPCSTR lpszVolumeMountPoint, - LPCSTR lpszVolumeName - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -BOOL -WINAPI -FindVolumeMountPointClose( - HANDLE hFindVolumeMountPoint - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -BOOL -WINAPI -DeleteVolumeMountPointW( - LPCWSTR lpszVolumeMountPoint - ) -{ - STUB; - return 0; -} - -/* - * @unimplemented - */ -HANDLE -WINAPI -FindFirstVolumeMountPointW( - LPCWSTR lpszRootPathName, - LPWSTR lpszVolumeMountPoint, - DWORD cchBufferLength - ) -{ - STUB; - return 0; -} - /* * @implemented */ BOOL WINAPI -FindNextVolumeW( - HANDLE handle, - LPWSTR volume, - DWORD len - ) +FindNextVolumeW(IN HANDLE handle, + IN LPWSTR volume, + IN DWORD len) { MOUNTMGR_MOUNT_POINTS *data = handle; @@ -1527,31 +712,28 @@ FindNextVolumeW( */ BOOL WINAPI -FindNextVolumeMountPointW( - HANDLE hFindVolumeMountPoint, - LPWSTR lpszVolumeMountPoint, - DWORD cchBufferLength - ) +GetVolumePathNamesForVolumeNameA(IN LPCSTR lpszVolumeName, + IN LPSTR lpszVolumePathNames, + IN DWORD cchBufferLength, + OUT PDWORD lpcchReturnLength) { STUB; return 0; } + /* * @unimplemented */ BOOL WINAPI -GetVolumePathNamesForVolumeNameW( - LPCWSTR lpszVolumeName, - LPWSTR lpszVolumePathNames, - DWORD cchBufferLength, - PDWORD lpcchReturnLength - ) +GetVolumePathNamesForVolumeNameW(IN LPCWSTR lpszVolumeName, + IN LPWSTR lpszVolumePathNames, + IN DWORD cchBufferLength, + OUT PDWORD lpcchReturnLength) { STUB; return 0; } - /* EOF */