15. 4.2BSD h/dir.h
35 structdirect {
36 u_long d_ino; /* inode number of entry */
37 u_short d_reclen; /* length of this record */
38 u_short d_namlen; /* length of string in d_name */
39 char d_name[MAXNAMLEN + 1];/* name must be no longer than this */
40 };
ad_ino
32bit
d_reclen d_namlen
16bit 16bit
. o
d_reclen
d_namlen
u t ・・・・・・
13/6/15 10時49分 15
32. 4.2bsd/h/fs.h
/*
230 * Cylinder group block for a file system.
231 */
232 #define CG_MAGIC 0x090255
233 struct cg {
234 struct cg *cg_link; /* linked list of cyl groups */
235 struct cg *cg_rlink; /* used for incore cyl groups */
236 time_t cg_time; /* time last written */
237 long cg_cgx; /* we are the cgx'th cylinder group */
238 short cg_ncyl; /* number of cyl's this cg */
239 short cg_niblk; /* number of inode blocks this cg */
240 long cg_ndblk; /* number of data blocks this cg */
241 struct csum cg_cs; /* cylinder summary information */
242 long cg_rotor; /* position of last used block */
243 long cg_frotor; /* position of last used frag */
244 long cg_irotor; /* position of last used inode */
245 long cg_frsum[MAXFRAG]; /* counts of available frags */
246 long cg_btot[MAXCPG]; /* block totals per cylinder */
247 short cg_b[MAXCPG][NRPOS]; /* positions of free blocks */
248 char cg_iused[MAXIPG/NBBY]; /* used inode map */
249 long cg_magic; /* magic number */
250 u_char cg_free[1]; /* free block map */
251 /* actually longer */
252 };
13/6/15 10時49分 32
33. 4.2bsd/h/fs.h
129 /*
130 * Super block for a file system.
131 */
132 #define FS_MAGIC 0x011954
133 struct fs
134 {
135 struct fs *fs_link; /* linked list of file systems */
136 struct fs *fs_rlink; /* used for incore super blocks */
137 daddr_t fs_sblkno; /* addr of super-block in filesys */
138 daddr_t fs_cblkno; /* offset of cyl-block in filesys */
139 daddr_t fs_iblkno; /* offset of inode-blocks in filesys */
140 daddr_t fs_dblkno; /* offset of first data after cg */
141 long fs_cgoffset; /* cylinder group offset in cylinder */
142 long fs_cgmask; /* used to calc mod fs_ntrak */
143 time_t fs_time; /* last time written */
144 long fs_size; /* number of blocks in fs */
145 long fs_dsize; /* number of data blocks in fs */
146 long fs_ncg; /* number of cylinder groups */
147 long fs_bsize; /* size of basic blocks in fs */
148 long fs_fsize; /* size of frag blocks in fs */
149 long fs_frag; /* number of frags in a block in fs */
150 /* these are configuration parameters */
154 /* these fields can be computed from the others */
159 /* these are configuration parameters */
162 /* these fields can be computed from the others */
173 /* sizes determined by number of cylinder groups and their sizes */
177 /* these fields should be derived from the hardware */
181 /* this comes from the disk driver partitioning */
183 /* these fields can be computed from the others */
187 /* this data must be re-computed after crashes */
189 /* these fields are cleared at mount time */
195 /* these fields retain the current block allocation info */
202 /* actually longer */
203 };
13/6/15 10時49分 33
35. Data
Inode
Cylinder group
FS FFS
data blocks
Inode blocks
Struct inode[]
Super block
Boot block
Super block
Boot block
Cylinder group
Data
Inode
Cylinder group
FreeListは
bitmap管理
13/6/15 10時49分 35
36. h/inode.h
14 struct inode {
15 struct inode *i_chain[2]; /* must be first */
16 u_short i_flag;
17 u_short i_count; /* reference count */
18 dev_t i_dev; /* device where inode resides */
19 u_short i_shlockc; /* count of shared locks on inode */
20 u_short i_exlockc; /* count of exclusive locks on inode */
21 ino_t i_number; /* i number, 1-to-1 with device address */
22 struct fs *i_fs; /* file sys associated with this inode */
23 struct dquot *i_dquot; /* quota structure controlling this file */
24 union {
25 daddr_t if_lastr; /* last read (read-ahead) */
26 struct socket *is_socket;
27 struct {
28 struct inode *if_freef; /* free list forward */
29 struct inode **if_freeb; /* free list back */
30 } i_fr;
31 } i_un;
32 struct icommon
33 {
34 u_short ic_mode; /* 0: mode and type of file */
35 short ic_nlink; /* 2: number of links to file */
36 short ic_uid; /* 4: owner's user id */
37 short ic_gid; /* 6: owner's group id */
38 quad ic_size; /* 8: number of bytes in file */
39 time_t ic_atime; /* 16: time last accessed */
40 long ic_atspare;
41 time_t ic_mtime; /* 24: time last modified */
42 long ic_mtspare;
43 time_t ic_ctime; /* 32: last time inode changed */
44 long ic_ctspare;
45 daddr_t ic_db[NDADDR]; /* 40: disk block addresses */
46 daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */
47 long ic_flags; /* 100: status, currently unused */
48 long ic_blocks; /* 104: blocks actually held */
49 long ic_spare[5]; /* 108: reserved, currently unused */
50 } i_ic;
51 };
52
53 struct dinode {
54 union {
55 struct icommon di_icom;
56 char di_size[128];
57 } di_un;
58 };
inode
icommon
struct dinode =
struct icommon
13/6/15 10時49分 36
37. Disk inode FSとFFSの違い
FSのdisk inode
5605 struct inode
5606 {
5607 int i_mode;
5608 char i_nlink;
5609 char i_uid;
5610 char i_gid;
5611 char i_size0;
5612 char *i_size1;
5613 int i_addr[8];
5614 int i_atime[2];
5615 int i_mtime[2];
5616 };
FFSのdisk inode
32 struct icommon
33 {
34 u_short ic_mode; /* 0: mode and type of file */
35 short ic_nlink; /* 2: number of links to file */
36 short ic_uid; /* 4: owner's user id */
37 short ic_gid; /* 6: owner's group id */
38 quad ic_size; /* 8: number of bytes in file */
39 time_t ic_atime; /* 16: time last accessed */
40 long ic_atspare;
41 time_t ic_mtime; /* 24: time last modified */
42 long ic_mtspare;
43 time_t ic_ctime; /* 32: last time inode changed */
44 long ic_ctspare;
45 daddr_t ic_db[NDADDR]; /* 40: disk block addresses */
46 daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */
47 long ic_flags; /* 100: status, currently unused */
48 long ic_blocks; /* 104: blocks actually held */
49 long ic_spare[5]; /* 108: reserved, currently unused */
50 } i_ic;
13/6/15 10時49分 37