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