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