Max OS 0.3
Loading...
Searching...
No Matches
ext2.h File Reference

Defines structures and enums for the Extended 2 (ext2) filesystem format and relevant Filesystem, Directory and File classes. More...

#include <cstdint>
#include <common/spinlock.h>
#include <common/macros.h>
#include <drivers/disk/disk.h>
#include <drivers/clock/clock.h>
#include <filesystem/filesystem.h>
#include <memory/memoryIO.h>

Go to the source code of this file.

Classes

struct  MaxOS::filesystem::format::ext2::SuperBlock
 The metadata of the ext2 filesystem. Found at an offset of 1024 bytes from the start of the partition. More...
 
struct  MaxOS::filesystem::format::ext2::BlockGroupDescriptor
 The metadata for a block group in ext2. More...
 
struct  MaxOS::filesystem::format::ext2::Inode
 The metadata for a file or directory in ext2. More...
 
struct  MaxOS::filesystem::format::ext2::InodeOS2Linux
 The OS specific data for Linux created ext2 inodes. More...
 
struct  MaxOS::filesystem::format::ext2::DirectoryEntry
 An entry in a directory that points to a file or subdirectory (the name follows this struct) More...
 
class  MaxOS::filesystem::format::ext2::Ext2Volume
 Common operations for an ext2 volume that are used by both files & directories (like block & inode allocation) More...
 
class  MaxOS::filesystem::format::ext2::InodeHandler
 Simplfies the management of an inode & its blocks. More...
 
class  MaxOS::filesystem::format::ext2::Ext2File
 Handles the file operations on the ext2 filesystem. More...
 
class  MaxOS::filesystem::format::ext2::Ext2Directory
 Handles the directory operations on the ext2 filesystem. More...
 
class  MaxOS::filesystem::format::ext2::Ext2FileSystem
 Handles the ext2 filesystem operations. More...
 

Typedefs

typedef struct PACKED MaxOS::filesystem::format::ext2::SuperBlock MaxOS::filesystem::format::ext2::superblock_t
 Alias for SuperBlock struct.
 
typedef struct PACKED MaxOS::filesystem::format::ext2::BlockGroupDescriptor MaxOS::filesystem::format::ext2::block_group_descriptor_t
 Alias for BlockGroupDescriptor struct.
 
typedef struct PACKED MaxOS::filesystem::format::ext2::Inode MaxOS::filesystem::format::ext2::inode_t
 Alias for Inode struct.
 
typedef struct PACKED MaxOS::filesystem::format::ext2::InodeOS2Linux MaxOS::filesystem::format::ext2::linux_os_2_t
 Alias for InodeOS2Linux struct.
 
typedef struct PACKED MaxOS::filesystem::format::ext2::DirectoryEntry MaxOS::filesystem::format::ext2::directory_entry_t
 Alias for DirectoryEntry struct.
 

Enumerations

enum class  MaxOS::filesystem::format::ext2::FileSystemState { CLEAN = 1 , ERROR = 2 }
 The state of the filesystem. More...
 
enum class  MaxOS::filesystem::format::ext2::ErrorOperation { IGNORE = 1 , REMOUNT = 2 , PANIC = 3 }
 What to do when an error occurs. More...
 
enum class  MaxOS::filesystem::format::ext2::CreatorOS {
  LINUX , GNU_HURD , MASIX , FREE_BSD ,
  OTHER_LITES
}
 The OS which created the filesystem. More...
 
enum class  MaxOS::filesystem::format::ext2::OptionalFeatures {
  PREALLOCATE_DIRECTORY = 0x1 , AFS_SERVER_INODES = 0x2 , JOURNAL_ENABLED = 0x4 , ATTRIBUTES_EXTENDED = 0x8 ,
  RESIZEABLE = 0x10 , HASH_INDEXING = 0x20
}
 What features that are optional are supported by this filesystem. More...
 
enum class  MaxOS::filesystem::format::ext2::RequiredFeatures { COMPRESSION = 0x1 , DIRECTORY_HAS_TYPE = 0x2 , MUST_REPLAY_JOURNAL = 0x4 , JOURNAL_DEVICE = 0x8 }
 What features that are required are supported by this filesystem. More...
 
enum class  MaxOS::filesystem::format::ext2::ReadOnlyFeatures { SPARSE_SUPER_BLOCKS = 0x1 , FILES_64_BIT = 0x2 , BINARY_TREE_DIRECTORIES = 0x4 }
 What features that are only required in read-only mode. More...
 
enum class  MaxOS::filesystem::format::ext2::InodeType {
  UNKNOWN , FIFO = 0x1000 , CHARACTER_DEVICE = 0x2000 , DIRECTORY = 0x4000 ,
  BLOCK_DEVICE = 0x6000 , FILE = 0x8000 , SYMBOLIC_LINK = 0xA000 , SOCKET = 0xC000
}
 The type of an inode. More...
 
enum class  MaxOS::filesystem::format::ext2::InodePermissions {
  OTHER_EXECUTE = 0x1 , OTHER_WRITE = 0x2 , OTHER_READ = 0x4 , GROUP_EXECUTE = 0x8 ,
  GROUP_WRITE = 0x10 , GROUP_READ = 0x20 , USER_EXECUTE = 0x40 , USER_WRITE = 0x80 ,
  USER_READ = 0x100 , STICKY = 0x200 , GROUP_ID = 0x400 , USER_ID = 0x800
}
 The permissions that an inode can have. More...
 
enum class  MaxOS::filesystem::format::ext2::InodePermissionsDefaults { FILE = 0x1A4 , DIRECTORY = 0x1ED }
 The default permissions for files and directories. More...
 
