Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

688 lines
20 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. hiveinit.c
  5. Abstract:
  6. Hive initialization code.
  7. Author:
  8. Bryan M. Willman (bryanwi) 12-Sep-91
  9. Environment:
  10. Revision History:
  11. Dragos C. Sambotin (dragoss) 25-Jan-99
  12. Implementation of bin-size chunk loading of hives.
  13. --*/
  14. #include "cmp.h"
  15. VOID
  16. HvpFillFileName(
  17. PHBASE_BLOCK BaseBlock,
  18. PUNICODE_STRING FileName
  19. );
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(PAGE,HvInitializeHive)
  22. #pragma alloc_text(PAGE,HvpFillFileName)
  23. #pragma alloc_text(PAGE,HvpFreeAllocatedBins)
  24. #endif
  25. // Dragos: Modified functions
  26. VOID
  27. HvpFreeAllocatedBins(
  28. PHHIVE Hive
  29. )
  30. /*++
  31. Routine Description:
  32. Free all the bins allocated for the specified hive.
  33. It applies only to stable storage. Not all bins are allocated.
  34. Those that are not allocated have BinAddress set to 0
  35. Arguments:
  36. Hive - supplies a pointer to hive control structure for hive who's bin to free.
  37. Return Value:
  38. NONE.
  39. --*/
  40. {
  41. ULONG Length;
  42. PHBIN Bin;
  43. ULONG MapSlots;
  44. ULONG Tables;
  45. PHMAP_ENTRY Me;
  46. PHMAP_TABLE Tab;
  47. ULONG i;
  48. ULONG j;
  49. //
  50. // calculate the number of tables in the map
  51. //
  52. Length = Hive->Storage[Stable].Length;
  53. MapSlots = Length / HBLOCK_SIZE;
  54. if( MapSlots > 0 ) {
  55. Tables = (MapSlots-1) / HTABLE_SLOTS;
  56. } else {
  57. Tables = 0;
  58. }
  59. if( Hive->Storage[Stable].Map ) {
  60. //
  61. // iterate through the directory
  62. //
  63. for (i = 0; i <= Tables; i++) {
  64. Tab = Hive->Storage[Stable].Map->Directory[i];
  65. ASSERT(Tab);
  66. //
  67. // iterate through the slots in the directory
  68. //
  69. for(j=0;j<HTABLE_SLOTS;j++) {
  70. Me = &(Tab->Table[j]);
  71. //
  72. // BinAddress non-zero means allocated bin
  73. //
  74. if( Me->BinAddress ) {
  75. //
  76. // a bin is freed if it is a new alloc AND it resides in paged pool
  77. //
  78. if( (Me->BinAddress & HMAP_NEWALLOC) && (Me->BinAddress & HMAP_INPAGEDPOOL) ) {
  79. Bin = (PHBIN)HBIN_BASE(Me->BinAddress);
  80. (Hive->Free)(Bin, HvpGetBinMemAlloc(Hive,Bin,Stable));
  81. }
  82. Me->BinAddress = 0;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. NTSTATUS
  89. HvInitializeHive(
  90. PHHIVE Hive,
  91. ULONG OperationType,
  92. ULONG HiveFlags,
  93. ULONG FileType,
  94. PVOID HiveData OPTIONAL,
  95. PALLOCATE_ROUTINE AllocateRoutine,
  96. PFREE_ROUTINE FreeRoutine,
  97. PFILE_SET_SIZE_ROUTINE FileSetSizeRoutine,
  98. PFILE_WRITE_ROUTINE FileWriteRoutine,
  99. PFILE_READ_ROUTINE FileReadRoutine,
  100. PFILE_FLUSH_ROUTINE FileFlushRoutine,
  101. ULONG Cluster,
  102. PUNICODE_STRING FileName OPTIONAL
  103. )
  104. /*++
  105. Routine Description:
  106. Initialize a hive.
  107. Core HHive fields are always inited.
  108. File calls WILL be made BEFORE this call returns.
  109. Caller is expected to create/open files and store file handles
  110. in a way that can be derived from the hive pointer.
  111. Three kinds of initialization can be done, selected by OperationType:
  112. HINIT_CREATE
  113. Create a new hive from scratch. Will have 0 storage.
  114. [Used to do things like create HARDWARE hive and for parts
  115. of SaveKey and RestoreKey]
  116. HINIT_MEMORY_INPLACE
  117. Build a hive control structure which allows read only
  118. access to a contiguous in-memory image of a hive.
  119. No part of the image will be copied, but a map will
  120. be made.
  121. [Used by osloader.]
  122. HINIT_FLAT
  123. Support very limited (read-only, no checking code) operation
  124. against a hive image.
  125. HINIT_MEMORY
  126. Create a new hive, using a hive image already in memory,
  127. at address supplied by pointer HiveData. The data will
  128. be copied. Caller is expected to free HiveData.
  129. [Used for SYSTEM hive]
  130. HINIT_FILE
  131. Create a hive, reading its data from a file. Recovery processing
  132. via log file will be done if a log is available. If a log
  133. is recovered, flush and clear operation will proceed.
  134. HINIT_MAPFILE
  135. Create a hive, reading its data from a file. Data reading is
  136. done by mapping views of the file in the system cache.
  137. NOTE: The HHive is not a completely opaque structure, because it
  138. is really only used by a limited set of code. Do not assume
  139. that only this routine sets all of these values.
  140. Arguments:
  141. Hive - supplies a pointer to hive control structure to be initialized
  142. to describe this hive.
  143. OperationType - specifies whether to create a new hive from scratch,
  144. from a memory image, or by reading a file from disk.
  145. HiveFlags - HIVE_VOLATILE - Entire hive is to be volatile, regardless
  146. of the types of cells allocated
  147. HIVE_NO_LAZY_FLUSH - Data in this hive is never written
  148. to disk except by an explicit FlushKey
  149. FileType - HFILE_TYPE_*, HFILE_TYPE_LOG set up for logging support respectively.
  150. HiveData - if present, supplies a pointer to an in memory image of
  151. from which to init the hive. Only useful when OperationType
  152. is set to HINIT_MEMORY.
  153. AllocateRoutine - supplies a pointer to routine called to allocate
  154. memory. WILL be called before this routine returns.
  155. FreeRoutine - supplies a pointer to routine called to free memory.
  156. CAN be called before this routine returns.
  157. FileSetSizeRoutine - supplies a pointer to a routine used to set the
  158. size of a file. CAN be called before this
  159. routine returns.
  160. FileWriteRoutine - supplies a pointer to routine called to write memory
  161. to a file.
  162. FileReadRoutine - supplies a pointer to routine called to read from
  163. a file into memory. CAN be called before this
  164. routine returns.
  165. FileFlushRoutine - supplies a pointer to routine called to flush a file.
  166. Cluster - clustering factor in HSECTOR_SIZE units. (i.e. Size of
  167. physical sector in media / HSECTOR_SIZE. 1 for 512 byte
  168. physical sectors (or smaller), 2 for 1024, 4 for 2048, etc.
  169. (Numbers greater than 8 won't work.)
  170. FileName - some path like "...\system32\config\system", last
  171. 32 or so characters will be copied into baseblock
  172. (and thus to disk) as a debugging aid. May be null.
  173. Return Value:
  174. NTSTATUS code.
  175. --*/
  176. {
  177. BOOLEAN UseForIo;
  178. PHBASE_BLOCK BaseBlock = NULL;
  179. NTSTATUS Status;
  180. ULONG i;
  181. ULONG Alignment;
  182. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_INIT,"HvInitializeHive:\n"));
  183. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_INIT,"\tHive=%p\n", Hive));
  184. //
  185. // reject invalid parameter combinations
  186. //
  187. if ( (! ARGUMENT_PRESENT(HiveData)) &&
  188. ((OperationType == HINIT_MEMORY) ||
  189. (OperationType == HINIT_FLAT) ||
  190. (OperationType == HINIT_MEMORY_INPLACE))
  191. )
  192. {
  193. return STATUS_INVALID_PARAMETER;
  194. }
  195. if ( ! ((OperationType == HINIT_CREATE) ||
  196. (OperationType == HINIT_MEMORY) ||
  197. (OperationType == HINIT_MEMORY_INPLACE) ||
  198. (OperationType == HINIT_FLAT) ||
  199. (OperationType == HINIT_FILE) ||
  200. (OperationType == HINIT_MAPFILE))
  201. )
  202. {
  203. return STATUS_INVALID_PARAMETER;
  204. }
  205. //
  206. // static and global control values
  207. //
  208. Hive->Signature = HHIVE_SIGNATURE;
  209. Hive->Allocate = AllocateRoutine;
  210. Hive->Free = FreeRoutine;
  211. Hive->FileSetSize = FileSetSizeRoutine;
  212. Hive->FileWrite = FileWriteRoutine;
  213. Hive->FileRead = FileReadRoutine;
  214. Hive->FileFlush = FileFlushRoutine;
  215. Hive->Log = (BOOLEAN)((FileType == HFILE_TYPE_LOG) ? TRUE : FALSE);
  216. if (Hive->Log && (HiveFlags & HIVE_VOLATILE)) {
  217. return STATUS_INVALID_PARAMETER;
  218. }
  219. Hive->HiveFlags = HiveFlags;
  220. if ((Cluster == 0) || (Cluster > HSECTOR_COUNT)) {
  221. return STATUS_INVALID_PARAMETER;
  222. }
  223. Hive->Cluster = Cluster;
  224. Hive->RefreshCount = 0;
  225. Hive->StorageTypeCount = HTYPE_COUNT;
  226. Hive->Storage[Volatile].Length = 0;
  227. #ifdef HV_TRACK_FREE_SPACE
  228. Hive->Storage[Volatile].FreeStorage = 0;
  229. #endif
  230. Hive->Storage[Volatile].Map = NULL;
  231. Hive->Storage[Volatile].SmallDir = NULL;
  232. Hive->Storage[Volatile].Guard = (ULONG)-1;
  233. Hive->Storage[Volatile].FreeSummary = 0;
  234. InitializeListHead(&Hive->Storage[Volatile].FreeBins);
  235. for (i = 0; i < HHIVE_FREE_DISPLAY_SIZE; i++) {
  236. RtlInitializeBitMap(&(Hive->Storage[Volatile].FreeDisplay[i]), NULL, 0);
  237. }
  238. Hive->Storage[Stable].Length = 0;
  239. #ifdef HV_TRACK_FREE_SPACE
  240. Hive->Storage[Stable].FreeStorage = 0;
  241. #endif
  242. Hive->Storage[Stable].Map = NULL;
  243. Hive->Storage[Stable].SmallDir = NULL;
  244. Hive->Storage[Stable].Guard = (ULONG)-1;
  245. Hive->Storage[Stable].FreeSummary = 0;
  246. InitializeListHead(&Hive->Storage[Stable].FreeBins);
  247. for (i = 0; i < HHIVE_FREE_DISPLAY_SIZE; i++) {
  248. RtlInitializeBitMap(&(Hive->Storage[Stable].FreeDisplay[i]), NULL, 0);
  249. }
  250. RtlInitializeBitMap(&(Hive->DirtyVector), NULL, 0);
  251. Hive->DirtyCount = 0;
  252. Hive->DirtyAlloc = 0;
  253. Hive->LogSize = 0;
  254. Hive->GetCellRoutine = HvpGetCellPaged;
  255. Hive->ReleaseCellRoutine = NULL;
  256. Hive->Flat = FALSE;
  257. Hive->ReadOnly = FALSE;
  258. UseForIo = (BOOLEAN)!(Hive->HiveFlags & HIVE_VOLATILE);
  259. //
  260. // new create case
  261. //
  262. if (OperationType == HINIT_CREATE) {
  263. BaseBlock = (PHBASE_BLOCK)((Hive->Allocate)(sizeof(HBASE_BLOCK), UseForIo,CM_FIND_LEAK_TAG11));
  264. if (BaseBlock == NULL) {
  265. return STATUS_INSUFFICIENT_RESOURCES;
  266. }
  267. //
  268. // Make sure the buffer we got back is cluster-aligned. If not, try
  269. // harder to get an aligned buffer.
  270. //
  271. Alignment = Cluster * HSECTOR_SIZE - 1;
  272. if (((ULONG_PTR)BaseBlock & Alignment) != 0) {
  273. (Hive->Free)(BaseBlock, sizeof(HBASE_BLOCK));
  274. BaseBlock = (PHBASE_BLOCK)((Hive->Allocate)(PAGE_SIZE, TRUE,CM_FIND_LEAK_TAG12));
  275. if (BaseBlock == NULL) {
  276. return STATUS_INSUFFICIENT_RESOURCES;
  277. }
  278. //
  279. // Return the quota for the extra allocation, as we are not really using
  280. // it and it will not be accounted for later when we free it.
  281. //
  282. CmpReleaseGlobalQuota(PAGE_SIZE - sizeof(HBASE_BLOCK));
  283. }
  284. BaseBlock->Signature = HBASE_BLOCK_SIGNATURE;
  285. BaseBlock->Sequence1 = 1;
  286. BaseBlock->Sequence2 = 1;
  287. BaseBlock->TimeStamp.HighPart = 0;
  288. BaseBlock->TimeStamp.LowPart = 0;
  289. BaseBlock->Major = HSYS_MAJOR;
  290. BaseBlock->Minor = HSYS_MINOR;
  291. BaseBlock->Type = HFILE_TYPE_PRIMARY;
  292. BaseBlock->Format = HBASE_FORMAT_MEMORY;
  293. BaseBlock->RootCell = HCELL_NIL;
  294. BaseBlock->Length = 0;
  295. BaseBlock->Cluster = Cluster;
  296. BaseBlock->CheckSum = 0;
  297. HvpFillFileName(BaseBlock, FileName);
  298. Hive->BaseBlock = BaseBlock;
  299. Hive->Version = HSYS_MINOR;
  300. Hive->BaseBlock->BootType = 0;
  301. return STATUS_SUCCESS;
  302. }
  303. //
  304. // flat image case
  305. //
  306. if (OperationType == HINIT_FLAT) {
  307. Hive->BaseBlock = (PHBASE_BLOCK)HiveData;
  308. Hive->Version = Hive->BaseBlock->Minor;
  309. Hive->Flat = TRUE;
  310. Hive->ReadOnly = TRUE;
  311. Hive->GetCellRoutine = HvpGetCellFlat;
  312. Hive->Storage[Stable].Length = Hive->BaseBlock->Length;
  313. Hive->StorageTypeCount = 1;
  314. Hive->BaseBlock->BootType = 0;
  315. // don't init this as we don't need it!!!
  316. //Status = HvpAdjustHiveFreeDisplay(Hive,Hive->Storage[Stable].Length,Stable);
  317. return STATUS_SUCCESS;
  318. }
  319. //
  320. // readonly image case
  321. //
  322. if (OperationType == HINIT_MEMORY_INPLACE) {
  323. BaseBlock = (PHBASE_BLOCK)HiveData;
  324. if ( (BaseBlock->Signature != HBASE_BLOCK_SIGNATURE) ||
  325. (BaseBlock->Type != HFILE_TYPE_PRIMARY) ||
  326. (BaseBlock->Major != HSYS_MAJOR) ||
  327. (BaseBlock->Minor > HSYS_MINOR_SUPPORTED) ||
  328. (BaseBlock->Format != HBASE_FORMAT_MEMORY) ||
  329. (BaseBlock->Sequence1 != BaseBlock->Sequence2) ||
  330. (HvpHeaderCheckSum(BaseBlock) !=
  331. (BaseBlock->CheckSum))
  332. )
  333. {
  334. return STATUS_REGISTRY_CORRUPT;
  335. }
  336. Hive->BaseBlock = BaseBlock;
  337. Hive->Version = BaseBlock->Minor;
  338. Hive->ReadOnly = TRUE;
  339. Hive->StorageTypeCount = 1;
  340. Hive->BaseBlock->BootType = 0;
  341. Status = HvpAdjustHiveFreeDisplay(Hive,BaseBlock->Length,Stable);
  342. if( !NT_SUCCESS(Status) ) {
  343. return Status;
  344. }
  345. if ( !NT_SUCCESS(HvpBuildMap(
  346. Hive,
  347. (PUCHAR)HiveData + HBLOCK_SIZE
  348. )))
  349. {
  350. return STATUS_REGISTRY_CORRUPT;
  351. }
  352. return(STATUS_SUCCESS);
  353. }
  354. //
  355. // memory copy case
  356. //
  357. if (OperationType == HINIT_MEMORY) {
  358. BaseBlock = (PHBASE_BLOCK)HiveData;
  359. if ( (BaseBlock->Signature != HBASE_BLOCK_SIGNATURE) ||
  360. (BaseBlock->Type != HFILE_TYPE_PRIMARY) ||
  361. (BaseBlock->Format != HBASE_FORMAT_MEMORY) ||
  362. (BaseBlock->Major != HSYS_MAJOR) ||
  363. (BaseBlock->Minor > HSYS_MINOR_SUPPORTED) ||
  364. (HvpHeaderCheckSum(BaseBlock) !=
  365. (BaseBlock->CheckSum))
  366. )
  367. {
  368. return STATUS_REGISTRY_CORRUPT;
  369. }
  370. Hive->BaseBlock = (PHBASE_BLOCK)((Hive->Allocate)(sizeof(HBASE_BLOCK), UseForIo,CM_FIND_LEAK_TAG13));
  371. if (Hive->BaseBlock==NULL) {
  372. return(STATUS_INSUFFICIENT_RESOURCES);
  373. }
  374. //
  375. // Make sure the buffer we got back is cluster-aligned. If not, try
  376. // harder to get an aligned buffer.
  377. //
  378. Alignment = Cluster * HSECTOR_SIZE - 1;
  379. if (((ULONG_PTR)Hive->BaseBlock & Alignment) != 0) {
  380. (Hive->Free)(Hive->BaseBlock, sizeof(HBASE_BLOCK));
  381. Hive->BaseBlock = (PHBASE_BLOCK)((Hive->Allocate)(PAGE_SIZE, TRUE,CM_FIND_LEAK_TAG14));
  382. if (Hive->BaseBlock == NULL) {
  383. return (STATUS_INSUFFICIENT_RESOURCES);
  384. }
  385. }
  386. RtlCopyMemory(Hive->BaseBlock, BaseBlock, HSECTOR_SIZE);
  387. Hive->BaseBlock->BootRecover = BaseBlock->BootRecover;
  388. Hive->BaseBlock->BootType = BaseBlock->BootType;
  389. Hive->Version = Hive->BaseBlock->Minor;
  390. Status = HvpAdjustHiveFreeDisplay(Hive,BaseBlock->Length,Stable);
  391. if( !NT_SUCCESS(Status) ) {
  392. (Hive->Free)(Hive->BaseBlock, sizeof(HBASE_BLOCK));
  393. Hive->BaseBlock = NULL;
  394. return Status;
  395. }
  396. if ( !NT_SUCCESS(HvpBuildMapAndCopy(Hive,
  397. (PUCHAR)HiveData + HBLOCK_SIZE))) {
  398. (Hive->Free)(Hive->BaseBlock, sizeof(HBASE_BLOCK));
  399. Hive->BaseBlock = NULL;
  400. return STATUS_REGISTRY_CORRUPT;
  401. }
  402. HvpFillFileName(Hive->BaseBlock, FileName);
  403. return(STATUS_SUCCESS);
  404. }
  405. #ifndef CM_ENABLE_MAPPED_VIEWS
  406. if( OperationType == HINIT_MAPFILE ) {
  407. OperationType = HINIT_FILE;
  408. }
  409. #endif //CM_ENABLE_MAPPED_VIEWS
  410. //
  411. // file read case
  412. //
  413. if (OperationType == HINIT_FILE) {
  414. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_BIN_MAP,"HvInitializeHive(%wZ,HINIT_FILE) :\n", FileName));
  415. //
  416. // get the file image (possible recovered via log) into memory
  417. //
  418. Status = HvLoadHive(Hive);
  419. if ((Status != STATUS_SUCCESS) && (Status != STATUS_REGISTRY_RECOVERED)) {
  420. return Status;
  421. }
  422. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_BIN_MAP,"\n"));
  423. if (Status == STATUS_REGISTRY_RECOVERED) {
  424. //
  425. // We have a good hive, with a log, and a dirty map,
  426. // all set up. Only problem is that we need to flush
  427. // the file so the log can be cleared and new writes
  428. // posted against the hive. Since we know we have
  429. // a good log in hand, we just write the hive image.
  430. //
  431. if ( ! HvpDoWriteHive(Hive, HFILE_TYPE_PRIMARY)) {
  432. //
  433. // DRAGOS: Here we need cleanup
  434. // Clean up the bins already allocated
  435. //
  436. HvpFreeAllocatedBins( Hive );
  437. return STATUS_REGISTRY_IO_FAILED;
  438. }
  439. //
  440. // If we get here, we have recovered the hive, and
  441. // written it out to disk correctly. So we clear
  442. // the log here.
  443. //
  444. RtlClearAllBits(&(Hive->DirtyVector));
  445. Hive->DirtyCount = 0;
  446. (Hive->FileSetSize)(Hive, HFILE_TYPE_LOG, 0,0);
  447. Hive->LogSize = 0;
  448. }
  449. //
  450. // slam debug name data into base block
  451. //
  452. HvpFillFileName(Hive->BaseBlock, FileName);
  453. return STATUS_SUCCESS;
  454. }
  455. //
  456. // file map case
  457. //
  458. if (OperationType == HINIT_MAPFILE) {
  459. Hive->GetCellRoutine = HvpGetCellMapped;
  460. Hive->ReleaseCellRoutine = HvpReleaseCellMapped;
  461. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_BIN_MAP,"HvInitializeHive(%wZ,HINIT_MAPFILE) :\n", FileName));
  462. Status = HvMapHive(Hive);
  463. if ((Status != STATUS_SUCCESS) && (Status != STATUS_REGISTRY_RECOVERED)) {
  464. return Status;
  465. }
  466. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_BIN_MAP,"\n"));
  467. if (Status == STATUS_REGISTRY_RECOVERED) {
  468. //
  469. // We have a good hive, with a log, and a dirty map,
  470. // all set up. Only problem is that we need to flush
  471. // the file so the log can be cleared and new writes
  472. // posted against the hive. Since we know we have
  473. // a good log in hand, we just write the hive image.
  474. //
  475. if ( ! HvpDoWriteHive(Hive, HFILE_TYPE_PRIMARY)) {
  476. //
  477. // DRAGOS: Here we need cleanup
  478. // Clean up the bins already allocated
  479. //
  480. HvpFreeAllocatedBins( Hive );
  481. return STATUS_REGISTRY_IO_FAILED;
  482. }
  483. //
  484. // If we get here, we have recovered the hive, and
  485. // written it out to disk correctly. So we clear
  486. // the log here.
  487. //
  488. RtlClearAllBits(&(Hive->DirtyVector));
  489. Hive->DirtyCount = 0;
  490. (Hive->FileSetSize)(Hive, HFILE_TYPE_LOG, 0,0);
  491. Hive->LogSize = 0;
  492. }
  493. //
  494. // slam debug name data into base block
  495. //
  496. HvpFillFileName(Hive->BaseBlock, FileName);
  497. return STATUS_SUCCESS;
  498. }
  499. return STATUS_INVALID_PARAMETER;
  500. }
  501. VOID
  502. HvpFillFileName(
  503. PHBASE_BLOCK BaseBlock,
  504. PUNICODE_STRING FileName
  505. )
  506. /*++
  507. Routine Description:
  508. Zero out the filename portion of the base block.
  509. If FileName is not NULL, copy last 64 bytes into name tail
  510. field of base block
  511. Arguments:
  512. BaseBlock - supplies pointer to a base block
  513. FileName - supplies pointer to a unicode STRING
  514. Return Value:
  515. None.
  516. --*/
  517. {
  518. ULONG offset;
  519. ULONG length;
  520. PUCHAR sptr;
  521. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_HIVE,"HvpFillFileName: %wZ\n", FileName));
  522. RtlZeroMemory((PVOID)&(BaseBlock->FileName[0]), HBASE_NAME_ALLOC);
  523. if (FileName == NULL) {
  524. return;
  525. }
  526. //
  527. // Account for 0 at the end, so we have nice debug spews
  528. //
  529. if (FileName->Length < HBASE_NAME_ALLOC) {
  530. offset = 0;
  531. length = FileName->Length;
  532. } else {
  533. offset = FileName->Length - HBASE_NAME_ALLOC + sizeof(WCHAR);
  534. length = HBASE_NAME_ALLOC - sizeof(WCHAR);
  535. }
  536. sptr = (PUCHAR)&(FileName->Buffer[0]);
  537. RtlCopyMemory(
  538. (PVOID)&(BaseBlock->FileName[0]),
  539. (PVOID)&(sptr[offset]),
  540. length
  541. );
  542. }