00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "UdfProcs.h"
00022
00023
00024
00025
00026
00027 #define BugCheckFileId (UDFS_BUG_CHECK_NAMESUP)
00028
00029
00030
00031
00032
00033 #define Dbg (UDFS_DEBUG_LEVEL_NAMESUP)
00034
00035
00036
00037
00038
00039 static CONST
CHAR UdfCrcChar[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ#_~-@";
00040
00041
#ifdef ALLOC_PRAGMA
00042
#pragma alloc_text(PAGE, UdfCandidateShortName)
00043
#pragma alloc_text(PAGE, UdfCheckLegalCS0Dstring)
00044
#pragma alloc_text(PAGE, UdfConvertCS0DstringToUnicode)
00045
#pragma alloc_text(PAGE, UdfDissectName)
00046
#pragma alloc_text(PAGE, UdfFullCompareNames)
00047
#pragma alloc_text(PAGE, UdfGenerate8dot3Name)
00048
#pragma alloc_text(PAGE, UdfIs8dot3Name)
00049
#pragma alloc_text(PAGE, UdfIsNameInExpression)
00050
#pragma alloc_text(PAGE, UdfRenderNameToLegalUnicode)
00051
#endif
00052
00053
00054
INLINE
00055 ULONG
00056 NativeDosCharLength (
00057 IN WCHAR Wchar
00058 )
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 {
00079
NTSTATUS Status;
00080
CHAR OemBuf[2];
00081 ULONG Length;
00082
00083
Status =
RtlUpcaseUnicodeToOemN( OemBuf,
00084
sizeof(OemBuf),
00085 &Length,
00086 &Wchar,
00087
sizeof(WCHAR));
00088
00089
ASSERT(
NT_SUCCESS(
Status ));
00090
00091
return Length;
00092 }
00093
00094
00095
VOID
00096 UdfDissectName (
00097 IN
PIRP_CONTEXT IrpContext,
00098 IN OUT PUNICODE_STRING RemainingName,
00099 OUT PUNICODE_STRING FinalName
00100 )
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 {
00123 ULONG NameLength;
00124 PWCHAR NextWchar;
00125
00126
PAGED_CODE();
00127
00128
00129
00130
00131
00132
ASSERT_IRP_CONTEXT( IrpContext );
00133
00134
00135
00136
00137
00138
for (NameLength = 0, NextWchar = RemainingName->Buffer;
00139 (NameLength < RemainingName->Length) && (*NextWchar !=
L'\\');
00140 NameLength +=
sizeof( WCHAR) , NextWchar += 1);
00141
00142
00143
00144
00145
00146 FinalName->Buffer = RemainingName->Buffer;
00147
00148 FinalName->MaximumLength = FinalName->Length = (
USHORT) NameLength;
00149
00150
00151
00152
00153
00154
if (NameLength == RemainingName->Length) {
00155
00156 RemainingName->Length = 0;
00157
00158
00159
00160
00161
00162 }
else {
00163
00164 RemainingName->MaximumLength -= (
USHORT) (NameLength +
sizeof( WCHAR ));
00165 RemainingName->Length -= (
USHORT) (NameLength +
sizeof( WCHAR ));
00166 RemainingName->Buffer =
Add2Ptr( RemainingName->Buffer,
00167 NameLength +
sizeof( WCHAR ),
00168 PWCHAR );
00169 }
00170
00171
return;
00172 }
00173
00174
00175 BOOLEAN
00176 UdfIs8dot3Name (
00177 IN
PIRP_CONTEXT IrpContext,
00178 IN UNICODE_STRING FileName
00179 )
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 {
00199
CHAR DbcsNameBuffer[
BYTE_COUNT_8_DOT_3 ];
00200 STRING DbcsName;
00201
00202 PWCHAR NextWchar;
00203 ULONG
Count;
00204
00205 ULONG DotCount = 0;
00206 BOOLEAN LastCharDot =
FALSE;
00207
00208
PAGED_CODE();
00209
00210
00211
00212
00213
00214
ASSERT_IRP_CONTEXT( IrpContext );
00215
00216
00217
00218
00219
00220
ASSERT(
FileName.Length != 0 );
00221
if (
FileName.Length >
BYTE_COUNT_8_DOT_3) {
00222
00223
return FALSE;
00224 }
00225
00226
00227
00228
00229
00230 NextWchar =
FileName.Buffer;
00231
Count = 0;
00232
00233
do {
00234
00235
00236
00237
00238
00239
if (*NextWchar ==
L' ') {
return FALSE; }
00240
00241
if (*NextWchar ==
L'.') {
00242
00243
00244
00245
00246
00247
00248
00249
if ((DotCount > 0) ||
00250 (
Count > 8 *
sizeof( WCHAR ))) {
00251
00252
return FALSE;
00253 }
00254
00255 DotCount += 1;
00256 LastCharDot =
TRUE;
00257
00258 }
else {
00259
00260 LastCharDot =
FALSE;
00261 }
00262
00263
Count += 2;
00264 NextWchar += 1;
00265
00266 }
while (
Count <
FileName.Length);
00267
00268
00269
00270
00271
00272
if (LastCharDot) {
00273
00274
return FALSE;
00275 }
00276
00277
00278
00279
00280
00281 DbcsName.MaximumLength =
BYTE_COUNT_8_DOT_3;
00282 DbcsName.Buffer = DbcsNameBuffer;
00283
00284
if (!
NT_SUCCESS(
RtlUnicodeStringToCountedOemString( &DbcsName,
00285 &
FileName,
00286
FALSE ))) {
00287
00288
return FALSE;
00289 }
00290
00291
00292
00293
00294
00295
00296
return FsRtlIsFatDbcsLegal( DbcsName,
FALSE,
FALSE,
FALSE );
00297 }
00298
00299
00300 BOOLEAN
00301 UdfCandidateShortName (
00302 IN
PIRP_CONTEXT IrpContext,
00303 IN PUNICODE_STRING Name
00304 )
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 {
00324 ULONG
Index, SubIndex;
00325 BOOLEAN LooksShort =
FALSE;
00326
00327
PAGED_CODE();
00328
00329
00330
00331
00332
00333
ASSERT_IRP_CONTEXT( IrpContext );
00334
00335
00336
00337
00338
00339
00340
ASSERT(
Name->Length != 0 );
00341
00342
if (
Name->Length >
BYTE_COUNT_8_DOT_3 ||
00343
Name->Length <
DOS_CRC_LEN *
sizeof(WCHAR)) {
00344
00345
return FALSE;
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
for (
Index = 0;
00355
Index <= (
Name->Length /
sizeof(WCHAR)) -
DOS_CRC_LEN;
00356
Index++ ) {
00357
00358
00359
00360
00361
00362
if (
Name->Buffer[
Index] ==
CRC_MARK) {
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
if (
Index == (
Name->Length /
sizeof(WCHAR)) -
DOS_CRC_LEN ||
00376
Name->Buffer[
Index +
DOS_CRC_LEN] ==
PERIOD) {
00377
00378 LooksShort =
TRUE;
00379
break;
00380 }
00381 }
00382 }
00383
00384
return LooksShort;
00385 }
00386
00387
00388
VOID
00389 UdfGenerate8dot3Name (
00390 IN
PIRP_CONTEXT IrpContext,
00391 IN PUNICODE_STRING FileName,
00392 OUT PUNICODE_STRING ShortFileName
00393 )
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 {
00420
INT16 index;
00421
INT16 targetIndex;
00422
INT16 crcIndex;
00423
INT16 extLen;
00424
INT16 nameLen;
00425
INT16 charLen;
00426
INT16 overlayBytes;
00427
INT16 bytesLeft;
00428
UNICODE_CHAR current;
00429 BOOLEAN needsCRC;
00430
UNICODE_CHAR ext[
DOS_EXT_LEN];
00431
00432
00433
00434
00435
00436 PWCHAR dosName = ShortFileName->Buffer;
00437 PWCHAR udfName =
FileName->Buffer;
00438 LONG udfNameLen =
FileName->Length /
sizeof(WCHAR);
00439
00440 needsCRC =
FALSE;
00441
00442
00443
00444
00445 index = udfNameLen;
00446
while (index-- > 0) {
00447
if (udfName[index] ==
PERIOD)
00448
break;
00449 }
00450
00451
if (index < 0) {
00452
00453
00454 extLen = 0;
00455 nameLen = udfNameLen;
00456 }
00457
else {
00458
00459 extLen = udfNameLen - index - 1;
00460 nameLen = index;
00461 targetIndex = 0;
00462 bytesLeft =
DOS_EXT_LEN;
00463
00464
while (++index < udfNameLen && bytesLeft > 0) {
00465
00466
00467 current =
UnicodeToUpper(udfName[index]);
00468
if (current ==
SPACE) {
00469
00470
00471 needsCRC =
TRUE;
00472 }
00473
else {
00474
00475
00476
00477
00478 charLen = (
IsFileNameCharLegal(current)) ?
00479
NativeDosCharLength(current) : 0;
00480
00481
00482
00483
if (charLen > bytesLeft)
00484 charLen = 0;
00485
00486
if (charLen == 0) {
00487
00488
00489
00490
00491 needsCRC =
TRUE;
00492 charLen = 1;
00493 current =
ILLEGAL_CHAR_MARK;
00494
00495
00496
00497
while (index + 1 < udfNameLen &&
00498 (!
IsFileNameCharLegal(udfName[index + 1]) ||
00499
NativeDosCharLength(udfName[index + 1]) == 0))
00500 index++;
00501 }
00502
00503
00504
00505
00506 ext[targetIndex++] = current;
00507 bytesLeft -= charLen;
00508 }
00509 }
00510
00511
00512 extLen = targetIndex;
00513
00514
00515
00516
00517
if (index < udfNameLen || extLen == 0)
00518 needsCRC =
TRUE;
00519 }
00520
00521
00522 index = 0;
00523 targetIndex = 0;
00524 crcIndex = 0;
00525 overlayBytes = -1;
00526 bytesLeft =
DOS_NAME_LEN;
00527
while (index < nameLen && bytesLeft > 0) {
00528
00529 current =
UnicodeToUpper(udfName[index]);
00530
if (current ==
SPACE || current ==
PERIOD) {
00531
00532
00533 needsCRC =
TRUE;
00534 }
00535
else {
00536
00537
00538
00539
00540 charLen = (
IsFileNameCharLegal(current)) ?
00541
NativeDosCharLength(current) : 0;
00542
00543
00544
00545
if (charLen > bytesLeft)
00546 charLen = 0;
00547
00548
if (charLen == 0) {
00549
00550
00551
00552
00553 needsCRC =
TRUE;
00554 charLen = 1;
00555 current =
ILLEGAL_CHAR_MARK;
00556
00557
00558
00559
while (index + 1 < nameLen &&
00560 (!
IsFileNameCharLegal(udfName[index + 1]) ||
00561
NativeDosCharLength(udfName[index + 1]) == 0))
00562 index++;
00563
00564
00565
if (index >= nameLen)
00566
break;
00567 }
00568
00569
00570
00571
00572 dosName[targetIndex++] = current;
00573 bytesLeft -= charLen;
00574
00575
00576
00577
if (bytesLeft >=
DOS_CRC_LEN) {
00578
00579
00580 crcIndex = targetIndex;
00581 }
00582
else {
00583
00584
00585
00586
00587
if (overlayBytes < 0) {
00588
00589
00590
00591
00592
00593 overlayBytes = (bytesLeft + charLen >
DOS_CRC_LEN)
00594 ? 1 : 0;
00595 crcIndex = targetIndex - 1;
00596 }
00597 }
00598 }
00599
00600
00601 index++;
00602 }
00603
00604
00605
00606
if (index < nameLen || index == 0)
00607 needsCRC =
TRUE;
00608
00609
00610
00611
if (needsCRC ==
FALSE && extLen == 0) {
00612
00613
00614
if (
IsDeviceName(udfName, udfNameLen))
00615 needsCRC =
TRUE;
00616 }
00617
00618
00619
if (needsCRC) {
00620
00621
UINT16 udfCRCValue;
00622
UINT16 modulus;
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634 udfCRCValue =
UdfComputeCrc16Uni(udfName, udfNameLen);
00635
00636
00637
00638 targetIndex = crcIndex;
00639
00640
00641
00642
if (overlayBytes > 0)
00643 dosName[targetIndex++] =
ILLEGAL_CHAR_MARK;
00644
00645
00646
00647
00648
00649
00650
00651 dosName[targetIndex++] =
CRC_MARK;
00652
00653 dosName[targetIndex++] =
00654
UdfCrcChar[udfCRCValue / (41 * 41)];
00655 udfCRCValue %= (41 * 41);
00656
00657 dosName[targetIndex++] =
00658
UdfCrcChar[udfCRCValue / 41];
00659 udfCRCValue %= 41;
00660
00661 dosName[targetIndex++] =
00662
UdfCrcChar[udfCRCValue];
00663 }
00664
00665
00666
if (extLen > 0) {
00667
00668
00669 dosName[targetIndex++] =
PERIOD;
00670
for (index = 0; index < extLen; index++)
00671 dosName[targetIndex++] = ext[index];
00672 }
00673
00674
ASSERT( (targetIndex *
sizeof(WCHAR)) <= ShortFileName->MaximumLength );
00675
00676 ShortFileName->Length = (
USHORT) (targetIndex *
sizeof(WCHAR));
00677
00678
00679
00680
00681
00682
UdfUpcaseName( IrpContext,
00683 ShortFileName,
00684 ShortFileName );
00685 }
00686
00687
00688
VOID
00689 UdfConvertCS0DstringToUnicode (
00690 IN
PIRP_CONTEXT IrpContext,
00691 IN PUCHAR Dstring,
00692 IN UCHAR Length OPTIONAL,
00693 IN UCHAR FieldLength OPTIONAL,
00694 IN OUT PUNICODE_STRING Name
00695 )
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726 {
00727 ULONG CompressID;
00728 ULONG UnicodeIndex, ByteIndex;
00729 PWCHAR
Unicode =
Name->Buffer;
00730
00731 UCHAR NameLength;
00732 ULONG CopyNameLength;
00733
00734
PAGED_CODE();
00735
00736
00737
00738
00739
00740
ASSERT_IRP_CONTEXT( IrpContext );
00741
00742 CompressID = *Dstring;
00743
00744
00745
00746
00747
00748
00749
ASSERT( Length || FieldLength );
00750
00751
if (Length) {
00752
00753 NameLength = FieldLength = Length;
00754
00755 }
else {
00756
00757 NameLength = *(Dstring + FieldLength - 1);
00758 }
00759
00760
00761
00762
00763
00764
00765
ASSERT( Length == 0 ||
Name->MaximumLength >=
UdfCS0DstringUnicodeSize( IrpContext, Dstring, NameLength ) );
00766
00767
00768
00769
00770
00771 CopyNameLength =
Min(
Name->MaximumLength,
UdfCS0DstringUnicodeSize( IrpContext, Dstring, NameLength ));
00772
00773
00774
00775
00776
00777
Name->Length = 0;
00778 Dstring++;
00779
00780
00781
00782
00783
00784
while (CopyNameLength >
Name->Length) {
00785
00786
if (CompressID == 16) {
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
SwapCopyUchar2(
Unicode, Dstring );
00798 Dstring +=
sizeof(WCHAR);
00799
00800 }
else {
00801
00802
00803
00804
00805
00806 *
Unicode = *Dstring;
00807 Dstring +=
sizeof(
CHAR);
00808 }
00809
00810
Name->Length +=
sizeof(WCHAR);
00811
Unicode++;
00812 }
00813
00814
return;
00815 }
00816
00817
00818 BOOLEAN
00819 UdfCheckLegalCS0Dstring (
00820
PIRP_CONTEXT IrpContext,
00821 PUCHAR Dstring,
00822 UCHAR Length OPTIONAL,
00823 UCHAR FieldLength OPTIONAL,
00824 BOOLEAN ReturnOnError
00825 )
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853 {
00854 UCHAR NameLength;
00855
00856
00857
00858
00859
00860
ASSERT_IRP_CONTEXT( IrpContext );
00861
00862
00863
00864
00865
00866
00867
ASSERT( Length || FieldLength );
00868
00869
if (Length) {
00870
00871 NameLength = FieldLength = Length;
00872
00873 }
else {
00874
00875 NameLength = *(Dstring + FieldLength - 1);
00876 }
00877
00878
DebugTrace(( +1,
Dbg,
00879
"UdfCheckLegalCS0Dstring, Dstring %08x Length %02x FieldLength %02x (NameLength %02x)\n",
00880 Dstring,
00881 Length,
00882 FieldLength,
00883 NameLength ));
00884
00885
00886
00887
00888
00889
00890
00891
if ((NameLength <= 1 &&
00892
DebugTrace(( 0,
Dbg,
00893
"UdfCheckLegalCS0Dstring, NameLength is too small!\n" ))) ||
00894
00895 (NameLength > FieldLength &&
00896
DebugTrace(( 0,
Dbg,
00897
"UdfCheckLegalCS0Dstring, NameLength is bigger than the field itself!\n" ))) ||
00898
00899 ((*Dstring != 8 && *Dstring != 16) &&
00900
DebugTrace(( 0,
Dbg,
00901
"UdfCheckLegalCS0Dstring, claims encoding %02x, unknown! (not 0x8 or 0x10)\n",
00902 *Dstring ))) ||
00903
00904 ((*Dstring == 16 && !
FlagOn( NameLength, 1)) &&
00905
DebugTrace(( 0,
Dbg,
00906
"UdfCheckLegalCS0Dstring, NameLength not odd, encoding 0x10!\n" )))) {
00907
00908
if (ReturnOnError) {
00909
00910
DebugTrace(( -1,
Dbg,
"UdfCheckLegalCS0Dstring -> FALSE\n" ));
00911
00912
return FALSE;
00913 }
00914
00915
DebugTrace(( -1,
Dbg,
"UdfCheckLegalCS0Dstring -> raised status\n" ));
00916
00917
UdfRaiseStatus( IrpContext, STATUS_FILE_CORRUPT_ERROR );
00918 }
00919
00920
DebugTrace(( -1,
Dbg,
"UdfCheckLegalCS0Dstring -> TRUE\n" ));
00921
00922
return TRUE;
00923 }
00924
00925
00926
VOID
00927 UdfRenderNameToLegalUnicode (
00928 IN
PIRP_CONTEXT IrpContext,
00929 IN PUNICODE_STRING Name,
00930 IN PUNICODE_STRING RenderedName
00931 )
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958 {
00959
INT16 index;
00960
INT16 targetIndex;
00961
INT16 crcIndex;
00962
INT16 extLen;
00963
INT16 nameLen;
00964
INT16 charLen;
00965
INT16 overlayBytes;
00966
INT16 bytesLeft;
00967
UNICODE_CHAR current;
00968 BOOLEAN needsCRC;
00969 BOOLEAN foundDot;
00970
UNICODE_CHAR ext[
EXT_LEN];
00971
00972
00973
00974
00975
00976 PWCHAR newName = RenderedName->Buffer;
00977 PWCHAR udfName =
Name->Buffer;
00978 LONG udfNameLen =
Name->Length /
sizeof(WCHAR);
00979
00980
00981
00982 foundDot =
FALSE;
00983 index = udfNameLen;
00984
while (index-- > 0) {
00985
if (udfName[index] ==
PERIOD)
00986 foundDot =
TRUE;
00987
else if (udfName[index] !=
SPACE)
00988
break;
00989 }
00990
00991
00992
00993 nameLen = index + 1;
00994
if (nameLen < udfNameLen)
00995 needsCRC =
TRUE;
00996
00997 needsCRC =
FALSE;
00998 bytesLeft =
MAX_LEN;
00999 extLen = 0;
01000
01001
if (needsCRC ==
FALSE || foundDot ==
FALSE) {
01002
01003
01004
01005
INT16 endIndex;
01006
INT16 prevCharLen = 1;
01007
INT16 extBytes = 0;
01008
01009 targetIndex = 0;
01010 index = nameLen;
01011
01012
01013
01014
01015
01016 endIndex = (udfNameLen >
EXT_LEN + 1) ?
01017 udfNameLen -
EXT_LEN - 1 : 1;
01018
01019
01020
01021
while (index-- > endIndex) {
01022
01023 current = udfName[index];
01024
01025
if (current ==
'.') {
01026
01027
01028
01029
01030 extLen = nameLen - index - 1;
01031 nameLen = index;
01032
break;
01033 }
01034
01035
01036
01037 charLen = (
IsFileNameCharLegal(current)) ?
01038
NativeCharLength(current) : 0;
01039
01040
if (charLen == 0) {
01041
01042
01043
01044
01045
01046
01047
if (prevCharLen != 0) {
01048 ext[targetIndex++] =
ILLEGAL_CHAR_MARK;
01049 extBytes++;
01050 }
01051 }
01052
else {
01053
01054
01055
01056
01057 ext[targetIndex++] = current;
01058 extBytes += charLen;
01059 }
01060
01061
01062
01063
01064 prevCharLen = charLen;
01065 }
01066
01067
01068
01069
if (extLen > 0)
01070 bytesLeft -= extBytes + 1;
01071 }
01072
01073 index = 0;
01074 targetIndex = 0;
01075 crcIndex = 0;
01076 overlayBytes = -1;
01077
while (index < nameLen && bytesLeft > 0) {
01078
01079 current = udfName[index];
01080
01081
01082
01083
01084
01085 charLen = (
IsFileNameCharLegal(current)) ?
01086
NativeCharLength(current) : 0;
01087
01088
01089
01090
if (charLen > bytesLeft)
01091 charLen = 0;
01092
01093
if (charLen == 0) {
01094
01095
01096
01097 needsCRC =
TRUE;
01098 charLen = 1;
01099 current =
'_';
01100
01101
01102
01103
while (index + 1 < udfNameLen &&
01104 (!
IsFileNameCharLegal(udfName[index + 1]) ||
01105
NativeCharLength(udfName[index + 1]) == 0))
01106 index++;
01107
01108
01109
if (index >= udfNameLen)
01110
break;
01111 }
01112
01113
01114
01115
01116 newName[targetIndex++] = current;
01117 bytesLeft -= charLen;
01118
01119
01120
01121
if (bytesLeft >=
CRC_LEN) {
01122
01123
01124 crcIndex = targetIndex;
01125 }
01126
else {
01127
01128
01129
01130
01131
if (overlayBytes < 0) {
01132
01133
01134
01135
01136
01137 overlayBytes = (bytesLeft + charLen >
CRC_LEN)
01138 ? 1 : 0;
01139 crcIndex = targetIndex - 1;
01140 }
01141 }
01142
01143
01144 index++;
01145 }
01146
01147
01148
01149
if (index < nameLen || index == 0)
01150 needsCRC =
TRUE;
01151
01152
01153
01154
if (needsCRC ==
FALSE && extLen == 0) {
01155
01156
01157
if (
IsDeviceName(udfName, udfNameLen))
01158 needsCRC =
TRUE;
01159 }
01160
01161
01162
if (needsCRC) {
01163
01164
UINT16 udfCRCValue =
UdfComputeCrc16Uni(udfName, udfNameLen);
01165
01166
01167
01168 targetIndex = crcIndex;
01169
01170
01171
01172
if (overlayBytes > 0)
01173 newName[targetIndex++] =
ILLEGAL_CHAR_MARK;
01174
01175
01176 newName[targetIndex++] =
CRC_MARK;
01177 newName[targetIndex++] =
UdfCrcChar[(udfCRCValue & 0xf000) >> 12];
01178 newName[targetIndex++] =
UdfCrcChar[(udfCRCValue & 0x0f00) >> 8];
01179 newName[targetIndex++] =
UdfCrcChar[(udfCRCValue & 0x00f0) >> 4];
01180 newName[targetIndex++] =
UdfCrcChar[(udfCRCValue & 0x000f)];
01181 }
01182
01183
01184
01185
if (extLen > 0) {
01186
01187 newName[targetIndex++] =
PERIOD;
01188
01189
01190
01191
01192
while (extLen-- > 0)
01193 newName[targetIndex++] = ext[extLen];
01194 }
01195
01196
ASSERT( (targetIndex *
sizeof(WCHAR)) <= RenderedName->MaximumLength );
01197
01198 RenderedName->Length = (
USHORT) (targetIndex *
sizeof(WCHAR));
01199 }
01200
01201
01202 BOOLEAN
01203 UdfIsNameInExpression (
01204 IN
PIRP_CONTEXT IrpContext,
01205 IN PUNICODE_STRING CurrentName,
01206 IN PUNICODE_STRING SearchExpression,
01207 IN BOOLEAN Wild
01208 )
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231 {
01232 BOOLEAN Match =
TRUE;
01233
01234
PAGED_CODE();
01235
01236
01237
01238
01239
01240
ASSERT_IRP_CONTEXT( IrpContext );
01241
01242
01243
01244
01245
01246
01247
if (Wild) {
01248
01249 Match =
FsRtlIsNameInExpression( SearchExpression,
01250 CurrentName,
01251
FALSE,
01252
NULL );
01253
01254
01255
01256
01257
01258 }
else {
01259
01260
if ((CurrentName->Length != SearchExpression->Length) ||
01261 (!RtlEqualMemory( CurrentName->Buffer,
01262 SearchExpression->Buffer,
01263 CurrentName->Length ))) {
01264
01265 Match =
FALSE;
01266 }
01267 }
01268
01269
return Match;
01270 }
01271
01272
01273
FSRTL_COMPARISON_RESULT
01274 UdfFullCompareNames (
01275 IN
PIRP_CONTEXT IrpContext,
01276 IN PUNICODE_STRING NameA,
01277 IN PUNICODE_STRING NameB
01278 )
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301 {
01302 ULONG i;
01303 ULONG MinLength = NameA->Length;
01304
FSRTL_COMPARISON_RESULT Result =
LessThan;
01305
01306
PAGED_CODE();
01307
01308
01309
01310
01311
01312
ASSERT_IRP_CONTEXT( IrpContext );
01313
01314
01315
01316
01317
01318
if (NameA->Length > NameB->Length) {
01319
01320 MinLength = NameB->Length;
01321 Result =
GreaterThan;
01322
01323 }
else if (NameA->Length == NameB->Length) {
01324
01325 Result =
EqualTo;
01326 }
01327
01328
01329
01330
01331
01332
01333 i = (ULONG) RtlCompareMemory( NameA->Buffer, NameB->Buffer, MinLength );
01334
01335
if (i < MinLength) {
01336
01337
01338
01339
01340
01341
return ((NameA->Buffer[ i / 2 ] < NameB->Buffer[ i / 2 ]) ?
01342
LessThan :
01343
GreaterThan);
01344 }
01345
01346
01347
01348
01349
01350
01351
return Result;
01352 }
01353