enum class  MaxOS::filesystem::format::ext2::InodeFlags {
  SECURE_DELETE = 0x1 , KEEP_DATA = 0x2 , FILE_COMPRESSION = 0x4 , SYNC_UPDATES = 0x8 ,
  FILE_IMMUTABLE = 0x10 , APPEND_ONLY = 0x20 , DONT_DUMP = 0x40 , NO_LAST_ACCESS = 0x80 ,
  HASH_INDEXED = 0x10000 , AFS_DIRECTORY = 0x20000 , JOURNAL_FILE_DATA = 0x40000
}
 The flags that can be set on an inode. More...
 
enum class  MaxOS::filesystem::format::ext2::EntryType {
  UNKNOWN , FILE , DIRECTORY , CHARACTER_DEVICE ,
  BLOCK_DEVICE , FIFO , SOCKET , SYMBOLIC_LINK
}
 The type of a directory entry. More...
 

Detailed Description

Defines structures and enums for the Extended 2 (ext2) filesystem format and relevant Filesystem, Directory and File classes.

Date
17th July 2025
Author
Max Tyson

Definition in file ext2.h.

Typedef Documentation

◆ block_group_descriptor_t

Alias for BlockGroupDescriptor struct.

Todo:
Support updating directory_count when creating/deleting directories

◆ linux_os_2_t

Alias for InodeOS2Linux struct.

Todo:
HURD, MASIX

Enumeration Type Documentation

◆ CreatorOS

The OS which created the filesystem.

Todo:
Add MaxOS

Definition at line 104 of file ext2.h.

104 {
105 LINUX,
106 GNU_HURD,
107 MASIX,
108 FREE_BSD,
109 OTHER_LITES,
110 };

◆ EntryType

The type of a directory entry.

Warning
MaxOS only supports FILE, DIRECTORY
Todo:
Support more

Definition at line 305 of file ext2.h.

305 {
306 UNKNOWN,
307 FILE,
308 DIRECTORY,
309 CHARACTER_DEVICE,
310 BLOCK_DEVICE,
311 FIFO,
312 SOCKET,
313 SYMBOLIC_LINK
314 };

◆ ErrorOperation

What to do when an error occurs.

Definition at line 92 of file ext2.h.

92 {
93 IGNORE = 1,
94 REMOUNT = 2,
95 PANIC = 3,
96 };

◆ FileSystemState

The state of the filesystem.

Definition at line 83 of file ext2.h.

83 {
84 CLEAN = 1,
85 ERROR = 2,
86 };

◆ InodeFlags

The flags that can be set on an inode.

Definition at line 251 of file ext2.h.

251 {
252 SECURE_DELETE = 0x1, // Zero out data on deletion
253 KEEP_DATA = 0x2,
254 FILE_COMPRESSION = 0x4,
255 SYNC_UPDATES = 0x8,
256 FILE_IMMUTABLE = 0x10,
257 APPEND_ONLY = 0x20,
258 DONT_DUMP = 0x40,
259 NO_LAST_ACCESS = 0x80,
260 HASH_INDEXED = 0x10000,
261 AFS_DIRECTORY = 0x20000,
262 JOURNAL_FILE_DATA = 0x40000,
263 };

◆ InodePermissions

The permissions that an inode can have.

Definition at line 221 of file ext2.h.

221 {
222 OTHER_EXECUTE = 0x1,
223 OTHER_WRITE = 0x2,
224 OTHER_READ = 0x4,
225 GROUP_EXECUTE = 0x8,
226 GROUP_WRITE = 0x10,
227 GROUP_READ = 0x20,
228 USER_EXECUTE = 0x40,
229 USER_WRITE = 0x80,
230 USER_READ = 0x100,
231 STICKY = 0x200,
232 GROUP_ID = 0x400,
233 USER_ID = 0x800,
234 };

◆ InodePermissionsDefaults

The default permissions for files and directories.

Todo:
Document these values

Definition at line 242 of file ext2.h.

242 {
243 FILE = 0x1A4,
244 DIRECTORY = 0x1ED,
245 };

◆ InodeType

The type of an inode.

Definition at line 206 of file ext2.h.

206 {
207 UNKNOWN,
208 FIFO = 0x1000,
209 CHARACTER_DEVICE = 0x2000,
210 DIRECTORY = 0x4000,
211 BLOCK_DEVICE = 0x6000,
212 FILE = 0x8000,
213 SYMBOLIC_LINK = 0xA000,
214 SOCKET = 0xC000,
215 };

◆ OptionalFeatures

What features that are optional are supported by this filesystem.

Definition at line 116 of file ext2.h.

116 {
117 PREALLOCATE_DIRECTORY = 0x1,
118 AFS_SERVER_INODES = 0x2,
119 JOURNAL_ENABLED = 0x4,
120 ATTRIBUTES_EXTENDED = 0x8,
121 RESIZEABLE = 0x10,
122 HASH_INDEXING = 0x20,
123 };

◆ ReadOnlyFeatures

What features that are only required in read-only mode.

Definition at line 140 of file ext2.h.

140 {
141 SPARSE_SUPER_BLOCKS = 0x1,
142 FILES_64_BIT = 0x2,
143 BINARY_TREE_DIRECTORIES = 0x4,
144 };

◆ RequiredFeatures

What features that are required are supported by this filesystem.

Definition at line 129 of file ext2.h.

129 {
130 COMPRESSION = 0x1,
131 DIRECTORY_HAS_TYPE = 0x2,
132 MUST_REPLAY_JOURNAL = 0x4,
133 JOURNAL_DEVICE = 0x8,
134 };