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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
.TH FILSYS 5
.CT 2 sa
.SH NAME
filsys, flblk, ino \- format of file system volume
.SH SYNOPSIS
.B #include <sys/types.h>
.br
.B #include <sys/fblk.h>
.br
.B #include <sys/filsys.h>
.br
.B #include <sys/ino.h>
.SH DESCRIPTION
Every
file system is divided into a certain number
of blocks of 1K or 4K bytes, as determined by
the predicate
.L BITFS()
applied to the minor device number
where the file system is mounted.
Block 0 is unused and is available to contain
a bootstrap program, pack label, or other information.
.PP
Block 1 is the
`super block'.
Its layout is defined in
.LR <sys/filsys.h> :
.PP
.EX
.ta \w'#define 'u +\w'unsigned 'u
struct filsys {
unsigned short s_isize;
daddr_t s_fsize;
short s_ninode;
ino_t s_inode[NICINOD];
char s_flock;
char s_ilock;
char s_fmod;
char s_ronly;
time_t s_time;
daddr_t s_tfree;
ino_t s_tinode;
short s_dinfo[2];
#define s_m s_dinfo[0]
#define s_n s_dinfo[1]
#define s_cylsize s_dinfo[0]
#define s_aspace s_dinfo[1]
char s_fsmnt[14];
ino_t s_lasti;
ino_t s_nbehind;
union {
struct {
short S_nfree;
daddr_t S_free[NICFREE];
} R;
struct {
char S_valid;
#define BITMAP 961
long S_bfree[BITMAP];
} B;
struct {
char S_valid;
char S_flag; /* 1 means bitmap not in S_bfree */
long S_bsize;/* how big the bitmap blocks are */
struct buf * S_blk[BITMAP-1];
} N;
} U;
};
#define s_nfree U.R.S_nfree
#define s_free U.R.S_free
#define s_valid U.B.S_valid
#define s_bfree U.B.S_bfree
.EE
.TF s_isize
.TP
.B s_isize
The address of the first block after the i-list,
which starts in block 2.
Thus the i-list is
.LR s_isize-2
blocks long.
.PD
.TP
.B s_fsize
The address of the first block not in the file system.
.TP
.B s_free
In a 1K file system, an array of free block numbers.
.LR s_free[0]
is the block address of the next
in a chain of blocks constituting the free list.
The layout of these blocks is defined in
.LR <sys/fblk.h> :
.EX
struct fblk {
int df_nfree;
daddr_t df_free[NICFREE];
}
.EE
.ns
.IP
where
.L df_nfree
and
.L df_free
are exactly like
.L s_nfree
and
.L s_free.
.TP
.B s_nfree
Blocks given in
.L s_free[1]
through
.L s_free[s_nfree-1]
are available for allocation.
Blocks are allocated in LIFO fashion from this list.
If freeing would cause
the array to overflow,
it is cleared by copying into the newly freed block,
which is pushed onto the free chain.
If allocation would cause underflow,
the array is replenished from the next block on the chain.
.TP
.B s_bfree
a bit array specifying the free blocks of a 4K file system.
The bit
.LR (s_bfree[i/w]>>(i%w))&1 ,
where
.I w
is the bit size of a long,
is nonzero if the
.IR i th
data block is free. If the file system is too large for the bitmap
to fit here, then it is stored at the end of the file system, and
locked into memory when the file system is mounted. The
.B N
variant of the union is used by the kernel in this case.
.TP
.B s_valid
The bitmap of a mounted file system is maintained only in main memory;
the bitmap on the medium is marked invalid by setting
.L s_valid
to zero.
Unmounting
updates the medium copy and sets
.L s_valid
to 1.
A file system with invalid bitmap may be mounted
read-only; its bitmap can be corrected by
.IR fsck (8)
or
.IR chuck (8).
.TP
.B s_inode
Array of free inode numbers.
.TP
.B s_ninode
The number of free i-numbers in the
.L s_inode
array.
Inodes are placed in the list in LIFO order.
If the list underflows, it is replenished by
searching the i-list
to obtain the numbers of free inodes.
When the list is full,
freed inodes are not recorded in
.LR s_inode .
.TP
.B s_lasti
Where the last search for free inodes ended.
.TP
.B s_nbehind
Number of free inodes before
.L s_lasti
that are not listed in
.LR s_inode .
The system will search forward for free inodes from
.L s_lasti
for more inodes unless
.L s_nbehind
is sufficiently large, in which case it will search the
i-list from the beginning.
.TP
.B s_flock
.br
.ns
.TP
.B s_ilock
Flags maintained in the core
copy of the file system
while it is mounted.
The values on disk are immaterial.
.TP
.B s_fmod
Flag to indicate that the super-block has
changed and should be copied to
the disk during the next periodic update of file
system information.
The value on disk is immaterial.
.TP
.B s_ronly
Flag for read-only file system.
The value on disk is immaterial.
.TP
.B s_time
Time of the last change to the super block.
.TP
.B s_dinfo
Disk interleave information:
.BR s_cylsize =
blocks per cylinder,
.BR s_aspace =
blocks to skip; see
.IR fsck (8).
.TP
.B s_fsmnt
Name of the file on which this file system is mounted; see
.IR fmount (2). (This field is no longer used.)
.TP
.B s_tfree
.br
.ns
.TP
.B s_tinode
Numbers of free blocks and free inodes.
Maintained for the benefit of
.IR df (1),
these values are otherwise irrelevant.
.PD
.PP
I-numbers begin at 1, and the storage for inodes
begins in block 2.
I-nodes are 128 bytes long; the first 64 bytes hold a security label.
I-node 2 is reserved for the root directory of the file
system, but no other i-number has a built-in
meaning.
Each inode represents one file.
.PP
The layout of an inode is defined in
.LR <sys/ino.h> :
.PP
.EX
struct dinode {
struct label di_label;
unsigned short di_mode;
short di_nlink;
short di_uid;
short di_gid;
off_t di_size;
char di_addr[40];
time_t di_atime;
time_t di_mtime;
time_t di_ctime;
};
.EE
.TF di_nlink
.TP
.B di_label
Security label; see
.IR getflab (2).
.TP
.B di_mode
The kind of file; it
is encoded as
.L st_mode field of
.IR stat (2),
and is 0 for a free inode.
.PD
.TP
.B di_nlink
The number of directory entries
(links) that refer to this inode
.TP
.B di_uid
Owner's userid.
.TP
.B di_gid
Owner's groupid.
.TP
.B size
Number of bytes in the file.
.TP
.B di_atime
Time of last access; see
.IR times (2).
.TP
.B di_mtime
Time of last modification.
.TP
.B di_ctime
Time of last change to inode or contents.
.TP
.B di_addr
For special files
.L di_addr
is the device code; see
.IR types (5).
The device codes
of block and character special files overlap.
.PD
.IP
For plain files and directories
.L di_addr
contains block numbers packed into 3 bytes each.
The first 10 numbers specify device blocks directly.
The last 3 are singly, doubly, and triply
indirect and point to blocks of 256 block pointers of type
.L daddr_t
(see
.IR types (5)).
A zero pointer indicates a `hole'
where no data has been written.
Holes read as if they contained all zeroes.
.PP
A symbolic link is, aside from mode,
a plain file whose sole content is the name of the file linked to.
.SH "SEE ALSO"
.IR chuck (8),
.IR fsck (8),
.IR icheck (8),
.IR dir (5),
.IR mount (8),
.IR stat (2),
.IR types (5),
.IR l3tol (3)
|