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

lfs.h

Go to the documentation of this file.
00001 /*++ BUILD Version: 0000 // Increment this if a change has global effects 00002 00003 Copyright (c) 1989 Microsoft Corporation 00004 00005 Module Name: 00006 00007 Lfs.h 00008 00009 Abstract: 00010 00011 This module contains the public data structures and procedure 00012 prototypes for the Log File Service. 00013 00014 Author: 00015 Brian Andrew [BrianAn] 20-June-1991 00016 00017 00018 Revision History: 00019 00020 --*/ 00021 00022 #ifndef _LFS_ 00023 #define _LFS_ 00024 00025 // 00026 // The Multi-Sector Header and Update Sequence Array provide detection of 00027 // incomplete multi-sector transfers for devices which either have a 00028 // physical sector size equal to the Sequence Number Stride or greater, or 00029 // which do not transfer sectors out of order. If a device exists which has 00030 // a sector size smaller than the Sequence Number Stride *and* it sometimes 00031 // transfers sectors out of order, then the Update Sequence Array will not 00032 // provide absolute detection of incomplete transfers. The Sequence Number 00033 // Stride is set to a small enough number to provide absolute protection for 00034 // all known hard disks. It is not set any smaller, in order to avoid 00035 // excessive run time and space overhead. 00036 // 00037 // The Multi-Sector Header contains space for a four-byte signature for the 00038 // convenience of its user. It then provides the offset to and length of the 00039 // the Update Sequence Array. The Update Sequence Array consists of an array 00040 // of n saved USHORTs, where n is the size of the structure being protected 00041 // divided by the sequence number stride. (The size of structure being 00042 // protected must be a nonzero power of 2 times the Sequence Number Stride, 00043 // and less than or equal to the physical page size of the machine.) The 00044 // first word of the Update Sequence Array contains the Update Sequence Number, 00045 // which is a cyclical counter (however 0 is not used) of the number of times 00046 // the containing structure has been written to disk. Following the Update 00047 // Sequence Number are the n saved USHORTs which were overwritten by the 00048 // Update Sequence Number the last time the containing structure was 00049 // written to disk. 00050 // 00051 // In detail, just prior to each time the protected structure is written to 00052 // disk, the last word in each Sequence Number Stride is saved to its 00053 // respective position in the Sequence Number Array, and then it is overwritten 00054 // with the next Update Sequence Number. Just after this write, or whenever 00055 // reading the structure, the saved word from the Sequence Number Array is 00056 // restored to its actual position in the structure. Before restoring the 00057 // saved words on reads, all of the sequence numbers at the end of each 00058 // stride are compared with the actual sequence number at the start of the 00059 // array. If any of these compares come up not equal, then a failed 00060 // multi-sector transfer has been detected. 00061 // 00062 // The size of the array is determined by the size of the containing structure. 00063 // As a C detail, the array is declared here with a size of 1, since its 00064 // actual size can only be determined at runtime. 00065 // 00066 // The Update Sequence Array should be included at the end of the header of 00067 // the structure it is protecting, since it is variable size. Its user must 00068 // insure that the correct size is reserved for it, namely: 00069 // 00070 // (sizeof-structure / SEQUENCE_NUMBER_STRIDE + 1) * sizeof(USHORT) 00071 // 00072 00073 #define SEQUENCE_NUMBER_STRIDE (512) 00074 00075 typedef USHORT UPDATE_SEQUENCE_NUMBER, *PUPDATE_SEQUENCE_NUMBER; 00076 00077 // 00078 // This structure must be allocated at the start of the structure being 00079 // protected. 00080 // 00081 00082 #if !defined( _AUTOCHECK_ ) 00083 00084 typedef struct _MULTI_SECTOR_HEADER { 00085 00086 // 00087 // Space for a four-character signature 00088 // 00089 00090 UCHAR Signature[4]; 00091 00092 // 00093 // Offset to Update Sequence Array, from start of structure. The Update 00094 // Sequence Array must end before the last USHORT in the first "sector" 00095 // of size SEQUENCE_NUMBER_STRIDE. (I.e., with the current constants, 00096 // the sum of the next two fields must be <= 510.) 00097 // 00098 00099 USHORT UpdateSequenceArrayOffset; 00100 00101 // 00102 // Size of Update Sequence Array (from above formula) 00103 // 00104 00105 USHORT UpdateSequenceArraySize; 00106 00107 } MULTI_SECTOR_HEADER, *PMULTI_SECTOR_HEADER; 00108 00109 #endif 00110 00111 // 00112 // This array must be present at the offset described above. 00113 // 00114 00115 typedef UPDATE_SEQUENCE_NUMBER UPDATE_SEQUENCE_ARRAY[1]; 00116 00117 typedef UPDATE_SEQUENCE_ARRAY *PUPDATE_SEQUENCE_ARRAY; 00118 00119 // 00120 // The following structure is allocated in the file system's Vcb and 00121 // its address is passed to Lfs during log file initialization. It 00122 // contains the offset of the current write as well as the system 00123 // page size being used by Lfs. 00124 // 00125 00126 typedef struct _LFS_WRITE_DATA { 00127 00128 LONGLONG FileOffset; 00129 ULONG Length; 00130 ULONG LfsStructureSize; 00131 PVOID Lfcb; 00132 00133 } LFS_WRITE_DATA, *PLFS_WRITE_DATA; 00134 00135 // 00136 // The following structure is used to identify a log record by a log 00137 // sequence number. 00138 // 00139 00140 typedef LARGE_INTEGER LSN, *PLSN; 00141 00142 // 00143 // The following Lsn will never occur in a file, it is used to indicate 00144 // a non-lsn. 00145 // 00146 00147 extern LSN LfsZeroLsn; 00148 00149 // 00150 // We set the default page size to 4K 00151 // 00152 00153 #define LFS_DEFAULT_LOG_PAGE_SIZE (0x1000) 00154 00155 // 00156 // The following type defines the different log record types. 00157 // 00158 00159 typedef enum _LFS_RECORD_TYPE { 00160 00161 LfsClientRecord = 1, 00162 LfsClientRestart 00163 00164 } LFS_RECORD_TYPE, *PLFS_RECORD_TYPE; 00165 00166 // 00167 // The following search modes are supported. 00168 // 00169 00170 typedef enum _LFS_CONTEXT_MODE { 00171 00172 LfsContextUndoNext = 1, 00173 LfsContextPrevious, 00174 LfsContextForward 00175 00176 } LFS_CONTEXT_MODE, *PLFS_CONTEXT_MODE; 00177 00178 typedef ULONG TRANSACTION_ID, *PTRANSACTION_ID; 00179 00180 typedef enum _TRANSACTION_STATE { 00181 00182 TransactionUninitialized = 0, 00183 TransactionActive, 00184 TransactionPrepared, 00185 TransactionCommitted 00186 00187 } TRANSACTION_STATE, *PTRANSACTION_STATE; 00188 00189 typedef enum _LFS_INFO { 00190 00191 LfsUseUsa = 1, 00192 LfsPackLog, 00193 LfsFixedPageSize 00194 00195 } LFS_INFO, *PLFS_INFO; 00196 00197 typedef PVOID LFS_LOG_HANDLE, *PLFS_LOG_HANDLE; 00198 00199 typedef PVOID LFS_LOG_CONTEXT, *PLFS_LOG_CONTEXT; 00200 00201 // 00202 // Write Entry for LfsWrite and LfsForceWrite. The interface to these 00203 // routines takes a pointer to a Write Entry along with a count of how 00204 // many Write Entries to expect to describe pieces of the caller's buffer 00205 // which are supposed to be copied in sequence to the log file. 00206 // 00207 00208 typedef struct _LFS_WRITE_ENTRY { 00209 00210 PVOID Buffer; 00211 ULONG ByteLength; 00212 00213 } LFS_WRITE_ENTRY, *PLFS_WRITE_ENTRY; 00214 00215 00216 // 00217 // Global Maintenance routines 00218 // 00219 00220 BOOLEAN 00221 LfsInitializeLogFileService ( 00222 ); 00223 00224 // 00225 // Log File Registration routines 00226 // 00227 00228 typedef struct _LOG_FILE_INFORMATION { 00229 00230 // 00231 // This is the total useable space in the log file after space for 00232 // headers and Lfs Restart Areas. 00233 // 00234 00235 LONGLONG TotalAvailable; 00236 00237 // 00238 // This is the useable space in the log file from the current position 00239 // in the log file to the lowest BaseLsn. This total as returned is not 00240 // yet reduced for undo commitments, returned separately below. 00241 // 00242 00243 LONGLONG CurrentAvailable; 00244 00245 // 00246 // This is the total undo commitment for all clients of the log file. 00247 // LfsWrite requests are refused when the sum of the write size of the 00248 // request plus the UndoRequirement for the request plus the TotalUndoCommitment 00249 // are greater than the CurrentAvailable. 00250 // 00251 00252 LONGLONG TotalUndoCommitment; 00253 00254 // 00255 // This is the total undo commitment for this client. 00256 // 00257 00258 LONGLONG ClientUndoCommitment; 00259 00260 // 00261 // Current system Lsn's. Includes the Oldest, LastFlushed and current 00262 // Lsn. 00263 // 00264 00265 LSN OldestLsn; 00266 LSN LastFlushedLsn; 00267 LSN LastLsn; 00268 00269 } LOG_FILE_INFORMATION, *PLOG_FILE_INFORMATION; 00270 00271 VOID 00272 LfsInitializeLogFile ( 00273 IN PFILE_OBJECT LogFile, 00274 IN USHORT MaximumClients, 00275 IN ULONG LogPageSize OPTIONAL, 00276 IN LONGLONG FileSize, 00277 OUT PLFS_WRITE_DATA WriteData 00278 ); 00279 00280 ULONG 00281 LfsOpenLogFile ( 00282 IN PFILE_OBJECT LogFile, 00283 IN UNICODE_STRING ClientName, 00284 IN USHORT MaximumClients, 00285 IN ULONG LogPageSize OPTIONAL, 00286 IN LONGLONG FileSize, 00287 IN OUT PLFS_INFO LfsInfo, 00288 OUT PLFS_LOG_HANDLE LogHandle, 00289 OUT PLFS_WRITE_DATA WriteData 00290 ); 00291 00292 VOID 00293 LfsCloseLogFile ( 00294 IN LFS_LOG_HANDLE LogHandle 00295 ); 00296 00297 VOID 00298 LfsDeleteLogHandle ( 00299 IN LFS_LOG_HANDLE LogHandle 00300 ); 00301 00302 VOID 00303 LfsReadLogFileInformation ( 00304 IN LFS_LOG_HANDLE LogHandle, 00305 IN PLOG_FILE_INFORMATION Buffer, 00306 IN OUT PULONG Length 00307 ); 00308 00309 BOOLEAN 00310 LfsVerifyLogFile ( 00311 IN LFS_LOG_HANDLE LogHandle, 00312 IN PVOID LogFileHeader, 00313 IN ULONG Length 00314 ); 00315 00316 // 00317 // Log File Client Restart routines 00318 // 00319 00320 NTSTATUS 00321 LfsReadRestartArea ( 00322 IN LFS_LOG_HANDLE LogHandle, 00323 IN OUT PULONG BufferLength, 00324 IN PVOID Buffer, 00325 OUT PLSN Lsn 00326 ); 00327 00328 VOID 00329 LfsWriteRestartArea ( 00330 IN LFS_LOG_HANDLE LogHandle, 00331 IN ULONG BufferLength, 00332 IN PVOID Buffer, 00333 OUT PLSN Lsn 00334 ); 00335 00336 VOID 00337 LfsSetBaseLsn ( 00338 IN LFS_LOG_HANDLE LogHandle, 00339 IN LSN BaseLsn 00340 ); 00341 00342 // 00343 // If ResetTotal is positive, then NumberRecords and ResetTotal set the absolute 00344 // values for the client. If ResetTotal is negative, then they are adjustments 00345 // to the totals for this client. 00346 // 00347 00348 VOID 00349 LfsResetUndoTotal ( 00350 IN LFS_LOG_HANDLE LogHandle, 00351 IN ULONG NumberRecords, 00352 IN LONG ResetTotal 00353 ); 00354 00355 // 00356 // Log File Write routines 00357 // 00358 00359 BOOLEAN 00360 LfsWrite ( 00361 IN LFS_LOG_HANDLE LogHandle, 00362 IN ULONG NumberOfWriteEntries, 00363 IN PLFS_WRITE_ENTRY WriteEntries, 00364 IN LFS_RECORD_TYPE RecordType, 00365 IN TRANSACTION_ID *TransactionId OPTIONAL, 00366 IN LSN UndoNextLsn, 00367 IN LSN PreviousLsn, 00368 IN LONG UndoRequirement, 00369 OUT PLSN Lsn 00370 ); 00371 00372 BOOLEAN 00373 LfsForceWrite ( 00374 IN LFS_LOG_HANDLE LogHandle, 00375 IN ULONG NumberOfWriteEntries, 00376 IN PLFS_WRITE_ENTRY WriteEntries, 00377 IN LFS_RECORD_TYPE RecordType, 00378 IN TRANSACTION_ID *TransactionId OPTIONAL, 00379 IN LSN UndoNextLsn, 00380 IN LSN PreviousLsn, 00381 IN LONG UndoRequirement, 00382 OUT PLSN Lsn 00383 ); 00384 00385 VOID 00386 LfsFlushToLsn ( 00387 IN LFS_LOG_HANDLE LogHandle, 00388 IN LSN Lsn 00389 ); 00390 00391 VOID 00392 LfsCheckWriteRange ( 00393 IN PLFS_WRITE_DATA WriteData, 00394 IN OUT PLONGLONG FlushOffset, 00395 IN OUT PULONG FlushLength 00396 ); 00397 00398 // 00399 // Log File Query Record routines 00400 // 00401 00402 VOID 00403 LfsReadLogRecord ( 00404 IN LFS_LOG_HANDLE LogHandle, 00405 IN LSN FirstLsn, 00406 IN LFS_CONTEXT_MODE ContextMode, 00407 OUT PLFS_LOG_CONTEXT Context, 00408 OUT PLFS_RECORD_TYPE RecordType, 00409 OUT TRANSACTION_ID *TransactionId, 00410 OUT PLSN UndoNextLsn, 00411 OUT PLSN PreviousLsn, 00412 OUT PULONG BufferLength, 00413 OUT PVOID *Buffer 00414 ); 00415 00416 BOOLEAN 00417 LfsReadNextLogRecord ( 00418 IN LFS_LOG_HANDLE LogHandle, 00419 IN OUT LFS_LOG_CONTEXT Context, 00420 OUT PLFS_RECORD_TYPE RecordType, 00421 OUT TRANSACTION_ID *TransactionId, 00422 OUT PLSN UndoNextLsn, 00423 OUT PLSN PreviousLsn, 00424 OUT PLSN Lsn, 00425 OUT PULONG BufferLength, 00426 OUT PVOID *Buffer 00427 ); 00428 00429 VOID 00430 LfsTerminateLogQuery ( 00431 IN LFS_LOG_HANDLE LogHandle, 00432 IN LFS_LOG_CONTEXT Context 00433 ); 00434 00435 LSN 00436 LfsQueryLastLsn ( 00437 IN LFS_LOG_HANDLE LogHandle 00438 ); 00439 00440 #endif // LFS 00441

Generated on Sat May 15 19:40:38 2004 for test by doxygen 1.3.7