1 /* 2 * Declarations for processing log data 3 * 4 * Copyright (c) 2000-2005 Anton Altaparmakov 5 * Copyright (c) 2014-2016 Jean-Pierre Andre 6 */ 7 8 /* 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program (in the main directory of the NTFS-3G 21 * distribution in the file COPYING); if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 */ 24 25 #define getle16(p,x) le16_to_cpu(*(const le16*)((const char*)(p) + (x))) 26 #define getle32(p,x) le32_to_cpu(*(const le32*)((const char*)(p) + (x))) 27 #define getle64(p,x) le64_to_cpu(*(const le64*)((const char*)(p) + (x))) 28 29 #define feedle16(p,x) (*(const le16*)((const char*)(p) + (x))) 30 #define feedle32(p,x) (*(const le32*)((const char*)(p) + (x))) 31 #define feedle64(p,x) (*(const le64*)((const char*)(p) + (x))) 32 33 enum ACTIONS { 34 Noop, /* 0 */ 35 CompensationlogRecord, /* 1 */ 36 InitializeFileRecordSegment, /* 2 */ 37 DeallocateFileRecordSegment, /* 3 */ 38 WriteEndofFileRecordSegment, /* 4 */ 39 CreateAttribute, /* 5 */ 40 DeleteAttribute, /* 6 */ 41 UpdateResidentValue, /* 7 */ 42 UpdateNonResidentValue, /* 8 */ 43 UpdateMappingPairs, /* 9 */ 44 DeleteDirtyClusters, /* 10 */ 45 SetNewAttributeSizes, /* 11 */ 46 AddIndexEntryRoot, /* 12 */ 47 DeleteIndexEntryRoot, /* 13 */ 48 AddIndexEntryAllocation, /* 14 */ 49 DeleteIndexEntryAllocation, /* 15 */ 50 WriteEndOfIndexBuffer, /* 16 */ 51 SetIndexEntryVcnRoot, /* 17 */ 52 SetIndexEntryVcnAllocation, /* 18 */ 53 UpdateFileNameRoot, /* 19 */ 54 UpdateFileNameAllocation, /* 20 */ 55 SetBitsInNonResidentBitMap, /* 21 */ 56 ClearBitsInNonResidentBitMap, /* 22 */ 57 HotFix, /* 23 */ 58 EndTopLevelAction, /* 24 */ 59 PrepareTransaction, /* 25 */ 60 CommitTransaction, /* 26 */ 61 ForgetTransaction, /* 27 */ 62 OpenNonResidentAttribute, /* 28 */ 63 OpenAttributeTableDump, /* 29 */ 64 AttributeNamesDump, /* 30 */ 65 DirtyPageTableDump, /* 31 */ 66 TransactionTableDump, /* 32 */ 67 UpdateRecordDataRoot, /* 33 */ 68 UpdateRecordDataAllocation, /* 34 */ 69 Win10Action35, /* 35 */ 70 Win10Action36, /* 36 */ 71 Win10Action37, /* 37 */ 72 LastAction /* 38 */ 73 } ; 74 75 struct BUFFER { 76 unsigned int num; 77 unsigned int rnum; 78 unsigned int size; 79 unsigned int headsz; 80 BOOL safe; 81 union { 82 u64 alignment; 83 RESTART_PAGE_HEADER restart; 84 RECORD_PAGE_HEADER record; 85 char data[1]; 86 } block; /* variable length, keep at the end */ 87 } ; 88 89 struct ACTION_RECORD { 90 struct ACTION_RECORD *next; 91 struct ACTION_RECORD *prev; 92 int num; 93 unsigned int flags; 94 LOG_RECORD record; /* variable length, keep at the end */ 95 } ; 96 97 enum { /* Flag values for ACTION_RECORD */ 98 ACTION_TO_REDO = 1 /* Committed, possibly not synced */ 99 } ; 100 101 struct ATTR { 102 u64 inode; 103 u64 lsn; 104 le32 type; 105 u16 key; 106 u16 namelen; 107 le16 name[1]; 108 } ; 109 110 extern u32 clustersz; 111 extern int clusterbits; 112 extern u32 blocksz; 113 extern int blockbits; 114 extern u16 bytespersect; 115 extern u64 mftlcn; 116 extern u32 mftrecsz; 117 extern int mftrecbits; 118 extern u32 mftcnt; /* number of entries */ 119 extern BOOL optc; 120 extern BOOL optn; 121 extern int opts; 122 extern int optv; 123 extern unsigned int redocount; 124 extern unsigned int undocount; 125 extern ntfs_inode *log_ni; 126 extern ntfs_attr *log_na; 127 extern u64 logfilelcn; 128 extern u32 logfilesz; /* bytes */ 129 extern u64 redos_met; 130 extern u64 committed_lsn; 131 extern u64 synced_lsn; 132 extern u64 latest_lsn; 133 extern u64 restart_lsn; 134 135 extern RESTART_AREA restart; 136 extern LOG_CLIENT_RECORD client; 137 138 const char *actionname(int op); 139 const char *mftattrname(ATTR_TYPES attr); 140 void showname(const char *prefix, const char *name, int cnt); 141 int fixnamelen(const char *name, int len); 142 BOOL within_lcn_range(const LOG_RECORD *logr); 143 struct ATTR *getattrentry(unsigned int key, unsigned int lth); 144 void copy_attribute(struct ATTR *pa, const char *buf, int length); 145 u32 get_undo_offset(const LOG_RECORD *logr); 146 u32 get_redo_offset(const LOG_RECORD *logr); 147 u32 get_extra_offset(const LOG_RECORD *logr); 148 BOOL exception(int num); 149 150 struct STORE; 151 extern int play_undos(ntfs_volume *vol, const struct ACTION_RECORD *firstundo); 152 extern int play_redos(ntfs_volume *vol, const struct ACTION_RECORD *firstredo); 153 extern void show_redos(void); 154 extern void freeclusterentry(struct STORE*); 155 void hexdump(const char *buf, unsigned int lth); 156