:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / fs / ext2 / ext2fs.h
1 #include <ddk/ntddk.h>
2 #include <ddk/ntifs.h>
3
4 BOOLEAN Ext2ReadSectors(IN PDEVICE_OBJECT pDeviceObject,
5                         IN ULONG        DiskSector,
6                         IN ULONG        SectorCount,
7                         IN PVOID        Buffer);
8
9 #define BLOCKSIZE (1024)
10
11 struct ext2_super_block {
12         ULONG   s_inodes_count;         /* Inodes count */
13         ULONG   s_blocks_count;         /* Blocks count */
14         ULONG   s_r_blocks_count;       /* Reserved blocks count */
15         ULONG   s_free_blocks_count;    /* Free blocks count */
16         ULONG   s_free_inodes_count;    /* Free inodes count */
17         ULONG   s_first_data_block;     /* First Data Block */
18         ULONG   s_log_block_size;       /* Block size */
19         LONG    s_log_frag_size;        /* Fragment size */
20         ULONG   s_blocks_per_group;     /* # Blocks per group */
21         ULONG   s_frags_per_group;      /* # Fragments per group */
22         ULONG   s_inodes_per_group;     /* # Inodes per group */
23         ULONG   s_mtime;                /* Mount time */
24         ULONG   s_wtime;                /* Write time */
25         USHORT  s_mnt_count;            /* Mount count */
26         SHORT   s_max_mnt_count;        /* Maximal mount count */
27         USHORT  s_magic;                /* Magic signature */
28         USHORT  s_state;                /* File system state */
29         USHORT  s_errors;               /* Behaviour when detecting errors */
30         USHORT  s_minor_rev_level;      /* minor revision level */
31         ULONG   s_lastcheck;            /* time of last check */
32         ULONG   s_checkinterval;        /* max. time between checks */
33         ULONG   s_creator_os;           /* OS */
34         ULONG   s_rev_level;            /* Revision level */
35         USHORT  s_def_resuid;           /* Default uid for reserved blocks */
36         USHORT  s_def_resgid;           /* Default gid for reserved blocks */
37         /*
38          * These fields are for EXT2_DYNAMIC_REV superblocks only.
39          *
40          * Note: the difference between the compatible feature set and
41          * the incompatible feature set is that if there is a bit set
42          * in the incompatible feature set that the kernel doesn't
43          * know about, it should refuse to mount the filesystem.
44          * 
45          * e2fsck's requirements are more strict; if it doesn't know
46          * about a feature in either the compatible or incompatible
47          * feature set, it must abort and not try to meddle with
48          * things it doesn't understand...
49          */
50         ULONG   s_first_ino;            /* First non-reserved inode */
51         USHORT   s_inode_size;          /* size of inode structure */
52         USHORT  s_block_group_nr;       /* block group # of this superblock */
53         ULONG   s_feature_compat;       /* compatible feature set */
54         ULONG   s_feature_incompat;     /* incompatible feature set */
55         ULONG   s_feature_ro_compat;    /* readonly-compatible feature set */
56         ULONG   s_reserved[230];        /* Padding to the end of the block */
57 };
58
59 /*
60  * Codes for operating systems
61  */
62 #define EXT2_OS_LINUX           0
63 #define EXT2_OS_HURD            1
64 #define EXT2_OS_MASIX           2
65 #define EXT2_OS_FREEBSD         3
66 #define EXT2_OS_LITES           4
67
68 /*
69  * Revision levels
70  */
71 #define EXT2_GOOD_OLD_REV       0       /* The good old (original) format */
72 #define EXT2_DYNAMIC_REV        1       /* V2 format w/ dynamic inode sizes */
73
74 #define EXT2_CURRENT_REV        EXT2_GOOD_OLD_REV
75 #define EXT2_MAX_SUPP_REV       EXT2_DYNAMIC_REV
76
77 /*
78  * The second extended file system magic number
79  */
80 #define EXT2_SUPER_MAGIC        0xEF53
81
82 /*
83  * Constants relative to the data blocks
84  */
85 #define EXT2_NDIR_BLOCKS                12
86 #define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
87 #define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
88 #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
89 #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
90
91
92 /*
93  * Structure of an inode on the disk
94  */
95 struct ext2_inode {
96         USHORT  i_mode;         /* File mode */
97         USHORT  i_uid;          /* Owner Uid */
98         ULONG   i_size;         /* Size in bytes */
99         ULONG   i_atime;        /* Access time */
100         ULONG   i_ctime;        /* Creation time */
101         ULONG   i_mtime;        /* Modification time */
102         ULONG   i_dtime;        /* Deletion Time */
103         USHORT  i_gid;          /* Group Id */
104         USHORT  i_links_count;  /* Links count */
105         ULONG   i_blocks;       /* Blocks count */
106         ULONG   i_flags;        /* File flags */
107         union {
108                 struct {
109                         ULONG  l_i_reserved1;
110                 } linux1;
111                 struct {
112                         ULONG  h_i_translator;
113                 } hurd1;
114                 struct {
115                         ULONG  m_i_reserved1;
116                 } masix1;
117         } osd1;                         /* OS dependent 1 */
118         ULONG   i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
119         ULONG   i_version;      /* File version (for NFS) */
120         ULONG   i_file_acl;     /* File ACL */
121         ULONG   i_dir_acl;      /* Directory ACL */
122         ULONG   i_faddr;        /* Fragment address */
123         union {
124                 struct {
125                         UCHAR   l_i_frag;       /* Fragment number */
126                         UCHAR   l_i_fsize;      /* Fragment size */
127                         USHORT  i_pad1;
128                         ULONG   l_i_reserved2[2];
129                 } linux2;
130                 struct {
131                         UCHAR   h_i_frag;       /* Fragment number */
132                         UCHAR   h_i_fsize;      /* Fragment size */
133                         USHORT  h_i_mode_high;
134                         USHORT  h_i_uid_high;
135                         USHORT  h_i_gid_high;
136                         ULONG   h_i_author;
137                 } hurd2;
138                 struct {
139                         UCHAR   m_i_frag;       /* Fragment number */
140                         UCHAR   m_i_fsize;      /* Fragment size */
141                         USHORT  m_pad1;
142                         ULONG   m_i_reserved2[2];
143                 } masix2;
144         } osd2;                         /* OS dependent 2 */
145 };
146
147 #if defined(__KERNEL__) || defined(__linux__)
148 #define i_reserved1     osd1.linux1.l_i_reserved1
149 #define i_frag          osd2.linux2.l_i_frag
150 #define i_fsize         osd2.linux2.l_i_fsize
151 #define i_reserved2     osd2.linux2.l_i_reserved2
152 #endif
153
154 #ifdef  __hurd__
155 #define i_translator    osd1.hurd1.h_i_translator
156 #define i_frag          osd2.hurd2.h_i_frag;
157 #define i_fsize         osd2.hurd2.h_i_fsize;
158 #define i_uid_high      osd2.hurd2.h_i_uid_high
159 #define i_gid_high      osd2.hurd2.h_i_gid_high
160 #define i_author        osd2.hurd2.h_i_author
161 #endif
162
163 #ifdef  __masix__
164 #define i_reserved1     osd1.masix1.m_i_reserved1
165 #define i_frag          osd2.masix2.m_i_frag
166 #define i_fsize         osd2.masix2.m_i_fsize
167 #define i_reserved2     osd2.masix2.m_i_reserved2
168 #endif
169
170 /*
171  * Constants relative to the data blocks
172  */
173 #define EXT2_NDIR_BLOCKS                12
174 #define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
175 #define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
176 #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
177 #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
178
179 /*
180  * Inode flags
181  */
182 #define EXT2_SECRM_FL                   0x00000001 /* Secure deletion */
183 #define EXT2_UNRM_FL                    0x00000002 /* Undelete */
184 #define EXT2_COMPR_FL                   0x00000004 /* Compress file */
185 #define EXT2_SYNC_FL                    0x00000008 /* Synchronous updates */
186 #define EXT2_IMMUTABLE_FL               0x00000010 /* Immutable file */
187 #define EXT2_APPEND_FL                  0x00000020 /* writes to file may only append */
188 #define EXT2_NODUMP_FL                  0x00000040 /* do not dump file */
189 #define EXT2_RESERVED_FL                0x80000000 /* reserved for ext2 lib */
190         
191
192 /*
193  * Structure of a blocks group descriptor
194  */
195 struct ext2_group_desc
196 {
197         ULONG   bg_block_bitmap;                /* Blocks bitmap block */
198         ULONG   bg_inode_bitmap;                /* Inodes bitmap block */
199         ULONG   bg_inode_table;         /* Inodes table block */
200         USHORT  bg_free_blocks_count;   /* Free blocks count */
201         USHORT  bg_free_inodes_count;   /* Free inodes count */
202         USHORT  bg_used_dirs_count;     /* Directories count */
203         USHORT  bg_pad;
204         ULONG   bg_reserved[3];
205 };
206
207 #define EXT2_NAME_LEN 255
208
209 struct ext2_dir_entry {
210         ULONG   inode;                  /* Inode number */
211         USHORT  rec_len;                /* Directory entry length */
212         USHORT  name_len;               /* Name length */
213         char    name[EXT2_NAME_LEN];    /* File name */
214 };
215
216 typedef struct
217 {
218    PDEVICE_OBJECT StorageDevice;
219    struct ext2_super_block* superblock;
220    PFILE_OBJECT FileObject;
221    PBCB Bcb;
222 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
223
224 typedef struct _EXT2_GROUP_DESC
225 {
226    ERESOURCE Lock;
227    struct ext2_group_desc* desc;
228    PCACHE_SEGMENT CacheSeg;
229    PVOID BaseAddress;
230 } EXT2_GROUP_DESC, *PEXT2_GROUP_DESC;
231
232 PEXT2_GROUP_DESC Ext2LoadGroup(PDEVICE_EXTENSION DeviceExt,
233                                ULONG BlockGrp);
234 VOID Ext2ReleaseGroup(PDEVICE_EXTENSION DeviceExt,
235                       PEXT2_GROUP_DESC GrpDesc);
236
237 VOID Ext2ReadInode(PDEVICE_EXTENSION DeviceExt,
238                    ULONG ino,
239                    struct ext2_inode* inode);
240 struct ext2_group_desc* Ext2LoadGroupDesc(PDEVICE_EXTENSION DeviceExt,
241                                           ULONG block_group);
242
243 typedef struct _EXT2_INODE
244 {
245    struct ext2_inode* inode;
246    PVOID BaseAddress;
247    PCACHE_SEGMENT CacheSeg;
248 } EXT2_INODE, *PEXT2_INODE;
249
250 typedef struct _EXT2_FCB
251 {
252    ULONG inode;
253    EXT2_INODE i;
254    PBCB Bcb;
255 } EXT2_FCB, *PEXT2_FCB;
256
257 ULONG Ext2BlockMap(PDEVICE_EXTENSION DeviceExt,
258                    struct ext2_inode* inode,
259                    ULONG offset);
260 NTSTATUS Ext2OpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, 
261                       PWSTR FileName);
262 NTSTATUS Ext2ReadFile(PDEVICE_EXTENSION DeviceExt, 
263                       PFILE_OBJECT FileObject,
264                       PVOID Buffer, 
265                       ULONG Length, 
266                       LARGE_INTEGER Offset);
267 NTSTATUS STDCALL Ext2Create(PDEVICE_OBJECT DeviceObject, PIRP Irp);
268 NTSTATUS STDCALL Ext2DirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
269 NTSTATUS STDCALL Ext2QueryQuota(PDEVICE_OBJECT DeviceObject, PIRP Irp);
270 NTSTATUS STDCALL Ext2SetQuota(PDEVICE_OBJECT DeviceObject, PIRP Irp);
271 NTSTATUS STDCALL Ext2SetSecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp);
272 NTSTATUS STDCALL Ext2QuerySecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp);
273 NTSTATUS STDCALL Ext2SetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
274 NTSTATUS STDCALL Ext2QueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
275 NTSTATUS STDCALL Ext2Read(PDEVICE_OBJECT DeviceObject, PIRP Irp);
276 NTSTATUS STDCALL Ext2Write(PDEVICE_OBJECT DeviceObject, PIRP Irp);
277 NTSTATUS STDCALL Ext2Cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp);
278 NTSTATUS STDCALL Ext2FlushBuffers(PDEVICE_OBJECT DeviceObject, PIRP Irp);
279 NTSTATUS STDCALL Ext2Shutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp);
280 NTSTATUS Ext2ReadPage(PDEVICE_EXTENSION DeviceExt,
281                       PEXT2_FCB Fcb,
282                       PVOID Buffer,
283                       ULONG Offset);
284 VOID Ext2LoadInode(PDEVICE_EXTENSION DeviceExt,
285                    ULONG ino,
286                    PEXT2_INODE Inode);
287 VOID Ext2ReleaseInode(PDEVICE_EXTENSION DeviceExt,
288                       PEXT2_INODE Inode);
289