00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include "UdfProcs.h"
00025
00026
00027
00028
00029
00030 #define BugCheckFileId (UDFS_BUG_CHECK_UDFDATA)
00031
00032
00033
00034
00035
00036 #define Dbg (UDFS_DEBUG_LEVEL_UDFDATA)
00037
00038
00039
00040
00041
00042 UDF_DATA UdfData;
00043 FAST_IO_DISPATCH UdfFastIoDispatch;
00044
00045
00046
00047
00048
00049
#ifdef UDF_SANITY
00050
00051
00052
00053
00054
00055
00056
#include <stdarg.h>
00057
#include <stdio.h>
00058
00059 BOOLEAN UdfTestTopLevel =
TRUE;
00060 BOOLEAN UdfTestRaisedStatus =
TRUE;
00061
00062 LONG UdfDebugTraceLevel = 0;
00063 LONG UdfDebugTraceIndent = 0;
00064
00065
00066
00067
00068
00069
00070 BOOLEAN UdfNoisyVerifyDescriptor =
FALSE;
00071
00072
#endif
00073
00074
00075
00076
00077
00078 WCHAR
UdfUnicodeSelfArray[] = {
L'.' };
00079 WCHAR
UdfUnicodeParentArray[] = {
L'.',
L'.' };
00080
00081 UNICODE_STRING
UdfUnicodeDirectoryNames[] = {
00082 {
sizeof(
UdfUnicodeSelfArray),
sizeof(
UdfUnicodeSelfArray),
UdfUnicodeSelfArray},
00083 {
sizeof(
UdfUnicodeParentArray),
sizeof(
UdfUnicodeParentArray),
UdfUnicodeParentArray}
00084 };
00085
00086
00087
00088
00089
00090 CHAR UdfCS0IdentifierArray[] = {
'O',
'S',
'T',
'A',
' ',
00091
'C',
'o',
'm',
'p',
'r',
'e',
's',
's',
'e',
'd',
' ',
00092
'U',
'n',
'i',
'c',
'o',
'd',
'e' };
00093
00094 STRING
UdfCS0Identifier = {
00095
sizeof(
UdfCS0IdentifierArray),
00096
sizeof(
UdfCS0IdentifierArray),
00097
UdfCS0IdentifierArray
00098 };
00099
00100 CHAR UdfDomainIdentifierArray[] = {
'*',
'O',
'S',
'T',
'A',
' ',
00101
'U',
'D',
'F',
' ',
00102
'C',
'o',
'm',
'p',
'l',
'i',
'a',
'n',
't' };
00103
00104 STRING
UdfDomainIdentifier = {
00105
sizeof(
UdfDomainIdentifierArray),
00106
sizeof(
UdfDomainIdentifierArray),
00107
UdfDomainIdentifierArray
00108 };
00109
00110 CHAR UdfVirtualPartitionDomainIdentifierArray[] = {
'*',
'U',
'D',
'F',
' ',
00111
'V',
'i',
'r',
't',
'u',
'a',
'l',
' ',
00112
'P',
'a',
'r',
't',
'i',
't',
'i',
'o',
'n' };
00113
00114 STRING
UdfVirtualPartitionDomainIdentifier = {
00115
sizeof(
UdfVirtualPartitionDomainIdentifierArray),
00116
sizeof(
UdfVirtualPartitionDomainIdentifierArray),
00117
UdfVirtualPartitionDomainIdentifierArray
00118 };
00119
00120 CHAR UdfVatTableIdentifierArray[] = {
'*',
'U',
'D',
'F',
' ',
00121
'V',
'i',
'r',
't',
'u',
'a',
'l',
' ',
00122
'A',
'l',
'l',
'o',
'c',
' ',
00123
'T',
'b',
'l' };
00124
00125 STRING
UdfVatTableIdentifier = {
00126
sizeof(
UdfVatTableIdentifierArray),
00127
sizeof(
UdfVatTableIdentifierArray),
00128
UdfVatTableIdentifierArray
00129 };
00130
00131 CHAR UdfSparablePartitionDomainIdentifierArray[] = {
'*',
'U',
'D',
'F',
' ',
00132
'S',
'p',
'a',
'r',
'a',
'b',
'l',
'e',
' ',
00133
'P',
'a',
'r',
't',
'i',
't',
'i',
'o',
'n' };
00134
00135 STRING
UdfSparablePartitionDomainIdentifier = {
00136
sizeof(
UdfSparablePartitionDomainIdentifierArray),
00137
sizeof(
UdfSparablePartitionDomainIdentifierArray),
00138
UdfSparablePartitionDomainIdentifierArray
00139 };
00140
00141 CHAR UdfSparingTableIdentifierArray[] = {
'*',
'U',
'D',
'F',
' ',
00142
'S',
'p',
'a',
'r',
'i',
'n',
'g',
' ',
00143
'T',
'a',
'b',
'l',
'e' };
00144
00145 STRING
UdfSparingTableIdentifier = {
00146
sizeof(
UdfSparingTableIdentifierArray),
00147
sizeof(
UdfSparingTableIdentifierArray),
00148
UdfSparingTableIdentifierArray
00149 };
00150
00151 CHAR UdfNSR02IdentifierArray[] =
NSR_PART_CONTID_NSR02;
00152
00153 STRING
UdfNSR02Identifier = {
00154
sizeof(
UdfNSR02IdentifierArray),
00155
sizeof(
UdfNSR02IdentifierArray),
00156
UdfNSR02IdentifierArray
00157 };
00158
00159
00160
00161
00162
00163 PARSE_KEYVALUE VsdIdentParseTable[] = {
00164 {
VSD_IDENT_BEA01,
VsdIdentBEA01 },
00165 {
VSD_IDENT_TEA01,
VsdIdentTEA01 },
00166 {
VSD_IDENT_CDROM,
VsdIdentCDROM },
00167 {
VSD_IDENT_CD001,
VsdIdentCD001 },
00168 {
VSD_IDENT_CDW01,
VsdIdentCDW01 },
00169 {
VSD_IDENT_CDW02,
VsdIdentCDW02 },
00170 {
VSD_IDENT_NSR01,
VsdIdentNSR01 },
00171 {
VSD_IDENT_NSR02,
VsdIdentNSR02 },
00172 {
VSD_IDENT_BOOT2,
VsdIdentBOOT2 },
00173 {
NULL,
VsdIdentBad }
00174 };
00175
00176 PARSE_KEYVALUE NsrPartContIdParseTable[] = {
00177 {
NSR_PART_CONTID_FDC01,
NsrPartContIdFDC01 },
00178 {
NSR_PART_CONTID_CD001,
NsrPartContIdCD001 },
00179 {
NSR_PART_CONTID_CDW01,
NsrPartContIdCDW01 },
00180 {
NSR_PART_CONTID_CDW02,
NsrPartContIdCDW02 },
00181 {
NSR_PART_CONTID_NSR01,
NsrPartContIdNSR01 },
00182 {
NSR_PART_CONTID_NSR02,
NsrPartContIdNSR02 },
00183 {
NULL,
NsrPartContIdBad }
00184 };
00185
00186
00187
00188
00189
00190 NPAGED_LOOKASIDE_LIST UdfFcbNonPagedLookasideList;
00191 NPAGED_LOOKASIDE_LIST UdfIrpContextLookasideList;
00192
00193 PAGED_LOOKASIDE_LIST UdfCcbLookasideList;
00194 PAGED_LOOKASIDE_LIST UdfFcbIndexLookasideList;
00195 PAGED_LOOKASIDE_LIST UdfFcbDataLookasideList;
00196 PAGED_LOOKASIDE_LIST UdfLcbLookasideList;
00197
00198
00199
00200
00201
00202 PUSHORT UdfCrcTable;
00203
00204
#ifdef ALLOC_PRAGMA
00205
#pragma alloc_text(PAGE, UdfComputeCrc16)
00206
#pragma alloc_text(PAGE, UdfComputeCrc16Uni)
00207
#ifdef UDF_SANITY
00208
#pragma alloc_text(PAGE, UdfDebugTrace)
00209
#endif
00210
#pragma alloc_text(PAGE, UdfFastIoCheckIfPossible)
00211
#pragma alloc_text(PAGE, UdfHighBit)
00212
#pragma alloc_text(PAGE, UdfInitializeCrc16)
00213
#pragma alloc_text(PAGE, UdfSerial32)
00214
#endif
00215
00216
00217
NTSTATUS
00218 UdfFsdDispatch (
00219 IN
PVOLUME_DEVICE_OBJECT VolumeDeviceObject,
00220 IN
PIRP Irp
00221 )
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 {
00258
THREAD_CONTEXT ThreadContext;
00259
PIRP_CONTEXT IrpContext =
NULL;
00260 BOOLEAN Wait;
00261
00262
#ifdef UDF_SANITY
00263
PVOID PreviousTopLevel;
00264
#endif
00265
00266
NTSTATUS Status;
00267
00268 KIRQL SaveIrql = KeGetCurrentIrql();
00269
00270
ASSERT_OPTIONAL_IRP(
Irp );
00271
00272
FsRtlEnterFileSystem();
00273
00274
#ifdef UDF_SANITY
00275
PreviousTopLevel =
IoGetTopLevelIrp();
00276
#endif
00277
00278
00279
00280
00281
00282
do {
00283
00284
00285
00286
00287
00288
try {
00289
00290
00291
00292
00293
00294
00295
if (IrpContext ==
NULL) {
00296
00297
00298
00299
00300
00301
00302
00303
00304
if (
IoGetCurrentIrpStackLocation(
Irp )->FileObject ==
NULL) {
00305
00306 Wait =
TRUE;
00307
00308 }
else {
00309
00310 Wait =
CanFsdWait(
Irp );
00311 }
00312
00313 IrpContext =
UdfCreateIrpContext(
Irp, Wait );
00314
00315
00316
00317
00318
00319
UdfSetThreadContext( IrpContext, &
ThreadContext );
00320
00321
#ifdef UDF_SANITY
00322
ASSERT( !UdfTestTopLevel ||
00323
SafeNodeType( IrpContext->
TopLevel ) ==
UDFS_NTC_IRP_CONTEXT );
00324
#endif
00325
00326
00327
00328
00329
00330 }
else {
00331
00332
00333
00334
00335
00336
00337
00338
SetFlag( IrpContext->
Flags,
IRP_CONTEXT_FLAG_MORE_PROCESSING );
00339
UdfCleanupIrpContext( IrpContext,
FALSE );
00340 }
00341
00342
00343
00344
00345
00346
switch (IrpContext->
MajorFunction) {
00347
00348
case IRP_MJ_CLEANUP :
00349
00350
Status =
UdfCommonCleanup( IrpContext,
Irp );
00351
break;
00352
00353
case IRP_MJ_CLOSE :
00354
00355
Status =
UdfCommonClose( IrpContext,
Irp );
00356
break;
00357
00358
case IRP_MJ_CREATE :
00359
00360
Status =
UdfCommonCreate( IrpContext,
Irp );
00361
break;
00362
00363
case IRP_MJ_DEVICE_CONTROL :
00364
00365
Status =
UdfCommonDevControl( IrpContext,
Irp );
00366
break;
00367
00368
case IRP_MJ_DIRECTORY_CONTROL :
00369
00370
Status =
UdfCommonDirControl( IrpContext,
Irp );
00371
break;
00372
00373
case IRP_MJ_FILE_SYSTEM_CONTROL :
00374
00375
Status =
UdfCommonFsControl( IrpContext,
Irp );
00376
break;
00377
00378
case IRP_MJ_LOCK_CONTROL :
00379
00380
Status =
UdfCommonLockControl( IrpContext,
Irp );
00381
break;
00382
00383
case IRP_MJ_PNP :
00384
00385
Status =
UdfCommonPnp( IrpContext,
Irp );
00386
break;
00387
00388
case IRP_MJ_QUERY_INFORMATION :
00389
00390
Status =
UdfCommonQueryInfo( IrpContext,
Irp );
00391
break;
00392
00393
case IRP_MJ_QUERY_VOLUME_INFORMATION :
00394
00395
Status =
UdfCommonQueryVolInfo( IrpContext,
Irp );
00396
break;
00397
00398
case IRP_MJ_READ :
00399
00400
00401
00402
00403
00404
00405
if (
FlagOn( IrpContext->
MinorFunction,
IRP_MN_COMPLETE )) {
00406
00407
Status =
UdfCompleteMdl( IrpContext,
Irp );
00408
00409 }
else {
00410
00411
Status =
UdfCommonRead( IrpContext,
Irp );
00412 }
00413
00414
break;
00415
00416
case IRP_MJ_SET_INFORMATION :
00417
00418
Status =
UdfCommonSetInfo( IrpContext,
Irp );
00419
break;
00420
00421
default :
00422
00423
Status = STATUS_INVALID_DEVICE_REQUEST;
00424
UdfCompleteRequest( IrpContext,
Irp,
Status );
00425 }
00426
00427 } except(
UdfExceptionFilter( IrpContext, GetExceptionInformation() )) {
00428
00429
Status =
UdfProcessException( IrpContext,
Irp, GetExceptionCode() );
00430 }
00431
00432 }
while (
Status == STATUS_CANT_WAIT);
00433
00434
#ifdef UDF_SANITY
00435
ASSERT( !UdfTestTopLevel ||
00436 (PreviousTopLevel ==
IoGetTopLevelIrp()) );
00437
#endif
00438
00439
FsRtlExitFileSystem();
00440
00441
ASSERT( SaveIrql == KeGetCurrentIrql( ));
00442
00443
return Status;
00444 }
00445
00446
00447 LONG
00448 UdfExceptionFilter (
00449 IN
PIRP_CONTEXT IrpContext,
00450 IN PEXCEPTION_POINTERS ExceptionPointer
00451 )
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 {
00473
NTSTATUS ExceptionCode;
00474 BOOLEAN TestStatus =
TRUE;
00475
00476
ASSERT_OPTIONAL_IRP_CONTEXT( IrpContext );
00477
00478 ExceptionCode = ExceptionPointer->ExceptionRecord->ExceptionCode;
00479
00480
DebugTrace(( 0,
Dbg,
00481
"UdfExceptionFilter: %08x (exr %08x cxr %08x)\n",
00482 ExceptionCode,
00483 ExceptionPointer->ExceptionRecord,
00484 ExceptionPointer->ContextRecord ));
00485
00486
00487
00488
00489
00490
00491
00492
if ((ExceptionCode == STATUS_IN_PAGE_ERROR) &&
00493 (ExceptionPointer->ExceptionRecord->NumberParameters >= 3)) {
00494
00495 ExceptionCode = (
NTSTATUS) ExceptionPointer->ExceptionRecord->ExceptionInformation[2];
00496 }
00497
00498
00499
00500
00501
00502
if (ARGUMENT_PRESENT( IrpContext )) {
00503
00504
if (IrpContext->ExceptionStatus == STATUS_SUCCESS) {
00505
00506
00507
00508
00509
00510 IrpContext->ExceptionStatus = ExceptionCode;
00511
00512 }
else {
00513
00514
00515
00516
00517
00518 TestStatus =
FALSE;
00519 }
00520 }
00521
00522
00523
00524
00525
00526
if (TestStatus && !
FsRtlIsNtstatusExpected( ExceptionCode )) {
00527
00528
UdfBugCheck( (ULONG_PTR) ExceptionPointer->ExceptionRecord,
00529 (ULONG_PTR) ExceptionPointer->ContextRecord,
00530 (ULONG_PTR) ExceptionPointer->ExceptionRecord->ExceptionAddress );
00531
00532 }
00533
00534
return EXCEPTION_EXECUTE_HANDLER;
00535 }
00536
00537
00538
NTSTATUS
00539 UdfProcessException (
00540 IN
PIRP_CONTEXT IrpContext OPTIONAL,
00541 IN
PIRP Irp,
00542 IN NTSTATUS ExceptionCode
00543 )
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 {
00572
PDEVICE_OBJECT Device;
00573
PVPB Vpb;
00574
PETHREAD Thread;
00575
00576
ASSERT_OPTIONAL_IRP_CONTEXT( IrpContext );
00577
ASSERT_IRP(
Irp );
00578
00579
00580
00581
00582
00583
00584
if (!ARGUMENT_PRESENT( IrpContext )) {
00585
00586
UdfCompleteRequest(
NULL,
Irp, ExceptionCode );
00587
return ExceptionCode;
00588 }
00589
00590
00591
00592
00593
00594 ExceptionCode = IrpContext->ExceptionStatus;
00595
00596
00597
00598
00599
00600
00601
if (!
FlagOn( IrpContext->Flags,
IRP_CONTEXT_FLAG_TOP_LEVEL )) {
00602
00603
UdfCompleteRequest( IrpContext,
Irp, ExceptionCode );
00604
00605
return ExceptionCode;
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
try {
00625
00626
if (ExceptionCode == STATUS_CANT_WAIT) {
00627
00628
if (
FlagOn( IrpContext->Flags,
IRP_CONTEXT_FLAG_FORCE_POST )) {
00629
00630 ExceptionCode =
UdfFsdPostRequest( IrpContext,
Irp );
00631 }
00632
00633 }
else if (ExceptionCode == STATUS_VERIFY_REQUIRED) {
00634
00635
if (KeGetCurrentIrql() >=
APC_LEVEL) {
00636
00637 ExceptionCode =
UdfFsdPostRequest( IrpContext,
Irp );
00638 }
00639 }
00640 }
00641 except (
UdfExceptionFilter( IrpContext, GetExceptionInformation())) {
00642
00643 ExceptionCode = GetExceptionCode();
00644 }
00645
00646
00647
00648
00649
00650
if ((ExceptionCode == STATUS_PENDING) ||
00651 (ExceptionCode == STATUS_CANT_WAIT)) {
00652
00653
return ExceptionCode;
00654 }
00655
00656
ClearFlag( IrpContext->Flags,
IRP_CONTEXT_FLAG_MORE_PROCESSING );
00657
00658
00659
00660
00661
00662
Irp->
IoStatus.Status = ExceptionCode;
00663
00664
if (
IoIsErrorUserInduced( ExceptionCode )) {
00665
00666
00667
00668
00669
00670
00671
if (ExceptionCode == STATUS_VERIFY_REQUIRED) {
00672
00673
00674
00675
00676
00677
00678
00679
00680 Device =
IoGetDeviceToVerify(
Irp->
Tail.Overlay.Thread );
00681
IoSetDeviceToVerify(
Irp->
Tail.Overlay.Thread,
NULL );
00682
00683
00684
00685
00686
00687
00688
if (Device ==
NULL) {
00689
00690 Device =
IoGetDeviceToVerify(
PsGetCurrentThread() );
00691
IoSetDeviceToVerify(
PsGetCurrentThread(),
NULL );
00692
00693
ASSERT( Device !=
NULL );
00694
00695
00696
00697
00698
00699
if (Device ==
NULL) {
00700
00701 ExceptionCode = STATUS_DRIVER_INTERNAL_ERROR;
00702
00703
UdfCompleteRequest( IrpContext,
Irp, ExceptionCode );
00704
00705
return ExceptionCode;
00706 }
00707 }
00708
00709
00710
00711
00712
00713
00714
00715
return UdfPerformVerify( IrpContext,
Irp, Device );
00716 }
00717
00718
00719
00720
00721
00722
00723
if (
FlagOn( IrpContext->Flags,
IRP_CONTEXT_FLAG_DISABLE_POPUPS )) {
00724
00725
UdfCompleteRequest( IrpContext,
Irp, ExceptionCode );
00726
00727
return ExceptionCode;
00728
00729 }
else {
00730
00731
00732
00733
00734
00735
if (
IoGetCurrentIrpStackLocation(
Irp )->FileObject !=
NULL) {
00736
00737 Vpb =
IoGetCurrentIrpStackLocation(
Irp )->FileObject->Vpb;
00738
00739 }
else {
00740
00741 Vpb =
NULL;
00742 }
00743
00744
00745
00746
00747
00748
00749 Thread =
Irp->
Tail.Overlay.Thread;
00750 Device =
IoGetDeviceToVerify( Thread );
00751
00752
if (Device ==
NULL) {
00753
00754 Thread =
PsGetCurrentThread();
00755 Device =
IoGetDeviceToVerify( Thread );
00756
00757
ASSERT( Device !=
NULL );
00758
00759
00760
00761
00762
00763
if (Device ==
NULL) {
00764
00765
UdfCompleteRequest( IrpContext,
Irp, ExceptionCode );
00766
00767
return ExceptionCode;
00768 }
00769 }
00770
00771
00772
00773
00774
00775
00776
00777
00778
IoMarkIrpPending(
Irp );
00779
IoRaiseHardError(
Irp, Vpb, Device );
00780
00781
00782
00783
00784
00785
00786
IoSetDeviceToVerify( Thread,
NULL );
00787
00788
00789
00790
00791
00792
00793
UdfCompleteRequest( IrpContext,
NULL, STATUS_SUCCESS );
00794
return STATUS_PENDING;
00795 }
00796 }
00797
00798
00799
00800
00801
00802
UdfCompleteRequest( IrpContext,
Irp, ExceptionCode );
00803
00804
return ExceptionCode;
00805 }
00806
00807
00808
VOID
00809 UdfCompleteRequest (
00810 IN
PIRP_CONTEXT IrpContext OPTIONAL,
00811 IN
PIRP Irp OPTIONAL,
00812 IN NTSTATUS Status
00813 )
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834 {
00835
ASSERT_OPTIONAL_IRP_CONTEXT( IrpContext );
00836
ASSERT_OPTIONAL_IRP(
Irp );
00837
00838
00839
00840
00841
00842
if (ARGUMENT_PRESENT( IrpContext )) {
00843
00844
UdfCleanupIrpContext( IrpContext,
FALSE );
00845 }
00846
00847
00848
00849
00850
00851
if (ARGUMENT_PRESENT(
Irp )) {
00852
00853
00854
00855
00856
00857
00858
if (
NT_ERROR(
Status ) &&
00859
FlagOn(
Irp->
Flags,
IRP_INPUT_OPERATION )) {
00860
00861
Irp->
IoStatus.Information = 0;
00862 }
00863
00864
Irp->
IoStatus.Status =
Status;
00865
IoCompleteRequest(
Irp,
IO_CD_ROM_INCREMENT );
00866 }
00867
00868
return;
00869 }
00870
00871
00872
VOID
00873 UdfSetThreadContext (
00874 IN
PIRP_CONTEXT IrpContext,
00875 IN
PTHREAD_CONTEXT ThreadContext
00876 )
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 {
00905
PTHREAD_CONTEXT CurrentThreadContext;
00906 ULONG_PTR StackTop;
00907 ULONG_PTR StackBottom;
00908
00909
PAGED_CODE();
00910
00911
ASSERT_IRP_CONTEXT( IrpContext );
00912
00913
00914
00915
00916
00917
00918 CurrentThreadContext = (
PTHREAD_CONTEXT)
IoGetTopLevelIrp();
00919
00920
if (CurrentThreadContext ==
NULL) {
00921
00922
SetFlag( IrpContext->Flags,
IRP_CONTEXT_FLAG_TOP_LEVEL );
00923 }
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
IoGetStackLimits( &StackTop, &StackBottom);
00941
00942
if (
FlagOn( IrpContext->Flags,
IRP_CONTEXT_FLAG_TOP_LEVEL ) ||
00943 (((ULONG_PTR) CurrentThreadContext > StackBottom -
sizeof(
THREAD_CONTEXT )) ||
00944 ((ULONG_PTR) CurrentThreadContext <= StackTop) ||
00945
LongOffsetPtr( CurrentThreadContext ) ||
00946 (CurrentThreadContext->
Udfs !=
UDFS_SIGNATURE))) {
00947
00948
ThreadContext->Udfs =
UDFS_SIGNATURE;
00949
ThreadContext->SavedTopLevelIrp = (
PIRP) CurrentThreadContext;
00950
ThreadContext->TopLevelIrpContext = IrpContext;
00951
IoSetTopLevelIrp( (
PIRP)
ThreadContext );
00952
00953 IrpContext->TopLevel = IrpContext;
00954 IrpContext->ThreadContext =
ThreadContext;
00955
00956
SetFlag( IrpContext->Flags,
IRP_CONTEXT_FLAG_TOP_LEVEL_UDFS );
00957
00958
00959
00960
00961
00962 }
else {
00963
00964 IrpContext->TopLevel = CurrentThreadContext->
TopLevelIrpContext;
00965 }
00966
00967
return;
00968 }
00969
00970
00971 BOOLEAN
00972 UdfFastIoCheckIfPossible (
00973 IN
PFILE_OBJECT FileObject,
00974 IN PLARGE_INTEGER FileOffset,
00975 IN ULONG Length,
00976 IN BOOLEAN Wait,
00977 IN ULONG LockKey,
00978 IN BOOLEAN CheckForReadOperation,
00979 OUT PIO_STATUS_BLOCK IoStatus,
00980 IN
PDEVICE_OBJECT DeviceObject
00981 )
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014 {
01015
PAGED_CODE();
01016
01017
return TRUE;
01018 }
01019
01020
01021 ULONG
01022 UdfSerial32 (
01023 IN PCHAR Buffer,
01024 IN ULONG ByteCount
01025 )
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047 {
01048
union {
01049 UCHAR Bytes[4];
01050 ULONG
SerialId;
01051 } Checksum;
01052
01053
PAGED_CODE();
01054
01055
01056
01057
01058
01059 Checksum.SerialId = 0;
01060
01061
01062
01063
01064
01065
while (ByteCount--) {
01066
01067
01068
01069
01070
01071 Checksum.Bytes[ByteCount & 0x3] += *(
Buffer++);
01072 }
01073
01074
01075
01076
01077
01078
return Checksum.SerialId;
01079 }
01080
01081
01082
VOID
01083 UdfInitializeCrc16 (
01084 ULONG Polynomial
01085 )
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103 {
01104 ULONG
n, i, Crc;
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
UdfCrcTable = (
PUSHORT)
FsRtlAllocatePoolWithTag(
UdfPagedPool,
01118 256 *
sizeof(
USHORT),
01119
TAG_CRC_TABLE );
01120
01121
for (
n = 0;
n < 256;
n++) {
01122
01123 Crc =
n << 8;
01124
01125
for (i = 0; i < 8; i++) {
01126
01127
if(Crc & 0x8000) {
01128
01129 Crc = (Crc << 1) ^ Polynomial;
01130
01131 }
else {
01132
01133 Crc <<= 1;
01134 }
01135
01136 Crc &= 0xffff;
01137 }
01138
01139
UdfCrcTable[
n] = (
USHORT) Crc;
01140 }
01141 }
01142
01143
01144
01145
USHORT
01146 UdfComputeCrc16 (
01147 PUCHAR Buffer,
01148 ULONG ByteCount
01149 )
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170 {
01171
USHORT Crc = 0;
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
while (ByteCount-- > 0) {
01185
01186 Crc =
UdfCrcTable[((Crc >> 8) ^ *
Buffer++) & 0xff] ^ (Crc << 8);
01187 }
01188
01189
return Crc;
01190 }
01191
01192
01193
USHORT
01194 UdfComputeCrc16Uni (
01195 PWCHAR Buffer,
01196 ULONG CharCount
01197 )
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221 {
01222
USHORT Crc = 0;
01223
01224
01225
01226
01227
01228
while (CharCount-- > 0) {
01229
01230 Crc =
UdfCrcTable[((Crc >> 8) ^ (*
Buffer >> 8)) & 0xff] ^ (Crc << 8);
01231 Crc =
UdfCrcTable[((Crc >> 8) ^ (*
Buffer++ & 0xff)) & 0xff] ^ (Crc << 8);
01232 }
01233
01234
return Crc;
01235 }
01236
01237
01238 ULONG
01239 UdfHighBit (
01240 ULONG Word
01241 )
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260 {
01261 ULONG
Offset = 31;
01262 ULONG Mask = (ULONG)(1 << 31);
01263
01264
if (Word == 0) {
01265
01266
return 0;
01267 }
01268
01269
while ((Word & Mask) == 0) {
01270
01271
Offset--;
01272 Mask >>= 1;
01273 }
01274
01275
return Offset;
01276 }
01277
01278
01279
#ifdef UDF_SANITY
01280
BOOLEAN
01281 UdfDebugTrace (
01282 LONG IndentIncrement,
01283 ULONG TraceMask,
01284 PCHAR Format,
01285 ...
01286 )
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 {
01312 va_list Arglist;
01313 LONG i;
01314 UCHAR
Buffer[128];
01315
int Bytes;
01316
01317
if (TraceMask == 0 || (UdfDebugTraceLevel & TraceMask) != 0) {
01318
01319
if (IndentIncrement < 0) {
01320
01321 UdfDebugTraceIndent += IndentIncrement;
01322 }
01323
01324
if (UdfDebugTraceIndent < 0) {
01325
01326 UdfDebugTraceIndent = 0;
01327 }
01328
01329
01330
01331
01332
01333
for (i = UdfDebugTraceIndent; i > 0; i -= (
sizeof(
Buffer) - 1)) {
01334
01335 RtlFillMemory( Buffer,
Min( i, (
sizeof(Buffer) - 1 )),
' ');
01336 *(
Buffer +
Min( i, (
sizeof(Buffer) - 1 ))) =
'\0';
01337
01338
DbgPrint( Buffer );
01339 }
01340
01341
01342
01343
01344
01345 va_start( Arglist, Format );
01346 Bytes = _vsnprintf( Buffer,
sizeof(Buffer), Format, Arglist );
01347 va_end( Arglist );
01348
01349
01350
01351
01352
01353
if (Bytes == -1) {
01354
01355
Buffer[
sizeof(
Buffer) - 1] =
'\n';
01356 }
01357
01358
DbgPrint( Buffer );
01359
01360
if (IndentIncrement > 0) {
01361
01362 UdfDebugTraceIndent += IndentIncrement;
01363 }
01364 }
01365
01366
return TRUE;
01367 }
01368
#endif
01369