ReactOS  0.4.13-dev-651-g5dbc677
ext2.h
Go to the documentation of this file.
1 /*
2  * FreeLoader
3  * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 /*
23  * grub/fs/ext2.c
24  *
25  * GRUB -- GRand Unified Bootloader
26  * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
27  *
28  * This program is free software; you can redistribute it and/or modify
29  * it under the terms of the GNU General Public License as published by
30  * the Free Software Foundation; either version 2 of the License, or
31  * (at your option) any later version.
32  *
33  * This program is distributed in the hope that it will be useful,
34  * but WITHOUT ANY WARRANTY; without even the implied warranty of
35  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36  * GNU General Public License for more details.
37  *
38  * You should have received a copy of the GNU General Public License
39  * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
40  */
41 
42 /* Magic value used to identify an ext2 filesystem. */
43 #define EXT2_MAGIC 0xEF53
44 /* Amount of indirect blocks in an inode. */
45 #define INDIRECT_BLOCKS 12
46 /* Maximum length of a pathname. */
47 #define EXT2_PATH_MAX 4096
48 /* Maximum nesting of symlinks, used to prevent a loop. */
49 #define EXT2_MAX_SYMLINKCNT 8
50 
51 /* The good old revision and the default inode size. */
52 #define EXT2_GOOD_OLD_REVISION 0
53 #define EXT2_DYNAMIC_REVISION 1
54 #define EXT2_GOOD_OLD_INODE_SIZE 128
55 
56 /* Filetype used in directory entry. */
57 #define FILETYPE_UNKNOWN 0
58 #define FILETYPE_REG 1
59 #define FILETYPE_DIRECTORY 2
60 #define FILETYPE_SYMLINK 7
61 
62 /* Filetype information as used in inodes. */
63 #define FILETYPE_INO_MASK 0170000
64 #define FILETYPE_INO_REG 0100000
65 #define FILETYPE_INO_DIRECTORY 0040000
66 #define FILETYPE_INO_SYMLINK 0120000
67 
68 /* The ext2 superblock. */
70 {
103  char volume_name[16];
104  char last_mounted_on[64];
107 };
108 
109 /* The ext2 blockgroup. */
111 {
120 };
121 
122 /* The ext2 inode. */
124 {
134  ULONG blockcnt; /* Blocks of 512 bytes!! */
137  union
138  {
139  struct datablocks
140  {
145  } blocks;
146  char symlink[60];
147  };
153 };
154 
155 /* The header of an ext2 directory entry. */
156 #define EXT2_NAME_LEN 255
157 
159 {
165 };
166 
167 /*
168  * End of code from grub/fs/ext2.c
169  */
170 
175 
176 /* Special inode numbers. */
177 #define EXT2_ROOT_INO 2
178 
179 /* Feature set definitions. */
180 #define EXT3_FEATURE_INCOMPAT_SUPP 0x0002
181 
182 /* Log2 size of ext2 block in bytes. */
183 #define LOG2_BLOCK_SIZE(sb) (sb->log2_block_size + 10)
184 
185 /* The size of an ext2 block in bytes. */
186 #define EXT2_BLOCK_SIZE(sb) (((SIZE_T)1) << LOG2_BLOCK_SIZE(sb))
187 
188 /* The revision level. */
189 #define EXT2_REVISION(sb) (sb->revision_level)
190 
191 /* The inode size. */
192 #define EXT2_INODE_SIZE(sb) (EXT2_REVISION(sb) == EXT2_GOOD_OLD_REVISION \
193  ? EXT2_GOOD_OLD_INODE_SIZE \
194  : sb->inode_size)
195 
196 #define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(struct ext2_block_group))
197 
198 // EXT2_INODE::mode values
199 #define EXT2_S_IRWXO 0x0007 // Other mask
200 #define EXT2_S_IXOTH 0x0001 // ---------x execute
201 #define EXT2_S_IWOTH 0x0002 // --------w- write
202 #define EXT2_S_IROTH 0x0004 // -------r-- read
203 
204 #define EXT2_S_IRWXG 0x0038 // Group mask
205 #define EXT2_S_IXGRP 0x0008 // ------x--- execute
206 #define EXT2_S_IWGRP 0x0010 // -----w---- write
207 #define EXT2_S_IRGRP 0x0020 // ----r----- read
208 
209 #define EXT2_S_IRWXU 0x01C0 // User mask
210 #define EXT2_S_IXUSR 0x0040 // ---x------ execute
211 #define EXT2_S_IWUSR 0x0080 // --w------- write
212 #define EXT2_S_IRUSR 0x0100 // -r-------- read
213 
214 #define EXT2_S_ISVTX 0x0200 // Sticky bit
215 #define EXT2_S_ISGID 0x0400 // SGID
216 #define EXT2_S_ISUID 0x0800 // SUID
217 
218 #define EXT2_S_IFMT 0xF000 // Format mask
219 #define EXT2_S_IFIFO 0x1000 // FIFO buffer
220 #define EXT2_S_IFCHR 0x2000 // Character device
221 #define EXT2_S_IFDIR 0x4000 // Directory
222 #define EXT2_S_IFBLK 0x6000 // Block device
223 #define EXT2_S_IFREG 0x8000 // Regular file
224 #define EXT2_S_IFLNK 0xA000 // Symbolic link
225 #define EXT2_S_IFSOCK 0xC000 // Socket
226 
227 #define FAST_SYMLINK_MAX_NAME_SIZE 60
228 
229 typedef struct
230 {
231  ULONGLONG FileSize; // File size
232  ULONGLONG FilePointer; // File pointer
233  ULONG* FileBlockList; // File block list
234  UCHAR DriveNumber; // Drive number of open file
235  EXT2_INODE Inode; // File's inode
237 
238 const DEVVTBL* Ext2Mount(ULONG DeviceId);
UCHAR filetype
Definition: ext2.h:163
ULONGLONG FilePointer
Definition: ext2.h:232
ULONG feature_incompat
Definition: ext2.h:100
ULONG tripple_indir_block
Definition: ext2.h:144
ULONG free_blocks
Definition: ext2.h:74
ULONG * FileBlockList
Definition: ext2.h:233
USHORT uid_reserved
Definition: ext2.h:94
USHORT inode_size
Definition: ext2.h:97
ULONG mtime
Definition: ext2.h:130
ULONG first_inode
Definition: ext2.h:96
USHORT fs_state
Definition: ext2.h:87
ULONG atime
Definition: ext2.h:128
ULONG checkinterval
Definition: ext2.h:91
ULONG block_id
Definition: ext2.h:112
ULONG inode_id
Definition: ext2.h:113
struct ext2_sblock * PEXT2_SUPER_BLOCK
Definition: ext2.h:171
USHORT free_inodes
Definition: ext2.h:116
ULONG fragment_addr
Definition: ext2.h:151
ULONG dtime
Definition: ext2.h:131
char CHAR
Definition: xmlstorage.h:175
ULONG feature_ro_compat
Definition: ext2.h:101
UCHAR namelen
Definition: ext2.h:162
Definition: fs.h:22
struct ext2_block_group * PEXT2_GROUP_DESC
Definition: ext2.h:173
EXT2_INODE Inode
Definition: ext2.h:235
ULONG inode
Definition: ext2.h:160
#define INDIRECT_BLOCKS
Definition: ext2.h:45
ULONG reserved[3]
Definition: ext2.h:119
ULONG dir_acl
Definition: ext2.h:150
USHORT uid
Definition: ext2.h:126
USHORT max_mnt_count
Definition: ext2.h:85
ULONG free_inodes
Definition: ext2.h:75
ULONG unique_id[4]
Definition: ext2.h:102
ULONG total_inodes
Definition: ext2.h:71
ULONG mtime
Definition: ext2.h:82
ULONG feature_compatibility
Definition: ext2.h:99
ULONG acl
Definition: ext2.h:149
char volume_name[16]
Definition: ext2.h:103
ULONG ctime
Definition: ext2.h:129
USHORT gid
Definition: ext2.h:132
ULONG size
Definition: ext2.h:127
ULONG reserved_blocks
Definition: ext2.h:73
ULONG compression_info
Definition: ext2.h:105
long LONG
Definition: pedump.c:60
ULONGLONG FileSize
Definition: ext2.h:231
ULONG version
Definition: ext2.h:148
USHORT direntlen
Definition: ext2.h:161
ULONG utime
Definition: ext2.h:83
USHORT magic
Definition: ext2.h:86
ULONG flags
Definition: ext2.h:135
ULONG log2_block_size
Definition: ext2.h:77
USHORT mnt_count
Definition: ext2.h:84
ULONG blockcnt
Definition: ext2.h:134
ULONG inode_table_id
Definition: ext2.h:114
ULONG revision_level
Definition: ext2.h:93
uint64_t ULONGLONG
Definition: typedefs.h:65
struct ext2_dirent * PEXT2_DIR_ENTRY
Definition: ext2.h:174
ULONG osd2[3]
Definition: ext2.h:152
ULONG first_data_block
Definition: ext2.h:76
USHORT pad
Definition: ext2.h:118
USHORT gid_reserved
Definition: ext2.h:95
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG blocks_per_group
Definition: ext2.h:79
#define EXT2_NAME_LEN
Definition: ext2.h:156
UCHAR DriveNumber
Definition: ext2.h:234
USHORT free_blocks
Definition: ext2.h:115
char last_mounted_on[64]
Definition: ext2.h:104
ULONG padding[77]
Definition: ext2.h:106
struct EXT2_FILE_INFO * PEXT2_FILE_INFO
ULONG indir_block
Definition: ext2.h:142
unsigned short USHORT
Definition: pedump.c:61
ULONG total_blocks
Definition: ext2.h:72
struct ext2_inode * PEXT2_INODE
Definition: ext2.h:172
USHORT nlinks
Definition: ext2.h:133
char symlink[60]
Definition: ext2.h:146
USHORT mode
Definition: ext2.h:125
ULONG osd1
Definition: ext2.h:136
const DEVVTBL * Ext2Mount(ULONG DeviceId)
Definition: ext2.c:1300
Definition: name.c:36
ULONG double_indir_block
Definition: ext2.h:143
ULONG dir_blocks[INDIRECT_BLOCKS]
Definition: ext2.h:141
USHORT used_dirs
Definition: ext2.h:117
ULONG lastcheck
Definition: ext2.h:90
unsigned int ULONG
Definition: retypes.h:1
struct ext2_inode::@162::datablocks blocks
ULONG inodes_per_group
Definition: ext2.h:81
ULONG creator_os
Definition: ext2.h:92
LONG log2_fragment_size
Definition: ext2.h:78
ULONG fragments_per_group
Definition: ext2.h:80
USHORT block_group_number
Definition: ext2.h:98
USHORT error_handling
Definition: ext2.h:88
USHORT minor_revision_level
Definition: ext2.h:89