Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

lsnsup.c File Reference

#include "lfsprocs.h"

Go to the source code of this file.

Defines

#define Dbg   (DEBUG_TRACE_LSN_SUP)

Functions

VOID LfsLsnFinalOffset (IN PLFCB Lfcb, IN LSN Lsn, IN ULONG DataLength, OUT PLONGLONG FinalOffset)
BOOLEAN LfsFindNextLsn (IN PLFCB Lfcb, IN PLFS_RECORD_HEADER RecordHeader, OUT PLSN Lsn)


Define Documentation

#define Dbg   (DEBUG_TRACE_LSN_SUP)
 

Definition at line 27 of file lsnsup.c.


Function Documentation

BOOLEAN LfsFindNextLsn IN PLFCB  Lfcb,
IN PLFS_RECORD_HEADER  RecordHeader,
OUT PLSN  Lsn
 

Definition at line 148 of file lsnsup.c.

References CcUnpinData(), Dbg, DebugTrace, DebugUnwind, FALSE, LfsFileOffsetToLsn, LfsFindNextLsn(), LfsIsLsnInFile, LfsLsnFinalOffset(), LfsLsnToFileOffset, LfsLsnToSeqNumber, LfsNextLogPageOffset(), LfsPinOrMapData(), LfsTruncateOffsetToLogPage, LiQuadAlign, NULL, PAGED_CODE, and TRUE.

Referenced by LfsFindNextLsn(), and LfsSearchForwardByClient().

