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 LfsDisk.h 00008 00009 Abstract: 00010 00011 This module defines the on-disk structures present in the log file. 00012 00013 Author: 00014 00015 Brian Andrew [BrianAn] 13-June-1991 00016 00017 Revision History: 00018 00019 IMPORTANT NOTE: 00020 00021 The Log File Service will by used on systems that require that on-disk 00022 structures guarantee the natural alignment of all arithmetic quantities 00023 up to and including quad-word (64-bit) numbers. Therefore, all Lfs 00024 on-disk structures are quad-word aligned, etc. 00025 00026 --*/ 00027 00028 #ifndef _LFSDISK_ 00029 #define _LFSDISK_ 00030 00031 #define MINIMUM_LFS_PAGES 0x00000030 00032 #define MINIMUM_LFS_CLIENTS 1 00033 00034 // 00035 // The following macros are used to set and query with respect to the 00036 // update sequence arrays. 00037 // 00038 00039 #define UpdateSequenceStructureSize( MSH ) \ 00040 ((((PMULTI_SECTOR_HEADER) (MSH))->UpdateSequenceArraySize - 1) * SEQUENCE_NUMBER_STRIDE) 00041 00042 #define UpdateSequenceArraySize( STRUCT_SIZE ) \ 00043 ((STRUCT_SIZE) / SEQUENCE_NUMBER_STRIDE + 1) 00044 00045 #define FIRST_STRIDE \ 00046 (SEQUENCE_NUMBER_STRIDE - sizeof( UPDATE_SEQUENCE_NUMBER )) 00047 00048 00049 // 00050 // Log client ID. This is used to uniquely identify a client for a 00051 // particular log file. 00052 // 00053 00054 typedef struct _LFS_CLIENT_ID { 00055 00056 USHORT SeqNumber; 00057 USHORT ClientIndex; 00058 00059 } LFS_CLIENT_ID, *PLFS_CLIENT_ID; 00060 00061 00062 // 00063 // Log Record Header. This is the header that begins every Log Record in 00064 // the log file. 00065 // 00066 00067 typedef struct _LFS_RECORD_HEADER { 00068 00069 // 00070 // Log File Sequence Number of this log record. 00071 // 00072 00073 LSN ThisLsn; 00074 00075 // 00076 // The following fields are used to back link Lsn's. The ClientPrevious 00077 // and ClientUndoNextLsn fields are used by a client to link his log 00078 // records. 00079 // 00080 00081 LSN ClientPreviousLsn; 00082 LSN ClientUndoNextLsn; 00083 00084 // 00085 // The following field is the size of data area for this record. The 00086 // log record header will be padded if necessary to fill to a 64-bit 00087 // boundary, so the client data will begin on a 64-bit boundary to 00088 // insure that all of his data is 64-bit aligned. The below value 00089 // has not been padded to 64 bits however. 00090 // 00091 00092 ULONG ClientDataLength; 00093 00094 // 00095 // Client ID. This identifies the owner of this log record. The owner 00096 // is uniquely identified by his offset in the client array and the 00097 // sequence number associated with that client record. 00098 // 00099 00100 LFS_CLIENT_ID ClientId; 00101 00102 // 00103 // This the Log Record type. This could be a commit protocol record, 00104 // a client restart area or a client update record. 00105 // 00106 00107 LFS_RECORD_TYPE RecordType; 00108 00109 // 00110 // Transaction ID. This is used externally by a client (Transaction 00111 // Manager) to group log file entries. 00112 // 00113 00114 TRANSACTION_ID TransactionId; 00115 00116 // 00117 // Log record flags. 00118 // 00119 00120 USHORT Flags; 00121 00122 // 00123 // Alignment field. 00124 // 00125 00126 USHORT AlignWord; 00127 00128 } LFS_RECORD_HEADER, *PLFS_RECORD_HEADER; 00129 00130 #define LOG_RECORD_MULTI_PAGE (0x0001) 00131 00132 #define LFS_RECORD_HEADER_SIZE QuadAlign( sizeof( LFS_RECORD_HEADER )) 00133 00134 00135 // 00136 // Following are the version specific fields in the record page header. 00137 // 00138 00139 typedef struct _LFS_UNPACKED_RECORD_PAGE { 00140 00141 // 00142 // This gives us the offset of the free space in the page. 00143 // 00144 00145 USHORT NextRecordOffset; 00146 00147 USHORT WordAlign; 00148 00149 // 00150 // Reserved. The following array is reserved for possible future use. 00151 // 00152 00153 USHORT Reserved; 00154 00155 // 00156 // Update Sequence Array. Used to protect the page block. 00157 // 00158 00159 UPDATE_SEQUENCE_ARRAY UpdateSequenceArray; 00160 00161 } LFS_UNPACKED_RECORD_PAGE, *PLFS_UNPACKED_RECORD_PAGE; 00162 00163 typedef struct _LFS_PACKED_RECORD_PAGE { 00164 00165 // 00166 // This gives us the offset of the free space in the page. 00167 // 00168 00169 USHORT NextRecordOffset; 00170 00171 USHORT WordAlign; 00172 00173 ULONG DWordAlign; 00174 00175 // 00176 // The following is the Lsn for the last log record which ends on the page. 00177 // 00178 00179 LSN LastEndLsn; 00180 00181 // 00182 // Update Sequence Array. Used to protect the page block. 00183 // 00184 00185 UPDATE_SEQUENCE_ARRAY UpdateSequenceArray; 00186 00187 } LFS_PACKED_RECORD_PAGE, *PLFS_PACKED_RECORD_PAGE; 00188 00189 00190 // 00191 // Log Record Page Header. This structure is present at the beginning of each 00192 // log file page in the client record section. 00193 // 00194 00195 typedef struct _LFS_RECORD_PAGE_HEADER { 00196 00197 // 00198 // Cache multisector protection header. 00199 // 00200 00201 MULTI_SECTOR_HEADER MultiSectorHeader; 00202 00203 union { 00204 00205 // 00206 // Highest Lsn in this log file page. This field is only for 00207 // regular log pages. 00208 // 00209 00210 LSN LastLsn; 00211 00212 // 00213 // Log file offset. This is for the tail copies and indicates the 00214 // location in the file where the original lays. In this case the 00215 // LastLsn field above can be obtained from the last ending Lsn 00216 // field in the PACKED_RECORD_PAGE structure. 00217 // 00218 00219 LONGLONG FileOffset; 00220 00221 } Copy; 00222 00223 // 00224 // Page Header Flags. These are the same flags that are stored in the 00225 // Lbcb->Flags field. 00226 // 00227 // LOG_PAGE_LOG_RECORD_END - Page contains the end of a log record 00228 // 00229 00230 ULONG Flags; 00231 00232 // 00233 // I/O Page Position. The following fields are used to determine 00234 // where this log page resides within a Lfs I/O transfer. 00235 // 00236 00237 USHORT PageCount; 00238 USHORT PagePosition; 00239 00240 // 00241 // The following is the difference between version 1.1 and earlier. 00242 // 00243 00244 union { 00245 00246 LFS_UNPACKED_RECORD_PAGE Unpacked; 00247 LFS_PACKED_RECORD_PAGE Packed; 00248 00249 } Header; 00250 00251 } LFS_RECORD_PAGE_HEADER, *PLFS_RECORD_PAGE_HEADER; 00252 00253 #define LOG_PAGE_LOG_RECORD_END (0x00000001) 00254 00255 #define LFS_UNPACKED_RECORD_PAGE_HEADER_SIZE ( \ 00256 FIELD_OFFSET( LFS_RECORD_PAGE_HEADER, Header.Unpacked.UpdateSequenceArray ) \ 00257 ) 00258 00259 #define LFS_PACKED_RECORD_PAGE_HEADER_SIZE ( \ 00260 FIELD_OFFSET( LFS_RECORD_PAGE_HEADER, Header.Packed.UpdateSequenceArray ) \ 00261 ) 00262 00263 00264 // 00265 // Log Restart Page Header. This structure is at the head of the restart 00266 // areas in a log file. 00267 // 00268 00269 typedef struct _LFS_RESTART_PAGE_HEADER { 00270 00271 // 00272 // Cache multisector protection header. 00273 // 00274 00275 MULTI_SECTOR_HEADER MultiSectorHeader; 00276 00277 // 00278 // This is the last Lsn found by checkdisk for this volume. 00279 // 00280 00281 LSN ChkDskLsn; 00282 00283 // 00284 // System page size. This is the page size of the system which 00285 // initialized the log file. Unless the log file has been gracefully 00286 // shutdown (there are no clients with restart areas), it is a fatal 00287 // error to attempt to write to a log file on a system with a differen 00288 // page size. 00289 // 00290 00291 ULONG SystemPageSize; 00292 00293 // 00294 // Log Page Size. This is the log page size used for this log file. 00295 // The entire Lfs restart area must fit on a single log page. 00296 // 00297 00298 ULONG LogPageSize; 00299 00300 // 00301 // Lfs restart area offset. This is the offset from the start of this 00302 // structure to the Lfs restart area. 00303 // 00304 00305 USHORT RestartOffset; 00306 00307 // 00308 // The indicates major and minor versions. Note that the pre-release versions 00309 // have -1 in both positions. Major version 0 indicates the transition 00310 // from Beta to USA support. 00311 // 00312 // Major Version 00313 // 00314 // -1 Beta Version 00315 // 0 Transition 00316 // 1 Update sequence support. 00317 // 00318 00319 SHORT MinorVersion; 00320 SHORT MajorVersion; 00321 00322 // 00323 // Update Sequence Array. Used to protect the page block. 00324 // 00325 00326 UPDATE_SEQUENCE_ARRAY UpdateSequenceArray; 00327 00328 } LFS_RESTART_PAGE_HEADER, *PLFS_RESTART_PAGE_HEADER; 00329 00330 #define LFS_RESTART_PAGE_HEADER_SIZE ( \ 00331 FIELD_OFFSET( LFS_RESTART_PAGE_HEADER, UpdateSequenceArray ) \ 00332 ) 00333 00334 // 00335 // Id strings for the page headers. 00336 // 00337 00338 #define LFS_SIGNATURE_RESTART_PAGE "RSTR" 00339 #define LFS_SIGNATURE_RESTART_PAGE_ULONG 0x52545352 00340 #define LFS_SIGNATURE_RECORD_PAGE "RCRD" 00341 #define LFS_SIGNATURE_RECORD_PAGE_ULONG 0x44524352 00342 #define LFS_SIGNATURE_BAD_USA "BAAD" 00343 #define LFS_SIGNATURE_BAD_USA_ULONG 0x44414142 00344 #define LFS_SIGNATURE_MODIFIED "CHKD" 00345 #define LFS_SIGNATURE_MODIFIED_ULONG 0x444b4843 00346 #define LFS_SIGNATURE_UNINITIALIZED "\377\377\377\377" 00347 #define LFS_SIGNATURE_UNINITIALIZED_ULONG 0xffffffff 00348 00349 00350 // 00351 // Log Client Record. A log client record exists for each client user of 00352 // the log file. One of these is in each Lfs restart area. 00353 // 00354 00355 #define LFS_NO_CLIENT 0xffff 00356 #define LFS_CLIENT_NAME_MAX 64 00357 00358 typedef struct _LFS_CLIENT_RECORD { 00359 00360 // 00361 // Oldest Lsn. This is the oldest Lsn that this client requires to 00362 // be in the log file. 00363 // 00364 00365 LSN OldestLsn; 00366 00367 // 00368 // Client Restart Lsn. This is the Lsn of the latest client restart 00369 // area written to the disk. A reserved Lsn will indicate that no 00370 // restart area exists for this client. 00371 // 00372 00373 LSN ClientRestartLsn; 00374 00375 // 00376 // 00377 // Previous/Next client area. These are the indexes into an array of 00378 // Log Client Records for the previous and next client records. 00379 // 00380 00381 USHORT PrevClient; 00382 USHORT NextClient; 00383 00384 // 00385 // Sequence Number. Incremented whenever this record is reused. This 00386 // will happen whenever a client opens (reopens) the log file and has 00387 // no current restart area. 00388 00389 USHORT SeqNumber; 00390 00391 // 00392 // Alignment field. 00393 // 00394 00395 USHORT AlignWord; 00396 00397 // 00398 // Align the entire record. 00399 // 00400 00401 ULONG AlignDWord; 00402 00403 // 00404 // The following fields are used to describe the client name. A client 00405 // name consists of at most 32 Unicode character (64 bytes). The Log 00406 // file service will treat client names as case sensitive. 00407 // 00408 00409 ULONG ClientNameLength; 00410 00411 WCHAR ClientName[LFS_CLIENT_NAME_MAX]; 00412 00413 } LFS_CLIENT_RECORD, *PLFS_CLIENT_RECORD; 00414 00415 00416 // 00417 // Lfs Restart Area. Two copies of these will exist at the beginning of the 00418 // log file. 00419 // 00420 00421 typedef struct _LFS_RESTART_AREA { 00422 00423 // 00424 // Current Lsn. This is periodic snapshot of the current logical end of 00425 // log file to facilitate restart. 00426 // 00427 00428 LSN CurrentLsn; 00429 00430 // 00431 // Number of Clients. This is the maximum number of clients supported 00432 // for this log file. 00433 // 00434 00435 USHORT LogClients; 00436 00437 // 00438 // The following are indexes into the client record arrays. The client 00439 // records are linked into two lists. A free list of client records and 00440 // an in-use list of records. 00441 // 00442 00443 USHORT ClientFreeList; 00444 USHORT ClientInUseList; 00445 00446 // 00447 // Flag field. 00448 // 00449 // RESTART_SINGLE_PAGE_IO All log pages written 1 by 1 00450 // 00451 00452 USHORT Flags; 00453 00454 // 00455 // The following is the number of bits to use for the sequence number. 00456 // 00457 00458 ULONG SeqNumberBits; 00459 00460 // 00461 // Length of this restart area. 00462 // 00463 00464 USHORT RestartAreaLength; 00465 00466 // 00467 // Offset from the start of this structure to the client array. 00468 // Ignored in versions prior to 1.1 00469 // 00470 00471 USHORT ClientArrayOffset; 00472 00473 // 00474 // Usable log file size. We will stop sharing the value in the page header. 00475 // 00476 00477 LONGLONG FileSize; 00478 00479 // 00480 // DataLength of last Lsn. This doesn't include the length of 00481 // the Lfs header. 00482 // 00483 00484 ULONG LastLsnDataLength; 00485 00486 // 00487 // The following apply to log pages. This is the log page data offset and 00488 // the length of the log record header. Ignored in versions prior to 1.1 00489 // 00490 00491 USHORT RecordHeaderLength; 00492 USHORT LogPageDataOffset; 00493 00494 // 00495 // Log file open count. Used to determine if there has been a change to the disk. 00496 // 00497 00498 ULONG RestartOpenLogCount; 00499 00500 // 00501 // Keep this structure quadword aligned. 00502 // 00503 00504 ULONG AlignDWord; 00505 00506 // 00507 // Client data. 00508 // 00509 00510 LFS_CLIENT_RECORD LogClientArray[1]; 00511 00512 } LFS_RESTART_AREA, *PLFS_RESTART_AREA; 00513 00514 #define RESTART_SINGLE_PAGE_IO (0x0001) 00515 00516 #define LFS_RESTART_AREA_SIZE (FIELD_OFFSET( LFS_RESTART_AREA, LogClientArray )) 00517 00518 // 00519 // Remember the old size of the restart area when accessing older disks. 00520 // 00521 00522 typedef struct _LFS_OLD_RESTART_AREA { 00523 00524 // 00525 // Current Lsn. This is periodic snapshot of the current logical end of 00526 // log file to facilitate restart. 00527 // 00528 00529 LSN CurrentLsn; 00530 00531 // 00532 // Number of Clients. This is the maximum number of clients supported 00533 // for this log file. 00534 // 00535 00536 USHORT LogClients; 00537 00538 // 00539 // The following are indexes into the client record arrays. The client 00540 // records are linked into two lists. A free list of client records and 00541 // an in-use list of records. 00542 // 00543 00544 USHORT ClientFreeList; 00545 USHORT ClientInUseList; 00546 00547 // 00548 // Flag field. 00549 // 00550 // RESTART_SINGLE_PAGE_IO All log pages written 1 by 1 00551 // 00552 00553 USHORT Flags; 00554 00555 // 00556 // The following is the number of bits to use for the sequence number. 00557 // 00558 00559 ULONG SeqNumberBits; 00560 00561 // 00562 // Length of this restart area. 00563 // 00564 00565 USHORT RestartAreaLength; 00566 00567 // 00568 // Offset from the start of this structure to the client array. 00569 // Ignored in versions prior to 1.1 00570 // 00571 00572 USHORT ClientArrayOffset; 00573 00574 // 00575 // Usable log file size. We will stop sharing the value in the page header. 00576 // 00577 00578 LONGLONG FileSize; 00579 00580 // 00581 // DataLength of last Lsn. This doesn't include the length of 00582 // the Lfs header. 00583 // 00584 00585 ULONG LastLsnDataLength; 00586 00587 // 00588 // The following apply to log pages. This is the log page data offset and 00589 // the length of the log record header. Ignored in versions prior to 1.1 00590 // 00591 00592 USHORT RecordHeaderLength; 00593 USHORT LogPageDataOffset; 00594 00595 // 00596 // Client data. 00597 // 00598 00599 LFS_CLIENT_RECORD LogClientArray[1]; 00600 00601 } LFS_OLD_RESTART_AREA, *PLFS_OLD_RESTART_AREA; 00602 #endif // _LFSDISK_