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
#include "iop.h"
00027
00028
#ifdef POOL_TAGGING
00029
#undef ExAllocatePool
00030
#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'lrpP')
00031
#endif
00032
00033
#ifdef ALLOC_PRAGMA
00034
#pragma alloc_text(PAGE, IopAddRelationToList)
00035
#pragma alloc_text(PAGE, IopAllocateRelationList)
00036
#pragma alloc_text(PAGE, IopCompressRelationList)
00037
#pragma alloc_text(PAGE, IopEnumerateRelations)
00038
#pragma alloc_text(PAGE, IopFreeRelationList)
00039
#pragma alloc_text(PAGE, IopGetRelationsCount)
00040
#pragma alloc_text(PAGE, IopGetRelationsTaggedCount)
00041
#pragma alloc_text(PAGE, IopIsRelationInList)
00042
#pragma alloc_text(PAGE, IopMergeRelationLists)
00043
#pragma alloc_text(PAGE, IopRemoveIndirectRelationsFromList)
00044
#pragma alloc_text(PAGE, IopRemoveRelationFromList)
00045
#pragma alloc_text(PAGE, IopSetAllRelationsTags)
00046
#pragma alloc_text(PAGE, IopSetRelationsTag)
00047
#endif
00048
00049 #define RELATION_FLAGS 0x00000003
00050
00051 #define RELATION_FLAG_TAGGED 0x00000001
00052 #define RELATION_FLAG_DESCENDANT 0x00000002
00053
00054
NTSTATUS
00055 IopAddRelationToList(
00056 IN
PRELATION_LIST List,
00057 IN
PDEVICE_OBJECT DeviceObject,
00058 IN BOOLEAN DirectDescendant,
00059 IN BOOLEAN Tagged
00060 )
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 {
00114
PDEVICE_NODE deviceNode;
00115
PRELATION_LIST_ENTRY entry;
00116 ULONG level;
00117 ULONG index;
00118 ULONG flags;
00119
00120
PAGED_CODE();
00121
00122 flags = 0;
00123
00124
if (Tagged) {
00125 Tagged = 1;
00126 flags |=
RELATION_FLAG_TAGGED;
00127 }
00128
00129
if (DirectDescendant) {
00130 flags |=
RELATION_FLAG_DESCENDANT;
00131 }
00132
00133
if ((deviceNode = DeviceObject->DeviceObjectExtension->DeviceNode) !=
NULL) {
00134 level = deviceNode->
Level;
00135
00136
00137
00138
00139
00140
00141
00142
ASSERT(
List->FirstLevel <= level && level <= List->MaxLevel);
00143
00144
if (
List->FirstLevel <= level && level <=
List->MaxLevel) {
00145
00146
if ((entry =
List->Entries[ level -
List->FirstLevel ]) ==
NULL) {
00147
00148
00149
00150
00151
00152 entry =
ExAllocatePool(
PagedPool,
00153
sizeof(
RELATION_LIST_ENTRY) +
00154
IopNumberDeviceNodes *
sizeof(
PDEVICE_OBJECT));
00155
00156
if (entry ==
NULL) {
00157
return STATUS_INSUFFICIENT_RESOURCES;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167 entry->
Count = 0;
00168 entry->
MaxCount =
IopNumberDeviceNodes;
00169
00170
List->Entries[ level -
List->FirstLevel ] = entry;
00171 }
00172
00173
00174
00175
00176
00177
00178
ASSERT(entry->
Count < entry->
MaxCount);
00179
00180
if (entry->
Count < entry->
MaxCount) {
00181
00182
00183
00184
00185
for (index = 0; index < entry->
Count; index++) {
00186
if (((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAGS) == (ULONG_PTR)DeviceObject) {
00187
00188
00189
00190
00191
00192
00193
00194
if (DirectDescendant) {
00195 entry->
Devices[ index ] = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ index ] |
RELATION_FLAG_DESCENDANT);
00196 }
00197
00198
return STATUS_OBJECT_NAME_COLLISION;
00199 }
00200 }
00201 }
else {
00202
00203
00204
00205
00206
return STATUS_INVALID_PARAMETER;
00207 }
00208
00209
00210
00211
00212
00213
ObReferenceObject( DeviceObject );
00214
00215 entry->
Devices[ index ] = (
PDEVICE_OBJECT)((ULONG_PTR)DeviceObject | flags);
00216 entry->
Count++;
00217
00218
List->Count++;
00219
List->TagCount += Tagged;
00220
00221
return STATUS_SUCCESS;
00222 }
else {
00223
00224
00225
00226
00227
00228
return STATUS_INVALID_PARAMETER;
00229 }
00230 }
else {
00231
00232
00233
00234
return STATUS_NO_SUCH_DEVICE;
00235 }
00236 }
00237
00238
PRELATION_LIST
00239 IopAllocateRelationList(
00240 VOID
00241 )
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 {
00261
PRELATION_LIST list;
00262 ULONG maxLevel;
00263 ULONG listSize;
00264
00265
PAGED_CODE();
00266
00267
00268
00269
00270
00271 maxLevel =
IopMaxDeviceNodeLevel;
00272 listSize =
sizeof(
RELATION_LIST) + maxLevel *
sizeof(
PRELATION_LIST_ENTRY);
00273
00274
if ((list =
ExAllocatePool(
PagedPool, listSize )) !=
NULL) {
00275 RtlZeroMemory(list, listSize);
00276
00277
00278
00279 list->
MaxLevel = maxLevel;
00280 }
00281
00282
return list;
00283 }
00284
00285
NTSTATUS
00286 IopCompressRelationList(
00287 IN OUT
PRELATION_LIST *List
00288 )
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 {
00316
PRELATION_LIST oldList, newList;
00317
PRELATION_LIST_ENTRY oldEntry, newEntry;
00318 ULONG lowestLevel;
00319 ULONG highestLevel;
00320 ULONG index;
00321
00322
PAGED_CODE();
00323
00324 oldList = *
List;
00325
00326
00327
00328
00329
00330 lowestLevel = oldList->
MaxLevel;
00331 highestLevel = oldList->
FirstLevel;
00332
00333
00334
00335
00336
for (index = 0; index <= (oldList->
MaxLevel - oldList->
FirstLevel); index++) {
00337
00338
if ((oldEntry = oldList->
Entries[ index ]) !=
NULL) {
00339
00340
00341
00342
00343
if (lowestLevel > index) {
00344 lowestLevel = index;
00345 }
00346
00347
if (highestLevel < index) {
00348 highestLevel = index;
00349 }
00350
00351
if (oldEntry->
Count < oldEntry->
MaxCount) {
00352
00353
00354
00355
00356
00357
00358 newEntry =
ExAllocatePool(
PagedPool,
00359
sizeof(
RELATION_LIST_ENTRY) +
00360 (oldEntry->
Count - 1) *
sizeof(
PDEVICE_OBJECT));
00361
00362
if (newEntry !=
NULL) {
00363
00364
00365
00366
00367
00368 newEntry->
Count = oldEntry->
Count;
00369 newEntry->
MaxCount = oldEntry->
Count;
00370
00371
00372
00373
00374
00375 RtlCopyMemory( newEntry->
Devices,
00376 oldEntry->
Devices,
00377 oldEntry->
Count *
sizeof(
PDEVICE_OBJECT));
00378
00379
00380
00381
00382
ExFreePool( oldEntry );
00383
00384 oldList->
Entries[ index ] = newEntry;
00385 }
00386 }
00387 }
00388 }
00389
00390
00391
00392
00393
ASSERT(lowestLevel <= highestLevel);
00394
00395
if (lowestLevel > highestLevel) {
00396
00397
00398
00399
00400 lowestLevel = 0;
00401 highestLevel = 0;
00402 }
00403
00404
00405
00406
00407
00408
if (lowestLevel != oldList->
FirstLevel || highestLevel != oldList->
MaxLevel) {
00409
00410
00411
00412
00413
00414 newList =
ExAllocatePool(
PagedPool,
00415
sizeof(
RELATION_LIST) +
00416 (highestLevel - lowestLevel) *
sizeof(
PRELATION_LIST_ENTRY));
00417
00418
if (newList !=
NULL) {
00419
00420
00421
00422 newList->
Count = oldList->
Count;
00423 newList->
TagCount = oldList->
TagCount;
00424 newList->
FirstLevel = lowestLevel;
00425 newList->
MaxLevel = highestLevel;
00426
00427 RtlCopyMemory( newList->
Entries,
00428 &oldList->
Entries[ lowestLevel ],
00429 (highestLevel - lowestLevel + 1) *
sizeof(
PRELATION_LIST_ENTRY));
00430
00431
ExFreePool( oldList );
00432
00433 *
List = newList;
00434 }
00435 }
00436
00437
return STATUS_SUCCESS;
00438 }
00439
00440 BOOLEAN
00441 IopEnumerateRelations(
00442 IN
PRELATION_LIST List,
00443 IN OUT PULONG Marker,
00444 OUT
PDEVICE_OBJECT *DeviceObject,
00445 OUT BOOLEAN *DirectDescendant, OPTIONAL
00446 OUT BOOLEAN *Tagged, OPTIONAL
00447 IN BOOLEAN Reverse
00448 )
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 {
00500
PRELATION_LIST_ENTRY entry;
00501 LONG levelIndex;
00502 ULONG entryIndex;
00503
00504
PAGED_CODE();
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
if (*Marker == ~0U) {
00517
00518
00519
00520
return FALSE;
00521 }
00522
00523
if (*Marker == 0) {
00524
00525
00526
00527
if (Reverse) {
00528
00529
00530
00531 levelIndex =
List->MaxLevel -
List->FirstLevel;
00532 }
else {
00533
00534
00535
00536 levelIndex = 0;
00537 }
00538
00539
00540
00541
00542
00543
00544
00545 entryIndex = ~0U;
00546 }
else {
00547
00548
00549
00550
00551
ASSERT(*Marker & ((ULONG)1 << 31));
00552
00553
00554
00555 levelIndex = (*Marker >> 24) & 0x7F;
00556
00557
00558
00559 entryIndex = *Marker & 0x00FFFFFF;
00560 }
00561
00562
if (Reverse) {
00563
00564
00565
00566
00567
for ( ; levelIndex >= 0; levelIndex--) {
00568
00569
00570
00571
00572
00573
if ((entry =
List->Entries[ levelIndex ]) !=
NULL) {
00574
00575
if (entryIndex > entry->
Count) {
00576
00577
00578
00579
00580
00581
00582 entryIndex = entry->
Count;
00583 }
00584
00585
if (entryIndex > 0) {
00586
00587
00588
00589
00590
00591
00592 entryIndex--;
00593
00594
00595
00596
00597 *DeviceObject = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ entryIndex ] & ~
RELATION_FLAGS);
00598
00599
if (Tagged !=
NULL) {
00600
00601
00602
00603 *Tagged = (BOOLEAN)((ULONG_PTR)entry->
Devices[ entryIndex ] &
RELATION_FLAG_TAGGED);
00604 }
00605
00606
if (DirectDescendant !=
NULL) {
00607
00608
00609
00610 *DirectDescendant = (BOOLEAN)((ULONG_PTR)entry->
Devices[ entryIndex ] &
RELATION_FLAG_DESCENDANT);
00611 }
00612
00613
00614
00615
00616 *Marker = ((ULONG)1 << 31) | (levelIndex << 24) | (entryIndex & 0x00FFFFFF);
00617
00618
return TRUE;
00619 }
00620 }
00621
00622
00623
00624
00625
00626
00627
00628 entryIndex = ~0U;
00629 }
00630 }
else {
00631
for ( ; levelIndex <= (LONG)(
List->MaxLevel -
List->FirstLevel); levelIndex++) {
00632
00633
00634
00635
00636
00637
if ((entry =
List->Entries[ levelIndex ]) !=
NULL) {
00638
00639
00640
00641
00642
00643
00644
00645 entryIndex++;
00646
00647
if (entryIndex < entry->
Count) {
00648
00649
00650
00651
00652
00653
00654
00655 *DeviceObject = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ entryIndex ] & ~
RELATION_FLAGS);
00656
00657
if (Tagged !=
NULL) {
00658
00659
00660
00661 *Tagged = (BOOLEAN)((ULONG_PTR)entry->
Devices[ entryIndex ] &
RELATION_FLAG_TAGGED);
00662 }
00663
00664
if (DirectDescendant !=
NULL) {
00665
00666
00667
00668 *DirectDescendant = (BOOLEAN)((ULONG_PTR)entry->
Devices[ entryIndex ] &
RELATION_FLAG_DESCENDANT);
00669 }
00670
00671
00672
00673
00674 *Marker = ((ULONG)1 << 31) | (levelIndex << 24) | (entryIndex & 0x00FFFFFF);
00675
00676
return TRUE;
00677 }
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687 entryIndex = ~0U;
00688 }
00689 }
00690
00691
00692
00693
00694 *Marker = ~0U;
00695 *DeviceObject =
NULL;
00696
00697
if (Tagged !=
NULL) {
00698 *Tagged =
FALSE;
00699 }
00700
00701
if (DirectDescendant !=
NULL) {
00702 *DirectDescendant =
FALSE;
00703 }
00704
00705
return FALSE;
00706 }
00707
00708
VOID
00709 IopFreeRelationList(
00710 IN
PRELATION_LIST List
00711 )
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729 {
00730
PRELATION_LIST_ENTRY entry;
00731 ULONG levelIndex;
00732 ULONG entryIndex;
00733
00734
PAGED_CODE();
00735
00736
00737
00738
00739
for (levelIndex = 0; levelIndex <= (
List->MaxLevel -
List->FirstLevel); levelIndex++) {
00740
00741
if ((entry =
List->Entries[ levelIndex ]) !=
NULL) {
00742
00743
00744
00745
for (entryIndex = 0; entryIndex < entry->
Count; entryIndex++) {
00746
00747
00748
00749
ObDereferenceObject((
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ entryIndex ] & ~
RELATION_FLAGS));
00750 }
00751
00752
00753
00754
ExFreePool( entry );
00755 }
00756 }
00757
00758
00759
00760
00761
00762
00763
00764
ExFreePool(
List );
00765 }
00766
00767 ULONG
00768 IopGetRelationsCount(
00769
PRELATION_LIST List
00770 )
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788 {
00789
PAGED_CODE();
00790
00791
return List->Count;
00792 }
00793
00794 ULONG
00795 IopGetRelationsTaggedCount(
00796
PRELATION_LIST List
00797 )
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816 {
00817
PAGED_CODE();
00818
00819
return List->TagCount;
00820 }
00821
00822 BOOLEAN
00823 IopIsRelationInList(
00824
PRELATION_LIST List,
00825
PDEVICE_OBJECT DeviceObject
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
PDEVICE_NODE deviceNode;
00855
PRELATION_LIST_ENTRY entry;
00856 ULONG level;
00857 ULONG index;
00858
00859
PAGED_CODE();
00860
00861
if ((deviceNode = DeviceObject->
DeviceObjectExtension->
DeviceNode) !=
NULL) {
00862
00863
00864
00865 level = deviceNode->
Level;
00866
00867
if (
List->FirstLevel <= level && level <=
List->MaxLevel) {
00868
00869
00870
00871
if ((entry =
List->Entries[ level -
List->FirstLevel ]) !=
NULL) {
00872
00873
00874
00875
for (index = 0; index < entry->
Count; index++) {
00876
00877
00878
00879
if (((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAGS) == (ULONG_PTR)DeviceObject) {
00880
00881
00882
00883
return TRUE;
00884 }
00885 }
00886 }
00887 }
00888 }
00889
00890
00891
00892
00893
00894
00895
00896
return FALSE;
00897 }
00898
00899
NTSTATUS
00900 IopMergeRelationLists(
00901 IN OUT
PRELATION_LIST TargetList,
00902 IN
PRELATION_LIST SourceList,
00903 IN BOOLEAN Tagged
00904 )
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
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
00960
00961
00962 {
00963
PRELATION_LIST_ENTRY entry;
00964 ULONG levelIndex;
00965 ULONG entryIndex;
00966
NTSTATUS status = STATUS_SUCCESS;
00967
00968
PAGED_CODE();
00969
00970
00971
00972
00973
for (levelIndex = 0;
00974 levelIndex <= (SourceList->MaxLevel - SourceList->FirstLevel);
00975 levelIndex++) {
00976
00977
if ((entry = SourceList->Entries[ levelIndex ]) !=
NULL) {
00978
00979
00980
00981
for (entryIndex = 0; entryIndex < entry->
Count; entryIndex++) {
00982
00983
00984
00985 status =
IopAddRelationToList( TargetList,
00986 (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ entryIndex ] & ~
RELATION_FLAGS),
00987
FALSE,
00988 Tagged);
00989
00990
00991
00992
00993
00994
00995
ASSERT(
NT_SUCCESS(status));
00996
00997
if (!
NT_SUCCESS(status)) {
00998
00999
01000
01001
01002
01003
break;
01004 }
01005 }
01006 }
01007 }
01008
01009
return status;
01010 }
01011
01012
NTSTATUS
01013 IopRemoveIndirectRelationsFromList(
01014 IN
PRELATION_LIST List
01015 )
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037 {
01038
PDEVICE_OBJECT deviceObject;
01039
PRELATION_LIST_ENTRY entry;
01040 ULONG level;
01041 LONG index;
01042
01043
PAGED_CODE();
01044
01045
01046
01047
01048
for (level =
List->FirstLevel; level <=
List->MaxLevel; level++) {
01049
01050
01051
01052
01053
if ((entry =
List->Entries[ level -
List->FirstLevel ]) !=
NULL) {
01054
01055
01056
01057
01058
for (index = entry->
Count - 1; index >= 0; index--) {
01059
if (!((ULONG_PTR)entry->
Devices[ index ] &
RELATION_FLAG_DESCENDANT)) {
01060
01061 deviceObject = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAGS);
01062
01063
ObDereferenceObject( deviceObject );
01064
01065
if ((ULONG_PTR)entry->
Devices[ index ] &
RELATION_FLAG_TAGGED) {
01066
List->TagCount--;
01067 }
01068
01069
if (index < ((LONG)entry->
Count - 1)) {
01070
01071 RtlMoveMemory( &entry->
Devices[ index ],
01072 &entry->
Devices[ index + 1 ],
01073 (entry->
Count - index - 1) *
sizeof(
PDEVICE_OBJECT));
01074 }
01075
01076
if (--entry->
Count == 0) {
01077
List->Entries[ level -
List->FirstLevel ] =
NULL;
01078
ExFreePool(entry);
01079 }
01080
01081
List->Count--;
01082 }
01083 }
01084 }
01085 }
01086
return STATUS_SUCCESS;
01087 }
01088
01089
NTSTATUS
01090 IopRemoveRelationFromList(
01091
PRELATION_LIST List,
01092
PDEVICE_OBJECT DeviceObject
01093 )
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119 {
01120
PDEVICE_NODE deviceNode;
01121
PRELATION_LIST_ENTRY entry;
01122 ULONG level;
01123 LONG index;
01124
01125
PAGED_CODE();
01126
01127
if ((deviceNode = DeviceObject->
DeviceObjectExtension->
DeviceNode) !=
NULL) {
01128 level = deviceNode->
Level;
01129
01130
ASSERT(
List->FirstLevel <= level && level <= List->MaxLevel);
01131
01132
if (
List->FirstLevel <= level && level <=
List->MaxLevel) {
01133
if ((entry =
List->Entries[ level -
List->FirstLevel ]) !=
NULL) {
01134
for (index = entry->
Count - 1; index >= 0; index--) {
01135
if (((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAGS) == (ULONG_PTR)DeviceObject) {
01136
01137
ObDereferenceObject( DeviceObject );
01138
01139
if (((ULONG_PTR)entry->
Devices[ index ] &
RELATION_FLAG_TAGGED) != 0) {
01140
List->TagCount--;
01141 }
01142
if (index < ((LONG)entry->
Count - 1)) {
01143
01144 RtlMoveMemory( &entry->
Devices[ index ],
01145 &entry->
Devices[ index + 1 ],
01146 (entry->
Count - index - 1) *
sizeof(
PDEVICE_OBJECT));
01147 }
01148
01149
if (--entry->
Count == 0) {
01150
List->Entries[ level -
List->FirstLevel ] =
NULL;
01151
ExFreePool(entry);
01152 }
01153
01154
List->Count--;
01155
01156
return STATUS_SUCCESS;
01157 }
01158 }
01159 }
01160 }
01161 }
01162
return STATUS_NO_SUCH_DEVICE;
01163 }
01164
01165
VOID
01166 IopSetAllRelationsTags(
01167
PRELATION_LIST List,
01168 BOOLEAN Tagged
01169 )
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190 {
01191
PRELATION_LIST_ENTRY entry;
01192 ULONG level;
01193 ULONG index;
01194
01195
PAGED_CODE();
01196
01197
01198
01199
01200
for (level =
List->FirstLevel; level <=
List->MaxLevel; level++) {
01201
01202
01203
01204
01205
if ((entry =
List->Entries[ level -
List->FirstLevel ]) !=
NULL) {
01206
01207
01208
01209
01210
for (index = 0; index < entry->
Count; index++) {
01211
01212
01213
01214
01215
if (Tagged) {
01216 entry->
Devices[ index ] = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ index ] |
RELATION_FLAG_TAGGED);
01217 }
else {
01218 entry->
Devices[ index ] = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAG_TAGGED);
01219 }
01220 }
01221 }
01222 }
01223
01224
01225
01226
01227
01228
List->TagCount = Tagged ?
List->Count : 0;
01229 }
01230
01231
NTSTATUS
01232 IopSetRelationsTag(
01233 IN
PRELATION_LIST List,
01234 IN
PDEVICE_OBJECT DeviceObject,
01235 IN BOOLEAN Tagged
01236 )
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267 {
01268
PDEVICE_NODE deviceNode;
01269
PRELATION_LIST_ENTRY entry;
01270 ULONG level;
01271 LONG index;
01272
01273
PAGED_CODE();
01274
01275
if ((deviceNode = DeviceObject->DeviceObjectExtension->DeviceNode) !=
NULL) {
01276
01277
01278
01279 level = deviceNode->
Level;
01280
01281
if (
List->FirstLevel <= level && level <=
List->MaxLevel) {
01282
01283
01284
01285
if ((entry =
List->Entries[ level -
List->FirstLevel ]) !=
NULL) {
01286
01287
01288
01289
01290
for (index = entry->
Count - 1; index >= 0; index--) {
01291
01292
if (((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAGS) == (ULONG_PTR)DeviceObject) {
01293
01294
01295
01296
01297
if ((ULONG_PTR)entry->
Devices[ index ] &
RELATION_FLAG_TAGGED) {
01298
01299
01300
01301
01302
01303
01304
List->TagCount--;
01305 }
01306
01307
if (Tagged) {
01308
01309
01310
01311
01312 entry->
Devices[ index ] = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ index ] |
RELATION_FLAG_TAGGED);
01313
List->TagCount++;
01314 }
else {
01315
01316
01317
01318 entry->
Devices[ index ] = (
PDEVICE_OBJECT)((ULONG_PTR)entry->
Devices[ index ] & ~
RELATION_FLAG_TAGGED);
01319 }
01320
01321
return STATUS_SUCCESS;
01322 }
01323 }
01324 }
01325 }
01326 }
01327
01328
01329
01330
01331
01332
01333
01334
return STATUS_NO_SUCH_DEVICE;
01335 }
01336