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
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 */
84 /* the following are only available with revlevel = 1 */
85 u32int firstino; /* First non-reserved inode */
86 u16int inosize; /* size of inode structure */
87 u16int blockgroupnr; /* block group # of this super block */
88 u32int reserved[233]; /* Padding to the end of the block */
89 };
91 /*
92 * Block group
93 */
94 struct Group
95 {
96 u32int bitblock; /* Blocks bitmap block */
97 u32int inodebitblock; /* Inodes bitmap block */
98 u32int inodeaddr; /* Inodes table block */
99 u16int freeblockscount; /* Free blocks count */
100 u16int freeinodescount; /* Free inodes count */
101 u16int useddirscount; /* Directories count */
102 };
103 enum
105 GroupSize = 32
106 };
108 /*
109 * Inode
110 */
111 struct Inode
113 u16int mode; /* File mode */
114 u16int uid; /* Owner Uid */
115 u32int size; /* Size in bytes */
116 u32int atime; /* Access time */
117 u32int ctime; /* Creation time */
118 u32int mtime; /* Modification time */
119 u32int dtime; /* Deletion Time */
120 u16int gid; /* Group Id */
121 u16int nlink; /* Links count */
122 u32int nblock; /* Blocks count */
123 u32int flags; /* File flags */
124 u32int block[NBLOCKS];/* Pointers to blocks */
125 u32int version; /* File version (for NFS) */
126 u32int fileacl; /* File ACL */
127 u32int diracl; /* Directory ACL or high size bits */
128 u32int faddr; /* Fragment address */
129 };
131 /*
132 * Directory entry
133 */
134 struct Dirent
136 u32int ino; /* Inode number */
137 u16int reclen; /* Directory entry length */
138 u8int namlen; /* Name length */
139 char *name; /* File name */
140 };
141 enum
143 MinDirentSize = 4+2+1+1
144 };
146 /*
147 * In-core fs info.
148 */
149 struct Ext2
151 uint blocksize;
152 uint nblock;
153 uint ngroup;
154 uint inospergroup;
155 uint blockspergroup;
156 uint inosperblock;
157 uint inosize;
158 uint groupaddr;
159 uint descperblock;
160 uint firstblock;
161 Disk *disk;
162 Fsys *fsys;
163 };