change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / include / ext_common.h
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  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31  */
32
33 #ifndef __EXT_COMMON__
34 #define __EXT_COMMON__
35
36 #define SECTOR_SIZE             0x200
37 #define SECTOR_BITS             9
38
39
40 /* Magic value used to identify an ext2 filesystem.  */
41 #define EXT2_MAGIC              0xEF53
42
43
44
45 /* Amount of indirect blocks in an inode.  */
46 #define INDIRECT_BLOCKS         12
47
48 /* richardfeng add */
49 #define EXT4_NDIR_BLOCKS 12
50 #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
51 #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
52 #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
53 #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
54
55 #define EXT4_SECRM_FL 0x00000001  
56 #define EXT4_UNRM_FL 0x00000002  
57 #define EXT4_COMPR_FL 0x00000004  
58 #define EXT4_SYNC_FL 0x00000008  
59 #define EXT4_IMMUTABLE_FL 0x00000010  
60 #define EXT4_APPEND_FL 0x00000020  
61 #define EXT4_NODUMP_FL 0x00000040  
62 #define EXT4_NOATIME_FL 0x00000080  
63
64 #define EXT4_DIRTY_FL 0x00000100
65 #define EXT4_COMPRBLK_FL 0x00000200  
66 #define EXT4_NOCOMPR_FL 0x00000400  
67 #define EXT4_ECOMPR_FL 0x00000800  
68
69 #define EXT4_INDEX_FL 0x00001000  
70 #define EXT4_IMAGIC_FL 0x00002000  
71 #define EXT4_JOURNAL_DATA_FL 0x00004000  
72 #define EXT4_NOTAIL_FL 0x00008000  
73 #define EXT4_DIRSYNC_FL 0x00010000  
74 #define EXT4_TOPDIR_FL 0x00020000  
75 #define EXT4_HUGE_FILE_FL 0x00040000  
76 #define EXT4_EXTENTS_FL 0x00080000  
77 #define EXT4_EA_INODE_FL 0x00200000  
78 #define EXT4_EOFBLOCKS_FL 0x00400000  
79 #define EXT4_RESERVED_FL 0x80000000  
80
81 #define EXT4_FL_USER_VISIBLE 0x004BDFFF  
82 #define EXT4_FL_USER_MODIFIABLE 0x004B80FF  
83
84 #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |  EXT4_SYNC_FL | EXT4_IMMUTABLE_FL | EXT4_APPEND_FL |  EXT4_NODUMP_FL | EXT4_NOATIME_FL |  EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |  EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL)
85
86 #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL))
87
88 #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL)
89
90 /* Maximum lenght of a pathname.  */
91 #define EXT2_PATH_MAX                   4096
92 /* Maximum nesting of symlinks, used to prevent a loop.  */
93 #define EXT2_MAX_SYMLINKCNT             8
94
95 /* Filetype used in directory entry.  */
96 #define FILETYPE_UNKNOWN                0
97 #define FILETYPE_REG                    1
98 #define FILETYPE_DIRECTORY              2
99 #define FILETYPE_SYMLINK                7
100
101 /* Filetype information as used in inodes.  */
102 #define FILETYPE_INO_MASK               0170000
103 #define FILETYPE_INO_REG                0100000
104 #define FILETYPE_INO_DIRECTORY          0040000
105 #define FILETYPE_INO_SYMLINK            0120000
106 #define EXT2_ROOT_INO                   2 /* Root inode */
107
108 /* Bits used as offset in sector */
109 #define DISK_SECTOR_BITS                9
110 /* The size of an ext2 block in bytes.  */
111 #define EXT2_BLOCK_SIZE(data)      (1 << LOG2_BLOCK_SIZE(data))
112
113 /* Log2 size of ext2 block in 512 blocks.  */
114 #define LOG2_EXT2_BLOCK_SIZE(data) (__le32_to_cpu \
115                                 (data->sblock.log2_block_size) + 1)
116
117 /* Log2 size of ext2 block in bytes.  */
118 #define LOG2_BLOCK_SIZE(data)      (__le32_to_cpu \
119                 (data->sblock.log2_block_size) + 10)
120 #define INODE_SIZE_FILESYSTEM(data)     (__le32_to_cpu \
121                         (data->sblock.inode_size))
122
123 #define EXT2_FT_DIR     2
124 #define SUCCESS 1
125
126 /* Macro-instructions used to manage several block sizes  */
127 #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
128 #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
129 #define EXT2_MIN_BLOCK_SIZE             (1 << EXT2_MIN_BLOCK_LOG_SIZE)
130 #define EXT2_MAX_BLOCK_SIZE             (1 << EXT2_MAX_BLOCK_LOG_SIZE)
131
132 /* The ext2 superblock.  */
133 struct ext2_sblock {
134         uint32_t total_inodes;
135         uint32_t total_blocks;
136         uint32_t reserved_blocks;
137         uint32_t free_blocks;
138         uint32_t free_inodes;
139         uint32_t first_data_block;
140         uint32_t log2_block_size;
141         uint32_t log2_fragment_size;
142         uint32_t blocks_per_group;
143         uint32_t fragments_per_group;
144         uint32_t inodes_per_group;
145         uint32_t mtime;
146         uint32_t utime;
147         uint16_t mnt_count;
148         uint16_t max_mnt_count;
149         uint16_t magic;
150         uint16_t fs_state;
151         uint16_t error_handling;
152         uint16_t minor_revision_level;
153         uint32_t lastcheck;
154         uint32_t checkinterval;
155         uint32_t creator_os;
156         uint32_t revision_level;
157         uint16_t uid_reserved;
158         uint16_t gid_reserved;
159         uint32_t first_inode;
160         uint16_t inode_size;
161         uint16_t block_group_number;
162         uint32_t feature_compatibility;
163         uint32_t feature_incompat;
164         uint32_t feature_ro_compat;
165         uint32_t unique_id[4];
166         char volume_name[16];
167         char last_mounted_on[64];
168         uint32_t compression_info;
169 };
170
171 struct ext4_super_block {
172   __le32 s_inodes_count;
173  __le32 s_blocks_count_lo;
174  __le32 s_r_blocks_count_lo;
175  __le32 s_free_blocks_count_lo;
176   __le32 s_free_inodes_count;
177  __le32 s_first_data_block;
178  __le32 s_log_block_size;
179  __le32 s_obso_log_frag_size;
180   __le32 s_blocks_per_group;
181  __le32 s_obso_frags_per_group;
182  __le32 s_inodes_per_group;
183  __le32 s_mtime;
184   __le32 s_wtime;
185  __le16 s_mnt_count;
186  __le16 s_max_mnt_count;
187  __le16 s_magic;
188  __le16 s_state;
189  __le16 s_errors;
190  __le16 s_minor_rev_level;
191   __le32 s_lastcheck;
192  __le32 s_checkinterval;
193  __le32 s_creator_os;
194  __le32 s_rev_level;
195   __le16 s_def_resuid;
196  __le16 s_def_resgid;
197
198  __le32 s_first_ino;
199  __le16 s_inode_size;
200  __le16 s_block_group_nr;
201  __le32 s_feature_compat;
202   __le32 s_feature_incompat;
203  __le32 s_feature_ro_compat;
204   __u8 s_uuid[16];
205   char s_volume_name[16];
206   char s_last_mounted[64];
207   __le32 s_algorithm_usage_bitmap;
208
209  __u8 s_prealloc_blocks;
210  __u8 s_prealloc_dir_blocks;
211  __le16 s_reserved_gdt_blocks;
212
213   __u8 s_journal_uuid[16];
214   __le32 s_journal_inum;
215  __le32 s_journal_dev;
216  __le32 s_last_orphan;
217  __le32 s_hash_seed[4];
218  __u8 s_def_hash_version;
219  __u8 s_reserved_char_pad;
220  __le16 s_desc_size;
221   __le32 s_default_mount_opts;
222  __le32 s_first_meta_bg;
223  __le32 s_mkfs_time;
224  __le32 s_jnl_blocks[17];
225
226   __le32 s_blocks_count_hi;
227  __le32 s_r_blocks_count_hi;
228  __le32 s_free_blocks_count_hi;
229  __le16 s_min_extra_isize;
230  __le16 s_want_extra_isize;
231  __le32 s_flags;
232  __le16 s_raid_stride;
233  __le16 s_mmp_interval;
234  __le64 s_mmp_block;
235  __le32 s_raid_stripe_width;
236  __u8 s_log_groups_per_flex;
237  __u8 s_reserved_char_pad2;
238  __le16 s_reserved_pad;
239  __le64 s_kbytes_written;
240  __u32 s_reserved[160];
241 };
242
243 struct ext2_block_group {
244         __u32 block_id; /* Blocks bitmap block */
245         __u32 inode_id; /* Inodes bitmap block */
246         __u32 inode_table_id;   /* Inodes table block */
247         __u16 free_blocks;      /* Free blocks count */
248         __u16 free_inodes;      /* Free inodes count */
249         __u16 used_dir_cnt;     /* Directories count */
250         __u16 bg_flags;
251         __u32 bg_reserved[2];
252         __u16 bg_itable_unused; /* Unused inodes count */
253         __u16 bg_checksum;      /* crc16(s_uuid+grouo_num+group_desc)*/
254 };
255
256 struct ext4_group_desc
257 {
258  __le32 bg_block_bitmap_lo;
259  __le32 bg_inode_bitmap_lo;
260  __le32 bg_inode_table_lo;
261  __le16 bg_free_blocks_count_lo;
262  __le16 bg_free_inodes_count_lo;
263  __le16 bg_used_dirs_count_lo;
264  __le16 bg_flags;
265  __u32 bg_reserved[2];
266  __le16 bg_itable_unused_lo;
267  __le16 bg_checksum;
268  __le32 bg_block_bitmap_hi;
269  __le32 bg_inode_bitmap_hi;
270  __le32 bg_inode_table_hi;
271  __le16 bg_free_blocks_count_hi;
272  __le16 bg_free_inodes_count_hi;
273  __le16 bg_used_dirs_count_hi;
274  __le16 bg_itable_unused_hi;
275  __u32 bg_reserved2[3];
276 };
277
278 /* The ext2 inode. */
279 struct ext2_inode {
280         uint16_t mode;
281         uint16_t uid;
282         uint32_t size;
283         uint32_t atime;
284         uint32_t ctime;
285         uint32_t mtime;
286         uint32_t dtime;
287         uint16_t gid;
288         uint16_t nlinks;
289         uint32_t blockcnt;      /* Blocks of 512 bytes!! */
290         uint32_t flags;
291         uint32_t osd1;
292         union {
293                 struct datablocks {
294                         uint32_t dir_blocks[INDIRECT_BLOCKS];
295                         uint32_t indir_block;
296                         uint32_t double_indir_block;
297                         uint32_t triple_indir_block;
298                 } blocks;
299                 char symlink[60];
300         } b;
301         uint32_t version;
302         uint32_t acl;
303         uint32_t dir_acl;
304         uint32_t fragment_addr;
305         uint32_t osd2[3];
306 };
307 /* The ext4 inode. */
308 struct ext4_inode {
309         uint16_t i_mode;
310         uint16_t i_uid;
311         uint32_t i_size_lo;
312         uint32_t i_atime;
313         uint32_t i_ctime;
314         uint32_t i_mtime;
315         uint32_t i_dtime;
316         uint16_t i_gid;
317         uint16_t i_links_count;
318         uint32_t i_blocks_lo;
319         uint32_t i_flags;
320  union {
321  struct {
322         uint32_t l_i_version;
323  } linux1;
324  struct {
325         __u32 h_i_translator;
326  } hurd1;
327  struct {
328         __u32 m_i_reserved1;
329  } masix1;
330  } osd1;
331         uint32_t i_block[EXT4_N_BLOCKS];
332         uint32_t i_generation;
333         uint32_t i_file_acl_lo;
334         uint32_t i_size_high;
335         uint32_t i_obso_faddr;
336  union {
337  struct {
338  uint16_t l_i_blocks_high;
339  uint16_t l_i_file_acl_high;
340  uint16_t l_i_uid_high;
341  uint16_t l_i_gid_high;
342  __u32 l_i_reserved2;
343  } linux2;
344  struct {
345  uint16_t h_i_reserved1;
346  __u16 h_i_mode_high;
347  __u16 h_i_uid_high;
348  __u16 h_i_gid_high;
349  __u32 h_i_author;
350  } hurd2;
351  struct {
352  uint16_t h_i_reserved1;
353  uint16_t m_i_file_acl_high;
354  __u32 m_i_reserved2[2];
355  } masix2;
356  } osd2;
357  uint16_t i_extra_isize;
358  uint16_t i_pad1;
359  uint32_t i_ctime_extra;
360  uint32_t i_mtime_extra;
361  uint32_t i_atime_extra;
362  uint32_t i_crtime;
363  uint32_t i_crtime_extra;
364  uint32_t i_version_hi;
365 };
366
367 /* The header of an ext2 directory entry. */
368 struct ext2_dirent {
369         uint32_t inode;
370         uint16_t direntlen;
371         uint8_t namelen;
372         uint8_t filetype;
373 };
374
375 struct ext2fs_node {
376         struct ext2_data *data;
377         struct ext2_inode inode;
378         int ino;
379         int inode_read;
380 };
381
382 /* Information about a "mounted" ext2 filesystem. */
383 struct ext2_data {
384         struct ext2_sblock sblock;
385         struct ext2_inode *inode;
386         struct ext2fs_node diropen;
387 };
388 #endif