Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenhivewrt.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: registry manipulation library 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org> 00005 * Copyright 2001 - 2005 Eric Kohl 00006 */ 00007 00008 #include "cmlib.h" 00009 #define NDEBUG 00010 #include <debug.h> 00011 00012 static BOOLEAN CMAPI 00013 HvpWriteLog( 00014 PHHIVE RegistryHive) 00015 { 00016 ULONG FileOffset; 00017 ULONG BufferSize; 00018 ULONG BitmapSize; 00019 PUCHAR Buffer; 00020 PUCHAR Ptr; 00021 ULONG BlockIndex; 00022 ULONG LastIndex; 00023 PVOID BlockPtr; 00024 BOOLEAN Success; 00025 00026 UNIMPLEMENTED; 00027 return TRUE; 00028 00029 ASSERT(RegistryHive->ReadOnly == FALSE); 00030 00031 DPRINT("HvpWriteLog called\n"); 00032 00033 if (RegistryHive->BaseBlock->Sequence1 != 00034 RegistryHive->BaseBlock->Sequence2) 00035 { 00036 return FALSE; 00037 } 00038 00039 BitmapSize = RegistryHive->DirtyVector.SizeOfBitMap; 00040 BufferSize = HV_LOG_HEADER_SIZE + sizeof(ULONG) + BitmapSize; 00041 BufferSize = ROUND_UP(BufferSize, HV_BLOCK_SIZE); 00042 00043 DPRINT("Bitmap size %lu buffer size: %lu\n", BitmapSize, BufferSize); 00044 00045 Buffer = RegistryHive->Allocate(BufferSize, TRUE, TAG_CM); 00046 if (Buffer == NULL) 00047 { 00048 return FALSE; 00049 } 00050 00051 /* Update first update counter and CheckSum */ 00052 RegistryHive->BaseBlock->Type = HFILE_TYPE_LOG; 00053 RegistryHive->BaseBlock->Sequence1++; 00054 RegistryHive->BaseBlock->CheckSum = 00055 HvpHiveHeaderChecksum(RegistryHive->BaseBlock); 00056 00057 /* Copy hive header */ 00058 RtlCopyMemory(Buffer, RegistryHive->BaseBlock, HV_LOG_HEADER_SIZE); 00059 Ptr = Buffer + HV_LOG_HEADER_SIZE; 00060 RtlCopyMemory(Ptr, "DIRT", 4); 00061 Ptr += 4; 00062 RtlCopyMemory(Ptr, RegistryHive->DirtyVector.Buffer, BitmapSize); 00063 00064 /* Write hive block and block bitmap */ 00065 FileOffset = 0; 00066 Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_LOG, 00067 &FileOffset, Buffer, BufferSize); 00068 RegistryHive->Free(Buffer, 0); 00069 00070 if (!Success) 00071 { 00072 return FALSE; 00073 } 00074 00075 /* Write dirty blocks */ 00076 FileOffset = BufferSize; 00077 BlockIndex = 0; 00078 while (BlockIndex < RegistryHive->Storage[Stable].Length) 00079 { 00080 LastIndex = BlockIndex; 00081 BlockIndex = RtlFindSetBits(&RegistryHive->DirtyVector, 1, BlockIndex); 00082 if (BlockIndex == ~0U || BlockIndex < LastIndex) 00083 { 00084 break; 00085 } 00086 00087 BlockPtr = (PVOID)RegistryHive->Storage[Stable].BlockList[BlockIndex].BlockAddress; 00088 00089 /* Write hive block */ 00090 Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_LOG, 00091 &FileOffset, BlockPtr, 00092 HV_BLOCK_SIZE); 00093 if (!Success) 00094 { 00095 return FALSE; 00096 } 00097 00098 BlockIndex++; 00099 FileOffset += HV_BLOCK_SIZE; 00100 } 00101 00102 Success = RegistryHive->FileSetSize(RegistryHive, HFILE_TYPE_LOG, FileOffset, FileOffset); 00103 if (!Success) 00104 { 00105 DPRINT("FileSetSize failed\n"); 00106 return FALSE; 00107 } 00108 00109 /* Flush the log file */ 00110 Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_LOG, NULL, 0); 00111 if (!Success) 00112 { 00113 DPRINT("FileFlush failed\n"); 00114 } 00115 00116 /* Update first and second update counter and CheckSum. */ 00117 RegistryHive->BaseBlock->Sequence2++; 00118 RegistryHive->BaseBlock->CheckSum = 00119 HvpHiveHeaderChecksum(RegistryHive->BaseBlock); 00120 00121 /* Write hive header again with updated sequence counter. */ 00122 FileOffset = 0; 00123 Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_LOG, 00124 &FileOffset, RegistryHive->BaseBlock, 00125 HV_LOG_HEADER_SIZE); 00126 if (!Success) 00127 { 00128 return FALSE; 00129 } 00130 00131 /* Flush the log file */ 00132 Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_LOG, NULL, 0); 00133 if (!Success) 00134 { 00135 DPRINT("FileFlush failed\n"); 00136 } 00137 00138 return TRUE; 00139 } 00140 00141 static BOOLEAN CMAPI 00142 HvpWriteHive( 00143 PHHIVE RegistryHive, 00144 BOOLEAN OnlyDirty) 00145 { 00146 ULONG FileOffset; 00147 ULONG BlockIndex; 00148 ULONG LastIndex; 00149 PVOID BlockPtr; 00150 BOOLEAN Success; 00151 00152 ASSERT(RegistryHive->ReadOnly == FALSE); 00153 00154 DPRINT("HvpWriteHive called\n"); 00155 00156 if (RegistryHive->BaseBlock->Sequence1 != 00157 RegistryHive->BaseBlock->Sequence2) 00158 { 00159 return FALSE; 00160 } 00161 00162 /* Update first update counter and CheckSum */ 00163 RegistryHive->BaseBlock->Type = HFILE_TYPE_PRIMARY; 00164 RegistryHive->BaseBlock->Sequence1++; 00165 RegistryHive->BaseBlock->CheckSum = 00166 HvpHiveHeaderChecksum(RegistryHive->BaseBlock); 00167 00168 /* Write hive block */ 00169 FileOffset = 0; 00170 Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_PRIMARY, 00171 &FileOffset, RegistryHive->BaseBlock, 00172 sizeof(HBASE_BLOCK)); 00173 if (!Success) 00174 { 00175 return FALSE; 00176 } 00177 00178 BlockIndex = 0; 00179 while (BlockIndex < RegistryHive->Storage[Stable].Length) 00180 { 00181 if (OnlyDirty) 00182 { 00183 LastIndex = BlockIndex; 00184 BlockIndex = RtlFindSetBits(&RegistryHive->DirtyVector, 1, BlockIndex); 00185 if (BlockIndex == ~0U || BlockIndex < LastIndex) 00186 { 00187 break; 00188 } 00189 } 00190 00191 BlockPtr = (PVOID)RegistryHive->Storage[Stable].BlockList[BlockIndex].BlockAddress; 00192 FileOffset = (BlockIndex + 1) * HV_BLOCK_SIZE; 00193 00194 /* Write hive block */ 00195 Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_PRIMARY, 00196 &FileOffset, BlockPtr, 00197 HV_BLOCK_SIZE); 00198 if (!Success) 00199 { 00200 return FALSE; 00201 } 00202 00203 BlockIndex++; 00204 } 00205 00206 Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_PRIMARY, NULL, 0); 00207 if (!Success) 00208 { 00209 DPRINT("FileFlush failed\n"); 00210 } 00211 00212 /* Update second update counter and CheckSum */ 00213 RegistryHive->BaseBlock->Sequence2++; 00214 RegistryHive->BaseBlock->CheckSum = 00215 HvpHiveHeaderChecksum(RegistryHive->BaseBlock); 00216 00217 /* Write hive block */ 00218 FileOffset = 0; 00219 Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_PRIMARY, 00220 &FileOffset, RegistryHive->BaseBlock, 00221 sizeof(HBASE_BLOCK)); 00222 if (!Success) 00223 { 00224 return FALSE; 00225 } 00226 00227 Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_PRIMARY, NULL, 0); 00228 if (!Success) 00229 { 00230 DPRINT("FileFlush failed\n"); 00231 } 00232 00233 return TRUE; 00234 } 00235 00236 BOOLEAN CMAPI 00237 HvSyncHive( 00238 PHHIVE RegistryHive) 00239 { 00240 ASSERT(RegistryHive->ReadOnly == FALSE); 00241 00242 if (RtlFindSetBits(&RegistryHive->DirtyVector, 1, 0) == ~0U) 00243 { 00244 return TRUE; 00245 } 00246 00247 /* Update hive header modification time */ 00248 KeQuerySystemTime(&RegistryHive->BaseBlock->TimeStamp); 00249 00250 /* Update log file */ 00251 if (!HvpWriteLog(RegistryHive)) 00252 { 00253 return FALSE; 00254 } 00255 00256 /* Update hive file */ 00257 if (!HvpWriteHive(RegistryHive, TRUE)) 00258 { 00259 return FALSE; 00260 } 00261 00262 /* Clear dirty bitmap. */ 00263 RtlClearAllBits(&RegistryHive->DirtyVector); 00264 00265 return TRUE; 00266 } 00267 00268 BOOLEAN 00269 CMAPI 00270 HvHiveWillShrink(IN PHHIVE RegistryHive) 00271 { 00272 /* No shrinking yet */ 00273 return FALSE; 00274 } 00275 00276 BOOLEAN CMAPI 00277 HvWriteHive( 00278 PHHIVE RegistryHive) 00279 { 00280 ASSERT(RegistryHive->ReadOnly == FALSE); 00281 00282 /* Update hive header modification time */ 00283 KeQuerySystemTime(&RegistryHive->BaseBlock->TimeStamp); 00284 00285 /* Update hive file */ 00286 if (!HvpWriteHive(RegistryHive, FALSE)) 00287 { 00288 return FALSE; 00289 } 00290 00291 return TRUE; 00292 } Generated on Sun May 27 2012 04:35:57 for ReactOS by
1.7.6.1
|