blob: 6c419f3a233759c7e0998a1e5a25d7792a00bcfe [file] [log] [blame]
Uma Shankar71014b62012-05-25 21:21:44 +05301/*
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
31#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
32#define EXT4_EXT_MAGIC 0xf30a
33#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
34#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
35#define EXT4_INDIRECT_BLOCKS 12
36
37#define EXT4_BG_INODE_UNINIT 0x0001
38#define EXT4_BG_BLOCK_UNINIT 0x0002
39#define EXT4_BG_INODE_ZEROED 0x0004
40
41/*
42 * ext4_inode has i_block array (60 bytes total).
43 * The first 12 bytes store ext4_extent_header;
44 * the remainder stores an array of ext4_extent.
45 */
46
47/*
48 * This is the extent on-disk structure.
49 * It's used at the bottom of the tree.
50 */
51struct ext4_extent {
52 __le32 ee_block; /* first logical block extent covers */
53 __le16 ee_len; /* number of blocks covered by extent */
54 __le16 ee_start_hi; /* high 16 bits of physical block */
55 __le32 ee_start_lo; /* low 32 bits of physical block */
56};
57
58/*
59 * This is index on-disk structure.
60 * It's used at all the levels except the bottom.
61 */
62struct ext4_extent_idx {
63 __le32 ei_block; /* index covers logical blocks from 'block' */
64 __le32 ei_leaf_lo; /* pointer to the physical block of the next *
65 * level. leaf or next index could be there */
66 __le16 ei_leaf_hi; /* high 16 bits of physical block */
67 __u16 ei_unused;
68};
69
70/* Each block (leaves and indexes), even inode-stored has header. */
71struct ext4_extent_header {
72 __le16 eh_magic; /* probably will support different formats */
73 __le16 eh_entries; /* number of valid entries */
74 __le16 eh_max; /* capacity of store in entries */
75 __le16 eh_depth; /* has tree real underlying blocks? */
76 __le32 eh_generation; /* generation of the tree */
77};
78
79struct ext_filesystem {
80 /* Total Sector of partition */
81 uint64_t total_sect;
82 /* Block size of partition */
83 uint32_t blksz;
84 /* Inode size of partition */
85 uint32_t inodesz;
86 /* Sectors per Block */
87 uint32_t sect_perblk;
88 /* Group Descriptor Block Number */
89 uint32_t gdtable_blkno;
90 /* Total block groups of partition */
91 uint32_t no_blkgrp;
92 /* No of blocks required for bgdtable */
93 uint32_t no_blk_pergdt;
94 /* Superblock */
95 struct ext2_sblock *sb;
96 /* Block group descritpor table */
Simon Glassea8e5192012-10-03 11:37:49 +000097 struct ext2_block_group *bgd;
Uma Shankar71014b62012-05-25 21:21:44 +053098 char *gdtable;
99
100 /* Block Bitmap Related */
101 unsigned char **blk_bmaps;
102 long int curr_blkno;
103 uint16_t first_pass_bbmap;
104
105 /* Inode Bitmap Related */
106 unsigned char **inode_bmaps;
107 int curr_inode_no;
108 uint16_t first_pass_ibmap;
109
110 /* Journal Related */
111
112 /* Block Device Descriptor */
113 block_dev_desc_t *dev_desc;
114};
115
Uma Shankar71014b62012-05-25 21:21:44 +0530116extern struct ext2_data *ext4fs_root;
117extern struct ext2fs_node *ext4fs_file;
118
Stephen Warren4f8662d2012-10-22 06:43:50 +0000119#if defined(CONFIG_EXT4_WRITE)
Uma Shankara74a99a2012-05-25 21:22:49 +0530120extern struct ext2_inode *g_parent_inode;
121extern int gd_index;
122extern int gindex;
123
124int ext4fs_init(void);
125void ext4fs_deinit(void);
126int ext4fs_filename_check(char *filename);
127int ext4fs_write(const char *fname, unsigned char *buffer,
128 unsigned long sizebytes);
129#endif
130
Uma Shankar71014b62012-05-25 21:21:44 +0530131struct ext_filesystem *get_fs(void);
Uma Shankar71014b62012-05-25 21:21:44 +0530132int ext4fs_open(const char *filename);
133int ext4fs_read(char *buf, unsigned len);
134int ext4fs_mount(unsigned part_length);
135void ext4fs_close(void);
Ɓukasz Majewski900db5d2014-05-06 09:36:05 +0200136void ext4fs_reinit_global(void);
Uma Shankar71014b62012-05-25 21:21:44 +0530137int ext4fs_ls(const char *dirname);
Stephen Warren12d6d0c2014-02-03 13:21:09 -0700138int ext4fs_exists(const char *filename);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600139int ext4fs_size(const char *filename);
Uma Shankar71014b62012-05-25 21:21:44 +0530140void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
Frederic Leroye7ee0282013-06-26 18:11:25 +0200141int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
Rob Herring752e1bd2012-08-23 11:31:46 +0000142void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
Uma Shankar71014b62012-05-25 21:21:44 +0530143long int read_allocated_block(struct ext2_inode *inode, int fileblock);
Simon Glass19e38582012-12-26 09:53:33 +0000144int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
145 disk_partition_t *fs_partition);
146int ext4_read_file(const char *filename, void *buf, int offset, int len);
Egbert Eich7b1b2552013-05-01 01:13:19 +0000147int ext4_read_superblock(char *buffer);
Uma Shankar71014b62012-05-25 21:21:44 +0530148#endif