ext4_journal.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * (C) Copyright 2011 - 2012 Samsung Electronics
  3. * EXT4 filesystem implementation in Uboot by
  4. * Uma Shankar <uma.shankar@samsung.com>
  5. * Manjunatha C Achar <a.manjunatha@samsung.com>
  6. *
  7. * Journal data structures and headers for Journaling feature of ext4
  8. * have been referred from JBD2 (Journaling Block device 2)
  9. * implementation in Linux Kernel.
  10. *
  11. * Written by Stephen C. Tweedie <sct@redhat.com>
  12. *
  13. * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
  14. * This file is part of the Linux kernel and is made available under
  15. * the terms of the GNU General Public License, version 2, or at your
  16. * option, any later version, incorporated herein by reference.
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #ifndef __EXT4_JRNL__
  33. #define __EXT4_JRNL__
  34. #define EXT2_JOURNAL_INO 8 /* Journal inode */
  35. #define EXT2_JOURNAL_SUPERBLOCK 0 /* Journal Superblock number */
  36. #define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001
  37. #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U
  38. #define TRANSACTION_RUNNING 1
  39. #define TRANSACTION_COMPLETE 0
  40. #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  41. #define EXT3_JOURNAL_DESCRIPTOR_BLOCK 1
  42. #define EXT3_JOURNAL_COMMIT_BLOCK 2
  43. #define EXT3_JOURNAL_SUPERBLOCK_V1 3
  44. #define EXT3_JOURNAL_SUPERBLOCK_V2 4
  45. #define EXT3_JOURNAL_REVOKE_BLOCK 5
  46. #define EXT3_JOURNAL_FLAG_ESCAPE 1
  47. #define EXT3_JOURNAL_FLAG_SAME_UUID 2
  48. #define EXT3_JOURNAL_FLAG_DELETED 4
  49. #define EXT3_JOURNAL_FLAG_LAST_TAG 8
  50. /* Maximum entries in 1 journal transaction */
  51. #define MAX_JOURNAL_ENTRIES 100
  52. struct journal_log {
  53. char *buf;
  54. int blknr;
  55. };
  56. struct dirty_blocks {
  57. char *buf;
  58. int blknr;
  59. };
  60. /* Standard header for all descriptor blocks: */
  61. struct journal_header_t {
  62. __u32 h_magic;
  63. __u32 h_blocktype;
  64. __u32 h_sequence;
  65. };
  66. /* The journal superblock. All fields are in big-endian byte order. */
  67. struct journal_superblock_t {
  68. /* 0x0000 */
  69. struct journal_header_t s_header;
  70. /* Static information describing the journal */
  71. __u32 s_blocksize; /* journal device blocksize */
  72. __u32 s_maxlen; /* total blocks in journal file */
  73. __u32 s_first; /* first block of log information */
  74. /* Dynamic information describing the current state of the log */
  75. __u32 s_sequence; /* first commit ID expected in log */
  76. __u32 s_start; /* blocknr of start of log */
  77. /* Error value, as set by journal_abort(). */
  78. __s32 s_errno;
  79. /* Remaining fields are only valid in a version-2 superblock */
  80. __u32 s_feature_compat; /* compatible feature set */
  81. __u32 s_feature_incompat; /* incompatible feature set */
  82. __u32 s_feature_ro_compat; /* readonly-compatible feature set */
  83. /* 0x0030 */
  84. __u8 s_uuid[16]; /* 128-bit uuid for journal */
  85. /* 0x0040 */
  86. __u32 s_nr_users; /* Nr of filesystems sharing log */
  87. __u32 s_dynsuper; /* Blocknr of dynamic superblock copy */
  88. /* 0x0048 */
  89. __u32 s_max_transaction; /* Limit of journal blocks per trans. */
  90. __u32 s_max_trans_data; /* Limit of data blocks per trans. */
  91. /* 0x0050 */
  92. __u32 s_padding[44];
  93. /* 0x0100 */
  94. __u8 s_users[16 * 48]; /* ids of all fs'es sharing the log */
  95. /* 0x0400 */
  96. } ;
  97. struct ext3_journal_block_tag {
  98. uint32_t block;
  99. uint32_t flags;
  100. };
  101. struct journal_revoke_header_t {
  102. struct journal_header_t r_header;
  103. int r_count; /* Count of bytes used in the block */
  104. };
  105. struct revoke_blk_list {
  106. char *content; /* revoke block itself */
  107. struct revoke_blk_list *next;
  108. };
  109. extern struct ext2_data *ext4fs_root;
  110. int ext4fs_init_journal(void);
  111. int ext4fs_log_gdt(char *gd_table);
  112. int ext4fs_check_journal_state(int recovery_flag);
  113. int ext4fs_log_journal(char *journal_buffer, long int blknr);
  114. int ext4fs_put_metadata(char *metadata_buffer, long int blknr);
  115. void ext4fs_update_journal(void);
  116. void ext4fs_dump_metadata(void);
  117. void ext4fs_push_revoke_blk(char *buffer);
  118. void ext4fs_free_journal(void);
  119. void ext4fs_free_revoke_blks(void);
  120. #endif