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 3110a7a1b8SStefan Brüns #define EXT4_INDEX_FL 0x00001000 /* Inode uses hash tree index */ 32a1596438SUma Shankar #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 33a1596438SUma Shankar #define EXT4_EXT_MAGIC 0xf30a 34a1596438SUma Shankar #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 35a1596438SUma Shankar #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 366f94ab66STom Rini #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 37a1596438SUma Shankar #define EXT4_INDIRECT_BLOCKS 12 38a1596438SUma Shankar 39a1596438SUma Shankar #define EXT4_BG_INODE_UNINIT 0x0001 40a1596438SUma Shankar #define EXT4_BG_BLOCK_UNINIT 0x0002 41a1596438SUma Shankar #define EXT4_BG_INODE_ZEROED 0x0004 42a1596438SUma Shankar 43a1596438SUma Shankar /* 44a1596438SUma Shankar * ext4_inode has i_block array (60 bytes total). 45a1596438SUma Shankar * The first 12 bytes store ext4_extent_header; 46a1596438SUma Shankar * the remainder stores an array of ext4_extent. 47a1596438SUma Shankar */ 48a1596438SUma Shankar 49a1596438SUma Shankar /* 50a1596438SUma Shankar * This is the extent on-disk structure. 51a1596438SUma Shankar * It's used at the bottom of the tree. 52a1596438SUma Shankar */ 53a1596438SUma Shankar struct ext4_extent { 54a1596438SUma Shankar __le32 ee_block; /* first logical block extent covers */ 55a1596438SUma Shankar __le16 ee_len; /* number of blocks covered by extent */ 56a1596438SUma Shankar __le16 ee_start_hi; /* high 16 bits of physical block */ 57a1596438SUma Shankar __le32 ee_start_lo; /* low 32 bits of physical block */ 58a1596438SUma Shankar }; 59a1596438SUma Shankar 60a1596438SUma Shankar /* 61a1596438SUma Shankar * This is index on-disk structure. 62a1596438SUma Shankar * It's used at all the levels except the bottom. 63a1596438SUma Shankar */ 64a1596438SUma Shankar struct ext4_extent_idx { 65a1596438SUma Shankar __le32 ei_block; /* index covers logical blocks from 'block' */ 66a1596438SUma Shankar __le32 ei_leaf_lo; /* pointer to the physical block of the next * 67a1596438SUma Shankar * level. leaf or next index could be there */ 68a1596438SUma Shankar __le16 ei_leaf_hi; /* high 16 bits of physical block */ 69a1596438SUma Shankar __u16 ei_unused; 70a1596438SUma Shankar }; 71a1596438SUma Shankar 72a1596438SUma Shankar /* Each block (leaves and indexes), even inode-stored has header. */ 73a1596438SUma Shankar struct ext4_extent_header { 74a1596438SUma Shankar __le16 eh_magic; /* probably will support different formats */ 75a1596438SUma Shankar __le16 eh_entries; /* number of valid entries */ 76a1596438SUma Shankar __le16 eh_max; /* capacity of store in entries */ 77a1596438SUma Shankar __le16 eh_depth; /* has tree real underlying blocks? */ 78a1596438SUma Shankar __le32 eh_generation; /* generation of the tree */ 79a1596438SUma Shankar }; 80a1596438SUma Shankar 81a1596438SUma Shankar struct ext_filesystem { 82a1596438SUma Shankar /* Total Sector of partition */ 83a1596438SUma Shankar uint64_t total_sect; 84a1596438SUma Shankar /* Block size of partition */ 85a1596438SUma Shankar uint32_t blksz; 86a1596438SUma Shankar /* Inode size of partition */ 87a1596438SUma Shankar uint32_t inodesz; 88a1596438SUma Shankar /* Sectors per Block */ 89a1596438SUma Shankar uint32_t sect_perblk; 90fc214ef9SStefan Brüns /* Group Descriptor size */ 91fc214ef9SStefan Brüns uint16_t gdsize; 92a1596438SUma Shankar /* Group Descriptor Block Number */ 93a1596438SUma Shankar uint32_t gdtable_blkno; 94a1596438SUma Shankar /* Total block groups of partition */ 95a1596438SUma Shankar uint32_t no_blkgrp; 96a1596438SUma Shankar /* No of blocks required for bgdtable */ 97a1596438SUma Shankar uint32_t no_blk_pergdt; 98a1596438SUma Shankar /* Superblock */ 99a1596438SUma Shankar struct ext2_sblock *sb; 100a1596438SUma Shankar /* Block group descritpor table */ 101a1596438SUma Shankar char *gdtable; 102a1596438SUma Shankar 103a1596438SUma Shankar /* Block Bitmap Related */ 104a1596438SUma Shankar unsigned char **blk_bmaps; 105a1596438SUma Shankar long int curr_blkno; 106a1596438SUma Shankar uint16_t first_pass_bbmap; 107a1596438SUma Shankar 108a1596438SUma Shankar /* Inode Bitmap Related */ 109a1596438SUma Shankar unsigned char **inode_bmaps; 110a1596438SUma Shankar int curr_inode_no; 111a1596438SUma Shankar uint16_t first_pass_ibmap; 112a1596438SUma Shankar 113a1596438SUma Shankar /* Journal Related */ 114a1596438SUma Shankar 115a1596438SUma Shankar /* Block Device Descriptor */ 1164101f687SSimon Glass struct blk_desc *dev_desc; 117a1596438SUma Shankar }; 118a1596438SUma Shankar 119a1596438SUma Shankar extern struct ext2_data *ext4fs_root; 120a1596438SUma Shankar extern struct ext2fs_node *ext4fs_file; 121a1596438SUma Shankar 12203e2ecf6SStephen Warren #if defined(CONFIG_EXT4_WRITE) 123ed34f34dSUma Shankar extern struct ext2_inode *g_parent_inode; 124ed34f34dSUma Shankar extern int gd_index; 125ed34f34dSUma Shankar extern int gindex; 126ed34f34dSUma Shankar 127ed34f34dSUma Shankar int ext4fs_init(void); 128ed34f34dSUma Shankar void ext4fs_deinit(void); 12976a29519SStefan Brüns int ext4fs_filename_unlink(char *filename); 130ed34f34dSUma Shankar int ext4fs_write(const char *fname, unsigned char *buffer, 131ed34f34dSUma Shankar unsigned long sizebytes); 1329f12cd0eSSuriyan Ramasami int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len, 1339f12cd0eSSuriyan Ramasami loff_t *actwrite); 134ed34f34dSUma Shankar #endif 135*2433663cSJoseph Chen #if defined(CONFIG_CMD_EXT4_SPARSE_WRITE) 136*2433663cSJoseph Chen int ext4_unsparse(struct blk_desc *desc, const u8 *buf, ulong start); 137*2433663cSJoseph Chen #endif 138a1596438SUma Shankar struct ext_filesystem *get_fs(void); 1399f12cd0eSSuriyan Ramasami int ext4fs_open(const char *filename, loff_t *len); 14066a47ff2SStefan Brüns int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread); 141a1596438SUma Shankar int ext4fs_mount(unsigned part_length); 142a1596438SUma Shankar void ext4fs_close(void); 1438b454eeeSŁukasz Majewski void ext4fs_reinit_global(void); 144a1596438SUma Shankar int ext4fs_ls(const char *dirname); 14555af5c93SStephen Warren int ext4fs_exists(const char *filename); 146d455d878SSuriyan Ramasami int ext4fs_size(const char *filename, loff_t *size); 147a1596438SUma Shankar void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); 14804735e9cSFrederic Leroy int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf); 1494101f687SSimon Glass void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info); 150a1596438SUma Shankar long int read_allocated_block(struct ext2_inode *inode, int fileblock); 1514101f687SSimon Glass int ext4fs_probe(struct blk_desc *fs_dev_desc, 152e6d52415SSimon Glass disk_partition_t *fs_partition); 153d455d878SSuriyan Ramasami int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len, 154d455d878SSuriyan Ramasami loff_t *actread); 15550ce4c07SEgbert Eich int ext4_read_superblock(char *buffer); 15659e890efSChristian Gmeiner int ext4fs_uuid(char *uuid_str); 157a1596438SUma Shankar #endif 158