]>
Commit | Line | Data |
---|---|---|
a1596438 US |
1 | /* |
2 | * (C) Copyright 2011 - 2012 Samsung Electronics | |
3 | * EXT4 filesystem implementation in Uboot by | |
4 | * Uma Shankar <[email protected]> | |
5 | * Manjunatha C Achar <[email protected]> | |
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, [email protected] | |
11 | * Written by Alex Tomas <[email protected]> | |
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 | ||
e6f6f9e6 SG |
31 | struct disk_partition; |
32 | ||
10a7a1b8 | 33 | #define EXT4_INDEX_FL 0x00001000 /* Inode uses hash tree index */ |
0bf3fec2 | 34 | #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ |
a1596438 US |
35 | #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ |
36 | #define EXT4_EXT_MAGIC 0xf30a | |
37 | #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 | |
2e736551 | 38 | #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 |
a1596438 | 39 | #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 |
6f94ab66 | 40 | #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 |
a1596438 US |
41 | #define EXT4_INDIRECT_BLOCKS 12 |
42 | ||
43 | #define EXT4_BG_INODE_UNINIT 0x0001 | |
44 | #define EXT4_BG_BLOCK_UNINIT 0x0002 | |
45 | #define EXT4_BG_INODE_ZEROED 0x0004 | |
46 | ||
47 | /* | |
48 | * ext4_inode has i_block array (60 bytes total). | |
49 | * The first 12 bytes store ext4_extent_header; | |
50 | * the remainder stores an array of ext4_extent. | |
51 | */ | |
52 | ||
53 | /* | |
54 | * This is the extent on-disk structure. | |
55 | * It's used at the bottom of the tree. | |
56 | */ | |
57 | struct ext4_extent { | |
58 | __le32 ee_block; /* first logical block extent covers */ | |
59 | __le16 ee_len; /* number of blocks covered by extent */ | |
60 | __le16 ee_start_hi; /* high 16 bits of physical block */ | |
61 | __le32 ee_start_lo; /* low 32 bits of physical block */ | |
62 | }; | |
63 | ||
64 | /* | |
65 | * This is index on-disk structure. | |
66 | * It's used at all the levels except the bottom. | |
67 | */ | |
68 | struct ext4_extent_idx { | |
69 | __le32 ei_block; /* index covers logical blocks from 'block' */ | |
70 | __le32 ei_leaf_lo; /* pointer to the physical block of the next * | |
71 | * level. leaf or next index could be there */ | |
72 | __le16 ei_leaf_hi; /* high 16 bits of physical block */ | |
73 | __u16 ei_unused; | |
74 | }; | |
75 | ||
76 | /* Each block (leaves and indexes), even inode-stored has header. */ | |
77 | struct ext4_extent_header { | |
78 | __le16 eh_magic; /* probably will support different formats */ | |
79 | __le16 eh_entries; /* number of valid entries */ | |
80 | __le16 eh_max; /* capacity of store in entries */ | |
81 | __le16 eh_depth; /* has tree real underlying blocks? */ | |
82 | __le32 eh_generation; /* generation of the tree */ | |
83 | }; | |
84 | ||
85 | struct ext_filesystem { | |
86 | /* Total Sector of partition */ | |
87 | uint64_t total_sect; | |
88 | /* Block size of partition */ | |
89 | uint32_t blksz; | |
90 | /* Inode size of partition */ | |
91 | uint32_t inodesz; | |
92 | /* Sectors per Block */ | |
93 | uint32_t sect_perblk; | |
fc214ef9 SB |
94 | /* Group Descriptor size */ |
95 | uint16_t gdsize; | |
a1596438 US |
96 | /* Group Descriptor Block Number */ |
97 | uint32_t gdtable_blkno; | |
98 | /* Total block groups of partition */ | |
99 | uint32_t no_blkgrp; | |
100 | /* No of blocks required for bgdtable */ | |
101 | uint32_t no_blk_pergdt; | |
102 | /* Superblock */ | |
103 | struct ext2_sblock *sb; | |
104 | /* Block group descritpor table */ | |
a1596438 US |
105 | char *gdtable; |
106 | ||
107 | /* Block Bitmap Related */ | |
108 | unsigned char **blk_bmaps; | |
109 | long int curr_blkno; | |
110 | uint16_t first_pass_bbmap; | |
111 | ||
112 | /* Inode Bitmap Related */ | |
113 | unsigned char **inode_bmaps; | |
114 | int curr_inode_no; | |
115 | uint16_t first_pass_ibmap; | |
116 | ||
117 | /* Journal Related */ | |
118 | ||
119 | /* Block Device Descriptor */ | |
4101f687 | 120 | struct blk_desc *dev_desc; |
a1596438 US |
121 | }; |
122 | ||
d5aee659 SW |
123 | struct ext_block_cache { |
124 | char *buf; | |
125 | lbaint_t block; | |
126 | int size; | |
127 | }; | |
128 | ||
a1596438 US |
129 | extern struct ext2_data *ext4fs_root; |
130 | extern struct ext2fs_node *ext4fs_file; | |
131 | ||
03e2ecf6 | 132 | #if defined(CONFIG_EXT4_WRITE) |
ed34f34d US |
133 | extern struct ext2_inode *g_parent_inode; |
134 | extern int gd_index; | |
135 | extern int gindex; | |
136 | ||
137 | int ext4fs_init(void); | |
138 | void ext4fs_deinit(void); | |
76a29519 | 139 | int ext4fs_filename_unlink(char *filename); |
b000180b | 140 | int ext4fs_write(const char *fname, const char *buffer, |
5efc0686 | 141 | unsigned long sizebytes, int type); |
9f12cd0e SR |
142 | int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len, |
143 | loff_t *actwrite); | |
5efc0686 | 144 | int ext4fs_create_link(const char *target, const char *fname); |
ed34f34d US |
145 | #endif |
146 | ||
a1596438 | 147 | struct ext_filesystem *get_fs(void); |
9f12cd0e | 148 | int ext4fs_open(const char *filename, loff_t *len); |
66a47ff2 | 149 | int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread); |
7667bdeb | 150 | int ext4fs_mount(void); |
a1596438 | 151 | void ext4fs_close(void); |
8b454eee | 152 | void ext4fs_reinit_global(void); |
a1596438 | 153 | int ext4fs_ls(const char *dirname); |
55af5c93 | 154 | int ext4fs_exists(const char *filename); |
d455d878 | 155 | int ext4fs_size(const char *filename, loff_t *size); |
a1596438 | 156 | void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); |
04735e9c | 157 | int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf); |
0528979f | 158 | void ext4fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info); |
d5aee659 SW |
159 | long int read_allocated_block(struct ext2_inode *inode, int fileblock, |
160 | struct ext_block_cache *cache); | |
4101f687 | 161 | int ext4fs_probe(struct blk_desc *fs_dev_desc, |
0528979f | 162 | struct disk_partition *fs_partition); |
d455d878 SR |
163 | int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len, |
164 | loff_t *actread); | |
50ce4c07 | 165 | int ext4_read_superblock(char *buffer); |
59e890ef | 166 | int ext4fs_uuid(char *uuid_str); |
d5aee659 SW |
167 | void ext_cache_init(struct ext_block_cache *cache); |
168 | void ext_cache_fini(struct ext_block_cache *cache); | |
169 | int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size); | |
a1596438 | 170 | #endif |