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 35a1596438SUma Shankar #define EXT4_INDIRECT_BLOCKS 12 36a1596438SUma Shankar 37a1596438SUma Shankar #define EXT4_BG_INODE_UNINIT 0x0001 38a1596438SUma Shankar #define EXT4_BG_BLOCK_UNINIT 0x0002 39a1596438SUma Shankar #define EXT4_BG_INODE_ZEROED 0x0004 40a1596438SUma Shankar 41a1596438SUma Shankar /* 42a1596438SUma Shankar * ext4_inode has i_block array (60 bytes total). 43a1596438SUma Shankar * The first 12 bytes store ext4_extent_header; 44a1596438SUma Shankar * the remainder stores an array of ext4_extent. 45a1596438SUma Shankar */ 46a1596438SUma Shankar 47a1596438SUma Shankar /* 48a1596438SUma Shankar * This is the extent on-disk structure. 49a1596438SUma Shankar * It's used at the bottom of the tree. 50a1596438SUma Shankar */ 51a1596438SUma Shankar struct ext4_extent { 52a1596438SUma Shankar __le32 ee_block; /* first logical block extent covers */ 53a1596438SUma Shankar __le16 ee_len; /* number of blocks covered by extent */ 54a1596438SUma Shankar __le16 ee_start_hi; /* high 16 bits of physical block */ 55a1596438SUma Shankar __le32 ee_start_lo; /* low 32 bits of physical block */ 56a1596438SUma Shankar }; 57a1596438SUma Shankar 58a1596438SUma Shankar /* 59a1596438SUma Shankar * This is index on-disk structure. 60a1596438SUma Shankar * It's used at all the levels except the bottom. 61a1596438SUma Shankar */ 62a1596438SUma Shankar struct ext4_extent_idx { 63a1596438SUma Shankar __le32 ei_block; /* index covers logical blocks from 'block' */ 64a1596438SUma Shankar __le32 ei_leaf_lo; /* pointer to the physical block of the next * 65a1596438SUma Shankar * level. leaf or next index could be there */ 66a1596438SUma Shankar __le16 ei_leaf_hi; /* high 16 bits of physical block */ 67a1596438SUma Shankar __u16 ei_unused; 68a1596438SUma Shankar }; 69a1596438SUma Shankar 70a1596438SUma Shankar /* Each block (leaves and indexes), even inode-stored has header. */ 71a1596438SUma Shankar struct ext4_extent_header { 72a1596438SUma Shankar __le16 eh_magic; /* probably will support different formats */ 73a1596438SUma Shankar __le16 eh_entries; /* number of valid entries */ 74a1596438SUma Shankar __le16 eh_max; /* capacity of store in entries */ 75a1596438SUma Shankar __le16 eh_depth; /* has tree real underlying blocks? */ 76a1596438SUma Shankar __le32 eh_generation; /* generation of the tree */ 77a1596438SUma Shankar }; 78a1596438SUma Shankar 79a1596438SUma Shankar struct ext_filesystem { 80a1596438SUma Shankar /* Total Sector of partition */ 81a1596438SUma Shankar uint64_t total_sect; 82a1596438SUma Shankar /* Block size of partition */ 83a1596438SUma Shankar uint32_t blksz; 84a1596438SUma Shankar /* Inode size of partition */ 85a1596438SUma Shankar uint32_t inodesz; 86a1596438SUma Shankar /* Sectors per Block */ 87a1596438SUma Shankar uint32_t sect_perblk; 88a1596438SUma Shankar /* Group Descriptor Block Number */ 89a1596438SUma Shankar uint32_t gdtable_blkno; 90a1596438SUma Shankar /* Total block groups of partition */ 91a1596438SUma Shankar uint32_t no_blkgrp; 92a1596438SUma Shankar /* No of blocks required for bgdtable */ 93a1596438SUma Shankar uint32_t no_blk_pergdt; 94a1596438SUma Shankar /* Superblock */ 95a1596438SUma Shankar struct ext2_sblock *sb; 96a1596438SUma Shankar /* Block group descritpor table */ 9773c15c63SSimon Glass struct ext2_block_group *bgd; 98a1596438SUma Shankar char *gdtable; 99a1596438SUma Shankar 100a1596438SUma Shankar /* Block Bitmap Related */ 101a1596438SUma Shankar unsigned char **blk_bmaps; 102a1596438SUma Shankar long int curr_blkno; 103a1596438SUma Shankar uint16_t first_pass_bbmap; 104a1596438SUma Shankar 105a1596438SUma Shankar /* Inode Bitmap Related */ 106a1596438SUma Shankar unsigned char **inode_bmaps; 107a1596438SUma Shankar int curr_inode_no; 108a1596438SUma Shankar uint16_t first_pass_ibmap; 109a1596438SUma Shankar 110a1596438SUma Shankar /* Journal Related */ 111a1596438SUma Shankar 112a1596438SUma Shankar /* Block Device Descriptor */ 113a1596438SUma Shankar block_dev_desc_t *dev_desc; 114a1596438SUma Shankar }; 115a1596438SUma Shankar 116a1596438SUma Shankar extern struct ext2_data *ext4fs_root; 117a1596438SUma Shankar extern struct ext2fs_node *ext4fs_file; 118a1596438SUma Shankar 11903e2ecf6SStephen Warren #if defined(CONFIG_EXT4_WRITE) 120ed34f34dSUma Shankar extern struct ext2_inode *g_parent_inode; 121ed34f34dSUma Shankar extern int gd_index; 122ed34f34dSUma Shankar extern int gindex; 123ed34f34dSUma Shankar 124ed34f34dSUma Shankar int ext4fs_init(void); 125ed34f34dSUma Shankar void ext4fs_deinit(void); 126ed34f34dSUma Shankar int ext4fs_filename_check(char *filename); 127ed34f34dSUma Shankar int ext4fs_write(const char *fname, unsigned char *buffer, 128ed34f34dSUma Shankar unsigned long sizebytes); 129ed34f34dSUma Shankar #endif 130ed34f34dSUma Shankar 131a1596438SUma Shankar struct ext_filesystem *get_fs(void); 132a1596438SUma Shankar int ext4fs_open(const char *filename); 133a1596438SUma Shankar int ext4fs_read(char *buf, unsigned len); 134a1596438SUma Shankar int ext4fs_mount(unsigned part_length); 135a1596438SUma Shankar void ext4fs_close(void); 136a1596438SUma Shankar int ext4fs_ls(const char *dirname); 137a1596438SUma Shankar void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); 138*04735e9cSFrederic Leroy int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf); 13981180819SRob Herring void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); 140a1596438SUma Shankar long int read_allocated_block(struct ext2_inode *inode, int fileblock); 141e6d52415SSimon Glass int ext4fs_probe(block_dev_desc_t *fs_dev_desc, 142e6d52415SSimon Glass disk_partition_t *fs_partition); 143e6d52415SSimon Glass int ext4_read_file(const char *filename, void *buf, int offset, int len); 14450ce4c07SEgbert Eich int ext4_read_superblock(char *buffer); 145a1596438SUma Shankar #endif 146