]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/ext_common.h
ext4: Fix memory leak of journal buffer if block is updated multiple times
[people/ms/u-boot.git] / include / ext_common.h
CommitLineData
a1596438
US
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 * Data structures and headers for ext4 support have been taken from
8 * ext2 ls load support in Uboot
9 *
10 * (C) Copyright 2004
11 * esd gmbh <www.esd-electronics.com>
12 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
13 *
14 * based on code from grub2 fs/ext2.c and fs/fshelp.c by
15 * GRUB -- GRand Unified Bootloader
16 * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
17 *
1a459660 18 * SPDX-License-Identifier: GPL-2.0+
a1596438
US
19 */
20
21#ifndef __EXT_COMMON__
22#define __EXT_COMMON__
23#include <command.h>
24#define SECTOR_SIZE 0x200
a1596438
US
25
26/* Magic value used to identify an ext2 filesystem. */
27#define EXT2_MAGIC 0xEF53
28/* Amount of indirect blocks in an inode. */
29#define INDIRECT_BLOCKS 12
30/* Maximum lenght of a pathname. */
31#define EXT2_PATH_MAX 4096
32/* Maximum nesting of symlinks, used to prevent a loop. */
33#define EXT2_MAX_SYMLINKCNT 8
34
35/* Filetype used in directory entry. */
36#define FILETYPE_UNKNOWN 0
37#define FILETYPE_REG 1
38#define FILETYPE_DIRECTORY 2
39#define FILETYPE_SYMLINK 7
40
41/* Filetype information as used in inodes. */
42#define FILETYPE_INO_MASK 0170000
43#define FILETYPE_INO_REG 0100000
44#define FILETYPE_INO_DIRECTORY 0040000
45#define FILETYPE_INO_SYMLINK 0120000
46#define EXT2_ROOT_INO 2 /* Root inode */
47
a1596438
US
48/* The size of an ext2 block in bytes. */
49#define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
50
a1596438 51/* Log2 size of ext2 block in bytes. */
7f101be3 52#define LOG2_BLOCK_SIZE(data) (le32_to_cpu \
50ce4c07
EE
53 (data->sblock.log2_block_size) \
54 + EXT2_MIN_BLOCK_LOG_SIZE)
a1596438
US
55
56#define EXT2_FT_DIR 2
57#define SUCCESS 1
58
59/* Macro-instructions used to manage several block sizes */
60#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
61#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
62#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
63#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
64
65/* The ext2 superblock. */
66struct ext2_sblock {
2a0b7a97
MW
67 __le32 total_inodes;
68 __le32 total_blocks;
69 __le32 reserved_blocks;
70 __le32 free_blocks;
71 __le32 free_inodes;
72 __le32 first_data_block;
73 __le32 log2_block_size;
74 __le32 log2_fragment_size;
75 __le32 blocks_per_group;
76 __le32 fragments_per_group;
77 __le32 inodes_per_group;
78 __le32 mtime;
79 __le32 utime;
80 __le16 mnt_count;
81 __le16 max_mnt_count;
82 __le16 magic;
83 __le16 fs_state;
84 __le16 error_handling;
85 __le16 minor_revision_level;
86 __le32 lastcheck;
87 __le32 checkinterval;
88 __le32 creator_os;
89 __le32 revision_level;
90 __le16 uid_reserved;
91 __le16 gid_reserved;
92 __le32 first_inode;
93 __le16 inode_size;
94 __le16 block_group_number;
95 __le32 feature_compatibility;
96 __le32 feature_incompat;
97 __le32 feature_ro_compat;
98 __le32 unique_id[4];
a1596438
US
99 char volume_name[16];
100 char last_mounted_on[64];
2a0b7a97 101 __le32 compression_info;
a1596438
US
102};
103
104struct ext2_block_group {
2a0b7a97
MW
105 __le32 block_id; /* Blocks bitmap block */
106 __le32 inode_id; /* Inodes bitmap block */
107 __le32 inode_table_id; /* Inodes table block */
108 __le16 free_blocks; /* Free blocks count */
109 __le16 free_inodes; /* Free inodes count */
110 __le16 used_dir_cnt; /* Directories count */
111 __le16 bg_flags;
112 __le32 bg_reserved[2];
113 __le16 bg_itable_unused; /* Unused inodes count */
114 __le16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
a1596438
US
115};
116
117/* The ext2 inode. */
118struct ext2_inode {
2a0b7a97
MW
119 __le16 mode;
120 __le16 uid;
121 __le32 size;
122 __le32 atime;
123 __le32 ctime;
124 __le32 mtime;
125 __le32 dtime;
126 __le16 gid;
127 __le16 nlinks;
128 __le32 blockcnt; /* Blocks of 512 bytes!! */
129 __le32 flags;
130 __le32 osd1;
a1596438
US
131 union {
132 struct datablocks {
2a0b7a97
MW
133 __le32 dir_blocks[INDIRECT_BLOCKS];
134 __le32 indir_block;
135 __le32 double_indir_block;
136 __le32 triple_indir_block;
a1596438
US
137 } blocks;
138 char symlink[60];
139 } b;
2a0b7a97
MW
140 __le32 version;
141 __le32 acl;
142 __le32 dir_acl;
143 __le32 fragment_addr;
144 __le32 osd2[3];
a1596438
US
145};
146
147/* The header of an ext2 directory entry. */
148struct ext2_dirent {
2a0b7a97
MW
149 __le32 inode;
150 __le16 direntlen;
151 __u8 namelen;
152 __u8 filetype;
a1596438
US
153};
154
155struct ext2fs_node {
156 struct ext2_data *data;
157 struct ext2_inode inode;
158 int ino;
159 int inode_read;
160};
161
162/* Information about a "mounted" ext2 filesystem. */
163struct ext2_data {
164 struct ext2_sblock sblock;
165 struct ext2_inode *inode;
166 struct ext2fs_node diropen;
167};
168
04735e9c 169extern lbaint_t part_offset;
81180819 170
a1596438
US
171int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
172int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
173int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
174 char *const argv[]);
175int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
ed34f34d
US
176int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
177 char *const argv[]);
a1596438 178#endif