ext4fs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * Ext4 Extent data structures are taken from original ext4 fs code
  8. * as found in the linux kernel.
  9. *
  10. * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
  11. * Written by Alex Tomas <alex@clusterfs.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #ifndef __EXT4__
  27. #define __EXT4__
  28. #include <ext_common.h>
  29. #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
  30. #define EXT4_EXT_MAGIC 0xf30a
  31. #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
  32. #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
  33. #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
  34. #define EXT4_INDIRECT_BLOCKS 12
  35. #define EXT4_BG_INODE_UNINIT 0x0001
  36. #define EXT4_BG_BLOCK_UNINIT 0x0002
  37. #define EXT4_BG_INODE_ZEROED 0x0004
  38. /*
  39. * ext4_inode has i_block array (60 bytes total).
  40. * The first 12 bytes store ext4_extent_header;
  41. * the remainder stores an array of ext4_extent.
  42. */
  43. /*
  44. * This is the extent on-disk structure.
  45. * It's used at the bottom of the tree.
  46. */
  47. struct ext4_extent {
  48. __le32 ee_block; /* first logical block extent covers */
  49. __le16 ee_len; /* number of blocks covered by extent */
  50. __le16 ee_start_hi; /* high 16 bits of physical block */
  51. __le32 ee_start_lo; /* low 32 bits of physical block */
  52. };
  53. /*
  54. * This is index on-disk structure.
  55. * It's used at all the levels except the bottom.
  56. */
  57. struct ext4_extent_idx {
  58. __le32 ei_block; /* index covers logical blocks from 'block' */
  59. __le32 ei_leaf_lo; /* pointer to the physical block of the next *
  60. * level. leaf or next index could be there */
  61. __le16 ei_leaf_hi; /* high 16 bits of physical block */
  62. __u16 ei_unused;
  63. };
  64. /* Each block (leaves and indexes), even inode-stored has header. */
  65. struct ext4_extent_header {
  66. __le16 eh_magic; /* probably will support different formats */
  67. __le16 eh_entries; /* number of valid entries */
  68. __le16 eh_max; /* capacity of store in entries */
  69. __le16 eh_depth; /* has tree real underlying blocks? */
  70. __le32 eh_generation; /* generation of the tree */
  71. };
  72. struct ext_filesystem {
  73. /* Total Sector of partition */
  74. uint64_t total_sect;
  75. /* Block size of partition */
  76. uint32_t blksz;
  77. /* Inode size of partition */
  78. uint32_t inodesz;
  79. /* Sectors per Block */
  80. uint32_t sect_perblk;
  81. /* Group Descriptor Block Number */
  82. uint32_t gdtable_blkno;
  83. /* Total block groups of partition */
  84. uint32_t no_blkgrp;
  85. /* No of blocks required for bgdtable */
  86. uint32_t no_blk_pergdt;
  87. /* Superblock */
  88. struct ext2_sblock *sb;
  89. /* Block group descritpor table */
  90. struct ext2_block_group *bgd;
  91. char *gdtable;
  92. /* Block Bitmap Related */
  93. unsigned char **blk_bmaps;
  94. long int curr_blkno;
  95. uint16_t first_pass_bbmap;
  96. /* Inode Bitmap Related */
  97. unsigned char **inode_bmaps;
  98. int curr_inode_no;
  99. uint16_t first_pass_ibmap;
  100. /* Journal Related */
  101. /* Block Device Descriptor */
  102. struct blk_desc *dev_desc;
  103. };
  104. extern struct ext2_data *ext4fs_root;
  105. extern struct ext2fs_node *ext4fs_file;
  106. #if defined(CONFIG_EXT4_WRITE)
  107. extern struct ext2_inode *g_parent_inode;
  108. extern int gd_index;
  109. extern int gindex;
  110. int ext4fs_init(void);
  111. void ext4fs_deinit(void);
  112. int ext4fs_filename_check(char *filename);
  113. int ext4fs_write(const char *fname, unsigned char *buffer,
  114. unsigned long sizebytes);
  115. int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len,
  116. loff_t *actwrite);
  117. #endif
  118. struct ext_filesystem *get_fs(void);
  119. int ext4fs_open(const char *filename, loff_t *len);
  120. int ext4fs_read(char *buf, loff_t len, loff_t *actread);
  121. int ext4fs_mount(unsigned part_length);
  122. void ext4fs_close(void);
  123. void ext4fs_reinit_global(void);
  124. int ext4fs_ls(const char *dirname);
  125. int ext4fs_exists(const char *filename);
  126. int ext4fs_size(const char *filename, loff_t *size);
  127. void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
  128. int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
  129. void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
  130. long int read_allocated_block(struct ext2_inode *inode, int fileblock);
  131. int ext4fs_probe(struct blk_desc *fs_dev_desc,
  132. disk_partition_t *fs_partition);
  133. int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
  134. loff_t *actread);
  135. int ext4_read_superblock(char *buffer);
  136. int ext4fs_uuid(char *uuid_str);
  137. #endif