ReactOS 0.4.16-dev-470-g91b8923
query.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: File Management IFS Utility functions
4 * FILE: reactos/dll/win32/fmifs/query.c
5 * PURPOSE: Query volume information
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8 */
9
10#include "precomp.h"
11#include <ntddstor.h>
12#include <ntstrsafe.h>
13
14#define NTOS_MODE_USER
15#include <ndk/iofuncs.h>
16#include <ndk/obfuncs.h>
17
22 IN OUT PWCHAR FileSystem, /* FIXME: Probably one minimal size is mandatory, but which one? */
23 OUT UCHAR *Major,
25 OUT BOOLEAN *LatestVersion)
26{
27 PLIST_ENTRY ListEntry;
29
30 if (!FileSystem || !Major ||!Minor ||!LatestVersion)
31 return FALSE;
32
33 ListEntry = ProviderListHead.Flink;
34 while (TRUE)
35 {
36 if (ListEntry == &ProviderListHead)
37 return FALSE;
38 if (Index == 0)
39 break;
40 ListEntry = ListEntry->Flink;
41 Index--;
42 }
43
44 Provider = CONTAINING_RECORD(ListEntry, IFS_PROVIDER, ListEntry);
46 *Major = 0; /* FIXME */
47 *Minor = 0; /* FIXME */
48 *LatestVersion = TRUE; /* FIXME */
49
50 return TRUE;
51}
52
77BOOL
80 _In_ PWCHAR DriveRoot,
81 _Out_ PVOID DeviceInformation,
83{
84 PDEVICE_INFORMATION DeviceInfo = DeviceInformation;
86 DISK_GEOMETRY DiskGeometry;
87 STORAGE_HOTPLUG_INFO HotplugInfo;
88 GET_LENGTH_INFORMATION LengthInformation;
94 WCHAR DriveName[MAX_PATH];
95
96 /* Buffer should be able to at least hold DeviceFlags */
97 if (BufferSize < sizeof(ULONG) ||
98 !NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
99 {
100 return FALSE;
101 }
102
103 if (DriveName[wcslen(DriveName) - 1] != L'\\')
104 {
105 /* Append the trailing backslash for GetVolumeNameForVolumeMountPointW */
106 if (!NT_SUCCESS(RtlStringCchCatW(DriveName, ARRAYSIZE(DriveName), L"\\")))
107 return FALSE;
108 }
109
112 {
113 /* Disk has no volume GUID, fallback to QueryDosDevice */
114 DriveName[wcslen(DriveName) - 1] = UNICODE_NULL;
116 return FALSE;
118 }
119 else
120 {
121 /* Trim the trailing backslash since we will work with a device object */
122 DeviceName.Length -= sizeof(WCHAR);
123 }
124
126 &DeviceName,
128 NULL,
129 NULL);
130
134 &Iosb,
137 if (!NT_SUCCESS(Status))
138 return FALSE;
139
141 NULL,
142 NULL,
143 NULL,
144 &Iosb,
146 NULL,
147 0,
148 &HotplugInfo,
149 sizeof(HotplugInfo));
150 if (!NT_SUCCESS(Status))
151 goto Quit;
152
153 DeviceInfo->DeviceFlags = 0;
154 if (HotplugInfo.MediaHotplug || HotplugInfo.DeviceHotplug)
155 {
156 /* This is a hotplug device */
157 DeviceInfo->DeviceFlags |= DEVICE_HOTPLUG;
158 }
159
160 /* Other flags that would be set here are related to Sony "Memory Stick"
161 * type of devices which we do not have any special support for */
162
163 if (BufferSize >= sizeof(DEVICE_INFORMATION))
164 {
165 /* This is the Vista+ version of the structure.
166 * We need to also provide disk sector size and volume length in sectors. */
168 NULL,
169 NULL,
170 NULL,
171 &Iosb,
173 NULL,
174 0,
175 &DiskGeometry,
176 sizeof(DiskGeometry));
177 if (!NT_SUCCESS(Status))
178 goto Quit;
179
181 NULL,
182 NULL,
183 NULL,
184 &Iosb,
186 NULL,
187 0,
188 &LengthInformation,
189 sizeof(LengthInformation));
190 if (!NT_SUCCESS(Status))
191 goto Quit;
192
193 LengthInformation.Length.QuadPart /= DiskGeometry.BytesPerSector;
194 DeviceInfo->SectorSize = DiskGeometry.BytesPerSector;
195 DeviceInfo->SectorCount = LengthInformation.Length;
196 }
197
199
200Quit:
202 return NT_SUCCESS(Status);
203}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
PWCHAR FileSystem
Definition: format.c:72
@ DiskDevice
Definition: bl.h:247
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
LIST_ENTRY ProviderListHead
Definition: init.c:20
BOOLEAN NTAPI QueryAvailableFileSystemFormat(IN DWORD Index, IN OUT PWCHAR FileSystem, OUT UCHAR *Major, OUT UCHAR *Minor, OUT BOOLEAN *LatestVersion)
Definition: query.c:20
BOOL NTAPI QueryDeviceInformation(_In_ PWCHAR DriveRoot, _Out_ PVOID DeviceInformation, _In_ ULONG BufferSize)
Retrieves disk device information.
Definition: query.c:79
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
Definition: dosdev.c:542
return Iosb
Definition: create.c:4403
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define DEVICE_HOTPLUG
Definition: fmifs.h:47
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
BOOL WINAPI GetVolumeNameForVolumeMountPointW(IN LPCWSTR VolumeMountPoint, OUT LPWSTR VolumeName, IN DWORD VolumeNameLength)
Definition: mntpoint.c:496
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
#define IOCTL_STORAGE_GET_HOTPLUG_INFO
Definition: imports.h:238
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3953
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define UNICODE_NULL
NTSTRSAFEAPI RtlStringCchCopyW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:127
NTSTRSAFEAPI RtlStringCchCatW(_Inout_updates_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:601
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG BytesPerSector
Definition: ntdddisk.h:404
LARGE_INTEGER Length
Definition: imports.h:232
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
BOOLEAN DeviceHotplug
Definition: imports.h:248
BOOLEAN MediaHotplug
Definition: imports.h:247
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180