1 #ifndef SQUASHFS_SWAP_H 2 #define SQUASHFS_SWAP_H 3 /* 4 * Squashfs 5 * 6 * Copyright (c) 2008, 2009, 2010, 2013, 2014 7 * Phillip Lougher <phillip@squashfs.org.uk> 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 2, 12 * or (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; if not, write to the Free Software 21 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 23 * squashfs_swap.h 24 */ 25 26 /* 27 * macros to convert each stucture from big endian to little endian 28 */ 29 30 #if __BYTE_ORDER == __BIG_ENDIAN 31 #include <stddef.h> 32 extern void swap_le16(void *, void *); 33 extern void swap_le32(void *, void *); 34 extern void swap_le64(void *, void *); 35 extern void swap_le16_num(void *, void *, int); 36 extern void swap_le32_num(void *, void *, int); 37 extern void swap_le64_num(void *, void *, int); 38 extern unsigned short inswap_le16(unsigned short); 39 extern unsigned int inswap_le32(unsigned int); 40 extern long long inswap_le64(long long); 41 extern void inswap_le16_num(unsigned short *, int); 42 extern void inswap_le32_num(unsigned int *, int); 43 extern void inswap_le64_num(long long *, int); 44 45 #define _SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_FUNC) {\ 46 SWAP_FUNC(32, s, d, s_magic, struct squashfs_super_block);\ 47 SWAP_FUNC(32, s, d, inodes, struct squashfs_super_block);\ 48 SWAP_FUNC##S(32, s, d, mkfs_time, struct squashfs_super_block);\ 49 SWAP_FUNC(32, s, d, block_size, struct squashfs_super_block);\ 50 SWAP_FUNC(32, s, d, fragments, struct squashfs_super_block);\ 51 SWAP_FUNC(16, s, d, compression, struct squashfs_super_block);\ 52 SWAP_FUNC(16, s, d, block_log, struct squashfs_super_block);\ 53 SWAP_FUNC(16, s, d, flags, struct squashfs_super_block);\ 54 SWAP_FUNC(16, s, d, no_ids, struct squashfs_super_block);\ 55 SWAP_FUNC(16, s, d, s_major, struct squashfs_super_block);\ 56 SWAP_FUNC(16, s, d, s_minor, struct squashfs_super_block);\ 57 SWAP_FUNC(64, s, d, root_inode, struct squashfs_super_block);\ 58 SWAP_FUNC(64, s, d, bytes_used, struct squashfs_super_block);\ 59 SWAP_FUNC(64, s, d, id_table_start, struct squashfs_super_block);\ 60 SWAP_FUNC(64, s, d, xattr_id_table_start, struct squashfs_super_block);\ 61 SWAP_FUNC(64, s, d, inode_table_start, struct squashfs_super_block);\ 62 SWAP_FUNC(64, s, d, directory_table_start, struct squashfs_super_block);\ 63 SWAP_FUNC(64, s, d, fragment_table_start, struct squashfs_super_block);\ 64 SWAP_FUNC(64, s, d, lookup_table_start, struct squashfs_super_block);\ 65 } 66 67 #define _SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_FUNC) {\ 68 SWAP_FUNC(32, s, d, index, struct squashfs_dir_index);\ 69 SWAP_FUNC(32, s, d, start_block, struct squashfs_dir_index);\ 70 SWAP_FUNC(32, s, d, size, struct squashfs_dir_index);\ 71 } 72 73 #define _SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_FUNC) {\ 74 SWAP_FUNC(16, s, d, inode_type, struct squashfs_base_inode_header);\ 75 SWAP_FUNC(16, s, d, mode, struct squashfs_base_inode_header);\ 76 SWAP_FUNC(16, s, d, uid, struct squashfs_base_inode_header);\ 77 SWAP_FUNC(16, s, d, guid, struct squashfs_base_inode_header);\ 78 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_base_inode_header);\ 79 SWAP_FUNC(32, s, d, inode_number, struct squashfs_base_inode_header);\ 80 } 81 82 #define _SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_FUNC) {\ 83 SWAP_FUNC(16, s, d, inode_type, struct squashfs_ipc_inode_header);\ 84 SWAP_FUNC(16, s, d, mode, struct squashfs_ipc_inode_header);\ 85 SWAP_FUNC(16, s, d, uid, struct squashfs_ipc_inode_header);\ 86 SWAP_FUNC(16, s, d, guid, struct squashfs_ipc_inode_header);\ 87 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_ipc_inode_header);\ 88 SWAP_FUNC(32, s, d, inode_number, struct squashfs_ipc_inode_header);\ 89 SWAP_FUNC(32, s, d, nlink, struct squashfs_ipc_inode_header);\ 90 } 91 92 #define _SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d, SWAP_FUNC) {\ 93 SWAP_FUNC(16, s, d, inode_type, struct squashfs_lipc_inode_header);\ 94 SWAP_FUNC(16, s, d, mode, struct squashfs_lipc_inode_header);\ 95 SWAP_FUNC(16, s, d, uid, struct squashfs_lipc_inode_header);\ 96 SWAP_FUNC(16, s, d, guid, struct squashfs_lipc_inode_header);\ 97 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_lipc_inode_header);\ 98 SWAP_FUNC(32, s, d, inode_number, struct squashfs_lipc_inode_header);\ 99 SWAP_FUNC(32, s, d, nlink, struct squashfs_lipc_inode_header);\ 100 SWAP_FUNC(32, s, d, xattr, struct squashfs_lipc_inode_header);\ 101 } 102 103 #define _SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_FUNC) {\ 104 SWAP_FUNC(16, s, d, inode_type, struct squashfs_dev_inode_header);\ 105 SWAP_FUNC(16, s, d, mode, struct squashfs_dev_inode_header);\ 106 SWAP_FUNC(16, s, d, uid, struct squashfs_dev_inode_header);\ 107 SWAP_FUNC(16, s, d, guid, struct squashfs_dev_inode_header);\ 108 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_dev_inode_header);\ 109 SWAP_FUNC(32, s, d, inode_number, struct squashfs_dev_inode_header);\ 110 SWAP_FUNC(32, s, d, nlink, struct squashfs_dev_inode_header);\ 111 SWAP_FUNC(32, s, d, rdev, struct squashfs_dev_inode_header);\ 112 } 113 114 #define _SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d, SWAP_FUNC) {\ 115 SWAP_FUNC(16, s, d, inode_type, struct squashfs_ldev_inode_header);\ 116 SWAP_FUNC(16, s, d, mode, struct squashfs_ldev_inode_header);\ 117 SWAP_FUNC(16, s, d, uid, struct squashfs_ldev_inode_header);\ 118 SWAP_FUNC(16, s, d, guid, struct squashfs_ldev_inode_header);\ 119 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_ldev_inode_header);\ 120 SWAP_FUNC(32, s, d, inode_number, struct squashfs_ldev_inode_header);\ 121 SWAP_FUNC(32, s, d, nlink, struct squashfs_ldev_inode_header);\ 122 SWAP_FUNC(32, s, d, rdev, struct squashfs_ldev_inode_header);\ 123 SWAP_FUNC(32, s, d, xattr, struct squashfs_ldev_inode_header);\ 124 } 125 126 #define _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_FUNC) {\ 127 SWAP_FUNC(16, s, d, inode_type, struct squashfs_symlink_inode_header);\ 128 SWAP_FUNC(16, s, d, mode, struct squashfs_symlink_inode_header);\ 129 SWAP_FUNC(16, s, d, uid, struct squashfs_symlink_inode_header);\ 130 SWAP_FUNC(16, s, d, guid, struct squashfs_symlink_inode_header);\ 131 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_symlink_inode_header);\ 132 SWAP_FUNC(32, s, d, inode_number, struct squashfs_symlink_inode_header);\ 133 SWAP_FUNC(32, s, d, nlink, struct squashfs_symlink_inode_header);\ 134 SWAP_FUNC(32, s, d, symlink_size, struct squashfs_symlink_inode_header);\ 135 } 136 137 #define _SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_FUNC) {\ 138 SWAP_FUNC(16, s, d, inode_type, struct squashfs_reg_inode_header);\ 139 SWAP_FUNC(16, s, d, mode, struct squashfs_reg_inode_header);\ 140 SWAP_FUNC(16, s, d, uid, struct squashfs_reg_inode_header);\ 141 SWAP_FUNC(16, s, d, guid, struct squashfs_reg_inode_header);\ 142 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_reg_inode_header);\ 143 SWAP_FUNC(32, s, d, inode_number, struct squashfs_reg_inode_header);\ 144 SWAP_FUNC(32, s, d, start_block, struct squashfs_reg_inode_header);\ 145 SWAP_FUNC(32, s, d, fragment, struct squashfs_reg_inode_header);\ 146 SWAP_FUNC(32, s, d, offset, struct squashfs_reg_inode_header);\ 147 SWAP_FUNC(32, s, d, file_size, struct squashfs_reg_inode_header);\ 148 } 149 150 #define _SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_FUNC) {\ 151 SWAP_FUNC(16, s, d, inode_type, struct squashfs_lreg_inode_header);\ 152 SWAP_FUNC(16, s, d, mode, struct squashfs_lreg_inode_header);\ 153 SWAP_FUNC(16, s, d, uid, struct squashfs_lreg_inode_header);\ 154 SWAP_FUNC(16, s, d, guid, struct squashfs_lreg_inode_header);\ 155 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_lreg_inode_header);\ 156 SWAP_FUNC(32, s, d, inode_number, struct squashfs_lreg_inode_header);\ 157 SWAP_FUNC(64, s, d, start_block, struct squashfs_lreg_inode_header);\ 158 SWAP_FUNC(64, s, d, file_size, struct squashfs_lreg_inode_header);\ 159 SWAP_FUNC(64, s, d, sparse, struct squashfs_lreg_inode_header);\ 160 SWAP_FUNC(32, s, d, nlink, struct squashfs_lreg_inode_header);\ 161 SWAP_FUNC(32, s, d, fragment, struct squashfs_lreg_inode_header);\ 162 SWAP_FUNC(32, s, d, offset, struct squashfs_lreg_inode_header);\ 163 SWAP_FUNC(32, s, d, xattr, struct squashfs_lreg_inode_header);\ 164 } 165 166 #define _SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_FUNC) {\ 167 SWAP_FUNC(16, s, d, inode_type, struct squashfs_dir_inode_header);\ 168 SWAP_FUNC(16, s, d, mode, struct squashfs_dir_inode_header);\ 169 SWAP_FUNC(16, s, d, uid, struct squashfs_dir_inode_header);\ 170 SWAP_FUNC(16, s, d, guid, struct squashfs_dir_inode_header);\ 171 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_dir_inode_header);\ 172 SWAP_FUNC(32, s, d, inode_number, struct squashfs_dir_inode_header);\ 173 SWAP_FUNC(32, s, d, start_block, struct squashfs_dir_inode_header);\ 174 SWAP_FUNC(32, s, d, nlink, struct squashfs_dir_inode_header);\ 175 SWAP_FUNC(16, s, d, file_size, struct squashfs_dir_inode_header);\ 176 SWAP_FUNC(16, s, d, offset, struct squashfs_dir_inode_header);\ 177 SWAP_FUNC(32, s, d, parent_inode, struct squashfs_dir_inode_header);\ 178 } 179 180 #define _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_FUNC) {\ 181 SWAP_FUNC(16, s, d, inode_type, struct squashfs_ldir_inode_header);\ 182 SWAP_FUNC(16, s, d, mode, struct squashfs_ldir_inode_header);\ 183 SWAP_FUNC(16, s, d, uid, struct squashfs_ldir_inode_header);\ 184 SWAP_FUNC(16, s, d, guid, struct squashfs_ldir_inode_header);\ 185 SWAP_FUNC##S(32, s, d, mtime, struct squashfs_ldir_inode_header);\ 186 SWAP_FUNC(32, s, d, inode_number, struct squashfs_ldir_inode_header);\ 187 SWAP_FUNC(32, s, d, nlink, struct squashfs_ldir_inode_header);\ 188 SWAP_FUNC(32, s, d, file_size, struct squashfs_ldir_inode_header);\ 189 SWAP_FUNC(32, s, d, start_block, struct squashfs_ldir_inode_header);\ 190 SWAP_FUNC(32, s, d, parent_inode, struct squashfs_ldir_inode_header);\ 191 SWAP_FUNC(16, s, d, i_count, struct squashfs_ldir_inode_header);\ 192 SWAP_FUNC(16, s, d, offset, struct squashfs_ldir_inode_header);\ 193 SWAP_FUNC(32, s, d, xattr, struct squashfs_ldir_inode_header);\ 194 } 195 196 #define _SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_FUNC) {\ 197 SWAP_FUNC(16, s, d, offset, struct squashfs_dir_entry);\ 198 SWAP_FUNC##S(16, s, d, inode_number, struct squashfs_dir_entry);\ 199 SWAP_FUNC(16, s, d, type, struct squashfs_dir_entry);\ 200 SWAP_FUNC(16, s, d, size, struct squashfs_dir_entry);\ 201 } 202 203 #define _SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_FUNC) {\ 204 SWAP_FUNC(32, s, d, count, struct squashfs_dir_header);\ 205 SWAP_FUNC(32, s, d, start_block, struct squashfs_dir_header);\ 206 SWAP_FUNC(32, s, d, inode_number, struct squashfs_dir_header);\ 207 } 208 209 #define _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_FUNC) {\ 210 SWAP_FUNC(64, s, d, start_block, struct squashfs_fragment_entry);\ 211 SWAP_FUNC(32, s, d, size, struct squashfs_fragment_entry);\ 212 } 213 214 #define _SQUASHFS_SWAP_XATTR_ENTRY(s, d, SWAP_FUNC) {\ 215 SWAP_FUNC(16, s, d, type, struct squashfs_xattr_entry);\ 216 SWAP_FUNC(16, s, d, size, struct squashfs_xattr_entry);\ 217 } 218 219 #define _SQUASHFS_SWAP_XATTR_VAL(s, d, SWAP_FUNC) {\ 220 SWAP_FUNC(32, s, d, vsize, struct squashfs_xattr_val);\ 221 } 222 223 #define _SQUASHFS_SWAP_XATTR_ID(s, d, SWAP_FUNC) {\ 224 SWAP_FUNC(64, s, d, xattr, struct squashfs_xattr_id);\ 225 SWAP_FUNC(32, s, d, count, struct squashfs_xattr_id);\ 226 SWAP_FUNC(32, s, d, size, struct squashfs_xattr_id);\ 227 } 228 229 #define _SQUASHFS_SWAP_XATTR_TABLE(s, d, SWAP_FUNC) {\ 230 SWAP_FUNC(64, s, d, xattr_table_start, struct squashfs_xattr_table);\ 231 SWAP_FUNC(32, s, d, xattr_ids, struct squashfs_xattr_table);\ 232 } 233 234 /* big endian architecture copy and swap macros */ 235 #define SQUASHFS_SWAP_SUPER_BLOCK(s, d) \ 236 _SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_LE) 237 #define SQUASHFS_SWAP_DIR_INDEX(s, d) \ 238 _SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_LE) 239 #define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \ 240 _SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_LE) 241 #define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \ 242 _SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_LE) 243 #define SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d) \ 244 _SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d, SWAP_LE) 245 #define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \ 246 _SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_LE) 247 #define SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d) \ 248 _SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d, SWAP_LE) 249 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \ 250 _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_LE) 251 #define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \ 252 _SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_LE) 253 #define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \ 254 _SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_LE) 255 #define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \ 256 _SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_LE) 257 #define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \ 258 _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_LE) 259 #define SQUASHFS_SWAP_DIR_ENTRY(s, d) \ 260 _SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_LE) 261 #define SQUASHFS_SWAP_DIR_HEADER(s, d) \ 262 _SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_LE) 263 #define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \ 264 _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_LE) 265 #define SQUASHFS_SWAP_XATTR_ENTRY(s, d) \ 266 _SQUASHFS_SWAP_XATTR_ENTRY(s, d, SWAP_LE) 267 #define SQUASHFS_SWAP_XATTR_VAL(s, d) \ 268 _SQUASHFS_SWAP_XATTR_VAL(s, d, SWAP_LE) 269 #define SQUASHFS_SWAP_XATTR_ID(s, d) \ 270 _SQUASHFS_SWAP_XATTR_ID(s, d, SWAP_LE) 271 #define SQUASHFS_SWAP_XATTR_TABLE(s, d) \ 272 _SQUASHFS_SWAP_XATTR_TABLE(s, d, SWAP_LE) 273 #define SWAP_LE(bits, s, d, field, type) \ 274 SWAP_LE##bits(((void *)(s)) + offsetof(type, field), \ 275 ((void *)(d)) + offsetof(type, field)) 276 #define SWAP_LES(bits, s, d, field, type) \ 277 SWAP_LE(bits, s, d, field, type) 278 #define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1) 279 #define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) \ 280 SQUASHFS_SWAP_LONG_LONGS(s, d, n) 281 #define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n) 282 #define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n) 283 284 #define SQUASHFS_SWAP_SHORTS(s, d, n) swap_le16_num(s, d, n) 285 #define SQUASHFS_SWAP_INTS(s, d, n) swap_le32_num(s, d, n) 286 #define SQUASHFS_SWAP_LONG_LONGS(s, d, n) swap_le64_num(s, d, n) 287 288 #define SWAP_LE16(s, d) swap_le16(s, d) 289 #define SWAP_LE32(s, d) swap_le32(s, d) 290 #define SWAP_LE64(s, d) swap_le64(s, d) 291 292 /* big endian architecture swap in-place macros */ 293 #define SQUASHFS_INSWAP_SUPER_BLOCK(s) \ 294 _SQUASHFS_SWAP_SUPER_BLOCK(s, s, INSWAP_LE) 295 #define SQUASHFS_INSWAP_DIR_INDEX(s) \ 296 _SQUASHFS_SWAP_DIR_INDEX(s, s, INSWAP_LE) 297 #define SQUASHFS_INSWAP_BASE_INODE_HEADER(s) \ 298 _SQUASHFS_SWAP_BASE_INODE_HEADER(s, s, INSWAP_LE) 299 #define SQUASHFS_INSWAP_IPC_INODE_HEADER(s) \ 300 _SQUASHFS_SWAP_IPC_INODE_HEADER(s, s, INSWAP_LE) 301 #define SQUASHFS_INSWAP_LIPC_INODE_HEADER(s) \ 302 _SQUASHFS_SWAP_LIPC_INODE_HEADER(s, s, INSWAP_LE) 303 #define SQUASHFS_INSWAP_DEV_INODE_HEADER(s) \ 304 _SQUASHFS_SWAP_DEV_INODE_HEADER(s, s, INSWAP_LE) 305 #define SQUASHFS_INSWAP_LDEV_INODE_HEADER(s) \ 306 _SQUASHFS_SWAP_LDEV_INODE_HEADER(s, s, INSWAP_LE) 307 #define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s) \ 308 _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, s, INSWAP_LE) 309 #define SQUASHFS_INSWAP_REG_INODE_HEADER(s) \ 310 _SQUASHFS_SWAP_REG_INODE_HEADER(s, s, INSWAP_LE) 311 #define SQUASHFS_INSWAP_LREG_INODE_HEADER(s) \ 312 _SQUASHFS_SWAP_LREG_INODE_HEADER(s, s, INSWAP_LE) 313 #define SQUASHFS_INSWAP_DIR_INODE_HEADER(s) \ 314 _SQUASHFS_SWAP_DIR_INODE_HEADER(s, s, INSWAP_LE) 315 #define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s) \ 316 _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, s, INSWAP_LE) 317 #define SQUASHFS_INSWAP_DIR_ENTRY(s) \ 318 _SQUASHFS_SWAP_DIR_ENTRY(s, s, INSWAP_LE) 319 #define SQUASHFS_INSWAP_DIR_HEADER(s) \ 320 _SQUASHFS_SWAP_DIR_HEADER(s, s, INSWAP_LE) 321 #define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s) \ 322 _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, s, INSWAP_LE) 323 #define SQUASHFS_INSWAP_XATTR_ENTRY(s) \ 324 _SQUASHFS_SWAP_XATTR_ENTRY(s, s, INSWAP_LE) 325 #define SQUASHFS_INSWAP_XATTR_VAL(s) \ 326 _SQUASHFS_SWAP_XATTR_VAL(s, s, INSWAP_LE) 327 #define SQUASHFS_INSWAP_XATTR_ID(s) \ 328 _SQUASHFS_SWAP_XATTR_ID(s, s, INSWAP_LE) 329 #define SQUASHFS_INSWAP_XATTR_TABLE(s) \ 330 _SQUASHFS_SWAP_XATTR_TABLE(s, s, INSWAP_LE) 331 #define INSWAP_LE(bits, s, d, field, type) \ 332 (s)->field = inswap_le##bits((s)->field) 333 #define INSWAP_LES(bits, s, d, field, type) \ 334 (s)->field = INSWAP_LES##bits((s)->field) 335 #define INSWAP_LES16(num) (short) inswap_le16((unsigned short) (num)) 336 #define INSWAP_LES32(num) (int) inswap_le32((unsigned int) (num)) 337 #define SQUASHFS_INSWAP_INODE_T(s) s = inswap_le64(s) 338 #define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n) inswap_le64_num(s, n) 339 #define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n) inswap_le64_num(s, n) 340 #define SQUASHFS_INSWAP_ID_BLOCKS(s, n) inswap_le64_num(s, n) 341 #define SQUASHFS_INSWAP_SHORTS(s, n) inswap_le16_num(s, n) 342 #define SQUASHFS_INSWAP_INTS(s, n) inswap_le32_num(s, n) 343 #define SQUASHFS_INSWAP_LONG_LONGS(s, n) inswap_le64_num(s, n) 344 #else 345 /* little endian architecture, just copy */ 346 #define SQUASHFS_SWAP_SUPER_BLOCK(s, d) \ 347 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_super_block)) 348 #define SQUASHFS_SWAP_DIR_INDEX(s, d) \ 349 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_dir_index)) 350 #define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \ 351 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_base_inode_header)) 352 #define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \ 353 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_ipc_inode_header)) 354 #define SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d) \ 355 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_lipc_inode_header)) 356 #define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \ 357 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_dev_inode_header)) 358 #define SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d) \ 359 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_ldev_inode_header)) 360 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \ 361 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_symlink_inode_header)) 362 #define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \ 363 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_reg_inode_header)) 364 #define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \ 365 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_lreg_inode_header)) 366 #define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \ 367 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_dir_inode_header)) 368 #define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \ 369 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_ldir_inode_header)) 370 #define SQUASHFS_SWAP_DIR_ENTRY(s, d) \ 371 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_dir_entry)) 372 #define SQUASHFS_SWAP_DIR_HEADER(s, d) \ 373 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_dir_header)) 374 #define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \ 375 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_fragment_entry)) 376 #define SQUASHFS_SWAP_XATTR_ENTRY(s, d) \ 377 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_xattr_entry)) 378 #define SQUASHFS_SWAP_XATTR_VAL(s, d) \ 379 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_xattr_val)) 380 #define SQUASHFS_SWAP_XATTR_ID(s, d) \ 381 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_xattr_id)) 382 #define SQUASHFS_SWAP_XATTR_TABLE(s, d) \ 383 SQUASHFS_MEMCPY(s, d, sizeof(struct squashfs_xattr_table)) 384 #define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1) 385 #define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) \ 386 SQUASHFS_SWAP_LONG_LONGS(s, d, n) 387 #define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n) 388 #define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n) 389 390 #define SQUASHFS_MEMCPY(s, d, n) memcpy(d, s, n) 391 #define SQUASHFS_SWAP_SHORTS(s, d, n) memcpy(d, s, n * sizeof(short)) 392 #define SQUASHFS_SWAP_INTS(s, d, n) memcpy(d, s, n * sizeof(int)) 393 #define SQUASHFS_SWAP_LONG_LONGS(s, d, n) \ 394 memcpy(d, s, n * sizeof(long long)) 395 396 /* little endian architecture, data already in place so do nothing */ 397 #define SQUASHFS_INSWAP_SUPER_BLOCK(s) 398 #define SQUASHFS_INSWAP_DIR_INDEX(s) 399 #define SQUASHFS_INSWAP_BASE_INODE_HEADER(s) 400 #define SQUASHFS_INSWAP_IPC_INODE_HEADER(s) 401 #define SQUASHFS_INSWAP_LIPC_INODE_HEADER(s) 402 #define SQUASHFS_INSWAP_DEV_INODE_HEADER(s) 403 #define SQUASHFS_INSWAP_LDEV_INODE_HEADER(s) 404 #define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s) 405 #define SQUASHFS_INSWAP_REG_INODE_HEADER(s) 406 #define SQUASHFS_INSWAP_LREG_INODE_HEADER(s) 407 #define SQUASHFS_INSWAP_DIR_INODE_HEADER(s) 408 #define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s) 409 #define SQUASHFS_INSWAP_DIR_ENTRY(s) 410 #define SQUASHFS_INSWAP_DIR_HEADER(s) 411 #define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s) 412 #define SQUASHFS_INSWAP_XATTR_ENTRY(s) 413 #define SQUASHFS_INSWAP_XATTR_VAL(s) 414 #define SQUASHFS_INSWAP_XATTR_ID(s) 415 #define SQUASHFS_INSWAP_XATTR_TABLE(s) 416 #define SQUASHFS_INSWAP_INODE_T(s) 417 #define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n) 418 #define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n) 419 #define SQUASHFS_INSWAP_ID_BLOCKS(s, n) 420 #define SQUASHFS_INSWAP_SHORTS(s, n) 421 #define SQUASHFS_INSWAP_INTS(s, n) 422 #define SQUASHFS_INSWAP_LONG_LONGS(s, n) 423 #endif 424 #endif 425