1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef __EXT4__
28#define __EXT4__
29#include <ext_common.h>
30
31struct disk_partition;
32
33#define EXT4_INDEX_FL 0x00001000
34#define EXT4_EXTENTS_FL 0x00080000
35#define EXT4_EXT_MAGIC 0xf30a
36#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
37#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
38#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
39#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
40#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
48
49
50
51
52
53
54
55
56struct ext4_extent {
57 __le32 ee_block;
58 __le16 ee_len;
59 __le16 ee_start_hi;
60 __le32 ee_start_lo;
61};
62
63
64
65
66
67struct ext4_extent_idx {
68 __le32 ei_block;
69 __le32 ei_leaf_lo;
70
71 __le16 ei_leaf_hi;
72 __u16 ei_unused;
73};
74
75
76struct ext4_extent_header {
77 __le16 eh_magic;
78 __le16 eh_entries;
79 __le16 eh_max;
80 __le16 eh_depth;
81 __le32 eh_generation;
82};
83
84struct ext_filesystem {
85
86 uint64_t total_sect;
87
88 uint32_t blksz;
89
90 uint32_t inodesz;
91
92 uint32_t sect_perblk;
93
94 uint16_t gdsize;
95
96 uint32_t gdtable_blkno;
97
98 uint32_t no_blkgrp;
99
100 uint32_t no_blk_pergdt;
101
102 struct ext2_sblock *sb;
103
104 char *gdtable;
105
106
107 unsigned char **blk_bmaps;
108 long int curr_blkno;
109 uint16_t first_pass_bbmap;
110
111
112 unsigned char **inode_bmaps;
113 int curr_inode_no;
114 uint16_t first_pass_ibmap;
115
116
117
118
119 struct blk_desc *dev_desc;
120};
121
122struct ext_block_cache {
123 char *buf;
124 lbaint_t block;
125 int size;
126};
127
128extern struct ext2_data *ext4fs_root;
129extern struct ext2fs_node *ext4fs_file;
130
131#if defined(CONFIG_EXT4_WRITE)
132extern struct ext2_inode *g_parent_inode;
133extern int gd_index;
134extern int gindex;
135
136int ext4fs_init(void);
137void ext4fs_deinit(void);
138int ext4fs_filename_unlink(char *filename);
139int ext4fs_write(const char *fname, const char *buffer,
140 unsigned long sizebytes, int type);
141int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len,
142 loff_t *actwrite);
143int ext4fs_create_link(const char *target, const char *fname);
144#endif
145
146struct ext_filesystem *get_fs(void);
147int ext4fs_open(const char *filename, loff_t *len);
148int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread);
149int ext4fs_mount(unsigned part_length);
150void ext4fs_close(void);
151void ext4fs_reinit_global(void);
152int ext4fs_ls(const char *dirname);
153int ext4fs_exists(const char *filename);
154int ext4fs_size(const char *filename, loff_t *size);
155void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
156int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
157void ext4fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info);
158long int read_allocated_block(struct ext2_inode *inode, int fileblock,
159 struct ext_block_cache *cache);
160int ext4fs_probe(struct blk_desc *fs_dev_desc,
161 struct disk_partition *fs_partition);
162int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
163 loff_t *actread);
164int ext4_read_superblock(char *buffer);
165int ext4fs_uuid(char *uuid_str);
166void 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);
169#endif
170