ReactOS  0.4.15-dev-1018-g0695ecb
worker-thread.c File Reference
#include "btrfs_drv.h"
Include dependency graph for worker-thread.c:

Go to the source code of this file.

Classes

struct  job_info
 

Functions

NTSTATUS do_read_job (PIRP Irp)
 
NTSTATUS do_write_job (device_extension *Vcb, PIRP Irp)
 
 _Function_class_ (WORKER_THREAD_ROUTINE)
 
bool add_thread_job (device_extension *Vcb, PIRP Irp)
 

Function Documentation

◆ _Function_class_()

_Function_class_ ( WORKER_THREAD_ROUTINE  )

Definition at line 95 of file worker-thread.c.

96  {
97  job_info* ji = context;
99 
100  if (IrpSp->MajorFunction == IRP_MJ_READ) {
101  do_read_job(ji->Irp);
102  } else if (IrpSp->MajorFunction == IRP_MJ_WRITE) {
103  do_write_job(ji->Vcb, ji->Irp);
104  }
105 
106  ExFreePool(ji);
107 }
Definition: http.c:7094
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS do_write_job(device_extension *Vcb, PIRP Irp)
Definition: worker-thread.c:68
NTSTATUS do_read_job(PIRP Irp)
Definition: worker-thread.c:26
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
device_extension * Vcb
Definition: worker-thread.c:21
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ add_thread_job()

bool add_thread_job ( device_extension Vcb,
PIRP  Irp 
)

Definition at line 109 of file worker-thread.c.

109  {
110  job_info* ji;
111 
113  if (!ji) {
114  ERR("out of memory\n");
115  return false;
116  }
117 
118  ji->Vcb = Vcb;
119  ji->Irp = Irp;
120 
121  if (!Irp->MdlAddress) {
122  PMDL Mdl;
124  ULONG len;
126 
127  if (IrpSp->MajorFunction == IRP_MJ_READ) {
128  op = IoWriteAccess;
129  len = IrpSp->Parameters.Read.Length;
130  } else if (IrpSp->MajorFunction == IRP_MJ_WRITE) {
131  op = IoReadAccess;
132  len = IrpSp->Parameters.Write.Length;
133  } else {
134  ERR("unexpected major function %u\n", IrpSp->MajorFunction);
135  ExFreePool(ji);
136  return false;
137  }
138 
139  Mdl = IoAllocateMdl(Irp->UserBuffer, len, false, false, Irp);
140 
141  if (!Mdl) {
142  ERR("out of memory\n");
143  ExFreePool(ji);
144  return false;
145  }
146 
147  _SEH2_TRY {
148  MmProbeAndLockPages(Mdl, Irp->RequestorMode, op);
150  ERR("MmProbeAndLockPages raised status %08lx\n", _SEH2_GetExceptionCode());
151 
152  IoFreeMdl(Mdl);
153  Irp->MdlAddress = NULL;
154  ExFreePool(ji);
155 
156  _SEH2_YIELD(return FALSE);
157  } _SEH2_END;
158  }
159 
160  ExInitializeWorkItem(&ji->item, do_job, ji);
162 
163  return true;
164 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
_In_ PIRP Irp
Definition: csq.h:116
_SEH2_TRY
Definition: create.c:4226
#define ALLOC_TAG
Definition: btrfs_drv.h:91
#define FALSE
Definition: types.h:117
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define Vcb
Definition: cdprocs.h:1415
UINT op
Definition: effect.c:224
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
GLenum GLsizei len
Definition: glext.h:6722
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_SEH2_END
Definition: create.c:4400
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
enum _LOCK_OPERATION LOCK_OPERATION
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
device_extension * Vcb
Definition: worker-thread.c:21
#define IRP_MJ_READ
Definition: rdpdr.c:46
unsigned int ULONG
Definition: retypes.h:1
WORK_QUEUE_ITEM item
Definition: worker-thread.c:23
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2779
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by _Dispatch_type_().

◆ do_read_job()

NTSTATUS do_read_job ( PIRP  Irp)

Definition at line 26 of file worker-thread.c.

26  {
28  ULONG bytes_read;
29  bool top_level = is_top_level(Irp);
32  fcb* fcb = FileObject->FsContext;
33  bool acquired_fcb_lock = false;
34 
35  Irp->IoStatus.Information = 0;
36 
37  if (!ExIsResourceAcquiredSharedLite(fcb->Header.Resource)) {
38  ExAcquireResourceSharedLite(fcb->Header.Resource, true);
39  acquired_fcb_lock = true;
40  }
41 
42  _SEH2_TRY {
43  Status = do_read(Irp, true, &bytes_read);
46  } _SEH2_END;
47 
48  if (acquired_fcb_lock)
49  ExReleaseResourceLite(fcb->Header.Resource);
50 
51  if (!NT_SUCCESS(Status))
52  ERR("do_read returned %08lx\n", Status);
53 
54  Irp->IoStatus.Status = Status;
55 
56  TRACE("read %Iu bytes\n", Irp->IoStatus.Information);
57 
59 
60  if (top_level)
62 
63  TRACE("returning %08lx\n", Status);
64 
65  return Status;
66 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:294
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1962
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:2820
_SEH2_END
Definition: create.c:4400
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:570
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS do_read(PIRP Irp, bool wait, ULONG *bytes_read)
Definition: read.c:3361

Referenced by _Dispatch_type_(), and _Function_class_().

◆ do_write_job()

NTSTATUS do_write_job ( device_extension Vcb,
PIRP  Irp 
)

Definition at line 68 of file worker-thread.c.

68  {
69  bool top_level = is_top_level(Irp);
71 
72  _SEH2_TRY {
73  Status = write_file(Vcb, Irp, true, true);
76  } _SEH2_END;
77 
78  if (!NT_SUCCESS(Status))
79  ERR("write_file returned %08lx\n", Status);
80 
81  Irp->IoStatus.Status = Status;
82 
83  TRACE("wrote %Iu bytes\n", Irp->IoStatus.Information);
84 
86 
87  if (top_level)
89 
90  TRACE("returning %08lx\n", Status);
91 
92  return Status;
93 }
_In_ PIRP Irp
Definition: csq.h:116
static void write_file(HANDLE hFile, const WCHAR *str)
Definition: export.c:27
LONG NTSTATUS
Definition: precomp.h:26
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1415
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define ERR(fmt,...)
Definition: debug.h:110
_SEH2_END
Definition: create.c:4400
#define IO_NO_INCREMENT
Definition: iotypes.h:570
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12

Referenced by _Dispatch_type_(), and _Function_class_().