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>
7 * Ext4 Extent data structures are taken from original ext4 fs code
8 * as found in the linux kernel.
10 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
11 * Written by Alex Tomas <alex@clusterfs.com>
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.
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.
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.
29 #include <ext_common.h>
31 #define EXT4_INDEX_FL 0x00001000 /* Inode uses hash tree index */
32 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
33 #define EXT4_EXT_MAGIC 0xf30a
34 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
35 #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
36 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
37 #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
38 #define EXT4_INDIRECT_BLOCKS 12
40 #define EXT4_BG_INODE_UNINIT 0x0001
41 #define EXT4_BG_BLOCK_UNINIT 0x0002
42 #define EXT4_BG_INODE_ZEROED 0x0004
45 * ext4_inode has i_block array (60 bytes total).
46 * The first 12 bytes store ext4_extent_header;
47 * the remainder stores an array of ext4_extent.
51 * This is the extent on-disk structure.
52 * It's used at the bottom of the tree.
55 __le32 ee_block; /* first logical block extent covers */
56 __le16 ee_len; /* number of blocks covered by extent */
57 __le16 ee_start_hi; /* high 16 bits of physical block */
58 __le32 ee_start_lo; /* low 32 bits of physical block */
62 * This is index on-disk structure.
63 * It's used at all the levels except the bottom.
65 struct ext4_extent_idx {
66 __le32 ei_block; /* index covers logical blocks from 'block' */
67 __le32 ei_leaf_lo; /* pointer to the physical block of the next *
68 * level. leaf or next index could be there */
69 __le16 ei_leaf_hi; /* high 16 bits of physical block */
73 /* Each block (leaves and indexes), even inode-stored has header. */
74 struct ext4_extent_header {
75 __le16 eh_magic; /* probably will support different formats */
76 __le16 eh_entries; /* number of valid entries */
77 __le16 eh_max; /* capacity of store in entries */
78 __le16 eh_depth; /* has tree real underlying blocks? */
79 __le32 eh_generation; /* generation of the tree */
82 struct ext_filesystem {
83 /* Total Sector of partition */
85 /* Block size of partition */
87 /* Inode size of partition */
89 /* Sectors per Block */
91 /* Group Descriptor size */
93 /* Group Descriptor Block Number */
94 uint32_t gdtable_blkno;
95 /* Total block groups of partition */
97 /* No of blocks required for bgdtable */
98 uint32_t no_blk_pergdt;
100 struct ext2_sblock *sb;
101 /* Block group descritpor table */
104 /* Block Bitmap Related */
105 unsigned char **blk_bmaps;
107 uint16_t first_pass_bbmap;
109 /* Inode Bitmap Related */
110 unsigned char **inode_bmaps;
112 uint16_t first_pass_ibmap;
114 /* Journal Related */
116 /* Block Device Descriptor */
117 struct blk_desc *dev_desc;
120 struct ext_block_cache {
126 extern struct ext2_data *ext4fs_root;
127 extern struct ext2fs_node *ext4fs_file;
129 #if defined(CONFIG_EXT4_WRITE)
130 extern struct ext2_inode *g_parent_inode;
134 int ext4fs_init(void);
135 void ext4fs_deinit(void);
136 int ext4fs_filename_unlink(char *filename);
137 int ext4fs_write(const char *fname, const char *buffer,
138 unsigned long sizebytes, int type);
139 int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len,
141 int ext4fs_create_link(const char *target, const char *fname);
144 struct ext_filesystem *get_fs(void);
145 int ext4fs_open(const char *filename, loff_t *len);
146 int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread);
147 int ext4fs_mount(unsigned part_length);
148 void ext4fs_close(void);
149 void ext4fs_reinit_global(void);
150 int ext4fs_ls(const char *dirname);
151 int ext4fs_exists(const char *filename);
152 int ext4fs_size(const char *filename, loff_t *size);
153 void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
154 int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
155 void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
156 long int read_allocated_block(struct ext2_inode *inode, int fileblock,
157 struct ext_block_cache *cache);
158 int ext4fs_probe(struct blk_desc *fs_dev_desc,
159 disk_partition_t *fs_partition);
160 int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
162 int ext4_read_superblock(char *buffer);
163 int ext4fs_uuid(char *uuid_str);
164 void ext_cache_init(struct ext_block_cache *cache);
165 void ext_cache_fini(struct ext_block_cache *cache);
166 int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size);