blob: cb5d9cc0a5c050dcc0fa33b22eb72c4a8555205d [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
Simon Glasse6f6f9e2020-05-10 11:39:58 -060031struct disk_partition;
32
Stefan Brüns10a7a1b2016-09-06 04:36:45 +020033#define EXT4_INDEX_FL 0x00001000 /* Inode uses hash tree index */
Uma Shankara1596432012-05-25 21:21:44 +053034#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
35#define EXT4_EXT_MAGIC 0xf30a
36#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
Sébastien Szymanski2e736552019-03-22 09:33:52 +010037#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
Uma Shankara1596432012-05-25 21:21:44 +053038#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
Tom Rini6f94ab62016-07-22 17:59:11 -040039#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
Uma Shankara1596432012-05-25 21:21:44 +053040#define EXT4_INDIRECT_BLOCKS 12
41
42#define EXT4_BG_INODE_UNINIT 0x0001
43#define EXT4_BG_BLOCK_UNINIT 0x0002
44#define EXT4_BG_INODE_ZEROED 0x0004
45
46/*
47 * ext4_inode has i_block array (60 bytes total).
48 * The first 12 bytes store ext4_extent_header;
49 * the remainder stores an array of ext4_extent.
50 */
51
52/*
53 * This is the extent on-disk structure.
54 * It's used at the bottom of the tree.
55 */
56struct ext4_extent {
57 __le32 ee_block; /* first logical block extent covers */
58 __le16 ee_len; /* number of blocks covered by extent */
59 __le16 ee_start_hi; /* high 16 bits of physical block */
60 __le32 ee_start_lo; /* low 32 bits of physical block */
61};
62
63/*
64 * This is index on-disk structure.
65 * It's used at all the levels except the bottom.
66 */
67struct ext4_extent_idx {
68 __le32 ei_block; /* index covers logical blocks from 'block' */
69 __le32 ei_leaf_lo; /* pointer to the physical block of the next *
70 * level. leaf or next index could be there */
71 __le16 ei_leaf_hi; /* high 16 bits of physical block */
72 __u16 ei_unused;
73};
74
75/* Each block (leaves and indexes), even inode-stored has header. */
76struct ext4_extent_header {
77 __le16 eh_magic; /* probably will support different formats */
78 __le16 eh_entries; /* number of valid entries */
79 __le16 eh_max; /* capacity of store in entries */
80 __le16 eh_depth; /* has tree real underlying blocks? */
81 __le32 eh_generation; /* generation of the tree */
82};
83
84struct ext_filesystem {
85 /* Total Sector of partition */
86 uint64_t total_sect;
87 /* Block size of partition */
88 uint32_t blksz;
89 /* Inode size of partition */
90 uint32_t inodesz;
91 /* Sectors per Block */
92 uint32_t sect_perblk;
Stefan Brünsfc214ef2016-09-17 02:10:07 +020093 /* Group Descriptor size */
94 uint16_t gdsize;
Uma Shankara1596432012-05-25 21:21:44 +053095 /* Group Descriptor Block Number */
96 uint32_t gdtable_blkno;
97 /* Total block groups of partition */
98 uint32_t no_blkgrp;
99 /* No of blocks required for bgdtable */
100 uint32_t no_blk_pergdt;
101 /* Superblock */
102 struct ext2_sblock *sb;
103 /* Block group descritpor table */
Uma Shankara1596432012-05-25 21:21:44 +0530104 char *gdtable;
105
106 /* Block Bitmap Related */
107 unsigned char **blk_bmaps;
108 long int curr_blkno;
109 uint16_t first_pass_bbmap;
110
111 /* Inode Bitmap Related */
112 unsigned char **inode_bmaps;
113 int curr_inode_no;
114 uint16_t first_pass_ibmap;
115
116 /* Journal Related */
117
118 /* Block Device Descriptor */
Simon Glass4101f682016-02-29 15:25:34 -0700119 struct blk_desc *dev_desc;
Uma Shankara1596432012-05-25 21:21:44 +0530120};
121
Stephen Warrend5aee652019-01-30 12:58:05 -0700122struct ext_block_cache {
123 char *buf;
124 lbaint_t block;
125 int size;
126};
127
Uma Shankara1596432012-05-25 21:21:44 +0530128extern struct ext2_data *ext4fs_root;
129extern struct ext2fs_node *ext4fs_file;
130
Stephen Warren03e2ecf2012-10-22 06:43:50 +0000131#if defined(CONFIG_EXT4_WRITE)
Uma Shankared34f342012-05-25 21:22:49 +0530132extern struct ext2_inode *g_parent_inode;
133extern int gd_index;
134extern int gindex;
135
136int ext4fs_init(void);
137void ext4fs_deinit(void);
Stefan Brüns76a29512016-09-06 04:36:41 +0200138int ext4fs_filename_unlink(char *filename);
Jean-Jacques Hiblotb0001802019-02-13 12:15:24 +0100139int ext4fs_write(const char *fname, const char *buffer,
Jean-Jacques Hiblot5efc0682019-02-13 12:15:25 +0100140 unsigned long sizebytes, int type);
Suriyan Ramasami9f12cd02014-11-17 14:39:36 -0800141int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len,
142 loff_t *actwrite);
Jean-Jacques Hiblot5efc0682019-02-13 12:15:25 +0100143int ext4fs_create_link(const char *target, const char *fname);
Uma Shankared34f342012-05-25 21:22:49 +0530144#endif
145
Uma Shankara1596432012-05-25 21:21:44 +0530146struct ext_filesystem *get_fs(void);
Suriyan Ramasami9f12cd02014-11-17 14:39:36 -0800147int ext4fs_open(const char *filename, loff_t *len);
Stefan Brüns66a47ff2016-11-06 18:33:57 +0100148int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread);
Uma Shankara1596432012-05-25 21:21:44 +0530149int ext4fs_mount(unsigned part_length);
150void ext4fs_close(void);
Łukasz Majewski8b454ee2014-05-06 09:36:05 +0200151void ext4fs_reinit_global(void);
Uma Shankara1596432012-05-25 21:21:44 +0530152int ext4fs_ls(const char *dirname);
Stephen Warren55af5c92014-02-03 13:21:09 -0700153int ext4fs_exists(const char *filename);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800154int ext4fs_size(const char *filename, loff_t *size);
Uma Shankara1596432012-05-25 21:21:44 +0530155void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
Frederic Leroy04735e92013-06-26 18:11:25 +0200156int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
Simon Glass05289792020-05-10 11:39:57 -0600157void ext4fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info);
Stephen Warrend5aee652019-01-30 12:58:05 -0700158long int read_allocated_block(struct ext2_inode *inode, int fileblock,
159 struct ext_block_cache *cache);
Simon Glass4101f682016-02-29 15:25:34 -0700160int ext4fs_probe(struct blk_desc *fs_dev_desc,
Simon Glass05289792020-05-10 11:39:57 -0600161 struct disk_partition *fs_partition);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800162int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
163 loff_t *actread);
Egbert Eich50ce4c02013-05-01 01:13:19 +0000164int ext4_read_superblock(char *buffer);
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100165int ext4fs_uuid(char *uuid_str);
Stephen Warrend5aee652019-01-30 12:58:05 -0700166void ext_cache_init(struct ext_block_cache *cache);
167void ext_cache_fini(struct ext_block_cache *cache);
168int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size);
Uma Shankara1596432012-05-25 21:21:44 +0530169#endif