blob: 13d2c5603bddc0c2bb7dc30aea41240e14e5fccd [file] [log] [blame]
Uma Shankara1596432012-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
Tom Rini6f94ab62016-07-22 17:59:11 -040035#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
Uma Shankara1596432012-05-25 21:21:44 +053036#define EXT4_INDIRECT_BLOCKS 12
37
38#define EXT4_BG_INODE_UNINIT 0x0001
39#define EXT4_BG_BLOCK_UNINIT 0x0002
40#define EXT4_BG_INODE_ZEROED 0x0004
41
42/*
43 * ext4_inode has i_block array (60 bytes total).
44 * The first 12 bytes store ext4_extent_header;
45 * the remainder stores an array of ext4_extent.
46 */
47
48/*
49 * This is the extent on-disk structure.
50 * It's used at the bottom of the tree.
51 */
52struct ext4_extent {
53 __le32 ee_block; /* first logical block extent covers */
54 __le16 ee_len; /* number of blocks covered by extent */
55 __le16 ee_start_hi; /* high 16 bits of physical block */
56 __le32 ee_start_lo; /* low 32 bits of physical block */
57};
58
59/*
60 * This is index on-disk structure.
61 * It's used at all the levels except the bottom.
62 */
63struct ext4_extent_idx {
64 __le32 ei_block; /* index covers logical blocks from 'block' */
65 __le32 ei_leaf_lo; /* pointer to the physical block of the next *
66 * level. leaf or next index could be there */
67 __le16 ei_leaf_hi; /* high 16 bits of physical block */
68 __u16 ei_unused;
69};
70
71/* Each block (leaves and indexes), even inode-stored has header. */
72struct ext4_extent_header {
73 __le16 eh_magic; /* probably will support different formats */
74 __le16 eh_entries; /* number of valid entries */
75 __le16 eh_max; /* capacity of store in entries */
76 __le16 eh_depth; /* has tree real underlying blocks? */
77 __le32 eh_generation; /* generation of the tree */
78};
79
80struct ext_filesystem {
81 /* Total Sector of partition */
82 uint64_t total_sect;
83 /* Block size of partition */
84 uint32_t blksz;
85 /* Inode size of partition */
86 uint32_t inodesz;
87 /* Sectors per Block */
88 uint32_t sect_perblk;
89 /* Group Descriptor Block Number */
90 uint32_t gdtable_blkno;
91 /* Total block groups of partition */
92 uint32_t no_blkgrp;
93 /* No of blocks required for bgdtable */
94 uint32_t no_blk_pergdt;
95 /* Superblock */
96 struct ext2_sblock *sb;
97 /* Block group descritpor table */
Simon Glass73c15c62012-10-03 11:37:49 +000098 struct ext2_block_group *bgd;
Uma Shankara1596432012-05-25 21:21:44 +053099 char *gdtable;
100
101 /* Block Bitmap Related */
102 unsigned char **blk_bmaps;
103 long int curr_blkno;
104 uint16_t first_pass_bbmap;
105
106 /* Inode Bitmap Related */
107 unsigned char **inode_bmaps;
108 int curr_inode_no;
109 uint16_t first_pass_ibmap;
110
111 /* Journal Related */
112
113 /* Block Device Descriptor */
Simon Glass4101f682016-02-29 15:25:34 -0700114 struct blk_desc *dev_desc;
Uma Shankara1596432012-05-25 21:21:44 +0530115};
116
Uma Shankara1596432012-05-25 21:21:44 +0530117extern struct ext2_data *ext4fs_root;
118extern struct ext2fs_node *ext4fs_file;
119
Stephen Warren03e2ecf2012-10-22 06:43:50 +0000120#if defined(CONFIG_EXT4_WRITE)
Uma Shankared34f342012-05-25 21:22:49 +0530121extern struct ext2_inode *g_parent_inode;
122extern int gd_index;
123extern int gindex;
124
125int ext4fs_init(void);
126void ext4fs_deinit(void);
127int ext4fs_filename_check(char *filename);
128int ext4fs_write(const char *fname, unsigned char *buffer,
Suriyan Ramasami9f12cd02014-11-17 14:39:36 -0800129 unsigned long sizebytes);
130int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len,
131 loff_t *actwrite);
Uma Shankared34f342012-05-25 21:22:49 +0530132#endif
133
Uma Shankara1596432012-05-25 21:21:44 +0530134struct ext_filesystem *get_fs(void);
Suriyan Ramasami9f12cd02014-11-17 14:39:36 -0800135int ext4fs_open(const char *filename, loff_t *len);
136int ext4fs_read(char *buf, loff_t len, loff_t *actread);
Uma Shankara1596432012-05-25 21:21:44 +0530137int ext4fs_mount(unsigned part_length);
138void ext4fs_close(void);
Ɓukasz Majewski8b454ee2014-05-06 09:36:05 +0200139void ext4fs_reinit_global(void);
Uma Shankara1596432012-05-25 21:21:44 +0530140int ext4fs_ls(const char *dirname);
Stephen Warren55af5c92014-02-03 13:21:09 -0700141int ext4fs_exists(const char *filename);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800142int ext4fs_size(const char *filename, loff_t *size);
Uma Shankara1596432012-05-25 21:21:44 +0530143void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
Frederic Leroy04735e92013-06-26 18:11:25 +0200144int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
Simon Glass4101f682016-02-29 15:25:34 -0700145void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
Uma Shankara1596432012-05-25 21:21:44 +0530146long int read_allocated_block(struct ext2_inode *inode, int fileblock);
Simon Glass4101f682016-02-29 15:25:34 -0700147int ext4fs_probe(struct blk_desc *fs_dev_desc,
Simon Glasse6d52412012-12-26 09:53:33 +0000148 disk_partition_t *fs_partition);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800149int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
150 loff_t *actread);
Egbert Eich50ce4c02013-05-01 01:13:19 +0000151int ext4_read_superblock(char *buffer);
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100152int ext4fs_uuid(char *uuid_str);
Uma Shankara1596432012-05-25 21:21:44 +0530153#endif