00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#include "iop.h"
00029
00030
#ifdef ALLOC_PRAGMA
00031
#pragma alloc_text(PAGE, NtCancelIoFile)
00032
#pragma alloc_text(PAGE, NtDeleteFile)
00033
#pragma alloc_text(PAGE, NtFlushBuffersFile)
00034
#pragma alloc_text(PAGE, NtQueryAttributesFile)
00035
#pragma alloc_text(PAGE, NtQueryFullAttributesFile)
00036
#endif
00037
00038
00039
00040
00041
00042
VOID
00043
IopProcessWorkItem(
00044 IN PVOID Parameter
00045 );
00046
00047
00048
NTSTATUS
00049 NtCancelIoFile(
00050 IN HANDLE FileHandle,
00051 OUT PIO_STATUS_BLOCK IoStatusBlock
00052 )
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 {
00081
PIRP irp;
00082
NTSTATUS status;
00083
PFILE_OBJECT fileObject;
00084
KPROCESSOR_MODE requestorMode;
00085
PETHREAD thread;
00086 BOOLEAN found =
FALSE;
00087 PLIST_ENTRY header;
00088 PLIST_ENTRY entry;
00089 KIRQL irql;
00090
00091
PAGED_CODE();
00092
00093
00094
00095
00096
00097 requestorMode = KeGetPreviousMode();
00098
00099
if (requestorMode !=
KernelMode) {
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
try {
00110
00111
00112
00113
00114
00115
ProbeForWriteIoStatus( IoStatusBlock );
00116
00117 } except(
EXCEPTION_EXECUTE_HANDLER) {
00118
00119
00120
00121
00122
00123
00124
00125
return GetExceptionCode();
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136 status =
ObReferenceObjectByHandle( FileHandle,
00137 0,
00138
IoFileObjectType,
00139 requestorMode,
00140 (PVOID *) &fileObject,
00141
NULL );
00142
if (!
NT_SUCCESS( status )) {
00143
return(status);
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 thread =
PsGetCurrentThread();
00161
00162
00163
00164
00165
00166
00167
IopUpdateOtherOperationCount();
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
KeRaiseIrql(
APC_LEVEL, &irql );
00181
00182 header = &thread->
IrpList;
00183 entry = thread->
IrpList.Flink;
00184
00185
while (header != entry) {
00186
00187
00188
00189
00190
00191
00192
00193 irp = CONTAINING_RECORD( entry,
IRP, ThreadListEntry );
00194
if (irp->
Tail.Overlay.OriginalFileObject == fileObject) {
00195 found =
TRUE;
00196
IoCancelIrp( irp );
00197 }
00198
00199 entry = entry->Flink;
00200 }
00201
00202
00203
00204
00205
00206
KeLowerIrql( irql );
00207
00208
if (found) {
00209
00210 LARGE_INTEGER interval;
00211
00212
00213
00214
00215
00216
00217 interval.QuadPart = -10 * 1000 * 10;
00218
00219
00220
00221
00222
00223
while (found) {
00224
00225 (
VOID)
KeDelayExecutionThread(
KernelMode,
FALSE, &interval );
00226
00227 found =
FALSE;
00228
00229
00230
00231
00232
00233
00234
KeRaiseIrql(
APC_LEVEL, &irql );
00235
00236
00237
00238
00239
00240
00241 entry = thread->
IrpList.Flink;
00242
00243
while (header != entry) {
00244
00245
00246
00247
00248
00249
00250
00251 irp = CONTAINING_RECORD( entry,
IRP, ThreadListEntry );
00252
if (irp->
Tail.Overlay.OriginalFileObject == fileObject) {
00253 found =
TRUE;
00254
break;
00255 }
00256
00257 entry = entry->Flink;
00258 }
00259
00260
00261
00262
00263
00264
KeLowerIrql( irql );
00265
00266 }
00267 }
00268
00269
try {
00270
00271
00272
00273
00274
00275 IoStatusBlock->Status = STATUS_SUCCESS;
00276 IoStatusBlock->Information = 0
L;
00277
00278 } except(
EXCEPTION_EXECUTE_HANDLER) {
00279
00280
00281
00282
00283
00284
00285
00286 }
00287
00288
00289
00290
00291
00292
ObDereferenceObject( fileObject );
00293
00294
return STATUS_SUCCESS;
00295 }
00296
00297
NTSTATUS
00298 NtDeleteFile(
00299 IN POBJECT_ATTRIBUTES ObjectAttributes
00300 )
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 {
00320
KPROCESSOR_MODE requestorMode;
00321
NTSTATUS status;
00322
OPEN_PACKET openPacket;
00323
DUMMY_FILE_OBJECT localFileObject;
00324 HANDLE handle;
00325
00326
PAGED_CODE();
00327
00328
00329
00330
00331
00332 requestorMode = KeGetPreviousMode();
00333
00334
00335
00336
00337
00338
00339 RtlZeroMemory( &openPacket,
sizeof(
OPEN_PACKET ) );
00340
00341 openPacket.
Type =
IO_TYPE_OPEN_PACKET;
00342 openPacket.
Size =
sizeof(
OPEN_PACKET );
00343 openPacket.
CreateOptions = FILE_DELETE_ON_CLOSE;
00344 openPacket.
ShareAccess = (
USHORT) FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
00345 openPacket.
Disposition = FILE_OPEN;
00346 openPacket.
DeleteOnly =
TRUE;
00347 openPacket.
LocalFileObject = &localFileObject;
00348
00349
00350
00351
00352
00353
IopUpdateOtherOperationCount();
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 status =
ObOpenObjectByName(
ObjectAttributes,
00365 (
POBJECT_TYPE)
NULL,
00366 requestorMode,
00367
NULL,
00368 DELETE,
00369 &openPacket,
00370 &handle );
00371
00372
00373
00374
00375
00376
00377
00378
if (openPacket.
ParseCheck !=
OPEN_PACKET_PATTERN) {
00379
return status;
00380 }
else {
00381
return openPacket.
FinalStatus;
00382 }
00383 }
00384
00385
NTSTATUS
00386 NtFlushBuffersFile(
00387 IN HANDLE FileHandle,
00388 OUT PIO_STATUS_BLOCK IoStatusBlock
00389 )
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 {
00410
PIRP irp;
00411
NTSTATUS status;
00412
PFILE_OBJECT fileObject;
00413
PDEVICE_OBJECT deviceObject;
00414
PKEVENT event;
00415
KPROCESSOR_MODE requestorMode;
00416
PIO_STACK_LOCATION irpSp;
00417 IO_STATUS_BLOCK localIoStatus;
00418
OBJECT_HANDLE_INFORMATION objectHandleInformation;
00419 BOOLEAN synchronousIo;
00420
00421
PAGED_CODE();
00422
00423
00424
00425
00426
00427 requestorMode = KeGetPreviousMode();
00428
00429
if (requestorMode !=
KernelMode) {
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
try {
00440
00441
00442
00443
00444
00445
ProbeForWriteIoStatus( IoStatusBlock );
00446
00447 } except(
EXCEPTION_EXECUTE_HANDLER) {
00448
00449
00450
00451
00452
00453
00454
00455
return GetExceptionCode();
00456
00457 }
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467 status =
ObReferenceObjectByHandle( FileHandle,
00468 0,
00469
IoFileObjectType,
00470 requestorMode,
00471 (PVOID *) &fileObject,
00472 &objectHandleInformation );
00473
if (!
NT_SUCCESS( status )) {
00474
return status;
00475 }
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
if (
SeComputeGrantedAccesses( objectHandleInformation.
GrantedAccess,
00487 (!(fileObject->Flags &
FO_NAMED_PIPE) ?
00488 FILE_APPEND_DATA : 0) |
00489 FILE_WRITE_DATA ) == 0) {
00490
ObDereferenceObject( fileObject );
00491
return STATUS_ACCESS_DENIED;
00492 }
00493
00494
00495
00496
00497
00498
00499
00500
00501
if (fileObject->Flags &
FO_SYNCHRONOUS_IO) {
00502
00503 BOOLEAN interrupted;
00504
00505
if (!
IopAcquireFastLock( fileObject )) {
00506 status =
IopAcquireFileObjectLock( fileObject,
00507 requestorMode,
00508 (BOOLEAN) ((fileObject->Flags &
FO_ALERTABLE_IO) != 0),
00509 &interrupted );
00510
if (interrupted) {
00511
ObDereferenceObject( fileObject );
00512
return status;
00513 }
00514 }
00515 synchronousIo =
TRUE;
00516 }
else {
00517
00518
00519
00520
00521
00522
00523
00524
00525 event =
ExAllocatePool(
NonPagedPool,
sizeof(
KEVENT ) );
00526
if (event ==
NULL) {
00527
ObDereferenceObject( fileObject );
00528
return STATUS_INSUFFICIENT_RESOURCES;
00529 }
00530
KeInitializeEvent( event, SynchronizationEvent,
FALSE );
00531 synchronousIo =
FALSE;
00532 }
00533
00534
00535
00536
00537
00538
KeClearEvent( &fileObject->Event );
00539
00540
00541
00542
00543
00544 deviceObject =
IoGetRelatedDeviceObject( fileObject );
00545
00546
00547
00548
00549
00550
00551 irp =
IoAllocateIrp( deviceObject->
StackSize,
TRUE );
00552
if (!irp) {
00553
00554
00555
00556
00557
00558
00559
if (!(fileObject->Flags &
FO_SYNCHRONOUS_IO)) {
00560
ExFreePool( event );
00561 }
00562
00563
IopAllocateIrpCleanup( fileObject, (
PKEVENT)
NULL );
00564
00565
return STATUS_INSUFFICIENT_RESOURCES;
00566 }
00567 irp->
Tail.Overlay.OriginalFileObject = fileObject;
00568 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
00569 irp->
RequestorMode = requestorMode;
00570
00571
00572
00573
00574
00575
if (synchronousIo) {
00576 irp->
UserEvent = (
PKEVENT)
NULL;
00577 irp->
UserIosb = IoStatusBlock;
00578 }
else {
00579 irp->
UserEvent = event;
00580 irp->
UserIosb = &localIoStatus;
00581 irp->
Flags =
IRP_SYNCHRONOUS_API;
00582 }
00583 irp->
Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
00584
00585
00586
00587
00588
00589
00590 irpSp =
IoGetNextIrpStackLocation( irp );
00591 irpSp->
MajorFunction =
IRP_MJ_FLUSH_BUFFERS;
00592 irpSp->
FileObject = fileObject;
00593
00594
00595
00596
00597
00598
00599 status =
IopSynchronousServiceTail( deviceObject,
00600 irp,
00601 fileObject,
00602
FALSE,
00603 requestorMode,
00604 synchronousIo,
00605
OtherTransfer );
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
if (!synchronousIo) {
00616
00617 status =
IopSynchronousApiServiceTail( status,
00618 event,
00619 irp,
00620 requestorMode,
00621 &localIoStatus,
00622 IoStatusBlock );
00623 }
00624
00625
return status;
00626 }
00627
00628
NTSTATUS
00629 NtQueryAttributesFile(
00630 IN POBJECT_ATTRIBUTES ObjectAttributes,
00631 OUT PFILE_BASIC_INFORMATION FileInformation
00632 )
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 {
00655
KPROCESSOR_MODE requestorMode;
00656
NTSTATUS status;
00657
OPEN_PACKET openPacket;
00658
DUMMY_FILE_OBJECT localFileObject;
00659 FILE_NETWORK_OPEN_INFORMATION networkInformation;
00660 HANDLE handle;
00661
00662
PAGED_CODE();
00663
00664
00665
00666
00667
00668 requestorMode = KeGetPreviousMode();
00669
00670
if (requestorMode !=
KernelMode) {
00671
00672
try {
00673
00674
00675
00676
00677
00678
ProbeForWrite( FileInformation,
00679
sizeof( FILE_BASIC_INFORMATION ),
00680
sizeof( ULONG ));
00681
00682 } except(
EXCEPTION_EXECUTE_HANDLER) {
00683
00684
00685
00686
00687
00688
00689
return GetExceptionCode();
00690 }
00691 }
00692
00693
00694
00695
00696
00697
00698 RtlZeroMemory( &openPacket,
sizeof(
OPEN_PACKET ) );
00699
00700 openPacket.
Type =
IO_TYPE_OPEN_PACKET;
00701 openPacket.
Size =
sizeof(
OPEN_PACKET );
00702 openPacket.
ShareAccess = (
USHORT) FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
00703 openPacket.
Disposition = FILE_OPEN;
00704 openPacket.
CreateOptions = FILE_OPEN_REPARSE_POINT;
00705 openPacket.
BasicInformation = FileInformation;
00706 openPacket.
NetworkInformation = &networkInformation;
00707 openPacket.
QueryOnly =
TRUE;
00708 openPacket.
LocalFileObject = &localFileObject;
00709
00710
00711
00712
00713
00714
IopUpdateOtherOperationCount();
00715
00716
00717
00718
00719
00720
00721
00722
00723 status =
ObOpenObjectByName(
ObjectAttributes,
00724 (
POBJECT_TYPE)
NULL,
00725 requestorMode,
00726
NULL,
00727 FILE_READ_ATTRIBUTES,
00728 &openPacket,
00729 &handle );
00730
00731
00732
00733
00734
00735
00736
00737
if (openPacket.
ParseCheck !=
OPEN_PACKET_PATTERN) {
00738
return status;
00739 }
else {
00740
return openPacket.
FinalStatus;
00741 }
00742 }
00743
00744
NTSTATUS
00745 NtQueryFullAttributesFile(
00746 IN POBJECT_ATTRIBUTES ObjectAttributes,
00747 OUT PFILE_NETWORK_OPEN_INFORMATION FileInformation
00748 )
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771 {
00772
KPROCESSOR_MODE requestorMode;
00773
NTSTATUS status;
00774
OPEN_PACKET openPacket;
00775
DUMMY_FILE_OBJECT localFileObject;
00776 FILE_NETWORK_OPEN_INFORMATION networkInformation;
00777 HANDLE handle;
00778
00779
PAGED_CODE();
00780
00781
00782
00783
00784
00785 requestorMode = KeGetPreviousMode();
00786
00787
if (requestorMode !=
KernelMode) {
00788
00789
try {
00790
00791
00792
00793
00794
00795
ProbeForWrite( FileInformation,
00796
sizeof( FILE_NETWORK_OPEN_INFORMATION ),
00797 #
if defined(
_X86_)
00798
sizeof( LONG ));
00799
#else
00800
sizeof( LONGLONG ));
00801
#endif // defined(_X86_)
00802
00803 } except(
EXCEPTION_EXECUTE_HANDLER) {
00804
00805
00806
00807
00808
00809
00810
return GetExceptionCode();
00811 }
00812 }
00813
00814
00815
00816
00817
00818
00819 RtlZeroMemory( &openPacket,
sizeof(
OPEN_PACKET ) );
00820
00821 openPacket.
Type =
IO_TYPE_OPEN_PACKET;
00822 openPacket.
Size =
sizeof(
OPEN_PACKET );
00823 openPacket.
ShareAccess = (
USHORT) FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
00824 openPacket.
Disposition = FILE_OPEN;
00825 openPacket.
CreateOptions = FILE_OPEN_REPARSE_POINT;
00826 openPacket.
QueryOnly =
TRUE;
00827 openPacket.
FullAttributes =
TRUE;
00828 openPacket.
LocalFileObject = &localFileObject;
00829
if (requestorMode !=
KernelMode) {
00830 openPacket.
NetworkInformation = &networkInformation;
00831 }
else {
00832 openPacket.
NetworkInformation = FileInformation;
00833 }
00834
00835
00836
00837
00838
00839
IopUpdateOtherOperationCount();
00840
00841
00842
00843
00844
00845
00846
00847
00848 status =
ObOpenObjectByName(
ObjectAttributes,
00849 (
POBJECT_TYPE)
NULL,
00850 requestorMode,
00851
NULL,
00852 FILE_READ_ATTRIBUTES,
00853 &openPacket,
00854 &handle );
00855
00856
00857
00858
00859
00860
00861
00862
if (openPacket.
ParseCheck !=
OPEN_PACKET_PATTERN) {
00863
return status;
00864 }
else {
00865 status = openPacket.
FinalStatus;
00866 }
00867
00868
if (
NT_SUCCESS( status )) {
00869
if (requestorMode !=
KernelMode) {
00870
try {
00871
00872
00873
00874
00875
00876
00877 RtlMoveMemory( FileInformation,
00878 &networkInformation,
00879
sizeof( FILE_NETWORK_OPEN_INFORMATION ) );
00880
00881 } except(
EXCEPTION_EXECUTE_HANDLER) {
00882 status = GetExceptionCode();
00883 }
00884 }
00885 }
00886
00887
return status;
00888 }
00889
00890
PIO_WORKITEM
00891 IoAllocateWorkItem(
00892
PDEVICE_OBJECT DeviceObject
00893 )
00894 {
00895
PIO_WORKITEM ioWorkItem;
00896
PWORK_QUEUE_ITEM exWorkItem;
00897
00898
00899
00900
00901
00902 ioWorkItem =
ExAllocatePool(
NonPagedPool,
sizeof(
IO_WORKITEM ));
00903
if (ioWorkItem !=
NULL) {
00904
00905
00906
00907
00908
00909
00910
#if DBG
00911
ioWorkItem->Size =
sizeof(
IO_WORKITEM );
00912
#endif
00913
00914 ioWorkItem->
DeviceObject = DeviceObject;
00915
00916 exWorkItem = &ioWorkItem->
WorkItem;
00917
ExInitializeWorkItem( exWorkItem,
IopProcessWorkItem, ioWorkItem );
00918 }
00919
00920
return ioWorkItem;
00921 }
00922
00923
VOID
00924 IoFreeWorkItem(
00925
PIO_WORKITEM IoWorkItem
00926 )
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946 {
00947
ASSERT( IoWorkItem->Size ==
sizeof(
IO_WORKITEM ));
00948
00949
ExFreePool( IoWorkItem );
00950 }
00951
00952
VOID
00953 IoQueueWorkItem(
00954 IN
PIO_WORKITEM IoWorkItem,
00955 IN PIO_WORKITEM_ROUTINE WorkerRoutine,
00956 IN WORK_QUEUE_TYPE QueueType,
00957 IN PVOID Context
00958 )
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987 {
00988
PWORK_QUEUE_ITEM exWorkItem;
00989
00990
ASSERT( KeGetCurrentIrql() <=
DISPATCH_LEVEL );
00991
ASSERT( IoWorkItem->Size ==
sizeof(
IO_WORKITEM ));
00992
00993
00994
00995
00996
00997
ObReferenceObject( IoWorkItem->DeviceObject );
00998
00999
01000
01001
01002
01003 IoWorkItem->Routine = WorkerRoutine;
01004 IoWorkItem->Context = Context;
01005
01006
01007
01008
01009
01010
01011 exWorkItem = &IoWorkItem->WorkItem;
01012
ExQueueWorkItem( exWorkItem, QueueType );
01013 }
01014
01015
VOID
01016 IopProcessWorkItem(
01017 IN PVOID Parameter
01018 )
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038 {
01039
PIO_WORKITEM ioWorkItem;
01040
PDEVICE_OBJECT deviceObject;
01041
01042
PAGED_CODE();
01043
01044
01045
01046
01047
01048
01049
01050 ioWorkItem = (
PIO_WORKITEM)Parameter;
01051 deviceObject = ioWorkItem->
DeviceObject;
01052
01053
01054
01055
01056
01057 ioWorkItem->
Routine( deviceObject,
01058 ioWorkItem->
Context );
01059
01060
01061
01062
01063
01064
01065
ObDereferenceObject( deviceObject );
01066 }
01067