Blob


1 typedef struct Super Super;
2 typedef struct Group Group;
3 typedef struct Inode Inode;
4 typedef struct Dirent Dirent;
5 typedef struct Ext2 Ext2;
7 enum
8 {
9 BYTESPERSEC = 512,
11 SBOFF = 1024,
12 SBSIZE = 1024,
14 SUPERMAGIC = 0xEF53,
15 MINBLOCKSIZE = 1024,
16 MAXBLOCKSIZE = 4096,
17 ROOTINODE = 2,
18 FIRSTINODE = 11,
19 VALIDFS = 0x0001,
20 ERRORFS = 0x0002,
22 NDIRBLOCKS = 12,
23 INDBLOCK = NDIRBLOCKS,
24 DINDBLOCK = INDBLOCK+1,
25 TINDBLOCK = DINDBLOCK+1,
26 NBLOCKS = TINDBLOCK+1,
28 NAMELEN = 255,
30 /* some systems have these defined */
31 #undef IEXEC
32 #undef IWRITE
33 #undef IREAD
34 #undef ISVTX
35 #undef ISGID
36 #undef ISUID
37 #undef IFMT
38 #undef IFIFO
39 #undef IFCHR
40 #undef IFDIR
41 #undef IFBLK
42 #undef IFREG
43 #undef IFLNK
44 #undef IFSOCK
45 #undef IFWHT
47 #define IEXEC EXT2_IEXEC
48 #define IWRITE EXT2_IWRITE
49 #define IREAD EXT2_IREAD
50 #define ISVTX EXT2_ISVTX
51 #define ISGID EXT2_ISGID
52 #define ISUID EXT2_ISUID
53 #define IFMT EXT2_IFMT
54 #define IFIFO EXT2_IFIFO
55 #define IFCHR EXT2_IFCHR
56 #define IFDIR EXT2_IFDIR
57 #define IFBLK EXT2_IFBLK
58 #define IFREG EXT2_IFREG
59 #define IFLNK EXT2_IFLNK
60 #define IFSOCK EXT2_IFSOCK
61 #define IFWHT EXT2_IFWHT
63 /* permissions in Inode.mode */
64 IEXEC = 00100,
65 IWRITE = 0200,
66 IREAD = 0400,
67 ISVTX = 01000,
68 ISGID = 02000,
69 ISUID = 04000,
71 /* type in Inode.mode */
72 IFMT = 0170000,
73 IFIFO = 0010000,
74 IFCHR = 0020000,
75 IFDIR = 0040000,
76 IFBLK = 0060000,
77 IFREG = 0100000,
78 IFLNK = 0120000,
79 IFSOCK = 0140000,
80 IFWHT = 0160000
81 };
83 #define DIRLEN(namlen) (((namlen)+8+3)&~3)
86 /*
87 * Super block
88 */
89 struct Super
90 {
91 u32int ninode; /* Inodes count */
92 u32int nblock; /* Blocks count */
93 u32int rblockcount; /* Reserved blocks count */
94 u32int freeblockcount; /* Free blocks count */
95 u32int freeinodecount; /* Free inodes count */
96 u32int firstdatablock; /* First Data Block */
97 u32int logblocksize; /* Block size */
98 u32int logfragsize; /* Fragment size */
99 u32int blockspergroup; /* # Blocks per group */
100 u32int fragpergroup; /* # Fragments per group */
101 u32int inospergroup; /* # Inodes per group */
102 u32int mtime; /* Mount time */
103 u32int wtime; /* Write time */
104 u16int mntcount; /* Mount count */
105 u16int maxmntcount; /* Maximal mount count */
106 u16int magic; /* Magic signature */
107 u16int state; /* File system state */
108 u16int errors; /* Behaviour when detecting errors */
109 u16int pad;
110 u32int lastcheck; /* time of last check */
111 u32int checkinterval; /* max. time between checks */
112 u32int creatoros; /* OS */
113 u32int revlevel; /* Revision level */
114 u16int defresuid; /* Default uid for reserved blocks */
115 u16int defresgid; /* Default gid for reserved blocks */
117 /* the following are only available with revlevel = 1 */
118 u32int firstino; /* First non-reserved inode */
119 u16int inosize; /* size of inode structure */
120 u16int blockgroupnr; /* block group # of this super block */
121 u32int reserved[233]; /* Padding to the end of the block */
122 };
124 /*
125 * Block group
126 */
127 struct Group
129 u32int bitblock; /* Blocks bitmap block */
130 u32int inodebitblock; /* Inodes bitmap block */
131 u32int inodeaddr; /* Inodes table block */
132 u16int freeblockscount; /* Free blocks count */
133 u16int freeinodescount; /* Free inodes count */
134 u16int useddirscount; /* Directories count */
135 };
136 enum
138 GroupSize = 32
139 };
141 /*
142 * Inode
143 */
144 struct Inode
146 u16int mode; /* File mode */
147 u16int uid; /* Owner Uid */
148 u32int size; /* Size in bytes */
149 u32int atime; /* Access time */
150 u32int ctime; /* Creation time */
151 u32int mtime; /* Modification time */
152 u32int dtime; /* Deletion Time */
153 u16int gid; /* Group Id */
154 u16int nlink; /* Links count */
155 u32int nblock; /* Blocks count */
156 u32int flags; /* File flags */
157 u32int block[NBLOCKS];/* Pointers to blocks */
158 u32int version; /* File version (for NFS) */
159 u32int fileacl; /* File ACL */
160 u32int diracl; /* Directory ACL or high size bits */
161 u32int faddr; /* Fragment address */
162 };
164 /*
165 * Directory entry
166 */
167 struct Dirent
169 u32int ino; /* Inode number */
170 u16int reclen; /* Directory entry length */
171 u8int namlen; /* Name length */
172 char *name; /* File name */
173 };
174 enum
176 MinDirentSize = 4+2+1+1
177 };
179 /*
180 * In-core fs info.
181 */
182 struct Ext2
184 uint blocksize;
185 uint nblock;
186 uint ngroup;
187 uint inospergroup;
188 uint blockspergroup;
189 uint inosperblock;
190 uint inosize;
191 uint groupaddr;
192 uint descperblock;
193 uint firstblock;
194 Disk *disk;
195 Fsys *fsys;
196 };