ReactOS
0.4.16-dev-1946-g52006dd
ext.h
Go to the documentation of this file.
1
/*
2
* FreeLoader
3
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4
* Copyright (C) 2024-2025 Daniel Victor <ilauncherdeveloper@gmail.com>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
*/
20
21
#pragma once
22
23
/*
24
* grub/fs/ext2.c
25
*
26
* GRUB -- GRand Unified Bootloader
27
* Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
28
*
29
* This program is free software; you can redistribute it and/or modify
30
* it under the terms of the GNU General Public License as published by
31
* the Free Software Foundation; either version 2 of the License, or
32
* (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
41
*/
42
43
#include <pshpack1.h>
44
45
#define EXT_SUPERBLOCK_MAGIC 0xEF53
46
#define EXT_DYNAMIC_REVISION 1
47
#define EXT_DEFAULT_INODE_SIZE 128
48
#define EXT_DEFAULT_GROUP_DESC_SIZE 32
49
50
#define EXT_DIR_ENTRY_MAX_NAME_LENGTH 255
51
52
typedef
struct
_ExtSuperBlock
53
{
54
/* SuperBlock Information Ext2 */
55
ULONG
InodesCount
;
56
ULONG
BlocksCountLo
;
57
ULONG
RBlocksCountLo
;
58
ULONG
FreeBlocksCountLo
;
59
ULONG
FreeInodesCount
;
60
ULONG
FirstDataBlock
;
61
ULONG
LogBlockSize
;
62
LONG
LogFragSize
;
63
ULONG
BlocksPerGroup
;
64
ULONG
FragsPerGroup
;
65
ULONG
InodesPerGroup
;
66
ULONG
MTime
;
67
ULONG
WTime
;
68
USHORT
MntCount
;
69
USHORT
MaxMntCount
;
70
USHORT
Magic
;
71
USHORT
State
;
72
USHORT
Errors
;
73
USHORT
MinorRevisionLevel
;
74
ULONG
LastCheck
;
75
ULONG
CheckInterval
;
76
ULONG
CreatorOS
;
77
ULONG
RevisionLevel
;
78
USHORT
DefResUID
;
79
USHORT
DefResGID
;
80
81
/* SuperBlock Information Ext3 */
82
ULONG
FirstInode
;
83
USHORT
InodeSize
;
84
USHORT
BlockGroupNr
;
85
ULONG
FeatureCompat
;
86
ULONG
FeatureIncompat
;
87
ULONG
FeatureROCompat
;
88
UCHAR
UUID
[16];
89
CHAR
VolumeName
[16];
90
CHAR
LastMounted
[64];
91
ULONG
AlgorithmUsageBitmap
;
92
UCHAR
PreallocBlocks
;
93
UCHAR
PreallocDirBlocks
;
94
USHORT
ReservedGdtBlocks
;
95
UCHAR
JournalUUID
[16];
96
ULONG
JournalInum
;
97
ULONG
JournalDev
;
98
ULONG
LastOrphan
;
99
ULONG
HashSeed
[4];
100
UCHAR
DefHashVersion
;
101
UCHAR
JournalBackupType
;
102
USHORT
GroupDescSize
;
103
104
ULONG
DefaultMountOpts
;
105
ULONG
FirstMetaBg
;
106
ULONG
MkfsTime
;
107
ULONG
JnlBlocks
[17];
108
109
/* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
110
ULONG
BlocksCountHi
;
111
ULONG
RBlocksCountHi
;
112
ULONG
FreeBlocksCountHi
;
113
114
UCHAR
Reserved
[676];
115
}
EXT_SUPER_BLOCK
, *
PEXT_SUPER_BLOCK
;
116
C_ASSERT
(
sizeof
(
EXT_SUPER_BLOCK
) == 0x400);
117
118
typedef
struct
_ExtGroupDescriptor
119
{
120
ULONG
BlockBitmap
;
121
ULONG
InodeBitmap
;
122
ULONG
InodeTable
;
123
USHORT
FreeBlocksCount
;
124
USHORT
FreeInodesCount
;
125
USHORT
UsedDirsCount
;
126
}
EXT_GROUP_DESC
, *
PEXT_GROUP_DESC
;
127
128
typedef
struct
_Ext4ExtentHeader
129
{
130
USHORT
Magic
;
131
USHORT
Entries
;
132
USHORT
Max
;
133
USHORT
Depth
;
134
ULONG
Generation
;
135
}
EXT4_EXTENT_HEADER
, *
PEXT4_EXTENT_HEADER
;
136
137
typedef
struct
_Ext4ExtentIdx
138
{
139
ULONG
Block
;
140
ULONG
Leaf
;
141
USHORT
LeafHigh
;
142
USHORT
Unused
;
143
}
EXT4_EXTENT_IDX
, *
PEXT4_EXTENT_IDX
;
144
145
typedef
struct
_Ext4Extent
146
{
147
ULONG
Block
;
148
USHORT
Length
;
149
USHORT
StartHigh
;
150
ULONG
Start
;
151
}
EXT4_EXTENT
, *
PEXT4_EXTENT
;
152
153
typedef
struct
_ExtInode
154
{
155
USHORT
Mode
;
// Combination of _S_IF* mode flags (FILETYPE_INO_* in grub/fs/ext2.c)
156
USHORT
UID
;
157
ULONG
Size
;
158
ULONG
Atime
;
159
ULONG
Ctime
;
160
ULONG
Mtime
;
161
ULONG
Dtime
;
162
USHORT
GID
;
163
USHORT
LinksCount
;
164
ULONG
BlocksCount
;
165
ULONG
Flags
;
166
ULONG
OSD1
;
167
union
168
{
169
CHAR
SymLink
[60];
170
struct
171
{
172
ULONG
DirectBlocks
[12];
173
ULONG
IndirectBlock
;
174
ULONG
DoubleIndirectBlock
;
175
ULONG
TripleIndirectBlock
;
176
}
Blocks
;
177
EXT4_EXTENT_HEADER
ExtentHeader
;
178
};
179
ULONG
Generation
;
180
ULONG
FileACL
;
181
ULONG
DirACL
;
182
ULONG
FragAddress
;
183
ULONG
OSD2
[3];
184
}
EXT_INODE
, *
PEXT_INODE
;
185
186
typedef
struct
_ExtDirEntry
187
{
188
ULONG
Inode
;
189
USHORT
EntryLen
;
190
UCHAR
NameLen
;
191
UCHAR
FileType
;
// One of the FILETYPE_* values
192
CHAR
Name
[
EXT_DIR_ENTRY_MAX_NAME_LENGTH
];
193
}
EXT_DIR_ENTRY
, *
PEXT_DIR_ENTRY
;
194
195
#include <poppack.h>
196
197
/* Special inode numbers. */
198
#define EXT_ROOT_INODE 2
199
200
/* The revision level. */
201
#define EXT_REVISION(sb) (sb->RevisionLevel)
202
203
/* The inode size. */
204
#define EXT_INODE_SIZE(sb) \
205
(EXT_REVISION(sb) < EXT_DYNAMIC_REVISION ? EXT_DEFAULT_INODE_SIZE : sb->InodeSize)
206
207
/* The group descriptor size. */
208
#define EXT_GROUP_DESC_SIZE(sb) \
209
((EXT_REVISION(sb) >= EXT_DYNAMIC_REVISION && sb->GroupDescSize) ? sb->GroupDescSize : EXT_DEFAULT_GROUP_DESC_SIZE)
210
211
/* The inode extents flag. */
212
#define EXT4_INODE_FLAG_EXTENTS 0x80000
213
214
/* The extent header magic value. */
215
#define EXT4_EXTENT_HEADER_MAGIC 0xF30A
216
217
/* The maximum extent level. */
218
#define EXT4_EXTENT_MAX_LEVEL 5
219
220
/* The maximum extent length used to check for sparse extents. */
221
#define EXT4_EXTENT_MAX_LENGTH 32768
222
223
/* Filetype used in directory entry. */
224
#define FILETYPE_UNKNOWN 0
225
#define FILETYPE_REG 1
226
#define FILETYPE_DIRECTORY 2
227
#define FILETYPE_SYMLINK 7
228
229
#define FAST_SYMLINK_MAX_NAME_SIZE 60
230
231
typedef
struct
_EXT_VOLUME_INFO
*
PEXT_VOLUME_INFO
;
232
233
typedef
struct
_EXT_FILE_INFO
234
{
235
PEXT_VOLUME_INFO
Volume
;
236
PULONG
FileBlockList
;
// File block list
237
EXT_INODE
Inode
;
// File inode
238
ULONGLONG
FileSize
;
// File size
239
ULONGLONG
FilePointer
;
// File pointer
240
ULONG
FileNameLength
;
241
UCHAR
Attributes
;
242
CHAR
FileName
[
RTL_FIELD_SIZE
(
FILEINFORMATION
,
FileName
)];
243
}
EXT_FILE_INFO
, *
PEXT_FILE_INFO
;
244
245
ULONGLONG
246
ExtGetVolumeSize
(
247
_In_
ULONG
DeviceId);
248
249
const
DEVVTBL
*
ExtMount
(
ULONG
DeviceId);
EXT4_EXTENT
struct _Ext4Extent EXT4_EXTENT
PEXT4_EXTENT
struct _Ext4Extent * PEXT4_EXTENT
EXT_GROUP_DESC
struct _ExtGroupDescriptor EXT_GROUP_DESC
EXT_INODE
struct _ExtInode EXT_INODE
PEXT_VOLUME_INFO
struct _EXT_VOLUME_INFO * PEXT_VOLUME_INFO
Definition:
ext.h:231
ExtGetVolumeSize
ULONGLONG ExtGetVolumeSize(_In_ ULONG DeviceId)
Returns the size of the EXT2/3/4 volume laid on the storage media device opened via DeviceId.
Definition:
ext.c:1404
EXT_DIR_ENTRY
struct _ExtDirEntry EXT_DIR_ENTRY
EXT_FILE_INFO
struct _EXT_FILE_INFO EXT_FILE_INFO
PEXT_FILE_INFO
struct _EXT_FILE_INFO * PEXT_FILE_INFO
PEXT_SUPER_BLOCK
struct _ExtSuperBlock * PEXT_SUPER_BLOCK
EXT4_EXTENT_IDX
struct _Ext4ExtentIdx EXT4_EXTENT_IDX
EXT4_EXTENT_HEADER
struct _Ext4ExtentHeader EXT4_EXTENT_HEADER
PEXT_DIR_ENTRY
struct _ExtDirEntry * PEXT_DIR_ENTRY
PEXT_INODE
struct _ExtInode * PEXT_INODE
ExtMount
const DEVVTBL * ExtMount(ULONG DeviceId)
Definition:
ext.c:1431
PEXT4_EXTENT_HEADER
struct _Ext4ExtentHeader * PEXT4_EXTENT_HEADER
EXT_DIR_ENTRY_MAX_NAME_LENGTH
#define EXT_DIR_ENTRY_MAX_NAME_LENGTH
Definition:
ext.h:50
PEXT4_EXTENT_IDX
struct _Ext4ExtentIdx * PEXT4_EXTENT_IDX
EXT_SUPER_BLOCK
struct _ExtSuperBlock EXT_SUPER_BLOCK
PEXT_GROUP_DESC
struct _ExtGroupDescriptor * PEXT_GROUP_DESC
GUID
Definition:
shobjidl.idl:3021
C_ASSERT
#define C_ASSERT(e)
Definition:
intsafe.h:73
RTL_FIELD_SIZE
#define RTL_FIELD_SIZE(type, field)
Definition:
kdb_expr.c:86
_In_
#define _In_
Definition:
no_sal2.h:158
LONG
long LONG
Definition:
pedump.c:60
USHORT
unsigned short USHORT
Definition:
pedump.c:61
_EXT_FILE_INFO
Definition:
ext.h:234
_EXT_FILE_INFO::Inode
EXT_INODE Inode
Definition:
ext.h:237
_EXT_FILE_INFO::Volume
PEXT_VOLUME_INFO Volume
Definition:
ext.h:235
_EXT_FILE_INFO::Attributes
UCHAR Attributes
Definition:
ext.h:241
_EXT_FILE_INFO::FileBlockList
PULONG FileBlockList
Definition:
ext.h:236
_EXT_FILE_INFO::FileNameLength
ULONG FileNameLength
Definition:
ext.h:240
_EXT_FILE_INFO::FilePointer
ULONGLONG FilePointer
Definition:
ext.h:239
_EXT_FILE_INFO::FileSize
ULONGLONG FileSize
Definition:
ext.h:238
_EXT_VOLUME_INFO
Definition:
ext.c:50
_Ext4ExtentHeader
Definition:
ext.h:129
_Ext4ExtentHeader::Generation
ULONG Generation
Definition:
ext.h:134
_Ext4ExtentHeader::Magic
USHORT Magic
Definition:
ext.h:130
_Ext4ExtentHeader::Max
USHORT Max
Definition:
ext.h:132
_Ext4ExtentHeader::Depth
USHORT Depth
Definition:
ext.h:133
_Ext4ExtentHeader::Entries
USHORT Entries
Definition:
ext.h:131
_Ext4ExtentIdx
Definition:
ext.h:138
_Ext4ExtentIdx::Leaf
ULONG Leaf
Definition:
ext.h:140
_Ext4ExtentIdx::Unused
USHORT Unused
Definition:
ext.h:142
_Ext4ExtentIdx::Block
ULONG Block
Definition:
ext.h:139
_Ext4ExtentIdx::LeafHigh
USHORT LeafHigh
Definition:
ext.h:141
_Ext4Extent
Definition:
ext.h:146
_Ext4Extent::Block
ULONG Block
Definition:
ext.h:147
_Ext4Extent::StartHigh
USHORT StartHigh
Definition:
ext.h:149
_Ext4Extent::Length
USHORT Length
Definition:
ext.h:148
_Ext4Extent::Start
ULONG Start
Definition:
ext.h:150
_ExtDirEntry
Definition:
ext.h:187
_ExtDirEntry::EntryLen
USHORT EntryLen
Definition:
ext.h:189
_ExtDirEntry::Inode
ULONG Inode
Definition:
ext.h:188
_ExtDirEntry::FileType
UCHAR FileType
Definition:
ext.h:191
_ExtDirEntry::Name
CHAR Name[EXT_DIR_ENTRY_MAX_NAME_LENGTH]
Definition:
ext.h:192
_ExtDirEntry::NameLen
UCHAR NameLen
Definition:
ext.h:190
_ExtGroupDescriptor
Definition:
ext.h:119
_ExtGroupDescriptor::FreeBlocksCount
USHORT FreeBlocksCount
Definition:
ext.h:123
_ExtGroupDescriptor::InodeBitmap
ULONG InodeBitmap
Definition:
ext.h:121
_ExtGroupDescriptor::InodeTable
ULONG InodeTable
Definition:
ext.h:122
_ExtGroupDescriptor::BlockBitmap
ULONG BlockBitmap
Definition:
ext.h:120
_ExtGroupDescriptor::FreeInodesCount
USHORT FreeInodesCount
Definition:
ext.h:124
_ExtGroupDescriptor::UsedDirsCount
USHORT UsedDirsCount
Definition:
ext.h:125
_ExtInode
Definition:
ext.h:154
_ExtInode::Dtime
ULONG Dtime
Definition:
ext.h:161
_ExtInode::DirACL
ULONG DirACL
Definition:
ext.h:181
_ExtInode::Blocks
struct _ExtInode::@203::@205 Blocks
_ExtInode::LinksCount
USHORT LinksCount
Definition:
ext.h:163
_ExtInode::IndirectBlock
ULONG IndirectBlock
Definition:
ext.h:173
_ExtInode::ExtentHeader
EXT4_EXTENT_HEADER ExtentHeader
Definition:
ext.h:177
_ExtInode::SymLink
CHAR SymLink[60]
Definition:
ext.h:169
_ExtInode::FragAddress
ULONG FragAddress
Definition:
ext.h:182
_ExtInode::Flags
ULONG Flags
Definition:
ext.h:165
_ExtInode::TripleIndirectBlock
ULONG TripleIndirectBlock
Definition:
ext.h:175
_ExtInode::GID
USHORT GID
Definition:
ext.h:162
_ExtInode::Generation
ULONG Generation
Definition:
ext.h:179
_ExtInode::Ctime
ULONG Ctime
Definition:
ext.h:159
_ExtInode::Mode
USHORT Mode
Definition:
ext.h:155
_ExtInode::UID
USHORT UID
Definition:
ext.h:156
_ExtInode::OSD1
ULONG OSD1
Definition:
ext.h:166
_ExtInode::FileACL
ULONG FileACL
Definition:
ext.h:180
_ExtInode::Size
ULONG Size
Definition:
ext.h:157
_ExtInode::DirectBlocks
ULONG DirectBlocks[12]
Definition:
ext.h:172
_ExtInode::Mtime
ULONG Mtime
Definition:
ext.h:160
_ExtInode::OSD2
ULONG OSD2[3]
Definition:
ext.h:183
_ExtInode::BlocksCount
ULONG BlocksCount
Definition:
ext.h:164
_ExtInode::Atime
ULONG Atime
Definition:
ext.h:158
_ExtInode::DoubleIndirectBlock
ULONG DoubleIndirectBlock
Definition:
ext.h:174
_ExtSuperBlock
Definition:
ext.h:53
_ExtSuperBlock::DefaultMountOpts
ULONG DefaultMountOpts
Definition:
ext.h:104
_ExtSuperBlock::FreeBlocksCountHi
ULONG FreeBlocksCountHi
Definition:
ext.h:112
_ExtSuperBlock::GroupDescSize
USHORT GroupDescSize
Definition:
ext.h:102
_ExtSuperBlock::FreeInodesCount
ULONG FreeInodesCount
Definition:
ext.h:59
_ExtSuperBlock::PreallocDirBlocks
UCHAR PreallocDirBlocks
Definition:
ext.h:93
_ExtSuperBlock::FeatureCompat
ULONG FeatureCompat
Definition:
ext.h:85
_ExtSuperBlock::HashSeed
ULONG HashSeed[4]
Definition:
ext.h:99
_ExtSuperBlock::MkfsTime
ULONG MkfsTime
Definition:
ext.h:106
_ExtSuperBlock::FirstMetaBg
ULONG FirstMetaBg
Definition:
ext.h:105
_ExtSuperBlock::FeatureIncompat
ULONG FeatureIncompat
Definition:
ext.h:86
_ExtSuperBlock::DefHashVersion
UCHAR DefHashVersion
Definition:
ext.h:100
_ExtSuperBlock::InodesCount
ULONG InodesCount
Definition:
ext.h:55
_ExtSuperBlock::JournalBackupType
UCHAR JournalBackupType
Definition:
ext.h:101
_ExtSuperBlock::BlocksCountLo
ULONG BlocksCountLo
Definition:
ext.h:56
_ExtSuperBlock::MaxMntCount
USHORT MaxMntCount
Definition:
ext.h:69
_ExtSuperBlock::DefResUID
USHORT DefResUID
Definition:
ext.h:78
_ExtSuperBlock::InodesPerGroup
ULONG InodesPerGroup
Definition:
ext.h:65
_ExtSuperBlock::MTime
ULONG MTime
Definition:
ext.h:66
_ExtSuperBlock::CreatorOS
ULONG CreatorOS
Definition:
ext.h:76
_ExtSuperBlock::Magic
USHORT Magic
Definition:
ext.h:70
_ExtSuperBlock::LogBlockSize
ULONG LogBlockSize
Definition:
ext.h:61
_ExtSuperBlock::LastCheck
ULONG LastCheck
Definition:
ext.h:74
_ExtSuperBlock::RevisionLevel
ULONG RevisionLevel
Definition:
ext.h:77
_ExtSuperBlock::BlockGroupNr
USHORT BlockGroupNr
Definition:
ext.h:84
_ExtSuperBlock::CheckInterval
ULONG CheckInterval
Definition:
ext.h:75
_ExtSuperBlock::AlgorithmUsageBitmap
ULONG AlgorithmUsageBitmap
Definition:
ext.h:91
_ExtSuperBlock::LogFragSize
LONG LogFragSize
Definition:
ext.h:62
_ExtSuperBlock::FragsPerGroup
ULONG FragsPerGroup
Definition:
ext.h:64
_ExtSuperBlock::DefResGID
USHORT DefResGID
Definition:
ext.h:79
_ExtSuperBlock::VolumeName
CHAR VolumeName[16]
Definition:
ext.h:89
_ExtSuperBlock::BlocksPerGroup
ULONG BlocksPerGroup
Definition:
ext.h:63
_ExtSuperBlock::FirstInode
ULONG FirstInode
Definition:
ext.h:82
_ExtSuperBlock::BlocksCountHi
ULONG BlocksCountHi
Definition:
ext.h:110
_ExtSuperBlock::RBlocksCountHi
ULONG RBlocksCountHi
Definition:
ext.h:111
_ExtSuperBlock::WTime
ULONG WTime
Definition:
ext.h:67
_ExtSuperBlock::LastOrphan
ULONG LastOrphan
Definition:
ext.h:98
_ExtSuperBlock::RBlocksCountLo
ULONG RBlocksCountLo
Definition:
ext.h:57
_ExtSuperBlock::FeatureROCompat
ULONG FeatureROCompat
Definition:
ext.h:87
_ExtSuperBlock::MntCount
USHORT MntCount
Definition:
ext.h:68
_ExtSuperBlock::InodeSize
USHORT InodeSize
Definition:
ext.h:83
_ExtSuperBlock::JnlBlocks
ULONG JnlBlocks[17]
Definition:
ext.h:107
_ExtSuperBlock::State
USHORT State
Definition:
ext.h:71
_ExtSuperBlock::JournalUUID
UCHAR JournalUUID[16]
Definition:
ext.h:95
_ExtSuperBlock::LastMounted
CHAR LastMounted[64]
Definition:
ext.h:90
_ExtSuperBlock::Errors
USHORT Errors
Definition:
ext.h:72
_ExtSuperBlock::FreeBlocksCountLo
ULONG FreeBlocksCountLo
Definition:
ext.h:58
_ExtSuperBlock::ReservedGdtBlocks
USHORT ReservedGdtBlocks
Definition:
ext.h:94
_ExtSuperBlock::MinorRevisionLevel
USHORT MinorRevisionLevel
Definition:
ext.h:73
_ExtSuperBlock::FirstDataBlock
ULONG FirstDataBlock
Definition:
ext.h:60
_ExtSuperBlock::PreallocBlocks
UCHAR PreallocBlocks
Definition:
ext.h:92
_ExtSuperBlock::JournalDev
ULONG JournalDev
Definition:
ext.h:97
_ExtSuperBlock::JournalInum
ULONG JournalInum
Definition:
ext.h:96
_FILEINFORMATION
Definition:
arc.h:230
_FileName
Definition:
filecomp.c:348
tagDEVVTBL
Definition:
fs.h:25
PULONG
uint32_t * PULONG
Definition:
typedefs.h:59
ULONG
uint32_t ULONG
Definition:
typedefs.h:59
ULONGLONG
uint64_t ULONGLONG
Definition:
typedefs.h:67
Reserved
_Reserved_ PVOID Reserved
Definition:
winddi.h:3974
UCHAR
unsigned char UCHAR
Definition:
xmlstorage.h:181
CHAR
char CHAR
Definition:
xmlstorage.h:175
boot
freeldr
freeldr
include
fs
ext.h
Generated on Thu Dec 4 2025 06:06:12 for ReactOS by
1.9.6