uboot/fs/ubifs/ubifs-media.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0+ */
   2/*
   3 * This file is part of UBIFS.
   4 *
   5 * Copyright (C) 2006-2008 Nokia Corporation.
   6 *
   7 * Authors: Artem Bityutskiy (Битюцкий Артём)
   8 *          Adrian Hunter
   9 */
  10
  11/*
  12 * This file describes UBIFS on-flash format and contains definitions of all the
  13 * relevant data structures and constants.
  14 *
  15 * All UBIFS on-flash objects are stored in the form of nodes. All nodes start
  16 * with the UBIFS node magic number and have the same common header. Nodes
  17 * always sit at 8-byte aligned positions on the media and node header sizes are
  18 * 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  0x06101831
  26
  27/*
  28 * UBIFS on-flash format version. This version is increased when the on-flash
  29 * format is changing. If this happens, UBIFS is will support older versions as
  30 * well. But older UBIFS code will not support newer formats. Format changes
  31 * will be rare and only when absolutely necessary, e.g. to fix a bug or to add
  32 * a new feature.
  33 *
  34 * UBIFS went into mainline kernel with format version 4. The older formats
  35 * were development formats.
  36 */
  37#define UBIFS_FORMAT_VERSION 4
  38
  39/*
  40 * Read-only compatibility version. If the UBIFS format is changed, older UBIFS
  41 * 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 formats
  43 * in R/O mode. This is indicated by the R/O compatibility version which is
  44 * stored in the super-block.
  45 *
  46 * This is needed to support boot-loaders which only need R/O mounting. With
  47 * this flag it is possible to do UBIFS format changes without a need to update
  48 * boot-loaders.
  49 */
  50#define UBIFS_RO_COMPAT_VERSION 0
  51
  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 0xFFFFFFFFU
  57
  58/*
  59 * UBIFS does not try to compress data if its length is less than the below
  60 * constant.
  61 */
  62#define UBIFS_MIN_COMPR_LEN 128
  63
  64/*
  65 * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes
  66 * shorter than uncompressed data length, UBIFS prefers to leave this data
  67 * node uncompress, because it'll be read faster.
  68 */
  69#define UBIFS_MIN_COMPRESS_DIFF 64
  70
  71/* Root inode number */
  72#define UBIFS_ROOT_INO 1
  73
  74/* Lowest inode number used for regular inodes (not UBIFS-only internal ones) */
  75#define UBIFS_FIRST_INO 64
  76
  77/*
  78 * Maximum file name and extended attribute length (must be a multiple of 8,
  79 * minus 1).
  80 */
  81#define UBIFS_MAX_NLEN 255
  82
  83/* Maximum number of data journal heads */
  84#define UBIFS_MAX_JHEADS 1
  85
  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 of
  89 * blocks like in case of hard drives. Do not be confused. UBIFS block is just
  90 * the maximum amount of data which one data node can have or which can be
  91 * attached to an inode node.
  92 */
  93#define UBIFS_BLOCK_SIZE  4096
  94#define UBIFS_BLOCK_SHIFT 12
  95
  96/* UBIFS padding byte pattern (must not be first or last byte of node magic) */
  97#define UBIFS_PADDING_BYTE 0xCE
  98
  99/* Maximum possible key length */
 100#define UBIFS_MAX_KEY_LEN 16
 101
 102/* Key length ("simple" format) */
 103#define UBIFS_SK_LEN 8
 104
 105/* Minimum index tree fanout */
 106#define UBIFS_MIN_FANOUT 3
 107
 108/* Maximum number of levels in UBIFS indexing B-tree */
 109#define UBIFS_MAX_LEVELS 512
 110
 111/* Maximum amount of data attached to an inode in bytes */
 112#define UBIFS_MAX_INO_DATA UBIFS_BLOCK_SIZE
 113
 114/* LEB Properties Tree fanout (must be power of 2) and fanout shift */
 115#define UBIFS_LPT_FANOUT 4
 116#define UBIFS_LPT_FANOUT_SHIFT 2
 117
 118/* LEB Properties Tree bit field sizes */
 119#define UBIFS_LPT_CRC_BITS 16
 120#define UBIFS_LPT_CRC_BYTES 2
 121#define UBIFS_LPT_TYPE_BITS 4
 122
 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   0
 128/* Base journal head number */
 129#define UBIFS_BASE_HEAD 1
 130/* Data journal head number */
 131#define UBIFS_DATA_HEAD 2
 132
 133/*
 134 * LEB Properties Tree node types.
 135 *
 136 * UBIFS_LPT_PNODE: LPT leaf node (contains LEB properties)
 137 * UBIFS_LPT_NNODE: LPT internal node
 138 * UBIFS_LPT_LTAB: LPT's own lprops table
 139 * UBIFS_LPT_LSAVE: LPT's save table (big model only)
 140 * UBIFS_LPT_NODE_CNT: count of LPT node types
 141 * UBIFS_LPT_NOT_A_NODE: all ones (15 for 4 bits) is never a valid node type
 142 */
 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 file
 156 * UBIFS_ITYPE_DIR: directory
 157 * UBIFS_ITYPE_LNK: soft link
 158 * UBIFS_ITYPE_BLK: block device node
 159 * UBIFS_ITYPE_CHR: character device node
 160 * UBIFS_ITYPE_FIFO: fifo
 161 * UBIFS_ITYPE_SOCK: socket
 162 * UBIFS_ITYPES_CNT: count of supported file types
 163 */
 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 hash
 179 * UBIFS_KEY_HASH_TEST: test hash which just returns first 4 bytes of the name
 180 */
 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 format
 190 */
 191enum {
 192        UBIFS_SIMPLE_KEY_FMT,
 193};
 194
 195/*
 196 * The simple key format uses 29 bits for storing UBIFS block number and hash
 197 * value.
 198 */
 199#define UBIFS_S_KEY_BLOCK_BITS 29
 200#define UBIFS_S_KEY_BLOCK_MASK 0x1FFFFFFF
 201#define UBIFS_S_KEY_HASH_BITS  UBIFS_S_KEY_BLOCK_BITS
 202#define UBIFS_S_KEY_HASH_MASK  UBIFS_S_KEY_BLOCK_MASK
 203
 204/*
 205 * Key types.
 206 *
 207 * UBIFS_INO_KEY: inode node key
 208 * UBIFS_DATA_KEY: data node key
 209 * UBIFS_DENT_KEY: directory entry node key
 210 * UBIFS_XENT_KEY: extended attribute entry key
 211 * UBIFS_KEY_TYPES_CNT: number of supported key types
 212 */
 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 1
 223/* Count of LEBs reserved for the master area */
 224#define UBIFS_MST_LEBS 2
 225
 226/* First LEB of the superblock area */
 227#define UBIFS_SB_LNUM 0
 228/* 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 UBIFS
 235 * media areas. Many of them actually depend of flash geometry and the FS
 236 * configuration (number of journal heads, orphan LEBs, etc). This means that
 237 * the smallest volume size which can be used for UBIFS cannot be pre-defined
 238 * by these constants. The file-system that meets the below limitation will not
 239 * necessarily mount. UBIFS does run-time calculations and validates the FS
 240 * size.
 241 */
 242
 243/* Minimum number of logical eraseblocks in the log */
 244#define UBIFS_MIN_LOG_LEBS 2
 245/* Minimum number of bud logical eraseblocks (one for each head) */
 246#define UBIFS_MIN_BUD_LEBS 3
 247/* 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 2
 251/* Minimum number of orphan area logical eraseblocks */
 252#define UBIFS_MIN_ORPH_LEBS 1
 253/*
 254 * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1
 255 * 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/* Extended attribute entry nodes are identical to directory entry nodes */
 278#define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ
 279/* Only this does not have to be multiple of 8 bytes */
 280#define UBIFS_BRANCH_SZ    sizeof(struct ubifs_branch)
 281
 282/* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */
 283#define UBIFS_MAX_DATA_NODE_SZ  (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE)
 284#define UBIFS_MAX_INO_NODE_SZ   (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA)
 285#define UBIFS_MAX_DENT_NODE_SZ  (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1)
 286#define UBIFS_MAX_XENT_NODE_SZ  UBIFS_MAX_DENT_NODE_SZ
 287
 288/* The largest UBIFS node */
 289#define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ
 290
 291/*
 292 * On-flash inode flags.
 293 *
 294 * UBIFS_COMPR_FL: use compression for this inode
 295 * UBIFS_SYNC_FL:  I/O on this inode has to be synchronous
 296 * UBIFS_IMMUTABLE_FL: inode is immutable
 297 * UBIFS_APPEND_FL: writes to the inode may only append data
 298 * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous
 299 * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value
 300 *
 301 * Note, these are on-flash flags which correspond to ioctl flags
 302 * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not
 303 * have to be the same.
 304 */
 305enum {
 306        UBIFS_COMPR_FL     = 0x01,
 307        UBIFS_SYNC_FL      = 0x02,
 308        UBIFS_IMMUTABLE_FL = 0x04,
 309        UBIFS_APPEND_FL    = 0x08,
 310        UBIFS_DIRSYNC_FL   = 0x10,
 311        UBIFS_XATTR_FL     = 0x20,
 312};
 313
 314/* Inode flag bits used by UBIFS */
 315#define UBIFS_FL_MASK 0x0000001F
 316
 317/*
 318 * UBIFS compression algorithms.
 319 *
 320 * UBIFS_COMPR_NONE: no compression
 321 * UBIFS_COMPR_LZO: LZO compression
 322 * UBIFS_COMPR_ZLIB: ZLIB compression
 323 * UBIFS_COMPR_TYPES_CNT: count of supported compression types
 324 */
 325enum {
 326        UBIFS_COMPR_NONE,
 327        UBIFS_COMPR_LZO,
 328        UBIFS_COMPR_ZLIB,
 329        UBIFS_COMPR_TYPES_CNT,
 330};
 331
 332/*
 333 * UBIFS node types.
 334 *
 335 * UBIFS_INO_NODE: inode node
 336 * UBIFS_DATA_NODE: data node
 337 * UBIFS_DENT_NODE: directory entry node
 338 * UBIFS_XENT_NODE: extended attribute node
 339 * UBIFS_TRUN_NODE: truncation node
 340 * UBIFS_PAD_NODE: padding node
 341 * UBIFS_SB_NODE: superblock node
 342 * UBIFS_MST_NODE: master node
 343 * UBIFS_REF_NODE: LEB reference node
 344 * UBIFS_IDX_NODE: index node
 345 * UBIFS_CS_NODE: commit start node
 346 * UBIFS_ORPH_NODE: orphan node
 347 * UBIFS_NODE_TYPES_CNT: count of supported node types
 348 *
 349 * Note, we index arrays by these numbers, so keep them low and contiguous.
 350 * Node type constants for inodes, direntries and so on have to be the same as
 351 * corresponding key type constants.
 352 */
 353enum {
 354        UBIFS_INO_NODE,
 355        UBIFS_DATA_NODE,
 356        UBIFS_DENT_NODE,
 357        UBIFS_XENT_NODE,
 358        UBIFS_TRUN_NODE,
 359        UBIFS_PAD_NODE,
 360        UBIFS_SB_NODE,
 361        UBIFS_MST_NODE,
 362        UBIFS_REF_NODE,
 363        UBIFS_IDX_NODE,
 364        UBIFS_CS_NODE,
 365        UBIFS_ORPH_NODE,
 366        UBIFS_NODE_TYPES_CNT,
 367};
 368
 369/*
 370 * Master node flags.
 371 *
 372 * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty
 373 * UBIFS_MST_NO_ORPHS: no orphan inodes present
 374 * UBIFS_MST_RCVRY: written by recovery
 375 */
 376enum {
 377        UBIFS_MST_DIRTY = 1,
 378        UBIFS_MST_NO_ORPHS = 2,
 379        UBIFS_MST_RCVRY = 4,
 380};
 381
 382/*
 383 * Node group type (used by recovery to recover whole group or none).
 384 *
 385 * UBIFS_NO_NODE_GROUP: this node is not part of a group
 386 * UBIFS_IN_NODE_GROUP: this node is a part of a group
 387 * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group
 388 */
 389enum {
 390        UBIFS_NO_NODE_GROUP = 0,
 391        UBIFS_IN_NODE_GROUP,
 392        UBIFS_LAST_OF_NODE_GROUP,
 393};
 394
 395/*
 396 * Superblock flags.
 397 *
 398 * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set
 399 * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed
 400 */
 401enum {
 402        UBIFS_FLG_BIGLPT = 0x02,
 403        UBIFS_FLG_SPACE_FIXUP = 0x04,
 404};
 405
 406/**
 407 * struct ubifs_ch - common header node.
 408 * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)
 409 * @crc: CRC-32 checksum of the node header
 410 * @sqnum: sequence number
 411 * @len: full node length
 412 * @node_type: node type
 413 * @group_type: node group type
 414 * @padding: reserved for future, zeroes
 415 *
 416 * Every UBIFS node starts with this common part. If the node has a key, the
 417 * key always goes next.
 418 */
 419struct ubifs_ch {
 420        __le32 magic;
 421        __le32 crc;
 422        __le64 sqnum;
 423        __le32 len;
 424        __u8 node_type;
 425        __u8 group_type;
 426        __u8 padding[2];
 427} __packed;
 428
 429/**
 430 * union ubifs_dev_desc - device node descriptor.
 431 * @new: new type device descriptor
 432 * @huge: huge type device descriptor
 433 *
 434 * This data structure describes major/minor numbers of a device node. In an
 435 * inode is a device node then its data contains an object of this type. UBIFS
 436 * uses standard Linux "new" and "huge" device node encodings.
 437 */
 438union ubifs_dev_desc {
 439        __le32 new;
 440        __le64 huge;
 441} __packed;
 442
 443/**
 444 * struct ubifs_ino_node - inode node.
 445 * @ch: common header
 446 * @key: node key
 447 * @creat_sqnum: sequence number at time of creation
 448 * @size: inode size in bytes (amount of uncompressed data)
 449 * @atime_sec: access time seconds
 450 * @ctime_sec: creation time seconds
 451 * @mtime_sec: modification time seconds
 452 * @atime_nsec: access time nanoseconds
 453 * @ctime_nsec: creation time nanoseconds
 454 * @mtime_nsec: modification time nanoseconds
 455 * @nlink: number of hard links
 456 * @uid: owner ID
 457 * @gid: group ID
 458 * @mode: access flags
 459 * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc)
 460 * @data_len: inode data length
 461 * @xattr_cnt: count of extended attributes this inode has
 462 * @xattr_size: summarized size of all extended attributes in bytes
 463 * @padding1: reserved for future, zeroes
 464 * @xattr_names: sum of lengths of all extended attribute names belonging to
 465 *               this inode
 466 * @compr_type: compression type used for this inode
 467 * @padding2: reserved for future, zeroes
 468 * @data: data attached to the inode
 469 *
 470 * Note, even though inode compression type is defined by @compr_type, some
 471 * nodes of this inode may be compressed with different compressor - this
 472 * happens if compression type is changed while the inode already has data
 473 * nodes. But @compr_type will be use for further writes to the inode.
 474 *
 475 * Note, do not forget to amend 'zero_ino_node_unused()' function when changing
 476 * the padding fields.
 477 */
 478struct ubifs_ino_node {
 479        struct ubifs_ch ch;
 480        __u8 key[UBIFS_MAX_KEY_LEN];
 481        __le64 creat_sqnum;
 482        __le64 size;
 483        __le64 atime_sec;
 484        __le64 ctime_sec;
 485        __le64 mtime_sec;
 486        __le32 atime_nsec;
 487        __le32 ctime_nsec;
 488        __le32 mtime_nsec;
 489        __le32 nlink;
 490        __le32 uid;
 491        __le32 gid;
 492        __le32 mode;
 493        __le32 flags;
 494        __le32 data_len;
 495        __le32 xattr_cnt;
 496        __le32 xattr_size;
 497        __u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */
 498        __le32 xattr_names;
 499        __le16 compr_type;
 500        __u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */
 501        __u8 data[];
 502} __packed;
 503
 504/**
 505 * struct ubifs_dent_node - directory entry node.
 506 * @ch: common header
 507 * @key: node key
 508 * @inum: target inode number
 509 * @padding1: reserved for future, zeroes
 510 * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc)
 511 * @nlen: name length
 512 * @padding2: reserved for future, zeroes
 513 * @name: zero-terminated name
 514 *
 515 * Note, do not forget to amend 'zero_dent_node_unused()' function when
 516 * changing the padding fields.
 517 */
 518struct ubifs_dent_node {
 519        struct ubifs_ch ch;
 520        __u8 key[UBIFS_MAX_KEY_LEN];
 521        __le64 inum;
 522        __u8 padding1;
 523        __u8 type;
 524        __le16 nlen;
 525        __u8 padding2[4]; /* Watch 'zero_dent_node_unused()' if changing! */
 526#ifndef __UBOOT__
 527        __u8 name[];
 528#else
 529        char name[];
 530#endif
 531} __packed;
 532
 533/**
 534 * struct ubifs_data_node - data node.
 535 * @ch: common header
 536 * @key: node key
 537 * @size: uncompressed data size in bytes
 538 * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc)
 539 * @padding: reserved for future, zeroes
 540 * @data: data
 541 *
 542 * Note, do not forget to amend 'zero_data_node_unused()' function when
 543 * changing the padding fields.
 544 */
 545struct ubifs_data_node {
 546        struct ubifs_ch ch;
 547        __u8 key[UBIFS_MAX_KEY_LEN];
 548        __le32 size;
 549        __le16 compr_type;
 550        __u8 padding[2]; /* Watch 'zero_data_node_unused()' if changing! */
 551        __u8 data[];
 552} __packed;
 553
 554/**
 555 * struct ubifs_trun_node - truncation node.
 556 * @ch: common header
 557 * @inum: truncated inode number
 558 * @padding: reserved for future, zeroes
 559 * @old_size: size before truncation
 560 * @new_size: size after truncation
 561 *
 562 * This node exists only in the journal and never goes to the main area. Note,
 563 * do not forget to amend 'zero_trun_node_unused()' function when changing the
 564 * padding fields.
 565 */
 566struct ubifs_trun_node {
 567        struct ubifs_ch ch;
 568        __le32 inum;
 569        __u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */
 570        __le64 old_size;
 571        __le64 new_size;
 572} __packed;
 573
 574/**
 575 * struct ubifs_pad_node - padding node.
 576 * @ch: common header
 577 * @pad_len: how many bytes after this node are unused (because padded)
 578 * @padding: reserved for future, zeroes
 579 */
 580struct ubifs_pad_node {
 581        struct ubifs_ch ch;
 582        __le32 pad_len;
 583} __packed;
 584
 585/**
 586 * struct ubifs_sb_node - superblock node.
 587 * @ch: common header
 588 * @padding: reserved for future, zeroes
 589 * @key_hash: type of hash function used in keys
 590 * @key_fmt: format of the key
 591 * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
 592 * @min_io_size: minimal input/output unit size
 593 * @leb_size: logical eraseblock size in bytes
 594 * @leb_cnt: count of LEBs used by file-system
 595 * @max_leb_cnt: maximum count of LEBs used by file-system
 596 * @max_bud_bytes: maximum amount of data stored in buds
 597 * @log_lebs: log size in logical eraseblocks
 598 * @lpt_lebs: number of LEBs used for lprops table
 599 * @orph_lebs: number of LEBs used for recording orphans
 600 * @jhead_cnt: count of journal heads
 601 * @fanout: tree fanout (max. number of links per indexing node)
 602 * @lsave_cnt: number of LEB numbers in LPT's save table
 603 * @fmt_version: UBIFS on-flash format version
 604 * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
 605 * @padding1: reserved for future, zeroes
 606 * @rp_uid: reserve pool UID
 607 * @rp_gid: reserve pool GID
 608 * @rp_size: size of the reserved pool in bytes
 609 * @padding2: reserved for future, zeroes
 610 * @time_gran: time granularity in nanoseconds
 611 * @uuid: UUID generated when the file system image was created
 612 * @ro_compat_version: UBIFS R/O compatibility version
 613 */
 614struct ubifs_sb_node {
 615        struct ubifs_ch ch;
 616        __u8 padding[2];
 617        __u8 key_hash;
 618        __u8 key_fmt;
 619        __le32 flags;
 620        __le32 min_io_size;
 621        __le32 leb_size;
 622        __le32 leb_cnt;
 623        __le32 max_leb_cnt;
 624        __le64 max_bud_bytes;
 625        __le32 log_lebs;
 626        __le32 lpt_lebs;
 627        __le32 orph_lebs;
 628        __le32 jhead_cnt;
 629        __le32 fanout;
 630        __le32 lsave_cnt;
 631        __le32 fmt_version;
 632        __le16 default_compr;
 633        __u8 padding1[2];
 634        __le32 rp_uid;
 635        __le32 rp_gid;
 636        __le64 rp_size;
 637        __le32 time_gran;
 638        __u8 uuid[16];
 639        __le32 ro_compat_version;
 640        __u8 padding2[3968];
 641} __packed;
 642
 643/**
 644 * struct ubifs_mst_node - master node.
 645 * @ch: common header
 646 * @highest_inum: highest inode number in the committed index
 647 * @cmt_no: commit number
 648 * @flags: various flags (%UBIFS_MST_DIRTY, etc)
 649 * @log_lnum: start of the log
 650 * @root_lnum: LEB number of the root indexing node
 651 * @root_offs: offset within @root_lnum
 652 * @root_len: root indexing node length
 653 * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was
 654 * not reserved and should be reserved on mount)
 655 * @ihead_lnum: LEB number of index head
 656 * @ihead_offs: offset of index head
 657 * @index_size: size of index on flash
 658 * @total_free: total free space in bytes
 659 * @total_dirty: total dirty space in bytes
 660 * @total_used: total used space in bytes (includes only data LEBs)
 661 * @total_dead: total dead space in bytes (includes only data LEBs)
 662 * @total_dark: total dark space in bytes (includes only data LEBs)
 663 * @lpt_lnum: LEB number of LPT root nnode
 664 * @lpt_offs: offset of LPT root nnode
 665 * @nhead_lnum: LEB number of LPT head
 666 * @nhead_offs: offset of LPT head
 667 * @ltab_lnum: LEB number of LPT's own lprops table
 668 * @ltab_offs: offset of LPT's own lprops table
 669 * @lsave_lnum: LEB number of LPT's save table (big model only)
 670 * @lsave_offs: offset of LPT's save table (big model only)
 671 * @lscan_lnum: LEB number of last LPT scan
 672 * @empty_lebs: number of empty logical eraseblocks
 673 * @idx_lebs: number of indexing logical eraseblocks
 674 * @leb_cnt: count of LEBs used by file-system
 675 * @padding: reserved for future, zeroes
 676 */
 677struct ubifs_mst_node {
 678        struct ubifs_ch ch;
 679        __le64 highest_inum;
 680        __le64 cmt_no;
 681        __le32 flags;
 682        __le32 log_lnum;
 683        __le32 root_lnum;
 684        __le32 root_offs;
 685        __le32 root_len;
 686        __le32 gc_lnum;
 687        __le32 ihead_lnum;
 688        __le32 ihead_offs;
 689        __le64 index_size;
 690        __le64 total_free;
 691        __le64 total_dirty;
 692        __le64 total_used;
 693        __le64 total_dead;
 694        __le64 total_dark;
 695        __le32 lpt_lnum;
 696        __le32 lpt_offs;
 697        __le32 nhead_lnum;
 698        __le32 nhead_offs;
 699        __le32 ltab_lnum;
 700        __le32 ltab_offs;
 701        __le32 lsave_lnum;
 702        __le32 lsave_offs;
 703        __le32 lscan_lnum;
 704        __le32 empty_lebs;
 705        __le32 idx_lebs;
 706        __le32 leb_cnt;
 707        __u8 padding[344];
 708} __packed;
 709
 710/**
 711 * struct ubifs_ref_node - logical eraseblock reference node.
 712 * @ch: common header
 713 * @lnum: the referred logical eraseblock number
 714 * @offs: start offset in the referred LEB
 715 * @jhead: journal head number
 716 * @padding: reserved for future, zeroes
 717 */
 718struct ubifs_ref_node {
 719        struct ubifs_ch ch;
 720        __le32 lnum;
 721        __le32 offs;
 722        __le32 jhead;
 723        __u8 padding[28];
 724} __packed;
 725
 726/**
 727 * struct ubifs_branch - key/reference/length branch
 728 * @lnum: LEB number of the target node
 729 * @offs: offset within @lnum
 730 * @len: target node length
 731 * @key: key
 732 */
 733struct ubifs_branch {
 734        __le32 lnum;
 735        __le32 offs;
 736        __le32 len;
 737#ifndef __UBOOT__
 738        __u8 key[];
 739#else
 740        char key[];
 741#endif
 742} __packed;
 743
 744/**
 745 * struct ubifs_idx_node - indexing node.
 746 * @ch: common header
 747 * @child_cnt: number of child index nodes
 748 * @level: tree level
 749 * @branches: LEB number / offset / length / key branches
 750 */
 751struct ubifs_idx_node {
 752        struct ubifs_ch ch;
 753        __le16 child_cnt;
 754        __le16 level;
 755#ifndef __UBOOT__
 756        __u8 branches[];
 757#else
 758        char branches[];
 759#endif
 760} __packed;
 761
 762/**
 763 * struct ubifs_cs_node - commit start node.
 764 * @ch: common header
 765 * @cmt_no: commit number
 766 */
 767struct ubifs_cs_node {
 768        struct ubifs_ch ch;
 769        __le64 cmt_no;
 770} __packed;
 771
 772/**
 773 * struct ubifs_orph_node - orphan node.
 774 * @ch: common header
 775 * @cmt_no: commit number (also top bit is set on the last node of the commit)
 776 * @inos: inode numbers of orphans
 777 */
 778struct ubifs_orph_node {
 779        struct ubifs_ch ch;
 780        __le64 cmt_no;
 781        __le64 inos[];
 782} __packed;
 783
 784#endif /* __UBIFS_MEDIA_H__ */
 785