ext4_journal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2011 - 2012 Samsung Electronics
  4. * EXT4 filesystem implementation in Uboot by
  5. * Uma Shankar <uma.shankar@samsung.com>
  6. * Manjunatha C Achar <a.manjunatha@samsung.com>
  7. *
  8. * Journal data structures and headers for Journaling feature of ext4
  9. * have been referred from JBD2 (Journaling Block device 2)
  10. * implementation in Linux Kernel.
  11. *
  12. * Written by Stephen C. Tweedie <sct@redhat.com>
  13. *
  14. * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
  15. */
  16. #ifndef __EXT4_JRNL__
  17. #define __EXT4_JRNL__
  18. #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  19. #define EXT2_JOURNAL_INO 8 /* Journal inode */
  20. #define EXT2_JOURNAL_SUPERBLOCK 0 /* Journal Superblock number */
  21. #define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001
  22. #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U
  23. #define TRANSACTION_RUNNING 1
  24. #define TRANSACTION_COMPLETE 0
  25. #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  26. #define EXT3_JOURNAL_DESCRIPTOR_BLOCK 1
  27. #define EXT3_JOURNAL_COMMIT_BLOCK 2
  28. #define EXT3_JOURNAL_SUPERBLOCK_V1 3
  29. #define EXT3_JOURNAL_SUPERBLOCK_V2 4
  30. #define EXT3_JOURNAL_REVOKE_BLOCK 5
  31. #define EXT3_JOURNAL_FLAG_ESCAPE 1
  32. #define EXT3_JOURNAL_FLAG_SAME_UUID 2
  33. #define EXT3_JOURNAL_FLAG_DELETED 4
  34. #define EXT3_JOURNAL_FLAG_LAST_TAG 8
  35. /* Maximum entries in 1 journal transaction */
  36. #define MAX_JOURNAL_ENTRIES 100
  37. struct journal_log {
  38. char *buf;
  39. int blknr;
  40. };
  41. struct dirty_blocks {
  42. char *buf;
  43. int blknr;
  44. };
  45. /* Standard header for all descriptor blocks: */
  46. struct journal_header_t {
  47. __be32 h_magic;
  48. __be32 h_blocktype;
  49. __be32 h_sequence;
  50. };
  51. /* The journal superblock. All fields are in big-endian byte order. */
  52. struct journal_superblock_t {
  53. /* 0x0000 */
  54. struct journal_header_t s_header;
  55. /* Static information describing the journal */
  56. __be32 s_blocksize; /* journal device blocksize */
  57. __be32 s_maxlen; /* total blocks in journal file */
  58. __be32 s_first; /* first block of log information */
  59. /* Dynamic information describing the current state of the log */
  60. __be32 s_sequence; /* first commit ID expected in log */
  61. __be32 s_start; /* blocknr of start of log */
  62. /* Error value, as set by journal_abort(). */
  63. __be32 s_errno;
  64. /* Remaining fields are only valid in a version-2 superblock */
  65. __be32 s_feature_compat; /* compatible feature set */
  66. __be32 s_feature_incompat; /* incompatible feature set */
  67. __be32 s_feature_ro_compat; /* readonly-compatible feature set */
  68. /* 0x0030 */
  69. __u8 s_uuid[16]; /* 128-bit uuid for journal */
  70. /* 0x0040 */
  71. __be32 s_nr_users; /* Nr of filesystems sharing log */
  72. __be32 s_dynsuper; /* Blocknr of dynamic superblock copy */
  73. /* 0x0048 */
  74. __be32 s_max_transaction; /* Limit of journal blocks per trans. */
  75. __be32 s_max_trans_data; /* Limit of data blocks per trans. */
  76. /* 0x0050 */
  77. __be32 s_padding[44];
  78. /* 0x0100 */
  79. __u8 s_users[16 * 48]; /* ids of all fs'es sharing the log */
  80. /* 0x0400 */
  81. } ;
  82. struct ext3_journal_block_tag {
  83. __be32 block;
  84. __be32 flags;
  85. };
  86. struct journal_revoke_header_t {
  87. struct journal_header_t r_header;
  88. __be32 r_count; /* Count of bytes used in the block */
  89. };
  90. struct revoke_blk_list {
  91. char *content; /* revoke block itself */
  92. struct revoke_blk_list *next;
  93. };
  94. extern struct ext2_data *ext4fs_root;
  95. int ext4fs_init_journal(void);
  96. int ext4fs_log_gdt(char *gd_table);
  97. int ext4fs_check_journal_state(int recovery_flag);
  98. int ext4fs_log_journal(char *journal_buffer, uint32_t blknr);
  99. int ext4fs_put_metadata(char *metadata_buffer, uint32_t blknr);
  100. void ext4fs_update_journal(void);
  101. void ext4fs_dump_metadata(void);
  102. void ext4fs_push_revoke_blk(char *buffer);
  103. void ext4fs_free_journal(void);
  104. void ext4fs_free_revoke_blks(void);
  105. #endif