Sample Code
windows driver samples/ cdfs file system driver/ C++/ pathsup.c/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 | /*++ Copyright (c) 1989-2000 Microsoft Corporation Module Name: PathSup.c Abstract: This module implements the Path Table support routines for Cdfs. The path table on a CDROM is a condensed summary of the entire directory structure. It is stored on a number of contiguous sectors on the disk. Each directory on the disk has an entry in the path table. The entries are aligned on USHORT boundaries and MAY span sector boundaries. The entries are stored as a breadth-first search. The first entry in the table contains the entry for the root. The next entries will consist of the contents of the root directory. The next entries will consist of the all the directories at the next level of the tree. The children of a given directory will be grouped together. The directories are assigned ordinal numbers based on their position in the path table. The root dirctory is assigned ordinal value 1. Path table sectors: Ordinal 1 2 3 4 5 6 +-----------+ | Spanning | | Sectors | +----------------------------+ +------------------------+ | | | | | | | | | DirName | \ | a | b |c| | c | d | e | | | | | | | | | | Parent #| 1 | 1 | 1 | | | 2 | 2 | 3 | +----------------------------+ +------------------------+ Directory Tree: \ (root) / \ / \ a b / \ \ / \ \ c d e Path Table Entries: - Position scan at known offset in the path table. Path Entry at this offset must exist and is known to be valid. Used when scanning for the children of a given directory. - Position scan at known offset in the path table. Path Entry is known to start at this location but the bounds must be checked for validity. - Move to next path entry in the table. - Update a common path entry structure with the details of the on-disk structure. This is used to smooth out the differences in the on-disk structures. - Update the filename in the in-memory path entry with the bytes off the disk. For Joliet disks we will have to convert to little endian. We assume that directories don't have version numbers. --*/ #include "CdProcs.h" // // The Bug check file id for this module // #define BugCheckFileId (CDFS_BUG_CHECK_PATHSUP) // // Local macros // // // PRAW_PATH_ENTRY // CdRawPathEntry ( // _In_ PIRP_CONTEXT IrpContext, // _In_ PPATH_ENUM_CONTEXT PathContext // ); // #define CdRawPathEntry(IC, PC) \ Add2Ptr( (PC)->Data, (PC)->DataOffset, PRAW_PATH_ENTRY ) // // Local support routines // VOID CdMapPathTableBlock ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ LONGLONG BaseOffset, _Inout_ PPATH_ENUM_CONTEXT PathContext ); _Success_( return != FALSE) BOOLEAN CdUpdatePathEntryFromRawPathEntry ( _In_ PIRP_CONTEXT IrpContext, _In_ ULONG Ordinal, _In_ BOOLEAN VerifyBounds, _In_ PPATH_ENUM_CONTEXT PathContext, _Out_ PPATH_ENTRY PathEntry ); #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, CdFindPathEntry) #pragma alloc_text(PAGE, CdLookupPathEntry) #pragma alloc_text(PAGE, CdLookupNextPathEntry) #pragma alloc_text(PAGE, CdMapPathTableBlock) #pragma alloc_text(PAGE, CdUpdatePathEntryFromRawPathEntry) #pragma alloc_text(PAGE, CdUpdatePathEntryName) #endif
VOID CdLookupPathEntry ( _In_ PIRP_CONTEXT IrpContext, _In_ ULONG PathEntryOffset, _In_ ULONG Ordinal, _In_ BOOLEAN VerifyBounds, _Inout_ PCOMPOUND_PATH_ENTRY CompoundPathEntry ) /*++ Routine Description: This routine is called to initiate a walk through a path table. We are looking for a path table entry at location PathEntryOffset. Arguments: PathEntryOffset - This is our target point in the Path Table. We know that a path entry must begin at this point although we may have to verify the bounds. Ordinal - Ordinal number for the directory at the PathEntryOffset above. VerifyBounds - Indicates whether we need to check the validity of this entry. CompoundPathEntry - PathEnumeration context and in-memory path entry. This has been initialized outside of this call. Return Value: None. --*/ { PPATH_ENUM_CONTEXT PathContext = &CompoundPathEntry->PathContext; LONGLONG CurrentBaseOffset; PAGED_CODE(); // // Compute the starting base and starting path table offset. // CurrentBaseOffset = SectorTruncate( PathEntryOffset ); // // Map the next block in the Path Table. // CdMapPathTableBlock( IrpContext, IrpContext->Vcb->PathTableFcb, CurrentBaseOffset, PathContext ); // // Set up our current offset into the Path Context. // PathContext->DataOffset = PathEntryOffset - PathContext->BaseOffset; // // Update the in-memory structure for this path entry. // ( VOID ) CdUpdatePathEntryFromRawPathEntry( IrpContext, Ordinal, VerifyBounds, &CompoundPathEntry->PathContext, &CompoundPathEntry->PathEntry ); }
BOOLEAN CdLookupNextPathEntry ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PPATH_ENUM_CONTEXT PathContext, _Inout_ PPATH_ENTRY PathEntry ) /*++ Routine Description: This routine is called to move to the next path table entry. We know the offset and the length of the current entry. We start by computing the offset of the next entry and determine if it is contained in the table. Then we check to see if we need to move to the next sector in the path table. We always map two sectors at a time so we don't have to deal with any path entries which span sectors. We move to the next sector if we are in the second sector of the current mapped data block. We look up the next entry and update the path entry structure with the values out of the raw sector but don't update the CdName structure. Arguments: PathContext - Enumeration context for this scan of the path table. PathEntry - In-memory representation of the on-disk path table entry. Return Value: BOOLEAN - TRUE if another entry is found, FALSE otherwise. This routine may raise on error. --*/ { LONGLONG CurrentBaseOffset; PAGED_CODE(); // // Get the offset of the next path entry within the current // data block. // PathContext->DataOffset += PathEntry->PathEntryLength; // // If we are in the last data block then check if we are beyond the // end of the file. // if (PathContext->LastDataBlock) { if (PathContext->DataOffset >= PathContext->DataLength) { return FALSE; } // // If we are not in the last data block of the path table and // this offset is in the second sector then move to the next // data block. // } else if (PathContext->DataOffset >= SECTOR_SIZE) { CurrentBaseOffset = PathContext->BaseOffset + SECTOR_SIZE; CdMapPathTableBlock( IrpContext, IrpContext->Vcb->PathTableFcb, CurrentBaseOffset, PathContext ); // // Set up our current offset into the Path Context. // PathContext->DataOffset -= SECTOR_SIZE; } // // Now update the path entry with the values from the on-disk // structure. // return CdUpdatePathEntryFromRawPathEntry( IrpContext, PathEntry->Ordinal + 1, TRUE, PathContext, PathEntry ); } _Success_( return != FALSE) BOOLEAN CdFindPathEntry ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB ParentFcb, _In_ PCD_NAME DirName, _In_ BOOLEAN IgnoreCase, _Inout_ PCOMPOUND_PATH_ENTRY CompoundPathEntry ) /*++ Routine Description: This routine will walk through the path table looking for a matching entry for DirName among the child directories of the ParentFcb. Arguments: ParentFcb - This is the directory we are examining. We know the ordinal and path table offset for this directory in the path table. If this is the first scan for this Fcb we will update the first child offset for this directory in the path table. DirName - This is the name we are searching for. This name will not contain wildcard characters. The name will also not have a version string. IgnoreCase - Indicates if this search is exact or ignore case. CompoundPathEntry - Complete path table enumeration structure. We will have initialized it for the search on entry. This will be positioned at the matching name if found. Return Value: BOOLEAN - TRUE if matching entry found, FALSE otherwise. --*/ { BOOLEAN Found = FALSE; BOOLEAN UpdateChildOffset = TRUE; ULONG StartingOffset; ULONG StartingOrdinal; PAGED_CODE(); // // Position ourselves at either the first child or at the directory itself. // Lock the Fcb to get this value and remember whether to update with the first // child. // StartingOffset = CdQueryFidPathTableOffset( ParentFcb->FileId ); StartingOrdinal = ParentFcb->Ordinal; // // ISO 9660 9.4.4 restricts the backpointer from child to parent in a // pathtable entry to 16bits. Although we internally store ordinals // as 32bit values, it is impossible to search for the children of a // directory whose ordinal value is greater than MAXUSHORT. Media that // could induce such a search is illegal. // // Note that it is not illegal to have more than MAXUSHORT directories. // if (ParentFcb->Ordinal > MAXUSHORT) { CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR ); } CdLockFcb( IrpContext, ParentFcb ); if (ParentFcb->ChildPathTableOffset != 0) { StartingOffset = ParentFcb->ChildPathTableOffset; StartingOrdinal = ParentFcb->ChildOrdinal; UpdateChildOffset = FALSE; } else if (ParentFcb == ParentFcb->Vcb->RootIndexFcb) { UpdateChildOffset = FALSE; } CdUnlockFcb( IrpContext, ParentFcb ); CdLookupPathEntry( IrpContext, StartingOffset, StartingOrdinal, FALSE, CompoundPathEntry ); // // Loop until we find a match or are beyond the children for this directory. // do { // // If we are beyond this directory then return FALSE. // if (CompoundPathEntry->PathEntry.ParentOrdinal > ParentFcb->Ordinal) { // // Update the Fcb with the offsets for the children in the path table. // if (UpdateChildOffset) { CdLockFcb( IrpContext, ParentFcb ); ParentFcb->ChildPathTableOffset = StartingOffset; ParentFcb->ChildOrdinal = StartingOrdinal; CdUnlockFcb( IrpContext, ParentFcb ); } break ; } // // If we are within the children of this directory then check for a match. // if (CompoundPathEntry->PathEntry.ParentOrdinal == ParentFcb->Ordinal) { // // Update the child offset if not yet done. // if (UpdateChildOffset) { CdLockFcb( IrpContext, ParentFcb ); ParentFcb->ChildPathTableOffset = CompoundPathEntry->PathEntry.PathTableOffset; ParentFcb->ChildOrdinal = CompoundPathEntry->PathEntry.Ordinal; CdUnlockFcb( IrpContext, ParentFcb ); UpdateChildOffset = FALSE; } // // Update the name in the path entry. // CdUpdatePathEntryName( IrpContext, &CompoundPathEntry->PathEntry, IgnoreCase ); // // Now compare the names for an exact match. // if (CdIsNameInExpression( IrpContext, &CompoundPathEntry->PathEntry.CdCaseDirName, DirName, 0, FALSE )) { // // Let our caller know we have a match. // Found = TRUE; break ; } } // // Go to the next entry in the path table. Remember the current position // in the event we update the Fcb. // StartingOffset = CompoundPathEntry->PathEntry.PathTableOffset; StartingOrdinal = CompoundPathEntry->PathEntry.Ordinal; } while (CdLookupNextPathEntry( IrpContext, &CompoundPathEntry->PathContext, &CompoundPathEntry->PathEntry )); return Found; }
// // Local support routine // VOID CdMapPathTableBlock ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ LONGLONG BaseOffset, _Inout_ PPATH_ENUM_CONTEXT PathContext ) /*++ Routine Description: This routine is called to map (or allocate and copy) the next data block in the path table. We check if the next block will span a view boundary and allocate an auxilary buffer in that case. Arguments: Fcb - This is the Fcb for the Path Table. BaseOffset - Offset of the first sector to map. This will be on a sector boundary. PathContext - Enumeration context to update in this routine. Return Value: None. --*/ { ULONG CurrentLength; ULONG SectorSize; ULONG DataOffset; ULONG PassCount; PVOID Sector; PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); // // Map the new block and set the enumeration context to this // point. Allocate an auxilary buffer if necessary. // CurrentLength = 2 * SECTOR_SIZE; if (CurrentLength >= ( ULONG ) (Fcb->FileSize.QuadPart - BaseOffset)) { CurrentLength = ( ULONG ) (Fcb->FileSize.QuadPart - BaseOffset); // // We know this is the last data block for this // path table. // PathContext->LastDataBlock = TRUE; } // // Set context values. // PathContext->BaseOffset = ( ULONG ) BaseOffset; PathContext->DataLength = CurrentLength; // // Drop the previous sector's mapping // CdUnpinData( IrpContext, &PathContext->Bcb ); // // Check if spanning a view section. The following must // be true before we take this step. // // Data length is more than one sector. // Starting offset must be one sector before the // cache manager VACB boundary. // if ((CurrentLength > SECTOR_SIZE) && (FlagOn( (( ULONG ) BaseOffset), VACB_MAPPING_MASK ) == LAST_VACB_SECTOR_OFFSET )) { // // Map each sector individually and store into an auxilary // buffer. // SectorSize = SECTOR_SIZE; DataOffset = 0; PassCount = 2; PathContext->Data = FsRtlAllocatePoolWithTag( CdPagedPool, CurrentLength, TAG_SPANNING_PATH_TABLE ); PathContext->AllocatedData = TRUE; while (PassCount--) { CcMapData( Fcb->FileObject, (PLARGE_INTEGER) &BaseOffset, SectorSize, TRUE, &PathContext->Bcb, &Sector ); RtlCopyMemory( Add2Ptr( PathContext->Data, DataOffset, PVOID ), Sector, SectorSize ); CdUnpinData( IrpContext, &PathContext->Bcb ); BaseOffset += SECTOR_SIZE; SectorSize = CurrentLength - SECTOR_SIZE; DataOffset = SECTOR_SIZE; } // // Otherwise we can just map the data into the cache. // } else { // // There is a slight chance that we have allocated an // auxilary buffer on the previous sector. // if (PathContext->AllocatedData) { CdFreePool( &PathContext->Data ); PathContext->AllocatedData = FALSE; } CcMapData( Fcb->FileObject, (PLARGE_INTEGER) &BaseOffset, CurrentLength, TRUE, &PathContext->Bcb, &PathContext->Data ); } return ; }
// // Local support routine // _Success_( return != FALSE) BOOLEAN CdUpdatePathEntryFromRawPathEntry ( _In_ PIRP_CONTEXT IrpContext, _In_ ULONG Ordinal, _In_ BOOLEAN VerifyBounds, _In_ PPATH_ENUM_CONTEXT PathContext, _Out_ PPATH_ENTRY PathEntry ) /*++ Routine Description: This routine is called to update the in-memory Path Entry from the on-disk path entry. We also do a careful check of the bounds if requested and we are in the last data block of the path table. Arguments: Ordinal - Ordinal number for this directory. VerifyBounds - Check that the current raw Path Entry actually fits within the data block. PathContext - Current path table enumeration context. PathEntry - Pointer to the in-memory path entry structure. Return Value: TRUE if updated ok, FALSE if we've hit the end of the pathtable - zero name length && PT size is a multiple of blocksize. This is a workaround for some Video CDs. Win 9x works around this. This routine may raise. --*/ { PRAW_PATH_ENTRY RawPathEntry = CdRawPathEntry( IrpContext, PathContext ); ULONG RemainingDataLength; PAGED_CODE(); // // Check for a name length of zero. This is the first byte of the record, // and there must be at least one byte remaining in the buffer else we // wouldn't be here (caller would have spotted buffer end). // PathEntry->DirNameLen = CdRawPathIdLen( IrpContext, RawPathEntry ); if (0 == PathEntry->DirNameLen) { // // If we are in the last block, and the path table size (ie last block) is a // multiple of block size, then we will consider this the end of the path table // rather than raising an error. Workaround for NTI Cd Maker video CDs which // round path table length to blocksize multiple. In all other cases we consider // a zero length name to be corruption. // if ( PathContext->LastDataBlock && (0 == BlockOffset( IrpContext->Vcb, PathContext->DataLength))) { return FALSE; } CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR ); } // // Check if we should verify the path entry. If we are not in the last // data block then there is nothing to check. // if (PathContext->LastDataBlock && VerifyBounds) { // // Quick check to see if the maximum size is still available. This // will handle most cases and we don't need to access any of the // fields. // RemainingDataLength = PathContext->DataLength - PathContext->DataOffset; if (RemainingDataLength < sizeof ( RAW_PATH_ENTRY )) { // // Make sure the remaining bytes hold the path table entries. // Do the following checks. // // - A minimal path table entry will fit (and then check) // - This path table entry (with dir name) will fit. // if ((RemainingDataLength < MIN_RAW_PATH_ENTRY_LEN) || (RemainingDataLength < ( ULONG ) (CdRawPathIdLen( IrpContext, RawPathEntry ) + MIN_RAW_PATH_ENTRY_LEN - 1))) { CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR ); } } } // // The ordinal number of this directory is passed in. // Compute the path table offset of this entry. // PathEntry->Ordinal = Ordinal; PathEntry->PathTableOffset = PathContext->BaseOffset + PathContext->DataOffset; // // We know we can safely access all of the fields of the raw path table at // this point. // // Bias the disk offset by the number of logical blocks // CopyUchar4( &PathEntry->DiskOffset, CdRawPathLoc( IrpContext, RawPathEntry )); PathEntry->DiskOffset += CdRawPathXar( IrpContext, RawPathEntry ); CopyUchar2( &PathEntry->ParentOrdinal, &RawPathEntry->ParentNum ); PathEntry->PathEntryLength = PathEntry->DirNameLen + MIN_RAW_PATH_ENTRY_LEN - 1; // // Align the path entry length on a ushort boundary. // PathEntry->PathEntryLength = WordAlign( PathEntry->PathEntryLength ); PathEntry->DirName = ( PCHAR )RawPathEntry->DirId; return TRUE; }
// // Local support routine // VOID CdUpdatePathEntryName ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PPATH_ENTRY PathEntry, _In_ BOOLEAN IgnoreCase ) /*++ Routine Description: This routine will store the directory name into the CdName in the path entry. If this is a Joliet name then we will make sure we have an allocated buffer and need to convert from big endian to little endian. We also correctly update the case name. If this operation is ignore case then we need an auxilary buffer for the name. For an Ansi disk we can use the name from the disk for the exact case. We only need to allocate a buffer for the ignore case name. The on-disk representation of a Unicode name is useless for us. In this case we will need a name buffer for both names. We store a buffer in the PathEntry which can hold two 8.3 unicode names. This means we will almost never need to allocate a buffer in the Ansi case (we only need one buffer and already have 48 characters). Arguments: PathEntry - Pointer to a path entry structure. We have already updated this path entry with the values from the raw path entry. Return Value: None. --*/ { ULONG Length; NTSTATUS Status; PAGED_CODE(); // // Check if this is a self entry. We use a fixed string for this. // // Self-Entry - Length is 1, value is 0. // if ((*PathEntry->DirName == 0) && (PathEntry->DirNameLen == 1)) { // // There should be no allocated buffers. // NT_ASSERT( !FlagOn( PathEntry->Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER )); // // Now use one of the hard coded directory names. // PathEntry->CdDirName.FileName = CdUnicodeDirectoryNames[0]; // // Show that there is no version number. // PathEntry->CdDirName.VersionString.Length = 0; // // The case name is identical. // PathEntry->CdCaseDirName = PathEntry->CdDirName; // // Return now. // return ; } // // Compute how large a buffer we will need. If this is an ignore // case operation then we will want a double size buffer. If the disk is not // a Joliet disk then we might need two bytes for each byte in the name. // Length = PathEntry->DirNameLen; if (IgnoreCase) { Length *= 2; } if (!FlagOn( IrpContext->Vcb->VcbState, VCB_STATE_JOLIET )) { Length *= sizeof ( WCHAR ); } // // Now decide if we need to allocate a new buffer. We will if // this name won't fit in the embedded name buffer and it is // larger than the current allocated buffer. We always use the // allocated buffer if present. // // If we haven't allocated a buffer then use the embedded buffer if the data // will fit. This is the typical case. // if (!FlagOn( PathEntry->Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER ) && (Length <= sizeof ( PathEntry->NameBuffer ))) { PathEntry->CdDirName.FileName.MaximumLength = sizeof ( PathEntry->NameBuffer ); PathEntry->CdDirName.FileName.Buffer = PathEntry->NameBuffer; } else { // // We need to use an allocated buffer. Check if the current buffer // is large enough. // if (Length > PathEntry->CdDirName.FileName.MaximumLength) { // // Free any allocated buffer. // if (FlagOn( PathEntry->Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER )) { CdFreePool( &PathEntry->CdDirName.FileName.Buffer ); ClearFlag( PathEntry->Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER ); } PathEntry->CdDirName.FileName.Buffer = FsRtlAllocatePoolWithTag( CdPagedPool, Length, TAG_PATH_ENTRY_NAME ); SetFlag( PathEntry->Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER ); PathEntry->CdDirName.FileName.MaximumLength = ( USHORT ) Length; } } // // We now have a buffer for the name. We need to either convert the on-disk bigendian // to little endian or covert the name to Unicode. // if (!FlagOn( IrpContext->Vcb->VcbState, VCB_STATE_JOLIET )) { Status = RtlOemToUnicodeN( PathEntry->CdDirName.FileName.Buffer, PathEntry->CdDirName.FileName.MaximumLength, &Length, PathEntry->DirName, PathEntry->DirNameLen ); NT_ASSERT( Status == STATUS_SUCCESS ); __analysis_assert( Status == STATUS_SUCCESS ); PathEntry->CdDirName.FileName.Length = ( USHORT ) Length; } else { // // Convert this string to little endian. // CdConvertBigToLittleEndian( IrpContext, PathEntry->DirName, PathEntry->DirNameLen, ( PCHAR ) PathEntry->CdDirName.FileName.Buffer ); PathEntry->CdDirName.FileName.Length = ( USHORT ) PathEntry->DirNameLen; } // // There is no version string. // PathEntry->CdDirName.VersionString.Length = PathEntry->CdCaseDirName.VersionString.Length = 0; // // If the name string ends with a period then knock off the last // character. // if (PathEntry->CdDirName.FileName.Buffer[(PathEntry->CdDirName.FileName.Length - sizeof ( WCHAR )) / 2] == L '.' ) { // // Shrink the filename length. // PathEntry->CdDirName.FileName.Length -= sizeof ( WCHAR ); } // // Update the case name buffer if necessary. If this is an exact case // operation then just copy the exact case string. // if (IgnoreCase) { PathEntry->CdCaseDirName.FileName.Buffer = Add2Ptr( PathEntry->CdDirName.FileName.Buffer, PathEntry->CdDirName.FileName.MaximumLength / 2, PWCHAR ); PathEntry->CdCaseDirName.FileName.MaximumLength = PathEntry->CdDirName.FileName.MaximumLength / 2; CdUpcaseName( IrpContext, &PathEntry->CdDirName, &PathEntry->CdCaseDirName ); } else { PathEntry->CdCaseDirName = PathEntry->CdDirName; } return ; } |
Our Services
-
What our customers say about us?
Read our customer testimonials to find out why our clients keep returning for their projects.
View Testimonials