ReactOS  0.4.14-dev-342-gdc047f9
devctrl.c File Reference
#include "btrfs_drv.h"
#include <ntdddisk.h>
#include <mountdev.h>
#include <diskguid.h>
Include dependency graph for devctrl.c:

Go to the source code of this file.

Functions

static NTSTATUS mountdev_query_stable_guid (device_extension *Vcb, PIRP Irp)
 
static NTSTATUS is_writable (device_extension *Vcb)
 
static NTSTATUS query_filesystems (void *data, ULONG length)
 
static NTSTATUS probe_volume (void *data, ULONG length, KPROCESSOR_MODE processor_mode)
 
static NTSTATUS ioctl_unload (PIRP Irp)
 
static NTSTATUS control_ioctl (PIRP Irp)
 
 _Dispatch_type_ (IRP_MJ_DEVICE_CONTROL)
 

Variables

PDRIVER_OBJECT drvobj
 
LIST_ENTRY VcbList
 
ERESOURCE global_loading_lock
 

Function Documentation

◆ _Dispatch_type_()

_Dispatch_type_ ( IRP_MJ_DEVICE_CONTROL  )

Definition at line 252 of file devctrl.c.

254  {
258  bool top_level;
259 
261 
262  top_level = is_top_level(Irp);
263 
264  Irp->IoStatus.Information = 0;
265 
266  if (Vcb) {
267  if (Vcb->type == VCB_TYPE_CONTROL) {
269  goto end;
270  } else if (Vcb->type == VCB_TYPE_VOLUME) {
272  goto end;
273  } else if (Vcb->type != VCB_TYPE_FS) {
275  goto end;
276  }
277  } else {
279  goto end;
280  }
281 
282  if (!IrpSp->FileObject || IrpSp->FileObject->FsContext != Vcb->volume_fcb) {
284  goto end;
285  }
286 
287  switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
290  goto end;
291 
294  goto end;
295 
296  default:
297  TRACE("unhandled control code %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
298  break;
299  }
300 
302 
303  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
304 
305  goto end2;
306 
307 end:
308  Irp->IoStatus.Status = Status;
309 
310  if (Status != STATUS_PENDING)
312 
313 end2:
314  TRACE("returning %08x\n", Status);
315 
316  if (top_level)
318 
320 
321  return Status;
322 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define IOCTL_MOUNTDEV_QUERY_STABLE_GUID
Definition: imports.h:255
#define TRACE(s)
Definition: solgame.cpp:4
static NTSTATUS control_ioctl(PIRP Irp)
Definition: devctrl.c:226
#define STATUS_PENDING
Definition: ntstatus.h:82
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
#define Vcb
Definition: cdprocs.h:1425
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:665
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS vol_device_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:820
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
static NTSTATUS is_writable(device_extension *Vcb)
Definition: devctrl.c:43
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
static NTSTATUS mountdev_query_stable_guid(device_extension *Vcb, PIRP Irp)
Definition: devctrl.c:27

◆ control_ioctl()

static NTSTATUS control_ioctl ( PIRP  Irp)
static

Definition at line 226 of file devctrl.c.

226  {
229 
230  switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
232  Status = query_filesystems(map_user_buffer(Irp, NormalPagePriority), IrpSp->Parameters.FileSystemControl.OutputBufferLength);
233  break;
234 
236  Status = probe_volume(Irp->AssociatedIrp.SystemBuffer, IrpSp->Parameters.FileSystemControl.InputBufferLength, Irp->RequestorMode);
237  break;
238 
239  case IOCTL_BTRFS_UNLOAD:
241  break;
242 
243  default:
244  TRACE("unhandled ioctl %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
246  break;
247  }
248 
249  return Status;
250 }
#define IOCTL_BTRFS_UNLOAD
Definition: btrfsioctl.h:39
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define IOCTL_BTRFS_QUERY_FILESYSTEMS
Definition: btrfsioctl.h:21
LONG NTSTATUS
Definition: precomp.h:26
#define TRACE(s)
Definition: solgame.cpp:4
static __inline void * map_user_buffer(PIRP Irp, ULONG priority)
Definition: btrfs_drv.h:952
#define IOCTL_BTRFS_PROBE_VOLUME
Definition: btrfsioctl.h:28
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static NTSTATUS ioctl_unload(PIRP Irp)
Definition: devctrl.c:215
static NTSTATUS query_filesystems(void *data, ULONG length)
Definition: devctrl.c:49
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
static NTSTATUS probe_volume(void *data, ULONG length, KPROCESSOR_MODE processor_mode)
Definition: devctrl.c:162

Referenced by _Dispatch_type_().

◆ ioctl_unload()

static NTSTATUS ioctl_unload ( PIRP  Irp)
static

Definition at line 215 of file devctrl.c.

215  {
216  if (!SeSinglePrivilegeCheck(RtlConvertLongToLuid(SE_LOAD_DRIVER_PRIVILEGE), Irp->RequestorMode)) {
217  ERR("insufficient privileges\n");
219  }
220 
221  do_shutdown(Irp);
222 
223  return STATUS_SUCCESS;
224 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
_In_ PIRP Irp
Definition: csq.h:116
#define SE_LOAD_DRIVER_PRIVILEGE
Definition: security.c:664
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
#define ERR(fmt,...)
Definition: debug.h:109
return STATUS_SUCCESS
Definition: btrfs.c:2938
void do_shutdown(PIRP Irp)
Definition: btrfs.c:5212

Referenced by control_ioctl().

◆ is_writable()

static NTSTATUS is_writable ( device_extension Vcb)
static

Definition at line 43 of file devctrl.c.

43  {
44  TRACE("IOCTL_DISK_IS_WRITABLE\n");
45 
46  return Vcb->readonly ? STATUS_MEDIA_WRITE_PROTECTED : STATUS_SUCCESS;
47 }
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define TRACE(s)
Definition: solgame.cpp:4
#define Vcb
Definition: cdprocs.h:1425
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by _Dispatch_type_().

◆ mountdev_query_stable_guid()

static NTSTATUS mountdev_query_stable_guid ( device_extension Vcb,
PIRP  Irp 
)
static

Definition at line 27 of file devctrl.c.

27  {
28  MOUNTDEV_STABLE_GUID* msg = Irp->UserBuffer;
30 
31  TRACE("IOCTL_MOUNTDEV_QUERY_STABLE_GUID\n");
32 
33  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUNTDEV_STABLE_GUID))
35 
36  RtlCopyMemory(&msg->StableGuid, &Vcb->superblock.uuid, sizeof(GUID));
37 
38  Irp->IoStatus.Information = sizeof(MOUNTDEV_STABLE_GUID);
39 
40  return STATUS_SUCCESS;
41 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _MOUNTDEV_STABLE_GUID MOUNTDEV_STABLE_GUID
#define TRACE(s)
Definition: solgame.cpp:4
#define Vcb
Definition: cdprocs.h:1425
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define msg(x)
Definition: auth_time.c:54
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by _Dispatch_type_().

◆ probe_volume()

static NTSTATUS probe_volume ( void data,
ULONG  length,
KPROCESSOR_MODE  processor_mode 
)
static

Definition at line 162 of file devctrl.c.

162  {
168  const GUID* guid;
169 
170  if (length < sizeof(MOUNTDEV_NAME))
172 
173  if (length < offsetof(MOUNTDEV_NAME, Name[0]) + mdn->NameLength)
175 
176  TRACE("%.*S\n", mdn->NameLength / sizeof(WCHAR), mdn->Name);
177 
178  if (!SeSinglePrivilegeCheck(RtlConvertLongToLuid(SE_MANAGE_VOLUME_PRIVILEGE), processor_mode))
180 
181  path.Buffer = mdn->Name;
182  path.Length = path.MaximumLength = mdn->NameLength;
183 
185  if (!NT_SUCCESS(Status)) {
186  ERR("IoGetDeviceObjectPointer returned %08x\n", Status);
187  return Status;
188  }
189 
191  if (!NT_SUCCESS(Status)) {
192  ERR("get_device_pnp_name returned %08x\n", Status);
194  return Status;
195  }
196 
197  if (RtlCompareMemory(guid, &GUID_DEVINTERFACE_DISK, sizeof(GUID)) == sizeof(GUID)) {
199  if (!NT_SUCCESS(Status))
200  WARN("IOCTL_DISK_UPDATE_PROPERTIES returned %08x\n", Status);
201  }
202 
204 
206 
207  if (RtlCompareMemory(guid, &GUID_DEVINTERFACE_DISK, sizeof(GUID)) == sizeof(GUID))
209  else
211 
212  return STATUS_SUCCESS;
213 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
GLsizei const GLchar ** path
Definition: glext.h:7234
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
const GUID * guid
void disk_arrival(PDRIVER_OBJECT DriverObject, PUNICODE_STRING devpath)
Definition: search.c:263
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS get_device_pnp_name(_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _Out_ const GUID **guid)
Definition: btrfs.c:4109
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR Name[1]
Definition: imports.h:144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
NTSTATUS dev_ioctl(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize, _Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _In_ bool Override, _Out_opt_ IO_STATUS_BLOCK *iosb)
Definition: btrfs.c:2813
* PFILE_OBJECT
Definition: iotypes.h:1955
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
void volume_arrival(PDRIVER_OBJECT DriverObject, PUNICODE_STRING devpath)
Definition: search.c:497
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define IOCTL_DISK_UPDATE_PROPERTIES
Definition: winioctl.h:69
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SE_MANAGE_VOLUME_PRIVILEGE
Definition: security.c:682
Definition: services.c:325
USHORT NameLength
Definition: imports.h:143
UNICODE_STRING pnp_name
Definition: btrfs.c:4139
PDRIVER_OBJECT drvobj
Definition: btrfs.c:66
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
void volume_removal(PDRIVER_OBJECT DriverObject, PUNICODE_STRING devpath)
Definition: search.c:591

Referenced by control_ioctl().

◆ query_filesystems()

static NTSTATUS query_filesystems ( void data,
ULONG  length 
)
static

Definition at line 49 of file devctrl.c.

49  {
51  LIST_ENTRY *le, *le2;
52  btrfs_filesystem* bfs = NULL;
53  ULONG itemsize;
54 
56 
57  if (IsListEmpty(&VcbList)) {
58  if (length < sizeof(btrfs_filesystem)) {
60  goto end;
61  } else {
64  goto end;
65  }
66  }
67 
68  le = VcbList.Flink;
69 
70  while (le != &VcbList) {
73 
74  if (bfs) {
75  bfs->next_entry = itemsize;
76  bfs = (btrfs_filesystem*)((uint8_t*)bfs + itemsize);
77  } else
78  bfs = data;
79 
82  goto end;
83  }
84 
85  itemsize = offsetof(btrfs_filesystem, device);
87 
88  bfs->next_entry = 0;
89  RtlCopyMemory(&bfs->uuid, &Vcb->superblock.uuid, sizeof(BTRFS_UUID));
90 
91  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
92 
93  bfs->num_devices = (uint32_t)Vcb->superblock.num_devices;
94 
95  bfd = NULL;
96 
97  le2 = Vcb->devices.Flink;
98  while (le2 != &Vcb->devices) {
100  MOUNTDEV_NAME mdn;
101 
102  if (bfd)
104  else
105  bfd = &bfs->device;
106 
108  ExReleaseResourceLite(&Vcb->tree_lock);
110  goto end;
111  }
112 
113  itemsize += (ULONG)offsetof(btrfs_filesystem_device, name[0]);
115 
116  RtlCopyMemory(&bfd->uuid, &dev->devitem.device_uuid, sizeof(BTRFS_UUID));
117 
118  if (dev->devobj) {
119  Status = dev_ioctl(dev->devobj, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, &mdn, sizeof(MOUNTDEV_NAME), true, NULL);
121  ExReleaseResourceLite(&Vcb->tree_lock);
122  ERR("IOCTL_MOUNTDEV_QUERY_DEVICE_NAME returned %08x\n", Status);
123  goto end;
124  }
125 
126  if (mdn.NameLength > length) {
127  ExReleaseResourceLite(&Vcb->tree_lock);
129  goto end;
130  }
131 
132  Status = dev_ioctl(dev->devobj, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, &bfd->name_length, (ULONG)offsetof(MOUNTDEV_NAME, Name[0]) + mdn.NameLength, true, NULL);
134  ExReleaseResourceLite(&Vcb->tree_lock);
135  ERR("IOCTL_MOUNTDEV_QUERY_DEVICE_NAME returned %08x\n", Status);
136  goto end;
137  }
138 
139  itemsize += bfd->name_length;
140  length -= bfd->name_length;
141  } else {
142  bfd->missing = true;
143  bfd->name_length = 0;
144  }
145 
146  le2 = le2->Flink;
147  }
148 
149  ExReleaseResourceLite(&Vcb->tree_lock);
150 
151  le = le->Flink;
152  }
153 
155 
156 end:
158 
159  return Status;
160 }
ERESOURCE global_loading_lock
Definition: btrfs.c:74
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
void * bfd
Definition: i386-dis.c:28
LONG NTSTATUS
Definition: precomp.h:26
GLuint GLuint end
Definition: gl.h:1545
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
while(1)
Definition: macro.lex.yy.c:740
uint32_t num_devices
Definition: btrfsioctl.h:190
Definition: devices.h:37
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
NTSTATUS dev_ioctl(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize, _Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _In_ bool Override, _Out_opt_ IO_STATUS_BLOCK *iosb)
Definition: btrfs.c:2813
#define Vcb
Definition: cdprocs.h:1425
uint32_t next_entry
Definition: btrfsioctl.h:188
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
LIST_ENTRY VcbList
Definition: btrfs.c:73
Definition: typedefs.h:117
BYTE uint8_t
Definition: msvideo1.c:66
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: list.h:27
USHORT NameLength
Definition: imports.h:143
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
uint8_t uuid[16]
Definition: btrfsioctl.h:189
Definition: name.c:36
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define uint32_t
Definition: nsiface.idl:61
return STATUS_SUCCESS
Definition: btrfs.c:2938
btrfs_filesystem_device device
Definition: btrfsioctl.h:191

Referenced by control_ioctl().

Variable Documentation

◆ drvobj

Definition at line 66 of file btrfs.c.

Referenced by probe_volume().

◆ global_loading_lock

ERESOURCE global_loading_lock

Definition at line 74 of file btrfs.c.

Referenced by query_filesystems().

◆ VcbList

LIST_ENTRY VcbList

Definition at line 73 of file btrfs.c.

Referenced by query_filesystems().