brintos

brintos / linux-shallow public Read only

0
0
Text · 24.8 KiB · 3c9792c Raw
856 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/*3 * This file is part of UBIFS.4 *5 * Copyright (C) 2006-2008 Nokia Corporation.6 *7 * Authors: Artem Bityutskiy (Битюцкий Артём)8 *          Adrian Hunter9 */10 11/*12 * This file describes UBIFS on-flash format and contains definitions of all the13 * relevant data structures and constants.14 *15 * All UBIFS on-flash objects are stored in the form of nodes. All nodes start16 * with the UBIFS node magic number and have the same common header. Nodes17 * always sit at 8-byte aligned positions on the media and node header sizes are18 * also 8-byte aligned (except for the indexing node and the padding node).19 */20 21#ifndef __UBIFS_MEDIA_H__22#define __UBIFS_MEDIA_H__23 24/* UBIFS node magic number (must not have the padding byte first or last) */25#define UBIFS_NODE_MAGIC  0x0610183126 27/*28 * UBIFS on-flash format version. This version is increased when the on-flash29 * format is changing. If this happens, UBIFS is will support older versions as30 * well. But older UBIFS code will not support newer formats. Format changes31 * will be rare and only when absolutely necessary, e.g. to fix a bug or to add32 * a new feature.33 *34 * UBIFS went into mainline kernel with format version 4. The older formats35 * were development formats.36 */37#define UBIFS_FORMAT_VERSION 538 39/*40 * Read-only compatibility version. If the UBIFS format is changed, older UBIFS41 * implementations will not be able to mount newer formats in read-write mode.42 * However, depending on the change, it may be possible to mount newer formats43 * in R/O mode. This is indicated by the R/O compatibility version which is44 * stored in the super-block.45 *46 * This is needed to support boot-loaders which only need R/O mounting. With47 * this flag it is possible to do UBIFS format changes without a need to update48 * boot-loaders.49 */50#define UBIFS_RO_COMPAT_VERSION 051 52/* Minimum logical eraseblock size in bytes */53#define UBIFS_MIN_LEB_SZ (15*1024)54 55/* Initial CRC32 value used when calculating CRC checksums */56#define UBIFS_CRC32_INIT 0xFFFFFFFFU57 58/*59 * UBIFS does not try to compress data if its length is less than the below60 * constant.61 */62#define UBIFS_MIN_COMPR_LEN 12863 64/*65 * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes66 * shorter than uncompressed data length, UBIFS prefers to leave this data67 * node uncompress, because it'll be read faster.68 */69#define UBIFS_MIN_COMPRESS_DIFF 6470 71/* Root inode number */72#define UBIFS_ROOT_INO 173 74/* Lowest inode number used for regular inodes (not UBIFS-only internal ones) */75#define UBIFS_FIRST_INO 6476 77/*78 * Maximum file name and extended attribute length (must be a multiple of 8,79 * minus 1).80 */81#define UBIFS_MAX_NLEN 25582 83/* Maximum number of data journal heads */84#define UBIFS_MAX_JHEADS 185 86/*87 * Size of UBIFS data block. Note, UBIFS is not a block oriented file-system,88 * which means that it does not treat the underlying media as consisting of89 * blocks like in case of hard drives. Do not be confused. UBIFS block is just90 * the maximum amount of data which one data node can have or which can be91 * attached to an inode node.92 */93#define UBIFS_BLOCK_SIZE  409694#define UBIFS_BLOCK_SHIFT 1295 96/* UBIFS padding byte pattern (must not be first or last byte of node magic) */97#define UBIFS_PADDING_BYTE 0xCE98 99/* Maximum possible key length */100#define UBIFS_MAX_KEY_LEN 16101 102/* Key length ("simple" format) */103#define UBIFS_SK_LEN 8104 105/* Minimum index tree fanout */106#define UBIFS_MIN_FANOUT 3107 108/* Maximum number of levels in UBIFS indexing B-tree */109#define UBIFS_MAX_LEVELS 512110 111/* Maximum amount of data attached to an inode in bytes */112#define UBIFS_MAX_INO_DATA UBIFS_BLOCK_SIZE113 114/* LEB Properties Tree fanout (must be power of 2) and fanout shift */115#define UBIFS_LPT_FANOUT 4116#define UBIFS_LPT_FANOUT_SHIFT 2117 118/* LEB Properties Tree bit field sizes */119#define UBIFS_LPT_CRC_BITS 16120#define UBIFS_LPT_CRC_BYTES 2121#define UBIFS_LPT_TYPE_BITS 4122 123/* The key is always at the same position in all keyed nodes */124#define UBIFS_KEY_OFFSET offsetof(struct ubifs_ino_node, key)125 126/* Garbage collector journal head number */127#define UBIFS_GC_HEAD   0128/* Base journal head number */129#define UBIFS_BASE_HEAD 1130/* Data journal head number */131#define UBIFS_DATA_HEAD 2132 133/*134 * LEB Properties Tree node types.135 *136 * UBIFS_LPT_PNODE: LPT leaf node (contains LEB properties)137 * UBIFS_LPT_NNODE: LPT internal node138 * UBIFS_LPT_LTAB: LPT's own lprops table139 * UBIFS_LPT_LSAVE: LPT's save table (big model only)140 * UBIFS_LPT_NODE_CNT: count of LPT node types141 * UBIFS_LPT_NOT_A_NODE: all ones (15 for 4 bits) is never a valid node type142 */143enum {144	UBIFS_LPT_PNODE,145	UBIFS_LPT_NNODE,146	UBIFS_LPT_LTAB,147	UBIFS_LPT_LSAVE,148	UBIFS_LPT_NODE_CNT,149	UBIFS_LPT_NOT_A_NODE = (1 << UBIFS_LPT_TYPE_BITS) - 1,150};151 152/*153 * UBIFS inode types.154 *155 * UBIFS_ITYPE_REG: regular file156 * UBIFS_ITYPE_DIR: directory157 * UBIFS_ITYPE_LNK: soft link158 * UBIFS_ITYPE_BLK: block device node159 * UBIFS_ITYPE_CHR: character device node160 * UBIFS_ITYPE_FIFO: fifo161 * UBIFS_ITYPE_SOCK: socket162 * UBIFS_ITYPES_CNT: count of supported file types163 */164enum {165	UBIFS_ITYPE_REG,166	UBIFS_ITYPE_DIR,167	UBIFS_ITYPE_LNK,168	UBIFS_ITYPE_BLK,169	UBIFS_ITYPE_CHR,170	UBIFS_ITYPE_FIFO,171	UBIFS_ITYPE_SOCK,172	UBIFS_ITYPES_CNT,173};174 175/*176 * Supported key hash functions.177 *178 * UBIFS_KEY_HASH_R5: R5 hash179 * UBIFS_KEY_HASH_TEST: test hash which just returns first 4 bytes of the name180 */181enum {182	UBIFS_KEY_HASH_R5,183	UBIFS_KEY_HASH_TEST,184};185 186/*187 * Supported key formats.188 *189 * UBIFS_SIMPLE_KEY_FMT: simple key format190 */191enum {192	UBIFS_SIMPLE_KEY_FMT,193};194 195/*196 * The simple key format uses 29 bits for storing UBIFS block number and hash197 * value.198 */199#define UBIFS_S_KEY_BLOCK_BITS 29200#define UBIFS_S_KEY_BLOCK_MASK 0x1FFFFFFF201#define UBIFS_S_KEY_HASH_BITS  UBIFS_S_KEY_BLOCK_BITS202#define UBIFS_S_KEY_HASH_MASK  UBIFS_S_KEY_BLOCK_MASK203 204/*205 * Key types.206 *207 * UBIFS_INO_KEY: inode node key208 * UBIFS_DATA_KEY: data node key209 * UBIFS_DENT_KEY: directory entry node key210 * UBIFS_XENT_KEY: extended attribute entry key211 * UBIFS_KEY_TYPES_CNT: number of supported key types212 */213enum {214	UBIFS_INO_KEY,215	UBIFS_DATA_KEY,216	UBIFS_DENT_KEY,217	UBIFS_XENT_KEY,218	UBIFS_KEY_TYPES_CNT,219};220 221/* Count of LEBs reserved for the superblock area */222#define UBIFS_SB_LEBS 1223/* Count of LEBs reserved for the master area */224#define UBIFS_MST_LEBS 2225 226/* First LEB of the superblock area */227#define UBIFS_SB_LNUM 0228/* First LEB of the master area */229#define UBIFS_MST_LNUM (UBIFS_SB_LNUM + UBIFS_SB_LEBS)230/* First LEB of the log area */231#define UBIFS_LOG_LNUM (UBIFS_MST_LNUM + UBIFS_MST_LEBS)232 233/*234 * The below constants define the absolute minimum values for various UBIFS235 * media areas. Many of them actually depend of flash geometry and the FS236 * configuration (number of journal heads, orphan LEBs, etc). This means that237 * the smallest volume size which can be used for UBIFS cannot be pre-defined238 * by these constants. The file-system that meets the below limitation will not239 * necessarily mount. UBIFS does run-time calculations and validates the FS240 * size.241 */242 243/* Minimum number of logical eraseblocks in the log */244#define UBIFS_MIN_LOG_LEBS 2245/* Minimum number of bud logical eraseblocks (one for each head) */246#define UBIFS_MIN_BUD_LEBS 3247/* Minimum number of journal logical eraseblocks */248#define UBIFS_MIN_JNL_LEBS (UBIFS_MIN_LOG_LEBS + UBIFS_MIN_BUD_LEBS)249/* Minimum number of LPT area logical eraseblocks */250#define UBIFS_MIN_LPT_LEBS 2251/* Minimum number of orphan area logical eraseblocks */252#define UBIFS_MIN_ORPH_LEBS 1253/*254 * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1255 * for GC, 1 for deletions, and at least 1 for committed data).256 */257#define UBIFS_MIN_MAIN_LEBS (UBIFS_MIN_BUD_LEBS + 6)258 259/* Minimum number of logical eraseblocks */260#define UBIFS_MIN_LEB_CNT (UBIFS_SB_LEBS + UBIFS_MST_LEBS + \261			   UBIFS_MIN_LOG_LEBS + UBIFS_MIN_LPT_LEBS + \262			   UBIFS_MIN_ORPH_LEBS + UBIFS_MIN_MAIN_LEBS)263 264/* Node sizes (N.B. these are guaranteed to be multiples of 8) */265#define UBIFS_CH_SZ        sizeof(struct ubifs_ch)266#define UBIFS_INO_NODE_SZ  sizeof(struct ubifs_ino_node)267#define UBIFS_DATA_NODE_SZ sizeof(struct ubifs_data_node)268#define UBIFS_DENT_NODE_SZ sizeof(struct ubifs_dent_node)269#define UBIFS_TRUN_NODE_SZ sizeof(struct ubifs_trun_node)270#define UBIFS_PAD_NODE_SZ  sizeof(struct ubifs_pad_node)271#define UBIFS_SB_NODE_SZ   sizeof(struct ubifs_sb_node)272#define UBIFS_MST_NODE_SZ  sizeof(struct ubifs_mst_node)273#define UBIFS_REF_NODE_SZ  sizeof(struct ubifs_ref_node)274#define UBIFS_IDX_NODE_SZ  sizeof(struct ubifs_idx_node)275#define UBIFS_CS_NODE_SZ   sizeof(struct ubifs_cs_node)276#define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node)277#define UBIFS_AUTH_NODE_SZ sizeof(struct ubifs_auth_node)278#define UBIFS_SIG_NODE_SZ  sizeof(struct ubifs_sig_node)279 280/* Extended attribute entry nodes are identical to directory entry nodes */281#define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ282/* Only this does not have to be multiple of 8 bytes */283#define UBIFS_BRANCH_SZ    sizeof(struct ubifs_branch)284 285/* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */286#define UBIFS_MAX_DATA_NODE_SZ  (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE)287#define UBIFS_MAX_INO_NODE_SZ   (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA)288#define UBIFS_MAX_DENT_NODE_SZ  (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1)289#define UBIFS_MAX_XENT_NODE_SZ  UBIFS_MAX_DENT_NODE_SZ290 291/* The largest UBIFS node */292#define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ293 294/* The maxmimum size of a hash, enough for sha512 */295#define UBIFS_MAX_HASH_LEN 64296 297/* The maxmimum size of a hmac, enough for hmac(sha512) */298#define UBIFS_MAX_HMAC_LEN 64299 300/*301 * xattr name of UBIFS encryption context, we don't use a prefix302 * nor a long name to not waste space on the flash.303 */304#define UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT "c"305 306/* Type field in ubifs_sig_node */307#define UBIFS_SIGNATURE_TYPE_PKCS7	1308 309/*310 * On-flash inode flags.311 *312 * UBIFS_COMPR_FL: use compression for this inode313 * UBIFS_SYNC_FL:  I/O on this inode has to be synchronous314 * UBIFS_IMMUTABLE_FL: inode is immutable315 * UBIFS_APPEND_FL: writes to the inode may only append data316 * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous317 * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value318 * UBIFS_CRYPT_FL: use encryption for this inode319 *320 * Note, these are on-flash flags which correspond to ioctl flags321 * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not322 * have to be the same.323 */324enum {325	UBIFS_COMPR_FL     = 0x01,326	UBIFS_SYNC_FL      = 0x02,327	UBIFS_IMMUTABLE_FL = 0x04,328	UBIFS_APPEND_FL    = 0x08,329	UBIFS_DIRSYNC_FL   = 0x10,330	UBIFS_XATTR_FL     = 0x20,331	UBIFS_CRYPT_FL     = 0x40,332};333 334/* Inode flag bits used by UBIFS */335#define UBIFS_FL_MASK 0x0000001F336 337/*338 * UBIFS compression algorithms.339 *340 * UBIFS_COMPR_NONE: no compression341 * UBIFS_COMPR_LZO: LZO compression342 * UBIFS_COMPR_ZLIB: ZLIB compression343 * UBIFS_COMPR_ZSTD: ZSTD compression344 * UBIFS_COMPR_TYPES_CNT: count of supported compression types345 */346enum {347	UBIFS_COMPR_NONE,348	UBIFS_COMPR_LZO,349	UBIFS_COMPR_ZLIB,350	UBIFS_COMPR_ZSTD,351	UBIFS_COMPR_TYPES_CNT,352};353 354/*355 * UBIFS node types.356 *357 * UBIFS_INO_NODE: inode node358 * UBIFS_DATA_NODE: data node359 * UBIFS_DENT_NODE: directory entry node360 * UBIFS_XENT_NODE: extended attribute node361 * UBIFS_TRUN_NODE: truncation node362 * UBIFS_PAD_NODE: padding node363 * UBIFS_SB_NODE: superblock node364 * UBIFS_MST_NODE: master node365 * UBIFS_REF_NODE: LEB reference node366 * UBIFS_IDX_NODE: index node367 * UBIFS_CS_NODE: commit start node368 * UBIFS_ORPH_NODE: orphan node369 * UBIFS_AUTH_NODE: authentication node370 * UBIFS_SIG_NODE: signature node371 * UBIFS_NODE_TYPES_CNT: count of supported node types372 *373 * Note, we index arrays by these numbers, so keep them low and contiguous.374 * Node type constants for inodes, direntries and so on have to be the same as375 * corresponding key type constants.376 */377enum {378	UBIFS_INO_NODE,379	UBIFS_DATA_NODE,380	UBIFS_DENT_NODE,381	UBIFS_XENT_NODE,382	UBIFS_TRUN_NODE,383	UBIFS_PAD_NODE,384	UBIFS_SB_NODE,385	UBIFS_MST_NODE,386	UBIFS_REF_NODE,387	UBIFS_IDX_NODE,388	UBIFS_CS_NODE,389	UBIFS_ORPH_NODE,390	UBIFS_AUTH_NODE,391	UBIFS_SIG_NODE,392	UBIFS_NODE_TYPES_CNT,393};394 395/*396 * Master node flags.397 *398 * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty399 * UBIFS_MST_NO_ORPHS: no orphan inodes present400 * UBIFS_MST_RCVRY: written by recovery401 */402enum {403	UBIFS_MST_DIRTY = 1,404	UBIFS_MST_NO_ORPHS = 2,405	UBIFS_MST_RCVRY = 4,406};407 408/*409 * Node group type (used by recovery to recover whole group or none).410 *411 * UBIFS_NO_NODE_GROUP: this node is not part of a group412 * UBIFS_IN_NODE_GROUP: this node is a part of a group413 * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group414 */415enum {416	UBIFS_NO_NODE_GROUP = 0,417	UBIFS_IN_NODE_GROUP,418	UBIFS_LAST_OF_NODE_GROUP,419};420 421/*422 * Superblock flags.423 *424 * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set425 * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed426 * UBIFS_FLG_DOUBLE_HASH: store a 32bit cookie in directory entry nodes to427 *			  support 64bit cookies for lookups by hash428 * UBIFS_FLG_ENCRYPTION: this filesystem contains encrypted files429 * UBIFS_FLG_AUTHENTICATION: this filesystem contains hashes for authentication430 */431enum {432	UBIFS_FLG_BIGLPT = 0x02,433	UBIFS_FLG_SPACE_FIXUP = 0x04,434	UBIFS_FLG_DOUBLE_HASH = 0x08,435	UBIFS_FLG_ENCRYPTION = 0x10,436	UBIFS_FLG_AUTHENTICATION = 0x20,437};438 439#define UBIFS_FLG_MASK (UBIFS_FLG_BIGLPT | UBIFS_FLG_SPACE_FIXUP | \440		UBIFS_FLG_DOUBLE_HASH | UBIFS_FLG_ENCRYPTION | \441		UBIFS_FLG_AUTHENTICATION)442 443/**444 * struct ubifs_ch - common header node.445 * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)446 * @crc: CRC-32 checksum of the node header447 * @sqnum: sequence number448 * @len: full node length449 * @node_type: node type450 * @group_type: node group type451 * @padding: reserved for future, zeroes452 *453 * Every UBIFS node starts with this common part. If the node has a key, the454 * key always goes next.455 */456struct ubifs_ch {457	__le32 magic;458	__le32 crc;459	__le64 sqnum;460	__le32 len;461	__u8 node_type;462	__u8 group_type;463	__u8 padding[2];464} __packed;465 466/**467 * union ubifs_dev_desc - device node descriptor.468 * @new: new type device descriptor469 * @huge: huge type device descriptor470 *471 * This data structure describes major/minor numbers of a device node. In an472 * inode is a device node then its data contains an object of this type. UBIFS473 * uses standard Linux "new" and "huge" device node encodings.474 */475union ubifs_dev_desc {476	__le32 new;477	__le64 huge;478} __packed;479 480/**481 * struct ubifs_ino_node - inode node.482 * @ch: common header483 * @key: node key484 * @creat_sqnum: sequence number at time of creation485 * @size: inode size in bytes (amount of uncompressed data)486 * @atime_sec: access time seconds487 * @ctime_sec: creation time seconds488 * @mtime_sec: modification time seconds489 * @atime_nsec: access time nanoseconds490 * @ctime_nsec: creation time nanoseconds491 * @mtime_nsec: modification time nanoseconds492 * @nlink: number of hard links493 * @uid: owner ID494 * @gid: group ID495 * @mode: access flags496 * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc)497 * @data_len: inode data length498 * @xattr_cnt: count of extended attributes this inode has499 * @xattr_size: summarized size of all extended attributes in bytes500 * @padding1: reserved for future, zeroes501 * @xattr_names: sum of lengths of all extended attribute names belonging to502 *               this inode503 * @compr_type: compression type used for this inode504 * @padding2: reserved for future, zeroes505 * @data: data attached to the inode506 *507 * Note, even though inode compression type is defined by @compr_type, some508 * nodes of this inode may be compressed with different compressor - this509 * happens if compression type is changed while the inode already has data510 * nodes. But @compr_type will be use for further writes to the inode.511 *512 * Note, do not forget to amend 'zero_ino_node_unused()' function when changing513 * the padding fields.514 */515struct ubifs_ino_node {516	struct ubifs_ch ch;517	__u8 key[UBIFS_MAX_KEY_LEN];518	__le64 creat_sqnum;519	__le64 size;520	__le64 atime_sec;521	__le64 ctime_sec;522	__le64 mtime_sec;523	__le32 atime_nsec;524	__le32 ctime_nsec;525	__le32 mtime_nsec;526	__le32 nlink;527	__le32 uid;528	__le32 gid;529	__le32 mode;530	__le32 flags;531	__le32 data_len;532	__le32 xattr_cnt;533	__le32 xattr_size;534	__u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */535	__le32 xattr_names;536	__le16 compr_type;537	__u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */538	__u8 data[];539} __packed;540 541/**542 * struct ubifs_dent_node - directory entry node.543 * @ch: common header544 * @key: node key545 * @inum: target inode number546 * @padding1: reserved for future, zeroes547 * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc)548 * @nlen: name length549 * @cookie: A 32bits random number, used to construct a 64bits550 *          identifier.551 * @name: zero-terminated name552 *553 * Note, do not forget to amend 'zero_dent_node_unused()' function when554 * changing the padding fields.555 */556struct ubifs_dent_node {557	struct ubifs_ch ch;558	__u8 key[UBIFS_MAX_KEY_LEN];559	__le64 inum;560	__u8 padding1;561	__u8 type;562	__le16 nlen;563	__le32 cookie;564	__u8 name[];565} __packed;566 567/**568 * struct ubifs_data_node - data node.569 * @ch: common header570 * @key: node key571 * @size: uncompressed data size in bytes572 * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc)573 * @compr_size: compressed data size in bytes, only valid when data is encrypted574 * @data: data575 *576 */577struct ubifs_data_node {578	struct ubifs_ch ch;579	__u8 key[UBIFS_MAX_KEY_LEN];580	__le32 size;581	__le16 compr_type;582	__le16 compr_size;583	__u8 data[];584} __packed;585 586/**587 * struct ubifs_trun_node - truncation node.588 * @ch: common header589 * @inum: truncated inode number590 * @padding: reserved for future, zeroes591 * @old_size: size before truncation592 * @new_size: size after truncation593 *594 * This node exists only in the journal and never goes to the main area. Note,595 * do not forget to amend 'zero_trun_node_unused()' function when changing the596 * padding fields.597 */598struct ubifs_trun_node {599	struct ubifs_ch ch;600	__le32 inum;601	__u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */602	__le64 old_size;603	__le64 new_size;604} __packed;605 606/**607 * struct ubifs_pad_node - padding node.608 * @ch: common header609 * @pad_len: how many bytes after this node are unused (because padded)610 * @padding: reserved for future, zeroes611 */612struct ubifs_pad_node {613	struct ubifs_ch ch;614	__le32 pad_len;615} __packed;616 617/**618 * struct ubifs_sb_node - superblock node.619 * @ch: common header620 * @padding: reserved for future, zeroes621 * @key_hash: type of hash function used in keys622 * @key_fmt: format of the key623 * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)624 * @min_io_size: minimal input/output unit size625 * @leb_size: logical eraseblock size in bytes626 * @leb_cnt: count of LEBs used by file-system627 * @max_leb_cnt: maximum count of LEBs used by file-system628 * @max_bud_bytes: maximum amount of data stored in buds629 * @log_lebs: log size in logical eraseblocks630 * @lpt_lebs: number of LEBs used for lprops table631 * @orph_lebs: number of LEBs used for recording orphans632 * @jhead_cnt: count of journal heads633 * @fanout: tree fanout (max. number of links per indexing node)634 * @lsave_cnt: number of LEB numbers in LPT's save table635 * @fmt_version: UBIFS on-flash format version636 * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)637 * @padding1: reserved for future, zeroes638 * @rp_uid: reserve pool UID639 * @rp_gid: reserve pool GID640 * @rp_size: size of the reserved pool in bytes641 * @padding2: reserved for future, zeroes642 * @time_gran: time granularity in nanoseconds643 * @uuid: UUID generated when the file system image was created644 * @ro_compat_version: UBIFS R/O compatibility version645 * @hmac: HMAC to authenticate the superblock node646 * @hmac_wkm: HMAC of a well known message (the string "UBIFS") as a convenience647 *            to the user to check if the correct key is passed.648 * @hash_algo: The hash algo used for this filesystem (one of enum hash_algo)649 * @hash_mst: hash of the master node, only valid for signed images in which the650 *            master node does not contain a hmac651 */652struct ubifs_sb_node {653	struct ubifs_ch ch;654	__u8 padding[2];655	__u8 key_hash;656	__u8 key_fmt;657	__le32 flags;658	__le32 min_io_size;659	__le32 leb_size;660	__le32 leb_cnt;661	__le32 max_leb_cnt;662	__le64 max_bud_bytes;663	__le32 log_lebs;664	__le32 lpt_lebs;665	__le32 orph_lebs;666	__le32 jhead_cnt;667	__le32 fanout;668	__le32 lsave_cnt;669	__le32 fmt_version;670	__le16 default_compr;671	__u8 padding1[2];672	__le32 rp_uid;673	__le32 rp_gid;674	__le64 rp_size;675	__le32 time_gran;676	__u8 uuid[16];677	__le32 ro_compat_version;678	__u8 hmac[UBIFS_MAX_HMAC_LEN];679	__u8 hmac_wkm[UBIFS_MAX_HMAC_LEN];680	__le16 hash_algo;681	__u8 hash_mst[UBIFS_MAX_HASH_LEN];682	__u8 padding2[3774];683} __packed;684 685/**686 * struct ubifs_mst_node - master node.687 * @ch: common header688 * @highest_inum: highest inode number in the committed index689 * @cmt_no: commit number690 * @flags: various flags (%UBIFS_MST_DIRTY, etc)691 * @log_lnum: start of the log692 * @root_lnum: LEB number of the root indexing node693 * @root_offs: offset within @root_lnum694 * @root_len: root indexing node length695 * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was696 * not reserved and should be reserved on mount)697 * @ihead_lnum: LEB number of index head698 * @ihead_offs: offset of index head699 * @index_size: size of index on flash700 * @total_free: total free space in bytes701 * @total_dirty: total dirty space in bytes702 * @total_used: total used space in bytes (includes only data LEBs)703 * @total_dead: total dead space in bytes (includes only data LEBs)704 * @total_dark: total dark space in bytes (includes only data LEBs)705 * @lpt_lnum: LEB number of LPT root nnode706 * @lpt_offs: offset of LPT root nnode707 * @nhead_lnum: LEB number of LPT head708 * @nhead_offs: offset of LPT head709 * @ltab_lnum: LEB number of LPT's own lprops table710 * @ltab_offs: offset of LPT's own lprops table711 * @lsave_lnum: LEB number of LPT's save table (big model only)712 * @lsave_offs: offset of LPT's save table (big model only)713 * @lscan_lnum: LEB number of last LPT scan714 * @empty_lebs: number of empty logical eraseblocks715 * @idx_lebs: number of indexing logical eraseblocks716 * @leb_cnt: count of LEBs used by file-system717 * @hash_root_idx: the hash of the root index node718 * @hash_lpt: the hash of the LPT719 * @hmac: HMAC to authenticate the master node720 * @padding: reserved for future, zeroes721 */722struct ubifs_mst_node {723	struct ubifs_ch ch;724	__le64 highest_inum;725	__le64 cmt_no;726	__le32 flags;727	__le32 log_lnum;728	__le32 root_lnum;729	__le32 root_offs;730	__le32 root_len;731	__le32 gc_lnum;732	__le32 ihead_lnum;733	__le32 ihead_offs;734	__le64 index_size;735	__le64 total_free;736	__le64 total_dirty;737	__le64 total_used;738	__le64 total_dead;739	__le64 total_dark;740	__le32 lpt_lnum;741	__le32 lpt_offs;742	__le32 nhead_lnum;743	__le32 nhead_offs;744	__le32 ltab_lnum;745	__le32 ltab_offs;746	__le32 lsave_lnum;747	__le32 lsave_offs;748	__le32 lscan_lnum;749	__le32 empty_lebs;750	__le32 idx_lebs;751	__le32 leb_cnt;752	__u8 hash_root_idx[UBIFS_MAX_HASH_LEN];753	__u8 hash_lpt[UBIFS_MAX_HASH_LEN];754	__u8 hmac[UBIFS_MAX_HMAC_LEN];755	__u8 padding[152];756} __packed;757 758/**759 * struct ubifs_ref_node - logical eraseblock reference node.760 * @ch: common header761 * @lnum: the referred logical eraseblock number762 * @offs: start offset in the referred LEB763 * @jhead: journal head number764 * @padding: reserved for future, zeroes765 */766struct ubifs_ref_node {767	struct ubifs_ch ch;768	__le32 lnum;769	__le32 offs;770	__le32 jhead;771	__u8 padding[28];772} __packed;773 774/**775 * struct ubifs_auth_node - node for authenticating other nodes776 * @ch: common header777 * @hmac: The HMAC778 */779struct ubifs_auth_node {780	struct ubifs_ch ch;781	__u8 hmac[];782} __packed;783 784/**785 * struct ubifs_sig_node - node for signing other nodes786 * @ch: common header787 * @type: type of the signature, currently only UBIFS_SIGNATURE_TYPE_PKCS7788 * supported789 * @len: The length of the signature data790 * @padding: reserved for future, zeroes791 * @sig: The signature data792 */793struct ubifs_sig_node {794	struct ubifs_ch ch;795	__le32 type;796	__le32 len;797	__u8 padding[32];798	__u8 sig[];799} __packed;800 801/**802 * struct ubifs_branch - key/reference/length branch803 * @lnum: LEB number of the target node804 * @offs: offset within @lnum805 * @len: target node length806 * @key: key807 *808 * In an authenticated UBIFS we have the hash of the referenced node after @key.809 * This can't be added to the struct type definition because @key is a810 * dynamically sized element already.811 */812struct ubifs_branch {813	__le32 lnum;814	__le32 offs;815	__le32 len;816	__u8 key[];817} __packed;818 819/**820 * struct ubifs_idx_node - indexing node.821 * @ch: common header822 * @child_cnt: number of child index nodes823 * @level: tree level824 * @branches: LEB number / offset / length / key branches825 */826struct ubifs_idx_node {827	struct ubifs_ch ch;828	__le16 child_cnt;829	__le16 level;830	__u8 branches[];831} __packed;832 833/**834 * struct ubifs_cs_node - commit start node.835 * @ch: common header836 * @cmt_no: commit number837 */838struct ubifs_cs_node {839	struct ubifs_ch ch;840	__le64 cmt_no;841} __packed;842 843/**844 * struct ubifs_orph_node - orphan node.845 * @ch: common header846 * @cmt_no: commit number (also top bit is set on the last node of the commit)847 * @inos: inode numbers of orphans848 */849struct ubifs_orph_node {850	struct ubifs_ch ch;851	__le64 cmt_no;852	__le64 inos[];853} __packed;854 855#endif /* __UBIFS_MEDIA_H__ */856