00156 : 00157 00158 This routine takes as a starting point the log record header of an 00159 Lsn in the log file. It searches for the next Lsn in the file and 00160 returns that value in the 'Lsn' argument. The boolean return value 00161 indicates whether there is another Lsn in the file. 00162 00163 Arguments: 00164 00165 Lfcb - This is the file control block for the log file. 00166 00167 RecordHeader - This is the log record for the Lsn starting point. 00168 00169 Lsn - This supplies the address to store the next Lsn, if found. 00170 00171 Return Value: 00172 00173 BOOLEAN - Indicates whether the next Lsn was found. 00174 00175 --*/ 00176 00177 { 00178 BOOLEAN FoundNextLsn; 00179 00180 LONGLONG LsnOffset; 00181 LONGLONG EndOfLogRecord; 00182 LONGLONG LogHeaderOffset; 00183 00184 LONGLONG SequenceNumber; 00185 00186 PLFS_RECORD_PAGE_HEADER LogRecordPage; 00187 PBCB LogRecordPageBcb; 00188 BOOLEAN UsaError; 00189 00190 PAGED_CODE(); 00191 00192 DebugTrace( +1, Dbg, "LfsFindNextLsn: Entered\n", 0 ); 00193 DebugTrace( 0, Dbg, "Lfcb -> %08lx\n", Lfcb ); 00194 DebugTrace( 0, Dbg, "Record Header -> %08lx\n", RecordHeader ); 00195 00196 LogRecordPageBcb = NULL; 00197 FoundNextLsn = FALSE; 00198 00199 // 00200 // Use a try-finally to facilitate cleanup. 00201 // 00202 00203 try { 00204 00205 // 00206 // Find the file offset of the log page which contains the end 00207 // of the log record for this Lsn. 00208 // 00209 00210 LsnOffset = LfsLsnToFileOffset( Lfcb, RecordHeader->ThisLsn ); 00211 00212 LfsLsnFinalOffset( Lfcb, 00213 RecordHeader->ThisLsn, 00214 RecordHeader->ClientDataLength, 00215 &EndOfLogRecord ); 00216 00217 LfsTruncateOffsetToLogPage( Lfcb, EndOfLogRecord, &LogHeaderOffset ); 00218 00219 // 00220 // Remember the sequence number for this page. 00221 // 00222 00223 SequenceNumber = LfsLsnToSeqNumber( Lfcb, RecordHeader->ThisLsn ); 00224 00225 // 00226 // Remember if we wrapped. 00227 // 00228 00229 if ( EndOfLogRecord <= LsnOffset ) { //**** xxLeq( EndOfLogRecord, LsnOffset ) 00230 00231 SequenceNumber = SequenceNumber + 1; //**** xxAdd( SequenceNumber, LfsLi1 ); 00232 } 00233 00234 // 00235 // Pin the log page header for this page. 00236 // 00237 00238 LfsPinOrMapData( Lfcb, 00239 LogHeaderOffset, 00240 (ULONG)Lfcb->LogPageSize, 00241 FALSE, 00242 FALSE, 00243 FALSE, 00244 &UsaError, 00245 (PVOID *)&LogRecordPage, 00246 &LogRecordPageBcb ); 00247 00248 // 00249 // If the Lsn we were given was not the last Lsn on this page, then 00250 // the starting offset for the next Lsn is on a quad word boundary 00251 // following the last file offset for the current Lsn. Otherwise 00252 // the file offset is the start of the data on the next page. 00253 // 00254 00255 if ( RecordHeader->ThisLsn.QuadPart == LogRecordPage->Copy.LastLsn.QuadPart ) { //**** xxEql( RecordHeader->ThisLsn, LogRecordPage->Copy.LastLsn ) 00256 00257 BOOLEAN Wrapped; 00258 00259 LfsNextLogPageOffset( Lfcb, 00260 LogHeaderOffset, 00261 &LogHeaderOffset, 00262 &Wrapped ); 00263 00264 LsnOffset = LogHeaderOffset + Lfcb->LogPageDataOffset; //**** xxAdd( LogHeaderOffset, Lfcb->LogPageDataOffset ); 00265 00266 // 00267 // If we wrapped, we need to increment the sequence number. 00268 // 00269 00270 if (Wrapped) { 00271 00272 SequenceNumber = SequenceNumber + 1; //**** xxAdd( SequenceNumber, LfsLi1 ); 00273 } 00274 00275 } else { 00276 00277 LiQuadAlign( EndOfLogRecord, &LsnOffset ); 00278 } 00279 00280 // 00281 // Compute the Lsn based on the file offset and the sequence count. 00282 // 00283 00284 Lsn->QuadPart = LfsFileOffsetToLsn( Lfcb, LsnOffset, SequenceNumber ); 00285 00286 // 00287 // If this Lsn is within the legal range for the file, we return TRUE. 00288 // Otherwise FALSE indicates that there are no more Lsn's. 00289 // 00290 00291 if (LfsIsLsnInFile( Lfcb, *Lsn )) { 00292 00293 FoundNextLsn = TRUE; 00294 } 00295 00296 } finally { 00297 00298 DebugUnwind( LfsFindNextLsn ); 00299 00300 // 00301 // Unpin the log page header if held. 00302 // 00303 00304 if (LogRecordPageBcb != NULL) { 00305 00306 CcUnpinData( LogRecordPageBcb ); 00307 } 00308 00309 DebugTrace( 0, Dbg, "Lsn (Low) -> %08lx\n", Lsn->LowPart ); 00310 DebugTrace( 0, Dbg, "Lsn (High) -> %08lx\n", Lsn->HighPart ); 00311 DebugTrace( -1, Dbg, "LfsFindNextLsn: Exit -> %08x\n", FoundNextLsn ); 00312 } 00313 00314 return FoundNextLsn; 00315 }

VOID LfsLsnFinalOffset IN PLFCB  Lfcb,
IN LSN  Lsn,
IN ULONG  DataLength,
OUT PLONGLONG  FinalOffset
 

Definition at line 36 of file lsnsup.c.

References Dbg, DebugTrace, LfsLsnToPageOffset, LfsNextLogPageOffset(), LfsTruncateLsnToLogPage, PAGED_CODE, and TRUE.

Referenced by LfsFindNextLsn(), and LfsUpdateLfcbFromRestart().

00045 : 00046 00047 This routine will compute the final offset of the last byte of the log 00048 record. It does this by computing how many bytes are on the current 00049 page and then computing how many more pages will be needed. 00050 00051 Arguments: 00052 00053 Lfcb - This is the file control block for the log file. 00054 00055 Lsn - This is the log record being considered. 00056 00057 DataLength - This is the length of the data for this log record. We will add the 00058 header length here. 00059 00060 FinalOffset - Address to store the result. 00061 00062 Return Value: 00063 00064 None. 00065 00066 --*/ 00067 00068 { 00069 ULONG RemainingPageBytes; 00070 ULONG PageOffset; 00071 00072 PAGED_CODE(); 00073 00074 DebugTrace( +1, Dbg, "LfsLsnFinalOffset: Entered\n", 0 ); 00075 DebugTrace( 0, Dbg, "Lfcb -> %08lx\n", Lfcb ); 00076 DebugTrace( 0, Dbg, "Lsn (Low) -> %08lx\n", Lsn.LowPart ); 00077 DebugTrace( 0, Dbg, "Lsn (High) -> %08lx\n", Lsn.HighPart ); 00078 DebugTrace( 0, Dbg, "DataLength -> %08lx\n", DataLength ); 00079 00080 // 00081 // We compute the starting log page file offset, the number of bytes 00082 // remaining in the current log page and the position on this page 00083 // before any data bytes. 00084 // 00085 00086 LfsTruncateLsnToLogPage( Lfcb, Lsn, FinalOffset ); 00087 00088 PageOffset = LfsLsnToPageOffset( Lfcb, Lsn ); 00089 00090 RemainingPageBytes = (ULONG)Lfcb->LogPageSize - PageOffset; 00091 00092 PageOffset -= 1; 00093 00094 // 00095 // Add the length of the header. 00096 // 00097 00098 DataLength += Lfcb->RecordHeaderLength; 00099 00100 // 00101 // If this Lsn is contained in this log page we are done. 00102 // Otherwise we need to walk through several log pages. 00103 // 00104 00105 if (DataLength > RemainingPageBytes) { 00106 00107 DataLength -= RemainingPageBytes; 00108 00109 RemainingPageBytes = (ULONG)Lfcb->LogPageDataSize; 00110 00111 PageOffset = (ULONG)Lfcb->LogPageDataOffset - 1; 00112 00113 while (TRUE) { 00114 00115 BOOLEAN Wrapped; 00116 00117 LfsNextLogPageOffset( Lfcb, *FinalOffset, FinalOffset, &Wrapped ); 00118 00119 // 00120 // We are done if the remaining bytes fit on this page. 00121 // 00122 00123 if (DataLength <= RemainingPageBytes) { 00124 00125 break; 00126 } 00127 00128 DataLength -= RemainingPageBytes; 00129 } 00130 } 00131 00132 // 00133 // We add the remaining bytes to our starting position on this page 00134 // and then add that value to the file offset of this log page. 00135 // 00136 00137 *(PULONG)FinalOffset += (DataLength + PageOffset); 00138 00139 DebugTrace( 0, Dbg, "FinalOffset (Low) -> %08lx\n", LogPageFileOffset.LowPart ); 00140 DebugTrace( 0, Dbg, "FinalOffset (High) -> %08lx\n", LogPageFileOffset.HighPart ); 00141 DebugTrace( -1, Dbg, "LfsLsnFinalOffset: Exit\n", 0 ); 00142 00143 return; 00144 }


Generated on Sat May 15 19:44:34 2004 for test by doxygen 1.3.7