^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * logfile.h - Defines for NTFS kernel journal ($LogFile) handling. Part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * the Linux-NTFS project.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2000-2005 Anton Altaparmakov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _LINUX_NTFS_LOGFILE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _LINUX_NTFS_LOGFILE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifdef NTFS_RW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "endian.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "layout.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Journal ($LogFile) organization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Two restart areas present in the first two pages (restart pages, one restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * area in each page). When the volume is dismounted they should be identical,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * except for the update sequence array which usually has a different update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * sequence number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * These are followed by log records organized in pages headed by a log record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * header going up to log file size. Not all pages contain log records when a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * volume is first formatted, but as the volume ages, all records will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * When the log file fills up, the records at the beginning are purged (by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * modifying the oldest_lsn to a higher value presumably) and writing begins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * at the beginning of the file. Effectively, the log file is viewed as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * circular entity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * NOTE: Windows NT, 2000, and XP all use log file version 1.1 but they accept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * versions <= 1.x, including 0.-1. (Yes, that is a minus one in there!) We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * probably only want to support 1.1 as this seems to be the current version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * and we don't know how that differs from the older versions. The only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * exception is if the journal is clean as marked by the two restart pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * then it doesn't matter whether we are on an earlier version. We can just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * reinitialize the logfile and start again with version 1.1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Some $LogFile related constants. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define MaxLogFileSize 0x100000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define DefaultLogPageSize 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define MinLogRecordPages 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Log file restart page header (begins the restart area).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /*Ofs*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* 0*/ NTFS_RECORD_TYPE magic; /* The magic is "RSTR". */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* 4*/ le16 usa_ofs; /* See NTFS_RECORD definition in layout.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) When creating, set this to be immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) after this header structure (without any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) alignment). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* 6*/ le16 usa_count; /* See NTFS_RECORD definition in layout.h. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* 8*/ leLSN chkdsk_lsn; /* The last log file sequence number found by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) chkdsk. Only used when the magic is changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) to "CHKD". Otherwise this is zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* 16*/ le32 system_page_size; /* Byte size of system pages when the log file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) was created, has to be >= 512 and a power of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 2. Use this to calculate the required size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) of the usa (usa_count) and add it to usa_ofs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) Then verify that the result is less than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) value of the restart_area_offset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* 20*/ le32 log_page_size; /* Byte size of log file pages, has to be >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 512 and a power of 2. The default is 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) and is used when the system page size is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) between 4096 and 8192. Otherwise this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) set to the system page size instead. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* 24*/ le16 restart_area_offset;/* Byte offset from the start of this header to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) the RESTART_AREA. Value has to be aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) to 8-byte boundary. When creating, set this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) to be after the usa. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* 26*/ sle16 minor_ver; /* Log file minor version. Only check if major
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) version is 1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* 28*/ sle16 major_ver; /* Log file major version. We only support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) version 1.1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* sizeof() = 30 (0x1e) bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) } __attribute__ ((__packed__)) RESTART_PAGE_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Constant for the log client indices meaning that there are no client records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * in this particular client array. Also inside the client records themselves,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * this means that there are no client records preceding or following this one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define LOGFILE_NO_CLIENT cpu_to_le16(0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define LOGFILE_NO_CLIENT_CPU 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * These are the so far known RESTART_AREA_* flags (16-bit) which contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * information about the log file in which they are present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) RESTART_VOLUME_IS_CLEAN = cpu_to_le16(0x0002),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) RESTART_SPACE_FILLER = cpu_to_le16(0xffff), /* gcc: Force enum bit width to 16. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) } __attribute__ ((__packed__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) typedef le16 RESTART_AREA_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Log file restart area record. The offset of this record is found by adding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * the offset of the RESTART_PAGE_HEADER to the restart_area_offset value found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * in it. See notes at restart_area_offset above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*Ofs*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* 0*/ leLSN current_lsn; /* The current, i.e. last LSN inside the log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) when the restart area was last written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) This happens often but what is the interval?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) Is it just fixed time or is it every time a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) check point is written or somethine else?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) On create set to 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* 8*/ le16 log_clients; /* Number of log client records in the array of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) log client records which follows this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) restart area. Must be 1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* 10*/ le16 client_free_list; /* The index of the first free log client record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) in the array of log client records.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) LOGFILE_NO_CLIENT means that there are no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) free log client records in the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) If != LOGFILE_NO_CLIENT, check that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) log_clients > client_free_list. On Win2k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) and presumably earlier, on a clean volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) this is != LOGFILE_NO_CLIENT, and it should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) be 0, i.e. the first (and only) client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) record is free and thus the logfile is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) closed and hence clean. A dirty volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) would have left the logfile open and hence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) this would be LOGFILE_NO_CLIENT. On WinXP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) and presumably later, the logfile is always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) open, even on clean shutdown so this should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) always be LOGFILE_NO_CLIENT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* 12*/ le16 client_in_use_list;/* The index of the first in-use log client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) record in the array of log client records.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) LOGFILE_NO_CLIENT means that there are no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) in-use log client records in the array. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) != LOGFILE_NO_CLIENT check that log_clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) > client_in_use_list. On Win2k and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) presumably earlier, on a clean volume this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) is LOGFILE_NO_CLIENT, i.e. there are no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) client records in use and thus the logfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) is closed and hence clean. A dirty volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) would have left the logfile open and hence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) this would be != LOGFILE_NO_CLIENT, and it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) should be 0, i.e. the first (and only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) client record is in use. On WinXP and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) presumably later, the logfile is always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) open, even on clean shutdown so this should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) always be 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* 14*/ RESTART_AREA_FLAGS flags;/* Flags modifying LFS behaviour. On Win2k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) and presumably earlier this is always 0. On
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) WinXP and presumably later, if the logfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) was shutdown cleanly, the second bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) RESTART_VOLUME_IS_CLEAN, is set. This bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) is cleared when the volume is mounted by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) WinXP and set when the volume is dismounted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) thus if the logfile is dirty, this bit is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) clear. Thus we don't need to check the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) Windows version to determine if the logfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) is clean. Instead if the logfile is closed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) we know it must be clean. If it is open and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) this bit is set, we also know it must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) clean. If on the other hand the logfile is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) open and this bit is clear, we can be almost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) certain that the logfile is dirty. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* 16*/ le32 seq_number_bits; /* How many bits to use for the sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) number. This is calculated as 67 - the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) number of bits required to store the logfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) size in bytes and this can be used in with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) the specified file_size as a consistency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) check. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* 20*/ le16 restart_area_length;/* Length of the restart area including the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) client array. Following checks required if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) version matches. Otherwise, skip them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) restart_area_offset + restart_area_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) has to be <= system_page_size. Also,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) restart_area_length has to be >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) client_array_offset + (log_clients *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) sizeof(log client record)). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* 22*/ le16 client_array_offset;/* Offset from the start of this record to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) the first log client record if versions are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) matched. When creating, set this to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) after this restart area structure, aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) to 8-bytes boundary. If the versions do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) match, this is ignored and the offset is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) assumed to be (sizeof(RESTART_AREA) + 7) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ~7, i.e. rounded up to first 8-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) boundary. Either way, client_array_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) has to be aligned to an 8-byte boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) Also, restart_area_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) client_array_offset has to be <= 510.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) Finally, client_array_offset + (log_clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * sizeof(log client record)) has to be <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) system_page_size. On Win2k and presumably
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) earlier, this is 0x30, i.e. immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) following this record. On WinXP and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) presumably later, this is 0x40, i.e. there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) are 16 extra bytes between this record and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) the client array. This probably means that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) the RESTART_AREA record is actually bigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) in WinXP and later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* 24*/ sle64 file_size; /* Usable byte size of the log file. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) restart_area_offset + the offset of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) file_size are > 510 then corruption has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) occurred. This is the very first check when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) starting with the restart_area as if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) fails it means that some of the above values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) will be corrupted by the multi sector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) transfer protection. The file_size has to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) be rounded down to be a multiple of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) log_page_size in the RESTART_PAGE_HEADER and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) then it has to be at least big enough to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) store the two restart pages and 48 (0x30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) log record pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* 32*/ le32 last_lsn_data_length;/* Length of data of last LSN, not including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) the log record header. On create set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* 36*/ le16 log_record_header_length;/* Byte size of the log record header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) If the version matches then check that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) value of log_record_header_length is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) multiple of 8, i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) (log_record_header_length + 7) & ~7 ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) log_record_header_length. When creating set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) it to sizeof(LOG_RECORD_HEADER), aligned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 8 bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* 38*/ le16 log_page_data_offset;/* Offset to the start of data in a log record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) page. Must be a multiple of 8. On create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) set it to immediately after the update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) sequence array of the log record page. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* 40*/ le32 restart_log_open_count;/* A counter that gets incremented every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) time the logfile is restarted which happens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) at mount time when the logfile is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) When creating set to a random value. Win2k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) sets it to the low 32 bits of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) system time in NTFS format (see time.h). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* 44*/ le32 reserved; /* Reserved/alignment to 8-byte boundary. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* sizeof() = 48 (0x30) bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) } __attribute__ ((__packed__)) RESTART_AREA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * Log client record. The offset of this record is found by adding the offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * of the RESTART_AREA to the client_array_offset value found in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*Ofs*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* 0*/ leLSN oldest_lsn; /* Oldest LSN needed by this client. On create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) set to 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* 8*/ leLSN client_restart_lsn;/* LSN at which this client needs to restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) the volume, i.e. the current position within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) the log file. At present, if clean this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) should = current_lsn in restart area but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) probably also = current_lsn when dirty most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) of the time. At create set to 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* 16*/ le16 prev_client; /* The offset to the previous log client record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) in the array of log client records.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) LOGFILE_NO_CLIENT means there is no previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) client record, i.e. this is the first one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) This is always LOGFILE_NO_CLIENT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* 18*/ le16 next_client; /* The offset to the next log client record in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) the array of log client records.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) LOGFILE_NO_CLIENT means there are no next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) client records, i.e. this is the last one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) This is always LOGFILE_NO_CLIENT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* 20*/ le16 seq_number; /* On Win2k and presumably earlier, this is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) to zero every time the logfile is restarted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) and it is incremented when the logfile is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) closed at dismount time. Thus it is 0 when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dirty and 1 when clean. On WinXP and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) presumably later, this is always 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* 22*/ u8 reserved[6]; /* Reserved/alignment. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* 28*/ le32 client_name_length;/* Length of client name in bytes. Should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) always be 8. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* 32*/ ntfschar client_name[64];/* Name of the client in Unicode. Should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) always be "NTFS" with the remaining bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) set to 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* sizeof() = 160 (0xa0) bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) } __attribute__ ((__packed__)) LOG_CLIENT_RECORD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) extern bool ntfs_check_logfile(struct inode *log_vi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) RESTART_PAGE_HEADER **rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) extern bool ntfs_is_logfile_clean(struct inode *log_vi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) const RESTART_PAGE_HEADER *rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) extern bool ntfs_empty_logfile(struct inode *log_vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif /* NTFS_RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #endif /* _LINUX_NTFS_LOGFILE_H */