The Pedigree Project  0.1
ext2.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef EXT2_H
21 #define EXT2_H
22 
23 #include "pedigree/kernel/processor/types.h"
24 
25 #define EXT2_UNKNOWN 0x0
26 #define EXT2_FILE 0x1
27 #define EXT2_DIRECTORY 0x2
28 #define EXT2_CHAR_DEV 0x3
29 #define EXT2_BLOCK_DEV 0x4
30 #define EXT2_FIFO 0x5
31 #define EXT2_SOCKET 0x6
32 #define EXT2_SYMLINK 0x7
33 #define EXT2_MAX 0x8
34 
35 #define EXT2_STATE_CLEAN 1
36 #define EXT2_STATE_UNCLEAN 2
37 
38 #define EXT2_S_IFSOCK 0xC000
39 #define EXT2_S_IFLNK 0xA000
40 #define EXT2_S_IFREG 0x8000
41 #define EXT2_S_IFBLK 0x6000
42 #define EXT2_S_IFDIR 0x4000
43 #define EXT2_S_IFCHR 0x2000
44 #define EXT2_S_IFIFO 0x1000
45 
46 #define EXT2_S_IRUSR 0x0100
47 #define EXT2_S_IWUSR 0x0080
48 #define EXT2_S_IXUSR 0x0040
49 #define EXT2_S_IRGRP 0x0020
50 #define EXT2_S_IWGRP 0x0010
51 #define EXT2_S_IXGRP 0x0008
52 #define EXT2_S_IROTH 0x0004
53 #define EXT2_S_IWOTH 0x0002
54 #define EXT2_S_IXOTH 0x0001
55 
56 #define EXT2_BAD_INO 0x01 // Bad blocks inode
57 #define EXT2_ROOT_INO 0x02 // root directory inode
58 #define EXT2_ACL_IDX_INO 0x03 // ACL index inode (deprecated?)
59 #define EXT2_ACL_DATA_INO 0x04 // ACL data inode (deprecated?)
60 #define EXT2_BOOT_LOADER_INO 0x05 // boot loader inode
61 #define EXT2_UNDEL_DIR_INO 0x06
62 
63 #define EXT2_LZV1_ALG 0x01
64 #define EXT2_LZRW3A_ALG 0x02
65 #define EXT2_GZIP_ALG 0x04
66 #define EXT2_BZIP2_ALG 0x08
67 #define EXT2_LZO_ALG 0x10
68 
69 #define EXT2_SECRM_FL 0x00000001
70 #define EXT2_UNRM_FL 0x00000002
71 #define EXT2_COMPR_FL 0x00000004
72 #define EXT2_SYNC_FL 0x00000008
73 #define EXT2_IMMUTABLE_FL 0x00000010
74 #define EXT2_APPEND_FL 0x00000020
75 #define EXT2_NODUMP_FL 0x00000040
76 #define EXT2_NOATIME_FL 0x00000080
77 #define EXT2_DIRTY_FL 0x00000100
78 #define EXT2_COMPRBLK_FL 0x00000200
79 #define EXT2_NOCOMPR_FL 0x00000400
80 #define EXT2_ECOMPR_FL 0x00000800
81 #define EXT2_BTREE_FL 0x00001000
82 #define EXT2_INDEX_FL 0x00001000
83 #define EXT2_IMAGIC_FL 0x00002000
84 #define EXT3_JOURNAL_DATA_FL 0x00004000
85 #define EXT2_RESERVED_FL 0x80000000
86 
88 struct Superblock
89 {
90  uint32_t s_inodes_count;
91  uint32_t s_blocks_count;
92  uint32_t s_r_blocks_count;
93  uint32_t s_free_blocks_count;
94  uint32_t s_free_inodes_count;
95  uint32_t s_first_data_block;
96  uint32_t s_log_block_size;
97  uint32_t s_log_frag_size;
98  uint32_t s_blocks_per_group;
99  uint32_t s_frags_per_group;
100  uint32_t s_inodes_per_group;
101  uint32_t s_mtime;
102  uint32_t s_wtime;
103  uint16_t s_mnt_count;
104  uint16_t s_max_mnt_count;
105  uint16_t s_magic;
106  uint16_t s_state;
107  uint16_t s_errors;
108  uint16_t s_minor_rev_level;
109  uint32_t s_lastcheck;
110  uint32_t s_checkinterval;
111  uint32_t s_creator_os;
112  uint32_t s_rev_level;
113  uint16_t s_def_resuid;
114  uint16_t s_def_resgid;
115  // -- EXT2_DYNAMIC_REV Specific --
116  uint32_t s_first_ino;
117  uint16_t s_inode_size;
118  uint16_t s_block_group_nr;
119  uint32_t s_feature_compat;
120  uint32_t s_feature_incompat;
121  uint32_t s_feature_ro_compat;
122  char s_uuid[16];
123 
124  char s_volume_name[16];
125  char s_last_mounted[64];
126  uint32_t s_algo_bitmap;
127  // -- Performance Hints --
128  uint8_t s_prealloc_blocks;
129  uint8_t s_prealloc_dir_blocks;
130  uint16_t alignment;
131  // -- Journaling Support --
132  char s_journal_uuid[16];
133  uint32_t s_journal_inum;
134  uint32_t s_journal_dev;
135  uint32_t s_last_orphan;
136 } __attribute__((packed));
137 
139 struct GroupDesc
140 {
141  uint32_t bg_block_bitmap;
142  uint32_t bg_inode_bitmap;
143  uint32_t bg_inode_table;
144  uint16_t bg_free_blocks_count;
145  uint16_t bg_free_inodes_count;
146  uint16_t bg_used_dirs_count;
147  uint16_t bg_pad;
148  uint8_t bg_reserved[12];
149 } __attribute__((packed));
150 
152 struct Inode
153 {
154  uint16_t i_mode;
155  uint16_t i_uid;
156  uint32_t i_size;
157  uint32_t i_atime;
158  uint32_t i_ctime;
159  uint32_t i_mtime;
160  uint32_t i_dtime;
161  uint16_t i_gid;
162  uint16_t i_links_count;
163  uint32_t i_blocks;
164  uint32_t i_flags;
165  uint32_t i_osd1;
166  uint32_t i_block[15];
167  uint32_t i_generation;
168  uint32_t i_file_acl;
169  uint32_t i_dir_acl; // Top 32-bits of file size.
170  uint32_t i_faddr;
171  uint8_t i_osd2[12];
172 } __attribute__((packed));
173 
175 struct Dir
176 {
177  uint32_t d_inode;
178  uint16_t d_reclen;
179  uint8_t d_namelen;
180  uint8_t d_file_type;
181  char d_name[256];
182 } __attribute__((packed));
183 
184 #endif
Definition: ext2.h:152
Definition: ext2.h:175