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 /* permissions in Inode.mode */
31 IEXEC = 00100,
32 IWRITE = 0200,
33 IREAD = 0400,
34 ISVTX = 01000,
35 ISGID = 02000,
36 ISUID = 04000,
38 /* type in Inode.mode */
39 IFMT = 0170000,
40 IFIFO = 0010000,
41 IFCHR = 0020000,
42 IFDIR = 0040000,
43 IFBLK = 0060000,
44 IFREG = 0100000,
45 IFLNK = 0120000,
46 IFSOCK = 0140000,
47 IFWHT = 0160000,
48 };
50 #define DIRLEN(namlen) (((namlen)+8+3)&~3)
53 /*
54 * Super block on-disk format.
55 */
56 struct Super
57 {
58 u32int ninode; /* Inodes count */
59 u32int nblock; /* Blocks count */
60 u32int rblockcount; /* Reserved blocks count */
61 u32int freeblockcount; /* Free blocks count */
62 u32int freeinodecount; /* Free inodes count */
63 u32int firstdatablock; /* First Data Block */
64 u32int logblocksize; /* Block size */
65 u32int logfragsize; /* Fragment size */
66 u32int blockspergroup; /* # Blocks per group */
67 u32int fragpergroup; /* # Fragments per group */
68 u32int inospergroup; /* # Inodes per group */
69 u32int mtime; /* Mount time */
70 u32int wtime; /* Write time */
71 u16int mntcount; /* Mount count */
72 u16int maxmntcount; /* Maximal mount count */
73 u16int magic; /* Magic signature */
74 u16int state; /* File system state */
75 u16int errors; /* Behaviour when detecting errors */
76 u16int pad;
77 u32int lastcheck; /* time of last check */
78 u32int checkinterval; /* max. time between checks */
79 u32int creatoros; /* OS */
80 u32int revlevel; /* Revision level */
81 u16int defresuid; /* Default uid for reserved blocks */
82 u16int defresgid; /* Default gid for reserved blocks */
83 u32int reserved[235]; /* Padding to the end of the block */
84 };
86 /*
87 * Blcok group on-disk format.
88 */
89 struct Group
90 {
91 u32int bitblock; /* Blocks bitmap block */
92 u32int inodebitblock; /* Inodes bitmap block */
93 u32int inodeaddr; /* Inodes table block */
94 u16int freeblockscount; /* Free blocks count */
95 u16int freeinodescount; /* Free inodes count */
96 u16int useddirscount; /* Directories count */
97 u16int pad;
98 u32int reserved[3];
99 };
100 enum
102 GroupSize = 32
103 };
105 /*
106 * Structure of an inode on the disk
107 */
108 struct Inode
110 u16int mode; /* File mode */
111 u16int uid; /* Owner Uid */
112 u32int size; /* Size in bytes */
113 u32int atime; /* Access time */
114 u32int ctime; /* Creation time */
115 u32int mtime; /* Modification time */
116 u32int dtime; /* Deletion Time */
117 u16int gid; /* Group Id */
118 u16int nlink; /* Links count */
119 u32int nblock; /* Blocks count */
120 u32int flags; /* File flags */
121 u32int osd1;
122 u32int block[NBLOCKS];/* Pointers to blocks */
123 u32int version; /* File version (for NFS) */
124 u32int fileacl; /* File ACL */
125 u32int diracl; /* Directory ACL */
126 u32int faddr; /* Fragment address */
127 uchar osd2[12];
128 };
129 enum
131 InodeSize = 128
132 };
134 /*
135 * Directory entry on-disk structure.
136 */
137 struct Dirent
139 u32int ino; /* Inode number */
140 u16int reclen; /* Directory entry length */
141 u8int namlen; /* Name length */
142 u8int pad;
143 char name[NAMELEN]; /* File name */
144 };
145 enum
147 MinDirentSize = 4+2+1+1,
148 };
150 /*
151 * In-core fs info.
152 */
153 struct Ext2
155 uint blocksize;
156 uint nblock;
157 uint ngroup;
158 uint inospergroup;
159 uint blockspergroup;
160 uint inosperblock;
161 uint groupaddr;
162 uint descperblock;
163 uint firstblock;
164 Disk *disk;
165 Fsys *fsys;
166 };