]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/ext_common.h
ext4: fix endianess problems in ext4 write support
[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)
58a9ecba 55#define INODE_SIZE_FILESYSTEM(data) (le16_to_cpu \
a1596438
US
56 (data->sblock.inode_size))
57
58#define EXT2_FT_DIR 2
59#define SUCCESS 1
60
61/* Macro-instructions used to manage several block sizes */
62#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
63#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
64#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
65#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
66
67/* The ext2 superblock. */
68struct ext2_sblock {
2a0b7a97
MW
69 __le32 total_inodes;
70 __le32 total_blocks;
71 __le32 reserved_blocks;
72 __le32 free_blocks;
73 __le32 free_inodes;
74 __le32 first_data_block;
75 __le32 log2_block_size;
76 __le32 log2_fragment_size;
77 __le32 blocks_per_group;
78 __le32 fragments_per_group;
79 __le32 inodes_per_group;
80 __le32 mtime;
81 __le32 utime;
82 __le16 mnt_count;
83 __le16 max_mnt_count;
84 __le16 magic;
85 __le16 fs_state;
86 __le16 error_handling;
87 __le16 minor_revision_level;
88 __le32 lastcheck;
89 __le32 checkinterval;
90 __le32 creator_os;
91 __le32 revision_level;
92 __le16 uid_reserved;
93 __le16 gid_reserved;
94 __le32 first_inode;
95 __le16 inode_size;
96 __le16 block_group_number;
97 __le32 feature_compatibility;
98 __le32 feature_incompat;
99 __le32 feature_ro_compat;
100 __le32 unique_id[4];
a1596438
US
101 char volume_name[16];
102 char last_mounted_on[64];
2a0b7a97 103 __le32 compression_info;
a1596438
US
104};
105
106struct ext2_block_group {
2a0b7a97
MW
107 __le32 block_id; /* Blocks bitmap block */
108 __le32 inode_id; /* Inodes bitmap block */
109 __le32 inode_table_id; /* Inodes table block */
110 __le16 free_blocks; /* Free blocks count */
111 __le16 free_inodes; /* Free inodes count */
112 __le16 used_dir_cnt; /* Directories count */
113 __le16 bg_flags;
114 __le32 bg_reserved[2];
115 __le16 bg_itable_unused; /* Unused inodes count */
116 __le16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
a1596438
US
117};
118
119/* The ext2 inode. */
120struct ext2_inode {
2a0b7a97
MW
121 __le16 mode;
122 __le16 uid;
123 __le32 size;
124 __le32 atime;
125 __le32 ctime;
126 __le32 mtime;
127 __le32 dtime;
128 __le16 gid;
129 __le16 nlinks;
130 __le32 blockcnt; /* Blocks of 512 bytes!! */
131 __le32 flags;
132 __le32 osd1;
a1596438
US
133 union {
134 struct datablocks {
2a0b7a97
MW
135 __le32 dir_blocks[INDIRECT_BLOCKS];
136 __le32 indir_block;
137 __le32 double_indir_block;
138 __le32 triple_indir_block;
a1596438
US
139 } blocks;
140 char symlink[60];
141 } b;
2a0b7a97
MW
142 __le32 version;
143 __le32 acl;
144 __le32 dir_acl;
145 __le32 fragment_addr;
146 __le32 osd2[3];
a1596438
US
147};
148
149/* The header of an ext2 directory entry. */
150struct ext2_dirent {
2a0b7a97
MW
151 __le32 inode;
152 __le16 direntlen;
153 __u8 namelen;
154 __u8 filetype;
a1596438
US
155};
156
157struct ext2fs_node {
158 struct ext2_data *data;
159 struct ext2_inode inode;
160 int ino;
161 int inode_read;
162};
163
164/* Information about a "mounted" ext2 filesystem. */
165struct ext2_data {
166 struct ext2_sblock sblock;
167 struct ext2_inode *inode;
168 struct ext2fs_node diropen;
169};
170
04735e9c 171extern lbaint_t part_offset;
81180819 172
a1596438
US
173int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
174int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
175int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
176 char *const argv[]);
177int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
ed34f34d
US
178int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
179 char *const argv[]);
a1596438 180#endif