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