12b27bdccSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 21e51764aSArtem Bityutskiy /* 31e51764aSArtem Bityutskiy * This file is part of UBIFS. 41e51764aSArtem Bityutskiy * 51e51764aSArtem Bityutskiy * Copyright (C) 2006-2008 Nokia Corporation. 61e51764aSArtem Bityutskiy * 71e51764aSArtem Bityutskiy * Authors: Artem Bityutskiy (Битюцкий Артём) 81e51764aSArtem Bityutskiy * Adrian Hunter 91e51764aSArtem Bityutskiy */ 101e51764aSArtem Bityutskiy 111e51764aSArtem Bityutskiy /* 121e51764aSArtem Bityutskiy * This file describes UBIFS on-flash format and contains definitions of all the 131e51764aSArtem Bityutskiy * relevant data structures and constants. 141e51764aSArtem Bityutskiy * 151e51764aSArtem Bityutskiy * All UBIFS on-flash objects are stored in the form of nodes. All nodes start 161e51764aSArtem Bityutskiy * with the UBIFS node magic number and have the same common header. Nodes 171e51764aSArtem Bityutskiy * always sit at 8-byte aligned positions on the media and node header sizes are 181e51764aSArtem Bityutskiy * also 8-byte aligned (except for the indexing node and the padding node). 191e51764aSArtem Bityutskiy */ 201e51764aSArtem Bityutskiy 211e51764aSArtem Bityutskiy #ifndef __UBIFS_MEDIA_H__ 221e51764aSArtem Bityutskiy #define __UBIFS_MEDIA_H__ 231e51764aSArtem Bityutskiy 241e51764aSArtem Bityutskiy /* UBIFS node magic number (must not have the padding byte first or last) */ 251e51764aSArtem Bityutskiy #define UBIFS_NODE_MAGIC 0x06101831 261e51764aSArtem Bityutskiy 27963f0cf6SArtem Bityutskiy /* 28963f0cf6SArtem Bityutskiy * UBIFS on-flash format version. This version is increased when the on-flash 29963f0cf6SArtem Bityutskiy * format is changing. If this happens, UBIFS is will support older versions as 30963f0cf6SArtem Bityutskiy * well. But older UBIFS code will not support newer formats. Format changes 31963f0cf6SArtem Bityutskiy * will be rare and only when absolutely necessary, e.g. to fix a bug or to add 32963f0cf6SArtem Bityutskiy * a new feature. 33963f0cf6SArtem Bityutskiy * 34963f0cf6SArtem Bityutskiy * UBIFS went into mainline kernel with format version 4. The older formats 35963f0cf6SArtem Bityutskiy * were development formats. 36963f0cf6SArtem Bityutskiy */ 37fc4b891bSRichard Weinberger #define UBIFS_FORMAT_VERSION 5 381e51764aSArtem Bityutskiy 39963f0cf6SArtem Bityutskiy /* 40963f0cf6SArtem Bityutskiy * Read-only compatibility version. If the UBIFS format is changed, older UBIFS 41963f0cf6SArtem Bityutskiy * implementations will not be able to mount newer formats in read-write mode. 42963f0cf6SArtem Bityutskiy * However, depending on the change, it may be possible to mount newer formats 43963f0cf6SArtem Bityutskiy * in R/O mode. This is indicated by the R/O compatibility version which is 44963f0cf6SArtem Bityutskiy * stored in the super-block. 45963f0cf6SArtem Bityutskiy * 46963f0cf6SArtem Bityutskiy * This is needed to support boot-loaders which only need R/O mounting. With 47963f0cf6SArtem Bityutskiy * this flag it is possible to do UBIFS format changes without a need to update 48963f0cf6SArtem Bityutskiy * boot-loaders. 49963f0cf6SArtem Bityutskiy */ 50963f0cf6SArtem Bityutskiy #define UBIFS_RO_COMPAT_VERSION 0 51963f0cf6SArtem Bityutskiy 521e51764aSArtem Bityutskiy /* Minimum logical eraseblock size in bytes */ 531e51764aSArtem Bityutskiy #define UBIFS_MIN_LEB_SZ (15*1024) 541e51764aSArtem Bityutskiy 551e51764aSArtem Bityutskiy /* Initial CRC32 value used when calculating CRC checksums */ 561e51764aSArtem Bityutskiy #define UBIFS_CRC32_INIT 0xFFFFFFFFU 571e51764aSArtem Bityutskiy 581e51764aSArtem Bityutskiy /* 591e51764aSArtem Bityutskiy * UBIFS does not try to compress data if its length is less than the below 601e51764aSArtem Bityutskiy * constant. 611e51764aSArtem Bityutskiy */ 621e51764aSArtem Bityutskiy #define UBIFS_MIN_COMPR_LEN 128 631e51764aSArtem Bityutskiy 64062e4feeSArtem Bityutskiy /* 65062e4feeSArtem Bityutskiy * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes 66963f0cf6SArtem Bityutskiy * shorter than uncompressed data length, UBIFS prefers to leave this data 67062e4feeSArtem Bityutskiy * node uncompress, because it'll be read faster. 68062e4feeSArtem Bityutskiy */ 69062e4feeSArtem Bityutskiy #define UBIFS_MIN_COMPRESS_DIFF 64 70062e4feeSArtem Bityutskiy 711e51764aSArtem Bityutskiy /* Root inode number */ 721e51764aSArtem Bityutskiy #define UBIFS_ROOT_INO 1 731e51764aSArtem Bityutskiy 741e51764aSArtem Bityutskiy /* Lowest inode number used for regular inodes (not UBIFS-only internal ones) */ 751e51764aSArtem Bityutskiy #define UBIFS_FIRST_INO 64 761e51764aSArtem Bityutskiy 771e51764aSArtem Bityutskiy /* 781e51764aSArtem Bityutskiy * Maximum file name and extended attribute length (must be a multiple of 8, 791e51764aSArtem Bityutskiy * minus 1). 801e51764aSArtem Bityutskiy */ 811e51764aSArtem Bityutskiy #define UBIFS_MAX_NLEN 255 821e51764aSArtem Bityutskiy 831e51764aSArtem Bityutskiy /* Maximum number of data journal heads */ 841e51764aSArtem Bityutskiy #define UBIFS_MAX_JHEADS 1 851e51764aSArtem Bityutskiy 861e51764aSArtem Bityutskiy /* 871e51764aSArtem Bityutskiy * Size of UBIFS data block. Note, UBIFS is not a block oriented file-system, 881e51764aSArtem Bityutskiy * which means that it does not treat the underlying media as consisting of 891e51764aSArtem Bityutskiy * blocks like in case of hard drives. Do not be confused. UBIFS block is just 901e51764aSArtem Bityutskiy * the maximum amount of data which one data node can have or which can be 911e51764aSArtem Bityutskiy * attached to an inode node. 921e51764aSArtem Bityutskiy */ 931e51764aSArtem Bityutskiy #define UBIFS_BLOCK_SIZE 4096 941e51764aSArtem Bityutskiy #define UBIFS_BLOCK_SHIFT 12 951e51764aSArtem Bityutskiy 961e51764aSArtem Bityutskiy /* UBIFS padding byte pattern (must not be first or last byte of node magic) */ 971e51764aSArtem Bityutskiy #define UBIFS_PADDING_BYTE 0xCE 981e51764aSArtem Bityutskiy 991e51764aSArtem Bityutskiy /* Maximum possible key length */ 1001e51764aSArtem Bityutskiy #define UBIFS_MAX_KEY_LEN 16 1011e51764aSArtem Bityutskiy 1021e51764aSArtem Bityutskiy /* Key length ("simple" format) */ 1031e51764aSArtem Bityutskiy #define UBIFS_SK_LEN 8 1041e51764aSArtem Bityutskiy 1051e51764aSArtem Bityutskiy /* Minimum index tree fanout */ 106a5cb562dSArtem Bityutskiy #define UBIFS_MIN_FANOUT 3 1071e51764aSArtem Bityutskiy 1081e51764aSArtem Bityutskiy /* Maximum number of levels in UBIFS indexing B-tree */ 1091e51764aSArtem Bityutskiy #define UBIFS_MAX_LEVELS 512 1101e51764aSArtem Bityutskiy 1111e51764aSArtem Bityutskiy /* Maximum amount of data attached to an inode in bytes */ 1121e51764aSArtem Bityutskiy #define UBIFS_MAX_INO_DATA UBIFS_BLOCK_SIZE 1131e51764aSArtem Bityutskiy 1141e51764aSArtem Bityutskiy /* LEB Properties Tree fanout (must be power of 2) and fanout shift */ 1151e51764aSArtem Bityutskiy #define UBIFS_LPT_FANOUT 4 1161e51764aSArtem Bityutskiy #define UBIFS_LPT_FANOUT_SHIFT 2 1171e51764aSArtem Bityutskiy 1181e51764aSArtem Bityutskiy /* LEB Properties Tree bit field sizes */ 1191e51764aSArtem Bityutskiy #define UBIFS_LPT_CRC_BITS 16 1201e51764aSArtem Bityutskiy #define UBIFS_LPT_CRC_BYTES 2 1211e51764aSArtem Bityutskiy #define UBIFS_LPT_TYPE_BITS 4 1221e51764aSArtem Bityutskiy 1231e51764aSArtem Bityutskiy /* The key is always at the same position in all keyed nodes */ 1241e51764aSArtem Bityutskiy #define UBIFS_KEY_OFFSET offsetof(struct ubifs_ino_node, key) 1251e51764aSArtem Bityutskiy 126d6d14009SArtem Bityutskiy /* Garbage collector journal head number */ 127d6d14009SArtem Bityutskiy #define UBIFS_GC_HEAD 0 128d6d14009SArtem Bityutskiy /* Base journal head number */ 129d6d14009SArtem Bityutskiy #define UBIFS_BASE_HEAD 1 130d6d14009SArtem Bityutskiy /* Data journal head number */ 131d6d14009SArtem Bityutskiy #define UBIFS_DATA_HEAD 2 132d6d14009SArtem Bityutskiy 1331e51764aSArtem Bityutskiy /* 1341e51764aSArtem Bityutskiy * LEB Properties Tree node types. 1351e51764aSArtem Bityutskiy * 1361e51764aSArtem Bityutskiy * UBIFS_LPT_PNODE: LPT leaf node (contains LEB properties) 1371e51764aSArtem Bityutskiy * UBIFS_LPT_NNODE: LPT internal node 1381e51764aSArtem Bityutskiy * UBIFS_LPT_LTAB: LPT's own lprops table 1391e51764aSArtem Bityutskiy * UBIFS_LPT_LSAVE: LPT's save table (big model only) 1401e51764aSArtem Bityutskiy * UBIFS_LPT_NODE_CNT: count of LPT node types 1411e51764aSArtem Bityutskiy * UBIFS_LPT_NOT_A_NODE: all ones (15 for 4 bits) is never a valid node type 1421e51764aSArtem Bityutskiy */ 1431e51764aSArtem Bityutskiy enum { 1441e51764aSArtem Bityutskiy UBIFS_LPT_PNODE, 1451e51764aSArtem Bityutskiy UBIFS_LPT_NNODE, 1461e51764aSArtem Bityutskiy UBIFS_LPT_LTAB, 1471e51764aSArtem Bityutskiy UBIFS_LPT_LSAVE, 1481e51764aSArtem Bityutskiy UBIFS_LPT_NODE_CNT, 1491e51764aSArtem Bityutskiy UBIFS_LPT_NOT_A_NODE = (1 << UBIFS_LPT_TYPE_BITS) - 1, 1501e51764aSArtem Bityutskiy }; 1511e51764aSArtem Bityutskiy 1521e51764aSArtem Bityutskiy /* 1531e51764aSArtem Bityutskiy * UBIFS inode types. 1541e51764aSArtem Bityutskiy * 1551e51764aSArtem Bityutskiy * UBIFS_ITYPE_REG: regular file 1561e51764aSArtem Bityutskiy * UBIFS_ITYPE_DIR: directory 1571e51764aSArtem Bityutskiy * UBIFS_ITYPE_LNK: soft link 1581e51764aSArtem Bityutskiy * UBIFS_ITYPE_BLK: block device node 1591e51764aSArtem Bityutskiy * UBIFS_ITYPE_CHR: character device node 1601e51764aSArtem Bityutskiy * UBIFS_ITYPE_FIFO: fifo 1611e51764aSArtem Bityutskiy * UBIFS_ITYPE_SOCK: socket 1621e51764aSArtem Bityutskiy * UBIFS_ITYPES_CNT: count of supported file types 1631e51764aSArtem Bityutskiy */ 1641e51764aSArtem Bityutskiy enum { 1651e51764aSArtem Bityutskiy UBIFS_ITYPE_REG, 1661e51764aSArtem Bityutskiy UBIFS_ITYPE_DIR, 1671e51764aSArtem Bityutskiy UBIFS_ITYPE_LNK, 1681e51764aSArtem Bityutskiy UBIFS_ITYPE_BLK, 1691e51764aSArtem Bityutskiy UBIFS_ITYPE_CHR, 1701e51764aSArtem Bityutskiy UBIFS_ITYPE_FIFO, 1711e51764aSArtem Bityutskiy UBIFS_ITYPE_SOCK, 1721e51764aSArtem Bityutskiy UBIFS_ITYPES_CNT, 1731e51764aSArtem Bityutskiy }; 1741e51764aSArtem Bityutskiy 1751e51764aSArtem Bityutskiy /* 1761e51764aSArtem Bityutskiy * Supported key hash functions. 1771e51764aSArtem Bityutskiy * 1781e51764aSArtem Bityutskiy * UBIFS_KEY_HASH_R5: R5 hash 1791e51764aSArtem Bityutskiy * UBIFS_KEY_HASH_TEST: test hash which just returns first 4 bytes of the name 1801e51764aSArtem Bityutskiy */ 1811e51764aSArtem Bityutskiy enum { 1821e51764aSArtem Bityutskiy UBIFS_KEY_HASH_R5, 1831e51764aSArtem Bityutskiy UBIFS_KEY_HASH_TEST, 1841e51764aSArtem Bityutskiy }; 1851e51764aSArtem Bityutskiy 1861e51764aSArtem Bityutskiy /* 1871e51764aSArtem Bityutskiy * Supported key formats. 1881e51764aSArtem Bityutskiy * 1891e51764aSArtem Bityutskiy * UBIFS_SIMPLE_KEY_FMT: simple key format 1901e51764aSArtem Bityutskiy */ 1911e51764aSArtem Bityutskiy enum { 1921e51764aSArtem Bityutskiy UBIFS_SIMPLE_KEY_FMT, 1931e51764aSArtem Bityutskiy }; 1941e51764aSArtem Bityutskiy 1951e51764aSArtem Bityutskiy /* 1961e51764aSArtem Bityutskiy * The simple key format uses 29 bits for storing UBIFS block number and hash 1971e51764aSArtem Bityutskiy * value. 1981e51764aSArtem Bityutskiy */ 1991e51764aSArtem Bityutskiy #define UBIFS_S_KEY_BLOCK_BITS 29 2001e51764aSArtem Bityutskiy #define UBIFS_S_KEY_BLOCK_MASK 0x1FFFFFFF 2011e51764aSArtem Bityutskiy #define UBIFS_S_KEY_HASH_BITS UBIFS_S_KEY_BLOCK_BITS 2021e51764aSArtem Bityutskiy #define UBIFS_S_KEY_HASH_MASK UBIFS_S_KEY_BLOCK_MASK 2031e51764aSArtem Bityutskiy 2041e51764aSArtem Bityutskiy /* 2051e51764aSArtem Bityutskiy * Key types. 2061e51764aSArtem Bityutskiy * 2071e51764aSArtem Bityutskiy * UBIFS_INO_KEY: inode node key 2081e51764aSArtem Bityutskiy * UBIFS_DATA_KEY: data node key 2091e51764aSArtem Bityutskiy * UBIFS_DENT_KEY: directory entry node key 2101e51764aSArtem Bityutskiy * UBIFS_XENT_KEY: extended attribute entry key 2111e51764aSArtem Bityutskiy * UBIFS_KEY_TYPES_CNT: number of supported key types 2121e51764aSArtem Bityutskiy */ 2131e51764aSArtem Bityutskiy enum { 2141e51764aSArtem Bityutskiy UBIFS_INO_KEY, 2151e51764aSArtem Bityutskiy UBIFS_DATA_KEY, 2161e51764aSArtem Bityutskiy UBIFS_DENT_KEY, 2171e51764aSArtem Bityutskiy UBIFS_XENT_KEY, 2181e51764aSArtem Bityutskiy UBIFS_KEY_TYPES_CNT, 2191e51764aSArtem Bityutskiy }; 2201e51764aSArtem Bityutskiy 2211e51764aSArtem Bityutskiy /* Count of LEBs reserved for the superblock area */ 2221e51764aSArtem Bityutskiy #define UBIFS_SB_LEBS 1 2231e51764aSArtem Bityutskiy /* Count of LEBs reserved for the master area */ 2241e51764aSArtem Bityutskiy #define UBIFS_MST_LEBS 2 2251e51764aSArtem Bityutskiy 2261e51764aSArtem Bityutskiy /* First LEB of the superblock area */ 2271e51764aSArtem Bityutskiy #define UBIFS_SB_LNUM 0 2281e51764aSArtem Bityutskiy /* First LEB of the master area */ 2291e51764aSArtem Bityutskiy #define UBIFS_MST_LNUM (UBIFS_SB_LNUM + UBIFS_SB_LEBS) 2301e51764aSArtem Bityutskiy /* First LEB of the log area */ 2311e51764aSArtem Bityutskiy #define UBIFS_LOG_LNUM (UBIFS_MST_LNUM + UBIFS_MST_LEBS) 2321e51764aSArtem Bityutskiy 2331e51764aSArtem Bityutskiy /* 2341e51764aSArtem Bityutskiy * The below constants define the absolute minimum values for various UBIFS 2351e51764aSArtem Bityutskiy * media areas. Many of them actually depend of flash geometry and the FS 2361e51764aSArtem Bityutskiy * configuration (number of journal heads, orphan LEBs, etc). This means that 2371e51764aSArtem Bityutskiy * the smallest volume size which can be used for UBIFS cannot be pre-defined 2381e51764aSArtem Bityutskiy * by these constants. The file-system that meets the below limitation will not 2391e51764aSArtem Bityutskiy * necessarily mount. UBIFS does run-time calculations and validates the FS 2401e51764aSArtem Bityutskiy * size. 2411e51764aSArtem Bityutskiy */ 2421e51764aSArtem Bityutskiy 2431e51764aSArtem Bityutskiy /* Minimum number of logical eraseblocks in the log */ 2441e51764aSArtem Bityutskiy #define UBIFS_MIN_LOG_LEBS 2 2451e51764aSArtem Bityutskiy /* Minimum number of bud logical eraseblocks (one for each head) */ 2461e51764aSArtem Bityutskiy #define UBIFS_MIN_BUD_LEBS 3 2471e51764aSArtem Bityutskiy /* Minimum number of journal logical eraseblocks */ 2481e51764aSArtem Bityutskiy #define UBIFS_MIN_JNL_LEBS (UBIFS_MIN_LOG_LEBS + UBIFS_MIN_BUD_LEBS) 2491e51764aSArtem Bityutskiy /* Minimum number of LPT area logical eraseblocks */ 2501e51764aSArtem Bityutskiy #define UBIFS_MIN_LPT_LEBS 2 2511e51764aSArtem Bityutskiy /* Minimum number of orphan area logical eraseblocks */ 2521e51764aSArtem Bityutskiy #define UBIFS_MIN_ORPH_LEBS 1 2531e51764aSArtem Bityutskiy /* 254b364b41aSArtem Bityutskiy * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1 2551e51764aSArtem Bityutskiy * for GC, 1 for deletions, and at least 1 for committed data). 2561e51764aSArtem Bityutskiy */ 257b364b41aSArtem Bityutskiy #define UBIFS_MIN_MAIN_LEBS (UBIFS_MIN_BUD_LEBS + 6) 2581e51764aSArtem Bityutskiy 2591e51764aSArtem Bityutskiy /* Minimum number of logical eraseblocks */ 2601e51764aSArtem Bityutskiy #define UBIFS_MIN_LEB_CNT (UBIFS_SB_LEBS + UBIFS_MST_LEBS + \ 2611e51764aSArtem Bityutskiy UBIFS_MIN_LOG_LEBS + UBIFS_MIN_LPT_LEBS + \ 2621e51764aSArtem Bityutskiy UBIFS_MIN_ORPH_LEBS + UBIFS_MIN_MAIN_LEBS) 2631e51764aSArtem Bityutskiy 2641e51764aSArtem Bityutskiy /* Node sizes (N.B. these are guaranteed to be multiples of 8) */ 2651e51764aSArtem Bityutskiy #define UBIFS_CH_SZ sizeof(struct ubifs_ch) 2661e51764aSArtem Bityutskiy #define UBIFS_INO_NODE_SZ sizeof(struct ubifs_ino_node) 2671e51764aSArtem Bityutskiy #define UBIFS_DATA_NODE_SZ sizeof(struct ubifs_data_node) 2681e51764aSArtem Bityutskiy #define UBIFS_DENT_NODE_SZ sizeof(struct ubifs_dent_node) 2691e51764aSArtem Bityutskiy #define UBIFS_TRUN_NODE_SZ sizeof(struct ubifs_trun_node) 2701e51764aSArtem Bityutskiy #define UBIFS_PAD_NODE_SZ sizeof(struct ubifs_pad_node) 2711e51764aSArtem Bityutskiy #define UBIFS_SB_NODE_SZ sizeof(struct ubifs_sb_node) 2721e51764aSArtem Bityutskiy #define UBIFS_MST_NODE_SZ sizeof(struct ubifs_mst_node) 2731e51764aSArtem Bityutskiy #define UBIFS_REF_NODE_SZ sizeof(struct ubifs_ref_node) 2741e51764aSArtem Bityutskiy #define UBIFS_IDX_NODE_SZ sizeof(struct ubifs_idx_node) 2751e51764aSArtem Bityutskiy #define UBIFS_CS_NODE_SZ sizeof(struct ubifs_cs_node) 2761e51764aSArtem Bityutskiy #define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node) 2775125cfdfSSascha Hauer #define UBIFS_AUTH_NODE_SZ sizeof(struct ubifs_auth_node) 278817aa094SSascha Hauer #define UBIFS_SIG_NODE_SZ sizeof(struct ubifs_sig_node) 279817aa094SSascha Hauer 2801e51764aSArtem Bityutskiy /* Extended attribute entry nodes are identical to directory entry nodes */ 2811e51764aSArtem Bityutskiy #define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ 2821e51764aSArtem Bityutskiy /* Only this does not have to be multiple of 8 bytes */ 2831e51764aSArtem Bityutskiy #define UBIFS_BRANCH_SZ sizeof(struct ubifs_branch) 2841e51764aSArtem Bityutskiy 2851e51764aSArtem Bityutskiy /* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */ 2861e51764aSArtem Bityutskiy #define UBIFS_MAX_DATA_NODE_SZ (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE) 2871e51764aSArtem Bityutskiy #define UBIFS_MAX_INO_NODE_SZ (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA) 2881e51764aSArtem Bityutskiy #define UBIFS_MAX_DENT_NODE_SZ (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1) 2891e51764aSArtem Bityutskiy #define UBIFS_MAX_XENT_NODE_SZ UBIFS_MAX_DENT_NODE_SZ 2901e51764aSArtem Bityutskiy 2911e51764aSArtem Bityutskiy /* The largest UBIFS node */ 2921e51764aSArtem Bityutskiy #define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ 2931e51764aSArtem Bityutskiy 2945125cfdfSSascha Hauer /* The maxmimum size of a hash, enough for sha512 */ 2955125cfdfSSascha Hauer #define UBIFS_MAX_HASH_LEN 64 2965125cfdfSSascha Hauer 2975125cfdfSSascha Hauer /* The maxmimum size of a hmac, enough for hmac(sha512) */ 2985125cfdfSSascha Hauer #define UBIFS_MAX_HMAC_LEN 64 2995125cfdfSSascha Hauer 3001e51764aSArtem Bityutskiy /* 3016a5e98abSRichard Weinberger * xattr name of UBIFS encryption context, we don't use a prefix 3026a5e98abSRichard Weinberger * nor a long name to not waste space on the flash. 3036a5e98abSRichard Weinberger */ 3046a5e98abSRichard Weinberger #define UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT "c" 3056a5e98abSRichard Weinberger 306817aa094SSascha Hauer /* Type field in ubifs_sig_node */ 307817aa094SSascha Hauer #define UBIFS_SIGNATURE_TYPE_PKCS7 1 3086a5e98abSRichard Weinberger 3096a5e98abSRichard Weinberger /* 3101e51764aSArtem Bityutskiy * On-flash inode flags. 3111e51764aSArtem Bityutskiy * 3121e51764aSArtem Bityutskiy * UBIFS_COMPR_FL: use compression for this inode 3131e51764aSArtem Bityutskiy * UBIFS_SYNC_FL: I/O on this inode has to be synchronous 3141e51764aSArtem Bityutskiy * UBIFS_IMMUTABLE_FL: inode is immutable 3151e51764aSArtem Bityutskiy * UBIFS_APPEND_FL: writes to the inode may only append data 3161e51764aSArtem Bityutskiy * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous 3171e51764aSArtem Bityutskiy * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value 318d475a507SRichard Weinberger * UBIFS_CRYPT_FL: use encryption for this inode 3191e51764aSArtem Bityutskiy * 3201e51764aSArtem Bityutskiy * Note, these are on-flash flags which correspond to ioctl flags 3211e51764aSArtem Bityutskiy * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not 3221e51764aSArtem Bityutskiy * have to be the same. 3231e51764aSArtem Bityutskiy */ 3241e51764aSArtem Bityutskiy enum { 3251e51764aSArtem Bityutskiy UBIFS_COMPR_FL = 0x01, 3261e51764aSArtem Bityutskiy UBIFS_SYNC_FL = 0x02, 3271e51764aSArtem Bityutskiy UBIFS_IMMUTABLE_FL = 0x04, 3281e51764aSArtem Bityutskiy UBIFS_APPEND_FL = 0x08, 3291e51764aSArtem Bityutskiy UBIFS_DIRSYNC_FL = 0x10, 3301e51764aSArtem Bityutskiy UBIFS_XATTR_FL = 0x20, 331d475a507SRichard Weinberger UBIFS_CRYPT_FL = 0x40, 3321e51764aSArtem Bityutskiy }; 3331e51764aSArtem Bityutskiy 3341e51764aSArtem Bityutskiy /* Inode flag bits used by UBIFS */ 3351e51764aSArtem Bityutskiy #define UBIFS_FL_MASK 0x0000001F 3361e51764aSArtem Bityutskiy 3371e51764aSArtem Bityutskiy /* 3381e51764aSArtem Bityutskiy * UBIFS compression algorithms. 3391e51764aSArtem Bityutskiy * 3401e51764aSArtem Bityutskiy * UBIFS_COMPR_NONE: no compression 3411e51764aSArtem Bityutskiy * UBIFS_COMPR_LZO: LZO compression 3421e51764aSArtem Bityutskiy * UBIFS_COMPR_ZLIB: ZLIB compression 343*eeabb986SMichele Dionisio * UBIFS_COMPR_ZSTD: ZSTD compression 3441e51764aSArtem Bityutskiy * UBIFS_COMPR_TYPES_CNT: count of supported compression types 3451e51764aSArtem Bityutskiy */ 3461e51764aSArtem Bityutskiy enum { 3471e51764aSArtem Bityutskiy UBIFS_COMPR_NONE, 3481e51764aSArtem Bityutskiy UBIFS_COMPR_LZO, 3491e51764aSArtem Bityutskiy UBIFS_COMPR_ZLIB, 350*eeabb986SMichele Dionisio UBIFS_COMPR_ZSTD, 3511e51764aSArtem Bityutskiy UBIFS_COMPR_TYPES_CNT, 3521e51764aSArtem Bityutskiy }; 3531e51764aSArtem Bityutskiy 3541e51764aSArtem Bityutskiy /* 3551e51764aSArtem Bityutskiy * UBIFS node types. 3561e51764aSArtem Bityutskiy * 3571e51764aSArtem Bityutskiy * UBIFS_INO_NODE: inode node 3581e51764aSArtem Bityutskiy * UBIFS_DATA_NODE: data node 3591e51764aSArtem Bityutskiy * UBIFS_DENT_NODE: directory entry node 3601e51764aSArtem Bityutskiy * UBIFS_XENT_NODE: extended attribute node 3611e51764aSArtem Bityutskiy * UBIFS_TRUN_NODE: truncation node 3621e51764aSArtem Bityutskiy * UBIFS_PAD_NODE: padding node 3631e51764aSArtem Bityutskiy * UBIFS_SB_NODE: superblock node 3641e51764aSArtem Bityutskiy * UBIFS_MST_NODE: master node 3651e51764aSArtem Bityutskiy * UBIFS_REF_NODE: LEB reference node 3661e51764aSArtem Bityutskiy * UBIFS_IDX_NODE: index node 3671e51764aSArtem Bityutskiy * UBIFS_CS_NODE: commit start node 3681e51764aSArtem Bityutskiy * UBIFS_ORPH_NODE: orphan node 3695125cfdfSSascha Hauer * UBIFS_AUTH_NODE: authentication node 370817aa094SSascha Hauer * UBIFS_SIG_NODE: signature node 3711e51764aSArtem Bityutskiy * UBIFS_NODE_TYPES_CNT: count of supported node types 3721e51764aSArtem Bityutskiy * 3731e51764aSArtem Bityutskiy * Note, we index arrays by these numbers, so keep them low and contiguous. 3741e51764aSArtem Bityutskiy * Node type constants for inodes, direntries and so on have to be the same as 3751e51764aSArtem Bityutskiy * corresponding key type constants. 3761e51764aSArtem Bityutskiy */ 3771e51764aSArtem Bityutskiy enum { 3781e51764aSArtem Bityutskiy UBIFS_INO_NODE, 3791e51764aSArtem Bityutskiy UBIFS_DATA_NODE, 3801e51764aSArtem Bityutskiy UBIFS_DENT_NODE, 3811e51764aSArtem Bityutskiy UBIFS_XENT_NODE, 3821e51764aSArtem Bityutskiy UBIFS_TRUN_NODE, 3831e51764aSArtem Bityutskiy UBIFS_PAD_NODE, 3841e51764aSArtem Bityutskiy UBIFS_SB_NODE, 3851e51764aSArtem Bityutskiy UBIFS_MST_NODE, 3861e51764aSArtem Bityutskiy UBIFS_REF_NODE, 3871e51764aSArtem Bityutskiy UBIFS_IDX_NODE, 3881e51764aSArtem Bityutskiy UBIFS_CS_NODE, 3891e51764aSArtem Bityutskiy UBIFS_ORPH_NODE, 3905125cfdfSSascha Hauer UBIFS_AUTH_NODE, 391817aa094SSascha Hauer UBIFS_SIG_NODE, 3921e51764aSArtem Bityutskiy UBIFS_NODE_TYPES_CNT, 3931e51764aSArtem Bityutskiy }; 3941e51764aSArtem Bityutskiy 3951e51764aSArtem Bityutskiy /* 3961e51764aSArtem Bityutskiy * Master node flags. 3971e51764aSArtem Bityutskiy * 3981e51764aSArtem Bityutskiy * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty 3991e51764aSArtem Bityutskiy * UBIFS_MST_NO_ORPHS: no orphan inodes present 4001e51764aSArtem Bityutskiy * UBIFS_MST_RCVRY: written by recovery 4011e51764aSArtem Bityutskiy */ 4021e51764aSArtem Bityutskiy enum { 4031e51764aSArtem Bityutskiy UBIFS_MST_DIRTY = 1, 4041e51764aSArtem Bityutskiy UBIFS_MST_NO_ORPHS = 2, 4051e51764aSArtem Bityutskiy UBIFS_MST_RCVRY = 4, 4061e51764aSArtem Bityutskiy }; 4071e51764aSArtem Bityutskiy 4081e51764aSArtem Bityutskiy /* 4091e51764aSArtem Bityutskiy * Node group type (used by recovery to recover whole group or none). 4101e51764aSArtem Bityutskiy * 4111e51764aSArtem Bityutskiy * UBIFS_NO_NODE_GROUP: this node is not part of a group 4121e51764aSArtem Bityutskiy * UBIFS_IN_NODE_GROUP: this node is a part of a group 4131e51764aSArtem Bityutskiy * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group 4141e51764aSArtem Bityutskiy */ 4151e51764aSArtem Bityutskiy enum { 4161e51764aSArtem Bityutskiy UBIFS_NO_NODE_GROUP = 0, 4171e51764aSArtem Bityutskiy UBIFS_IN_NODE_GROUP, 4181e51764aSArtem Bityutskiy UBIFS_LAST_OF_NODE_GROUP, 4191e51764aSArtem Bityutskiy }; 4201e51764aSArtem Bityutskiy 4211e51764aSArtem Bityutskiy /* 4221e51764aSArtem Bityutskiy * Superblock flags. 4231e51764aSArtem Bityutskiy * 4241e51764aSArtem Bityutskiy * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set 4259f58d350SMatthew L. Creech * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed 426d63d61c1SRichard Weinberger * UBIFS_FLG_DOUBLE_HASH: store a 32bit cookie in directory entry nodes to 427d63d61c1SRichard Weinberger * support 64bit cookies for lookups by hash 428e021986eSRichard Weinberger * UBIFS_FLG_ENCRYPTION: this filesystem contains encrypted files 4295125cfdfSSascha Hauer * UBIFS_FLG_AUTHENTICATION: this filesystem contains hashes for authentication 4301e51764aSArtem Bityutskiy */ 4311e51764aSArtem Bityutskiy enum { 4321e51764aSArtem Bityutskiy UBIFS_FLG_BIGLPT = 0x02, 4339f58d350SMatthew L. Creech UBIFS_FLG_SPACE_FIXUP = 0x04, 434d63d61c1SRichard Weinberger UBIFS_FLG_DOUBLE_HASH = 0x08, 435e021986eSRichard Weinberger UBIFS_FLG_ENCRYPTION = 0x10, 4365125cfdfSSascha Hauer UBIFS_FLG_AUTHENTICATION = 0x20, 4371e51764aSArtem Bityutskiy }; 4381e51764aSArtem Bityutskiy 4395125cfdfSSascha Hauer #define UBIFS_FLG_MASK (UBIFS_FLG_BIGLPT | UBIFS_FLG_SPACE_FIXUP | \ 4405125cfdfSSascha Hauer UBIFS_FLG_DOUBLE_HASH | UBIFS_FLG_ENCRYPTION | \ 4415125cfdfSSascha Hauer UBIFS_FLG_AUTHENTICATION) 442fc4b891bSRichard Weinberger 4431e51764aSArtem Bityutskiy /** 4441e51764aSArtem Bityutskiy * struct ubifs_ch - common header node. 4451e51764aSArtem Bityutskiy * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC) 4461e51764aSArtem Bityutskiy * @crc: CRC-32 checksum of the node header 4471e51764aSArtem Bityutskiy * @sqnum: sequence number 4481e51764aSArtem Bityutskiy * @len: full node length 4491e51764aSArtem Bityutskiy * @node_type: node type 4501e51764aSArtem Bityutskiy * @group_type: node group type 4511e51764aSArtem Bityutskiy * @padding: reserved for future, zeroes 4521e51764aSArtem Bityutskiy * 4531e51764aSArtem Bityutskiy * Every UBIFS node starts with this common part. If the node has a key, the 4541e51764aSArtem Bityutskiy * key always goes next. 4551e51764aSArtem Bityutskiy */ 4561e51764aSArtem Bityutskiy struct ubifs_ch { 4571e51764aSArtem Bityutskiy __le32 magic; 4581e51764aSArtem Bityutskiy __le32 crc; 4591e51764aSArtem Bityutskiy __le64 sqnum; 4601e51764aSArtem Bityutskiy __le32 len; 4611e51764aSArtem Bityutskiy __u8 node_type; 4621e51764aSArtem Bityutskiy __u8 group_type; 4631e51764aSArtem Bityutskiy __u8 padding[2]; 464cc64f774SArtem Bityutskiy } __packed; 4651e51764aSArtem Bityutskiy 4661e51764aSArtem Bityutskiy /** 4671e51764aSArtem Bityutskiy * union ubifs_dev_desc - device node descriptor. 4681e51764aSArtem Bityutskiy * @new: new type device descriptor 4691e51764aSArtem Bityutskiy * @huge: huge type device descriptor 4701e51764aSArtem Bityutskiy * 4711e51764aSArtem Bityutskiy * This data structure describes major/minor numbers of a device node. In an 4721e51764aSArtem Bityutskiy * inode is a device node then its data contains an object of this type. UBIFS 4731e51764aSArtem Bityutskiy * uses standard Linux "new" and "huge" device node encodings. 4741e51764aSArtem Bityutskiy */ 4751e51764aSArtem Bityutskiy union ubifs_dev_desc { 4761e51764aSArtem Bityutskiy __le32 new; 4771e51764aSArtem Bityutskiy __le64 huge; 478cc64f774SArtem Bityutskiy } __packed; 4791e51764aSArtem Bityutskiy 4801e51764aSArtem Bityutskiy /** 4811e51764aSArtem Bityutskiy * struct ubifs_ino_node - inode node. 4821e51764aSArtem Bityutskiy * @ch: common header 4831e51764aSArtem Bityutskiy * @key: node key 4841e51764aSArtem Bityutskiy * @creat_sqnum: sequence number at time of creation 4851e51764aSArtem Bityutskiy * @size: inode size in bytes (amount of uncompressed data) 4861e51764aSArtem Bityutskiy * @atime_sec: access time seconds 4871e51764aSArtem Bityutskiy * @ctime_sec: creation time seconds 4881e51764aSArtem Bityutskiy * @mtime_sec: modification time seconds 4891e51764aSArtem Bityutskiy * @atime_nsec: access time nanoseconds 4901e51764aSArtem Bityutskiy * @ctime_nsec: creation time nanoseconds 4911e51764aSArtem Bityutskiy * @mtime_nsec: modification time nanoseconds 4921e51764aSArtem Bityutskiy * @nlink: number of hard links 4931e51764aSArtem Bityutskiy * @uid: owner ID 4941e51764aSArtem Bityutskiy * @gid: group ID 4951e51764aSArtem Bityutskiy * @mode: access flags 4961e51764aSArtem Bityutskiy * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc) 4971e51764aSArtem Bityutskiy * @data_len: inode data length 4981e51764aSArtem Bityutskiy * @xattr_cnt: count of extended attributes this inode has 4991e51764aSArtem Bityutskiy * @xattr_size: summarized size of all extended attributes in bytes 5001e51764aSArtem Bityutskiy * @padding1: reserved for future, zeroes 5011e51764aSArtem Bityutskiy * @xattr_names: sum of lengths of all extended attribute names belonging to 5021e51764aSArtem Bityutskiy * this inode 5031e51764aSArtem Bityutskiy * @compr_type: compression type used for this inode 5041e51764aSArtem Bityutskiy * @padding2: reserved for future, zeroes 5051e51764aSArtem Bityutskiy * @data: data attached to the inode 5061e51764aSArtem Bityutskiy * 5071e51764aSArtem Bityutskiy * Note, even though inode compression type is defined by @compr_type, some 5081e51764aSArtem Bityutskiy * nodes of this inode may be compressed with different compressor - this 5091e51764aSArtem Bityutskiy * happens if compression type is changed while the inode already has data 5101e51764aSArtem Bityutskiy * nodes. But @compr_type will be use for further writes to the inode. 5111e51764aSArtem Bityutskiy * 5121e51764aSArtem Bityutskiy * Note, do not forget to amend 'zero_ino_node_unused()' function when changing 5131e51764aSArtem Bityutskiy * the padding fields. 5141e51764aSArtem Bityutskiy */ 5151e51764aSArtem Bityutskiy struct ubifs_ino_node { 5161e51764aSArtem Bityutskiy struct ubifs_ch ch; 5171e51764aSArtem Bityutskiy __u8 key[UBIFS_MAX_KEY_LEN]; 5181e51764aSArtem Bityutskiy __le64 creat_sqnum; 5191e51764aSArtem Bityutskiy __le64 size; 5201e51764aSArtem Bityutskiy __le64 atime_sec; 5211e51764aSArtem Bityutskiy __le64 ctime_sec; 5221e51764aSArtem Bityutskiy __le64 mtime_sec; 5231e51764aSArtem Bityutskiy __le32 atime_nsec; 5241e51764aSArtem Bityutskiy __le32 ctime_nsec; 5251e51764aSArtem Bityutskiy __le32 mtime_nsec; 5261e51764aSArtem Bityutskiy __le32 nlink; 5271e51764aSArtem Bityutskiy __le32 uid; 5281e51764aSArtem Bityutskiy __le32 gid; 5291e51764aSArtem Bityutskiy __le32 mode; 5301e51764aSArtem Bityutskiy __le32 flags; 5311e51764aSArtem Bityutskiy __le32 data_len; 5321e51764aSArtem Bityutskiy __le32 xattr_cnt; 5331e51764aSArtem Bityutskiy __le32 xattr_size; 5341e51764aSArtem Bityutskiy __u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */ 5351e51764aSArtem Bityutskiy __le32 xattr_names; 5361e51764aSArtem Bityutskiy __le16 compr_type; 5371e51764aSArtem Bityutskiy __u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */ 5381e51764aSArtem Bityutskiy __u8 data[]; 539cc64f774SArtem Bityutskiy } __packed; 5401e51764aSArtem Bityutskiy 5411e51764aSArtem Bityutskiy /** 5421e51764aSArtem Bityutskiy * struct ubifs_dent_node - directory entry node. 5431e51764aSArtem Bityutskiy * @ch: common header 5441e51764aSArtem Bityutskiy * @key: node key 5451e51764aSArtem Bityutskiy * @inum: target inode number 5461e51764aSArtem Bityutskiy * @padding1: reserved for future, zeroes 5471e51764aSArtem Bityutskiy * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc) 5481e51764aSArtem Bityutskiy * @nlen: name length 549528e3d17SRichard Weinberger * @cookie: A 32bits random number, used to construct a 64bits 550528e3d17SRichard Weinberger * identifier. 5511e51764aSArtem Bityutskiy * @name: zero-terminated name 5521e51764aSArtem Bityutskiy * 5531e51764aSArtem Bityutskiy * Note, do not forget to amend 'zero_dent_node_unused()' function when 5541e51764aSArtem Bityutskiy * changing the padding fields. 5551e51764aSArtem Bityutskiy */ 5561e51764aSArtem Bityutskiy struct ubifs_dent_node { 5571e51764aSArtem Bityutskiy struct ubifs_ch ch; 5581e51764aSArtem Bityutskiy __u8 key[UBIFS_MAX_KEY_LEN]; 5591e51764aSArtem Bityutskiy __le64 inum; 5601e51764aSArtem Bityutskiy __u8 padding1; 5611e51764aSArtem Bityutskiy __u8 type; 5621e51764aSArtem Bityutskiy __le16 nlen; 563528e3d17SRichard Weinberger __le32 cookie; 5641e51764aSArtem Bityutskiy __u8 name[]; 565cc64f774SArtem Bityutskiy } __packed; 5661e51764aSArtem Bityutskiy 5671e51764aSArtem Bityutskiy /** 5681e51764aSArtem Bityutskiy * struct ubifs_data_node - data node. 5691e51764aSArtem Bityutskiy * @ch: common header 5701e51764aSArtem Bityutskiy * @key: node key 5711e51764aSArtem Bityutskiy * @size: uncompressed data size in bytes 5721e51764aSArtem Bityutskiy * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc) 573f1f52d6bSRichard Weinberger * @compr_size: compressed data size in bytes, only valid when data is encrypted 5741e51764aSArtem Bityutskiy * @data: data 5751e51764aSArtem Bityutskiy * 5761e51764aSArtem Bityutskiy */ 5771e51764aSArtem Bityutskiy struct ubifs_data_node { 5781e51764aSArtem Bityutskiy struct ubifs_ch ch; 5791e51764aSArtem Bityutskiy __u8 key[UBIFS_MAX_KEY_LEN]; 5801e51764aSArtem Bityutskiy __le32 size; 5811e51764aSArtem Bityutskiy __le16 compr_type; 582f1f52d6bSRichard Weinberger __le16 compr_size; 5831e51764aSArtem Bityutskiy __u8 data[]; 584cc64f774SArtem Bityutskiy } __packed; 5851e51764aSArtem Bityutskiy 5861e51764aSArtem Bityutskiy /** 5871e51764aSArtem Bityutskiy * struct ubifs_trun_node - truncation node. 5881e51764aSArtem Bityutskiy * @ch: common header 5891e51764aSArtem Bityutskiy * @inum: truncated inode number 5901e51764aSArtem Bityutskiy * @padding: reserved for future, zeroes 5911e51764aSArtem Bityutskiy * @old_size: size before truncation 5921e51764aSArtem Bityutskiy * @new_size: size after truncation 5931e51764aSArtem Bityutskiy * 5941e51764aSArtem Bityutskiy * This node exists only in the journal and never goes to the main area. Note, 5951e51764aSArtem Bityutskiy * do not forget to amend 'zero_trun_node_unused()' function when changing the 5961e51764aSArtem Bityutskiy * padding fields. 5971e51764aSArtem Bityutskiy */ 5981e51764aSArtem Bityutskiy struct ubifs_trun_node { 5991e51764aSArtem Bityutskiy struct ubifs_ch ch; 6001e51764aSArtem Bityutskiy __le32 inum; 6011e51764aSArtem Bityutskiy __u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */ 6021e51764aSArtem Bityutskiy __le64 old_size; 6031e51764aSArtem Bityutskiy __le64 new_size; 604cc64f774SArtem Bityutskiy } __packed; 6051e51764aSArtem Bityutskiy 6061e51764aSArtem Bityutskiy /** 6071e51764aSArtem Bityutskiy * struct ubifs_pad_node - padding node. 6081e51764aSArtem Bityutskiy * @ch: common header 6091e51764aSArtem Bityutskiy * @pad_len: how many bytes after this node are unused (because padded) 6101e51764aSArtem Bityutskiy * @padding: reserved for future, zeroes 6111e51764aSArtem Bityutskiy */ 6121e51764aSArtem Bityutskiy struct ubifs_pad_node { 6131e51764aSArtem Bityutskiy struct ubifs_ch ch; 6141e51764aSArtem Bityutskiy __le32 pad_len; 615cc64f774SArtem Bityutskiy } __packed; 6161e51764aSArtem Bityutskiy 6171e51764aSArtem Bityutskiy /** 6181e51764aSArtem Bityutskiy * struct ubifs_sb_node - superblock node. 6191e51764aSArtem Bityutskiy * @ch: common header 6201e51764aSArtem Bityutskiy * @padding: reserved for future, zeroes 6211e51764aSArtem Bityutskiy * @key_hash: type of hash function used in keys 6221e51764aSArtem Bityutskiy * @key_fmt: format of the key 6231e51764aSArtem Bityutskiy * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc) 6241e51764aSArtem Bityutskiy * @min_io_size: minimal input/output unit size 6251e51764aSArtem Bityutskiy * @leb_size: logical eraseblock size in bytes 6261e51764aSArtem Bityutskiy * @leb_cnt: count of LEBs used by file-system 6271e51764aSArtem Bityutskiy * @max_leb_cnt: maximum count of LEBs used by file-system 6281e51764aSArtem Bityutskiy * @max_bud_bytes: maximum amount of data stored in buds 6291e51764aSArtem Bityutskiy * @log_lebs: log size in logical eraseblocks 6301e51764aSArtem Bityutskiy * @lpt_lebs: number of LEBs used for lprops table 6311e51764aSArtem Bityutskiy * @orph_lebs: number of LEBs used for recording orphans 6321e51764aSArtem Bityutskiy * @jhead_cnt: count of journal heads 6331e51764aSArtem Bityutskiy * @fanout: tree fanout (max. number of links per indexing node) 6341e51764aSArtem Bityutskiy * @lsave_cnt: number of LEB numbers in LPT's save table 6351e51764aSArtem Bityutskiy * @fmt_version: UBIFS on-flash format version 6361e51764aSArtem Bityutskiy * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) 6371e51764aSArtem Bityutskiy * @padding1: reserved for future, zeroes 6381e51764aSArtem Bityutskiy * @rp_uid: reserve pool UID 6391e51764aSArtem Bityutskiy * @rp_gid: reserve pool GID 6401e51764aSArtem Bityutskiy * @rp_size: size of the reserved pool in bytes 6411e51764aSArtem Bityutskiy * @padding2: reserved for future, zeroes 6421e51764aSArtem Bityutskiy * @time_gran: time granularity in nanoseconds 6431e51764aSArtem Bityutskiy * @uuid: UUID generated when the file system image was created 644963f0cf6SArtem Bityutskiy * @ro_compat_version: UBIFS R/O compatibility version 6455125cfdfSSascha Hauer * @hmac: HMAC to authenticate the superblock node 6465125cfdfSSascha Hauer * @hmac_wkm: HMAC of a well known message (the string "UBIFS") as a convenience 6475125cfdfSSascha Hauer * to the user to check if the correct key is passed. 6485125cfdfSSascha Hauer * @hash_algo: The hash algo used for this filesystem (one of enum hash_algo) 649817aa094SSascha Hauer * @hash_mst: hash of the master node, only valid for signed images in which the 650817aa094SSascha Hauer * master node does not contain a hmac 6511e51764aSArtem Bityutskiy */ 6521e51764aSArtem Bityutskiy struct ubifs_sb_node { 6531e51764aSArtem Bityutskiy struct ubifs_ch ch; 6541e51764aSArtem Bityutskiy __u8 padding[2]; 6551e51764aSArtem Bityutskiy __u8 key_hash; 6561e51764aSArtem Bityutskiy __u8 key_fmt; 6571e51764aSArtem Bityutskiy __le32 flags; 6581e51764aSArtem Bityutskiy __le32 min_io_size; 6591e51764aSArtem Bityutskiy __le32 leb_size; 6601e51764aSArtem Bityutskiy __le32 leb_cnt; 6611e51764aSArtem Bityutskiy __le32 max_leb_cnt; 6621e51764aSArtem Bityutskiy __le64 max_bud_bytes; 6631e51764aSArtem Bityutskiy __le32 log_lebs; 6641e51764aSArtem Bityutskiy __le32 lpt_lebs; 6651e51764aSArtem Bityutskiy __le32 orph_lebs; 6661e51764aSArtem Bityutskiy __le32 jhead_cnt; 6671e51764aSArtem Bityutskiy __le32 fanout; 6681e51764aSArtem Bityutskiy __le32 lsave_cnt; 6691e51764aSArtem Bityutskiy __le32 fmt_version; 6701e51764aSArtem Bityutskiy __le16 default_compr; 6711e51764aSArtem Bityutskiy __u8 padding1[2]; 6721e51764aSArtem Bityutskiy __le32 rp_uid; 6731e51764aSArtem Bityutskiy __le32 rp_gid; 6741e51764aSArtem Bityutskiy __le64 rp_size; 6751e51764aSArtem Bityutskiy __le32 time_gran; 6761e51764aSArtem Bityutskiy __u8 uuid[16]; 677963f0cf6SArtem Bityutskiy __le32 ro_compat_version; 6785125cfdfSSascha Hauer __u8 hmac[UBIFS_MAX_HMAC_LEN]; 6795125cfdfSSascha Hauer __u8 hmac_wkm[UBIFS_MAX_HMAC_LEN]; 6805125cfdfSSascha Hauer __le16 hash_algo; 681817aa094SSascha Hauer __u8 hash_mst[UBIFS_MAX_HASH_LEN]; 682817aa094SSascha Hauer __u8 padding2[3774]; 683cc64f774SArtem Bityutskiy } __packed; 6841e51764aSArtem Bityutskiy 6851e51764aSArtem Bityutskiy /** 6861e51764aSArtem Bityutskiy * struct ubifs_mst_node - master node. 6871e51764aSArtem Bityutskiy * @ch: common header 6881e51764aSArtem Bityutskiy * @highest_inum: highest inode number in the committed index 6891e51764aSArtem Bityutskiy * @cmt_no: commit number 6901e51764aSArtem Bityutskiy * @flags: various flags (%UBIFS_MST_DIRTY, etc) 6911e51764aSArtem Bityutskiy * @log_lnum: start of the log 6921e51764aSArtem Bityutskiy * @root_lnum: LEB number of the root indexing node 6931e51764aSArtem Bityutskiy * @root_offs: offset within @root_lnum 6941e51764aSArtem Bityutskiy * @root_len: root indexing node length 6951e51764aSArtem Bityutskiy * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was 6961e51764aSArtem Bityutskiy * not reserved and should be reserved on mount) 6971e51764aSArtem Bityutskiy * @ihead_lnum: LEB number of index head 6981e51764aSArtem Bityutskiy * @ihead_offs: offset of index head 6991e51764aSArtem Bityutskiy * @index_size: size of index on flash 7001e51764aSArtem Bityutskiy * @total_free: total free space in bytes 7011e51764aSArtem Bityutskiy * @total_dirty: total dirty space in bytes 7021e51764aSArtem Bityutskiy * @total_used: total used space in bytes (includes only data LEBs) 7031e51764aSArtem Bityutskiy * @total_dead: total dead space in bytes (includes only data LEBs) 7041e51764aSArtem Bityutskiy * @total_dark: total dark space in bytes (includes only data LEBs) 7051e51764aSArtem Bityutskiy * @lpt_lnum: LEB number of LPT root nnode 7061e51764aSArtem Bityutskiy * @lpt_offs: offset of LPT root nnode 7071e51764aSArtem Bityutskiy * @nhead_lnum: LEB number of LPT head 7081e51764aSArtem Bityutskiy * @nhead_offs: offset of LPT head 7091e51764aSArtem Bityutskiy * @ltab_lnum: LEB number of LPT's own lprops table 7101e51764aSArtem Bityutskiy * @ltab_offs: offset of LPT's own lprops table 7111e51764aSArtem Bityutskiy * @lsave_lnum: LEB number of LPT's save table (big model only) 7121e51764aSArtem Bityutskiy * @lsave_offs: offset of LPT's save table (big model only) 7131e51764aSArtem Bityutskiy * @lscan_lnum: LEB number of last LPT scan 7141e51764aSArtem Bityutskiy * @empty_lebs: number of empty logical eraseblocks 7151e51764aSArtem Bityutskiy * @idx_lebs: number of indexing logical eraseblocks 7161e51764aSArtem Bityutskiy * @leb_cnt: count of LEBs used by file-system 7175125cfdfSSascha Hauer * @hash_root_idx: the hash of the root index node 7185125cfdfSSascha Hauer * @hash_lpt: the hash of the LPT 7195125cfdfSSascha Hauer * @hmac: HMAC to authenticate the master node 7201e51764aSArtem Bityutskiy * @padding: reserved for future, zeroes 7211e51764aSArtem Bityutskiy */ 7221e51764aSArtem Bityutskiy struct ubifs_mst_node { 7231e51764aSArtem Bityutskiy struct ubifs_ch ch; 7241e51764aSArtem Bityutskiy __le64 highest_inum; 7251e51764aSArtem Bityutskiy __le64 cmt_no; 7261e51764aSArtem Bityutskiy __le32 flags; 7271e51764aSArtem Bityutskiy __le32 log_lnum; 7281e51764aSArtem Bityutskiy __le32 root_lnum; 7291e51764aSArtem Bityutskiy __le32 root_offs; 7301e51764aSArtem Bityutskiy __le32 root_len; 7311e51764aSArtem Bityutskiy __le32 gc_lnum; 7321e51764aSArtem Bityutskiy __le32 ihead_lnum; 7331e51764aSArtem Bityutskiy __le32 ihead_offs; 7341e51764aSArtem Bityutskiy __le64 index_size; 7351e51764aSArtem Bityutskiy __le64 total_free; 7361e51764aSArtem Bityutskiy __le64 total_dirty; 7371e51764aSArtem Bityutskiy __le64 total_used; 7381e51764aSArtem Bityutskiy __le64 total_dead; 7391e51764aSArtem Bityutskiy __le64 total_dark; 7401e51764aSArtem Bityutskiy __le32 lpt_lnum; 7411e51764aSArtem Bityutskiy __le32 lpt_offs; 7421e51764aSArtem Bityutskiy __le32 nhead_lnum; 7431e51764aSArtem Bityutskiy __le32 nhead_offs; 7441e51764aSArtem Bityutskiy __le32 ltab_lnum; 7451e51764aSArtem Bityutskiy __le32 ltab_offs; 7461e51764aSArtem Bityutskiy __le32 lsave_lnum; 7471e51764aSArtem Bityutskiy __le32 lsave_offs; 7481e51764aSArtem Bityutskiy __le32 lscan_lnum; 7491e51764aSArtem Bityutskiy __le32 empty_lebs; 7501e51764aSArtem Bityutskiy __le32 idx_lebs; 7511e51764aSArtem Bityutskiy __le32 leb_cnt; 7525125cfdfSSascha Hauer __u8 hash_root_idx[UBIFS_MAX_HASH_LEN]; 7535125cfdfSSascha Hauer __u8 hash_lpt[UBIFS_MAX_HASH_LEN]; 7545125cfdfSSascha Hauer __u8 hmac[UBIFS_MAX_HMAC_LEN]; 7555125cfdfSSascha Hauer __u8 padding[152]; 756cc64f774SArtem Bityutskiy } __packed; 7571e51764aSArtem Bityutskiy 7581e51764aSArtem Bityutskiy /** 7591e51764aSArtem Bityutskiy * struct ubifs_ref_node - logical eraseblock reference node. 7601e51764aSArtem Bityutskiy * @ch: common header 7611e51764aSArtem Bityutskiy * @lnum: the referred logical eraseblock number 7621e51764aSArtem Bityutskiy * @offs: start offset in the referred LEB 7631e51764aSArtem Bityutskiy * @jhead: journal head number 7641e51764aSArtem Bityutskiy * @padding: reserved for future, zeroes 7651e51764aSArtem Bityutskiy */ 7661e51764aSArtem Bityutskiy struct ubifs_ref_node { 7671e51764aSArtem Bityutskiy struct ubifs_ch ch; 7681e51764aSArtem Bityutskiy __le32 lnum; 7691e51764aSArtem Bityutskiy __le32 offs; 7701e51764aSArtem Bityutskiy __le32 jhead; 7711e51764aSArtem Bityutskiy __u8 padding[28]; 772cc64f774SArtem Bityutskiy } __packed; 7731e51764aSArtem Bityutskiy 7741e51764aSArtem Bityutskiy /** 7755125cfdfSSascha Hauer * struct ubifs_auth_node - node for authenticating other nodes 7765125cfdfSSascha Hauer * @ch: common header 7775125cfdfSSascha Hauer * @hmac: The HMAC 7785125cfdfSSascha Hauer */ 7795125cfdfSSascha Hauer struct ubifs_auth_node { 7805125cfdfSSascha Hauer struct ubifs_ch ch; 7815125cfdfSSascha Hauer __u8 hmac[]; 7825125cfdfSSascha Hauer } __packed; 7835125cfdfSSascha Hauer 7845125cfdfSSascha Hauer /** 785817aa094SSascha Hauer * struct ubifs_sig_node - node for signing other nodes 786817aa094SSascha Hauer * @ch: common header 787817aa094SSascha Hauer * @type: type of the signature, currently only UBIFS_SIGNATURE_TYPE_PKCS7 788817aa094SSascha Hauer * supported 789817aa094SSascha Hauer * @len: The length of the signature data 790817aa094SSascha Hauer * @padding: reserved for future, zeroes 791817aa094SSascha Hauer * @sig: The signature data 792817aa094SSascha Hauer */ 793817aa094SSascha Hauer struct ubifs_sig_node { 794817aa094SSascha Hauer struct ubifs_ch ch; 795817aa094SSascha Hauer __le32 type; 796817aa094SSascha Hauer __le32 len; 797817aa094SSascha Hauer __u8 padding[32]; 798817aa094SSascha Hauer __u8 sig[]; 799817aa094SSascha Hauer } __packed; 800817aa094SSascha Hauer 801817aa094SSascha Hauer /** 8021e51764aSArtem Bityutskiy * struct ubifs_branch - key/reference/length branch 8031e51764aSArtem Bityutskiy * @lnum: LEB number of the target node 8041e51764aSArtem Bityutskiy * @offs: offset within @lnum 8051e51764aSArtem Bityutskiy * @len: target node length 8061e51764aSArtem Bityutskiy * @key: key 8075125cfdfSSascha Hauer * 8085125cfdfSSascha Hauer * In an authenticated UBIFS we have the hash of the referenced node after @key. 8095125cfdfSSascha Hauer * This can't be added to the struct type definition because @key is a 8105125cfdfSSascha Hauer * dynamically sized element already. 8111e51764aSArtem Bityutskiy */ 8121e51764aSArtem Bityutskiy struct ubifs_branch { 8131e51764aSArtem Bityutskiy __le32 lnum; 8141e51764aSArtem Bityutskiy __le32 offs; 8151e51764aSArtem Bityutskiy __le32 len; 8161e51764aSArtem Bityutskiy __u8 key[]; 817cc64f774SArtem Bityutskiy } __packed; 8181e51764aSArtem Bityutskiy 8191e51764aSArtem Bityutskiy /** 8201e51764aSArtem Bityutskiy * struct ubifs_idx_node - indexing node. 8211e51764aSArtem Bityutskiy * @ch: common header 8221e51764aSArtem Bityutskiy * @child_cnt: number of child index nodes 8231e51764aSArtem Bityutskiy * @level: tree level 8241e51764aSArtem Bityutskiy * @branches: LEB number / offset / length / key branches 8251e51764aSArtem Bityutskiy */ 8261e51764aSArtem Bityutskiy struct ubifs_idx_node { 8271e51764aSArtem Bityutskiy struct ubifs_ch ch; 8281e51764aSArtem Bityutskiy __le16 child_cnt; 8291e51764aSArtem Bityutskiy __le16 level; 8301e51764aSArtem Bityutskiy __u8 branches[]; 831cc64f774SArtem Bityutskiy } __packed; 8321e51764aSArtem Bityutskiy 8331e51764aSArtem Bityutskiy /** 8341e51764aSArtem Bityutskiy * struct ubifs_cs_node - commit start node. 8351e51764aSArtem Bityutskiy * @ch: common header 8361e51764aSArtem Bityutskiy * @cmt_no: commit number 8371e51764aSArtem Bityutskiy */ 8381e51764aSArtem Bityutskiy struct ubifs_cs_node { 8391e51764aSArtem Bityutskiy struct ubifs_ch ch; 8401e51764aSArtem Bityutskiy __le64 cmt_no; 841cc64f774SArtem Bityutskiy } __packed; 8421e51764aSArtem Bityutskiy 8431e51764aSArtem Bityutskiy /** 8441e51764aSArtem Bityutskiy * struct ubifs_orph_node - orphan node. 8451e51764aSArtem Bityutskiy * @ch: common header 8461e51764aSArtem Bityutskiy * @cmt_no: commit number (also top bit is set on the last node of the commit) 8471e51764aSArtem Bityutskiy * @inos: inode numbers of orphans 8481e51764aSArtem Bityutskiy */ 8491e51764aSArtem Bityutskiy struct ubifs_orph_node { 8501e51764aSArtem Bityutskiy struct ubifs_ch ch; 8511e51764aSArtem Bityutskiy __le64 cmt_no; 8521e51764aSArtem Bityutskiy __le64 inos[]; 853cc64f774SArtem Bityutskiy } __packed; 8541e51764aSArtem Bityutskiy 8551e51764aSArtem Bityutskiy #endif /* __UBIFS_MEDIA_H__ */ 856