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