aboutsummaryrefslogtreecommitdiff
path: root/src/libdiskfs/ext2.h
blob: d0503b4036f78877e8d88379f14378962e9563b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
typedef struct Super Super;
typedef struct Group Group;
typedef struct Inode Inode;
typedef struct Dirent Dirent;
typedef struct Ext2 Ext2;

enum
{
	BYTESPERSEC	= 512,

	SBOFF = 1024,
	SBSIZE = 1024,

	SUPERMAGIC = 0xEF53,
	MINBLOCKSIZE = 1024,
	MAXBLOCKSIZE = 4096,
	ROOTINODE = 2,
	FIRSTINODE = 11,
	VALIDFS = 0x0001,
	ERRORFS = 0x0002,

	NDIRBLOCKS = 12,
	INDBLOCK = NDIRBLOCKS,
	DINDBLOCK = INDBLOCK+1,
	TINDBLOCK = DINDBLOCK+1,
	NBLOCKS = TINDBLOCK+1,

	NAMELEN = 255,

	/* permissions in Inode.mode */
	IEXEC = 00100,
	IWRITE = 0200,
	IREAD = 0400,
	ISVTX = 01000,
	ISGID = 02000,
	ISUID = 04000,

	/* type in Inode.mode */
	IFMT = 0170000,
	IFIFO = 0010000,
	IFCHR = 0020000,
	IFDIR = 0040000,
	IFBLK = 0060000,
	IFREG = 0100000,
	IFLNK = 0120000,
	IFSOCK = 0140000,
	IFWHT = 0160000
};

#define DIRLEN(namlen)	(((namlen)+8+3)&~3)


/*
 * Super block on-disk format.
 */
struct Super
{
	u32int	ninode;		/* Inodes count */
	u32int	nblock;		/* Blocks count */
	u32int	rblockcount;	/* Reserved blocks count */
	u32int	freeblockcount;	/* Free blocks count */
	u32int	freeinodecount;	/* Free inodes count */
	u32int	firstdatablock;	/* First Data Block */
	u32int	logblocksize;	/* Block size */
	u32int	logfragsize;	/* Fragment size */
	u32int	blockspergroup;	/* # Blocks per group */
	u32int	fragpergroup;	/* # Fragments per group */
	u32int	inospergroup;	/* # Inodes per group */
	u32int	mtime;		/* Mount time */
	u32int	wtime;		/* Write time */
	u16int	mntcount;		/* Mount count */
	u16int	maxmntcount;	/* Maximal mount count */
	u16int	magic;		/* Magic signature */
	u16int	state;		/* File system state */
	u16int	errors;		/* Behaviour when detecting errors */
	u16int	pad;
	u32int	lastcheck;		/* time of last check */
	u32int	checkinterval;	/* max. time between checks */
	u32int	creatoros;		/* OS */
	u32int	revlevel;		/* Revision level */
	u16int	defresuid;		/* Default uid for reserved blocks */
	u16int	defresgid;		/* Default gid for reserved blocks */
	u32int	reserved[235];	/* Padding to the end of the block */
};

/*
 * Blcok group on-disk format.
 */
struct Group
{
	u32int	bitblock;		/* Blocks bitmap block */
	u32int	inodebitblock;		/* Inodes bitmap block */
	u32int	inodeaddr;		/* Inodes table block */
	u16int	freeblockscount;	/* Free blocks count */
	u16int	freeinodescount;	/* Free inodes count */
	u16int	useddirscount;	/* Directories count */
	u16int	pad;
	u32int	reserved[3];
};
enum
{
	GroupSize = 32
};

/*
 * Structure of an inode on the disk
 */
struct Inode
{
	u16int	mode;		/* File mode */
	u16int	uid;		/* Owner Uid */
	u32int	size;		/* Size in bytes */
	u32int	atime;		/* Access time */
	u32int	ctime;		/* Creation time */
	u32int	mtime;		/* Modification time */
	u32int	dtime;		/* Deletion Time */
	u16int	gid;		/* Group Id */
	u16int	nlink;	/* Links count */
	u32int	nblock;	/* Blocks count */
	u32int	flags;		/* File flags */
	u32int	osd1;				
	u32int	block[NBLOCKS];/* Pointers to blocks */
	u32int	version;	/* File version (for NFS) */
	u32int	fileacl;	/* File ACL */
	u32int	diracl;	/* Directory ACL */
	u32int	faddr;		/* Fragment address */
	uchar	osd2[12];
};
enum
{
	InodeSize = 128
};

/*
 * Directory entry on-disk structure.
 */
struct Dirent
{
	u32int	ino;			/* Inode number */
	u16int	reclen;		/* Directory entry length */
	u8int	namlen;		/* Name length */
	u8int	pad;
	char	name[NAMELEN];	/* File name */
};
enum
{
	MinDirentSize = 4+2+1+1
};

/*
 * In-core fs info.
 */
struct Ext2
{
	uint	blocksize;
	uint	nblock;
	uint	ngroup;
	uint	inospergroup;
	uint	blockspergroup;
	uint	inosperblock;
	uint	groupaddr;
	uint	descperblock;
	uint	firstblock;
	Disk *disk;
	Fsys *fsys;
};