ReactOS  0.4.14-dev-376-gaedba84
calcthread.c File Reference
#include "btrfs_drv.h"
Include dependency graph for calcthread.c:

Go to the source code of this file.

Macros

#define SECTOR_BLOCK   16
 

Functions

NTSTATUS add_calc_job (device_extension *Vcb, uint8_t *data, uint32_t sectors, uint32_t *csum, calc_job **pcj)
 
void free_calc_job (calc_job *cj)
 
static bool do_calc (device_extension *Vcb, calc_job *cj)
 
 _Function_class_ (KSTART_ROUTINE)
 

Macro Definition Documentation

◆ SECTOR_BLOCK

#define SECTOR_BLOCK   16

Definition at line 20 of file calcthread.c.

Function Documentation

◆ _Function_class_()

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 94 of file calcthread.c.

95  {
97  device_extension* Vcb = thread->DeviceObject->DeviceExtension;
98 
99  ObReferenceObject(thread->DeviceObject);
100 
101  while (true) {
102  KeWaitForSingleObject(&Vcb->calcthreads.event, Executive, KernelMode, false, NULL);
103 
104  while (true) {
105  calc_job* cj;
106  bool b;
107 
108  ExAcquireResourceExclusiveLite(&Vcb->calcthreads.lock, true);
109 
110  if (IsListEmpty(&Vcb->calcthreads.job_list)) {
111  ExReleaseResourceLite(&Vcb->calcthreads.lock);
112  break;
113  }
114 
115  cj = CONTAINING_RECORD(Vcb->calcthreads.job_list.Flink, calc_job, list_entry);
116  cj->refcount++;
117 
118  ExReleaseResourceLite(&Vcb->calcthreads.lock);
119 
120  b = do_calc(Vcb, cj);
121 
122  free_calc_job(cj);
123 
124  if (!b)
125  break;
126  }
127 
128  if (thread->quit)
129  break;
130  }
131 
132  ObDereferenceObject(thread->DeviceObject);
133 
134  KeSetEvent(&thread->finished, 0, false);
135 
137 }
_In_ ULONG cj
Definition: winddi.h:3540
Definition: http.c:6587
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
smooth NULL
Definition: ftsmooth.c:416
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
#define b
Definition: ke_i.h:79
static bool do_calc(device_extension *Vcb, calc_job *cj)
Definition: calcthread.c:60
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
static HANDLE thread
Definition: service.c:33
void free_calc_job(calc_job *cj)
Definition: calcthread.c:53
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
Definition: list.h:27
#define ObReferenceObject
Definition: obfuncs.h:204
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ add_calc_job()

NTSTATUS add_calc_job ( device_extension Vcb,
uint8_t data,
uint32_t  sectors,
uint32_t csum,
calc_job **  pcj 
)

Definition at line 22 of file calcthread.c.

22  {
23  calc_job* cj;
24 
26  if (!cj) {
27  ERR("out of memory\n");
29  }
30 
31  cj->data = data;
32  cj->sectors = sectors;
33  cj->csum = csum;
34  cj->pos = 0;
35  cj->done = 0;
36  cj->refcount = 1;
37  KeInitializeEvent(&cj->event, NotificationEvent, false);
38 
39  ExAcquireResourceExclusiveLite(&Vcb->calcthreads.lock, true);
40 
41  InsertTailList(&Vcb->calcthreads.job_list, &cj->list_entry);
42 
43  KeSetEvent(&Vcb->calcthreads.event, 0, false);
44  KeClearEvent(&Vcb->calcthreads.event);
45 
46  ExReleaseResourceLite(&Vcb->calcthreads.lock);
47 
48  *pcj = cj;
49 
50  return STATUS_SUCCESS;
51 }
_In_ ULONG cj
Definition: winddi.h:3540
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG * pcj
Definition: winddi.h:3642
#define InsertTailList(ListHead, Entry)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define ALLOC_TAG
Definition: btrfs_drv.h:91
uint32_t * csum
Definition: write.c:2821
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
__u8 sectors[2]
Definition: mkdosfs.c:366
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by calc_csum(), and check_csum().

◆ do_calc()

static bool do_calc ( device_extension Vcb,
calc_job cj 
)
static

Definition at line 60 of file calcthread.c.

60  {
61  LONG pos, done;
62  uint32_t* csum;
63  uint8_t* data;
64  ULONG blocksize, i;
65 
66  pos = InterlockedIncrement(&cj->pos) - 1;
67 
68  if ((uint32_t)pos * SECTOR_BLOCK >= cj->sectors)
69  return false;
70 
71  csum = &cj->csum[pos * SECTOR_BLOCK];
72  data = cj->data + (pos * SECTOR_BLOCK * Vcb->superblock.sector_size);
73 
74  blocksize = min(SECTOR_BLOCK, cj->sectors - (pos * SECTOR_BLOCK));
75  for (i = 0; i < blocksize; i++) {
76  *csum = ~calc_crc32c(0xffffffff, data, Vcb->superblock.sector_size);
77  csum++;
78  data += Vcb->superblock.sector_size;
79  }
80 
81  done = InterlockedIncrement(&cj->done);
82 
83  if ((uint32_t)done * SECTOR_BLOCK >= cj->sectors) {
84  ExAcquireResourceExclusiveLite(&Vcb->calcthreads.lock, true);
85  RemoveEntryList(&cj->list_entry);
86  ExReleaseResourceLite(&Vcb->calcthreads.lock);
87 
88  KeSetEvent(&cj->event, 0, false);
89  }
90 
91  return true;
92 }
_In_ ULONG cj
Definition: winddi.h:3540
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
static uint32_t calc_crc32c(uint32_t seed, uint8_t *msg, ULONG msglen)
Definition: recv.cpp:134
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
uint32_t * csum
Definition: write.c:2821
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
BYTE uint8_t
Definition: msvideo1.c:66
#define InterlockedIncrement
Definition: armddk.h:53
#define min(a, b)
Definition: monoChain.cc:55
UINT32 uint32_t
Definition: types.h:75
Definition: fs.h:216
unsigned int ULONG
Definition: retypes.h:1
#define SECTOR_BLOCK
Definition: calcthread.c:20

Referenced by _Function_class_().

◆ free_calc_job()

void free_calc_job ( calc_job cj)

Definition at line 53 of file calcthread.c.

53  {
54  LONG rc = InterlockedDecrement(&cj->refcount);
55 
56  if (rc == 0)
57  ExFreePool(cj);
58 }
_In_ ULONG cj
Definition: winddi.h:3540
long LONG
Definition: pedump.c:60
#define InterlockedDecrement
Definition: armddk.h:52
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by _Function_class_(), calc_csum(), and check_csum().