ReactOS 0.4.16-dev-983-g23ad936
query.c File Reference
#include "precomp.h"
#include <ntddstor.h>
#include <ntstrsafe.h>
#include <ndk/iofuncs.h>
#include <ndk/obfuncs.h>
Include dependency graph for query.c:

Go to the source code of this file.

Macros

#define NTOS_MODE_USER
 

Functions

BOOLEAN NTAPI QueryAvailableFileSystemFormat (IN DWORD Index, IN OUT PWCHAR FileSystem, OUT UCHAR *Major, OUT UCHAR *Minor, OUT BOOLEAN *LatestVersion)
 
BOOL NTAPI QueryDeviceInformation (_In_ PWCHAR DriveRoot, _Out_ PVOID DeviceInformation, _In_ ULONG BufferSize)
 Retrieves disk device information.
 

Macro Definition Documentation

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 14 of file query.c.

Function Documentation

◆ QueryAvailableFileSystemFormat()

BOOLEAN NTAPI QueryAvailableFileSystemFormat ( IN DWORD  Index,
IN OUT PWCHAR  FileSystem,
OUT UCHAR Major,
OUT UCHAR Minor,
OUT BOOLEAN LatestVersion 
)

Definition at line 20 of file query.c.

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}
PWCHAR FileSystem
Definition: format.c:72
wcscpy
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LIST_ENTRY ProviderListHead
Definition: init.c:20
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ WDFCOLLECTION _In_ ULONG Index
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44

Referenced by InitializeFormatDriveDlg(), ShowInstalledFileSystems(), and Usage().

◆ QueryDeviceInformation()

BOOL NTAPI QueryDeviceInformation ( _In_ PWCHAR  DriveRoot,
_Out_ PVOID  DeviceInformation,
_In_ ULONG  BufferSize 
)

Retrieves disk device information.

Parameters
[in]DriveRootString which contains a DOS device name,
[in,out]DeviceInformationPointer to buffer with DEVICE_INFORMATION structure which will receive data.
[in]BufferSizeSize of buffer in bytes.
Returns
TRUE if the buffer was large enough and was filled with the requested information, FALSE otherwise.
Remarks
The returned information is mostly related to Sony Memory Stick devices. On Vista+ the returned information is disk sector size and volume length in sectors, regardless of the type of disk. ReactOS implementation returns DEVICE_HOTPLUG flag if inspected device is a hotplug device as well as sector size and volume length of disk device.

Definition at line 79 of file query.c.

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}
LONG NTSTATUS
Definition: precomp.h:26
@ 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 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
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
Definition: dosdev.c:542
return Iosb
Definition: create.c:4403
_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)
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
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG BytesPerSector
Definition: ntdddisk.h:404
LARGE_INTEGER Length
Definition: imports.h:232
BOOLEAN DeviceHotplug
Definition: imports.h:248
BOOLEAN MediaHotplug
Definition: imports.h:247
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
_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
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by MountMgrCreatePointWorker(), MountMgrNextDriveLetterWorker(), MountMgrVolumeMountPointChanged(), MountMgrVolumeMountPointCreated(), QueryPointsFromMemory(), QueryPointsFromSymbolicLinkName(), USBD_GetDeviceInformationEx(), USBH_GetDeviceType(), and wmain().