⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fs.5

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻 5
字号:
.th "FILE SYSTEM" V 2/9/75.sh NAMEfs \*- format of file system volume.sh DESCRIPTIONEveryfile system storage volume(e.g. RF disk, RK disk, RP disk, DECtape reel)has a common format for certain vital information.Every such volume is divided into a certain numberof 256 word (512 byte) blocks.Block 0 is unused and is available to containa bootstrap program, pack label, or other information..s3Block 1 is the.it "super block."Starting from its first word, the format of a super-block is.s3.nfstruct {	int	isize;	int	fsize;	int	nfree;	int	free[100];	int	ninode;	int	inode[100];	char	flock;	char	ilock;	char	fmod;	int	time[2];};.s3.fi.it Isizeis the number of blocks devoted to the i-list,which starts just after the super-block, in block 2..it Fsizeis the first block not potentially available for allocationto a file.These numbers are used by the system tocheck for bad block numbers;if an ``impossible'' block number is allocated from the free listor is freed,a diagnostic is written on the on-line console.Moreover, the free array is cleared, so as to prevent furtherallocation from a presumably corrupted free list..s3The free list for each volume is maintained asfollows.The.it freearray contains, in.it "free[1], ... , free[nfree\*-1],"up to 99 numbers of free blocks..it Free[0]is the block number of the headof a chain of blocks constituting the free list.The first word in each free-chain block is the number(up to 100) of free-block numbers listed in thenext 100 words of this chain member.The first of these 100 blocks is the link to thenext member of the chain.To allocate a block:decrement.it nfree,and the new block is.it free[nfree].If the new block number is 0,there are no blocks left, so give an error.If.it nfreebecame 0,read in the block named by the new block number,replace.it nfreeby its first word,and copy the block numbers in the next 100 words into the.it freearray.To free a block, check if.it nfreeis 100; if so,copy.it nfreeand the.it freearray into it,write it out, and set.it nfreeto 0.In any event set.it free[nfree]to the freed block's number andincrement.it nfree..s3.it Ninodeis the number of free i-numbers in the.it inodearray.To allocate an i-node:if.it ninodeis greater than 0,decrement it and return.it inode[ninode].If it was 0, read the i-listand place the numbers of all free inodes(up to 100) into the.it inodearray,then try again.To free an i-node,provided.it ninodeis less than 100,place its number into.it inode[ninode]and increment.it ninode.If.it ninodeis already 100, don't bother to enter the freed i-node into any table.This list of i-nodes is only to speedup the allocation process; the informationas to whether the inode is really freeor not is maintained in the inode itself..s3.it Flockand.it ilockare flags maintained in the corecopy of the file systemwhile it is mountedand their values on disk are immaterial.The value of.it fmodon disk is likewise immaterial;it is used as a flag to indicate that the super-block haschanged and should be copied tothe disk during the next periodic update of filesystem information..s3.it Timeis the last time the super-block of the file system was changed,and is a double-precision representationof the number of seconds that have elapsedsince0000 Jan. 1 1970 (GMT).During a reboot, the.it timeof the super-block for the root file systemis used to set the system's idea of the time..s3I-numbers begin at 1, and the storage for i-nodesbegins in block 2..tr |Also, i-nodes are 32 bytes long, so 16 of them fit into a block.Therefore, i-node.it iis located in block (\fIi\fR|+|31)|/|16, and begins32\u\fB.\fR\d((\fIi\fR|+|31)|(mod 16) bytes from its start.I-node 1 is reserved for the root directory of the filesystem, but no other i-number has a built-inmeaning.Each i-node represents one file.The format of an i-node is as follows..s3.nf.if t .ta .5i 1.i 2.5istruct {	int	flags;	/* +0: see below */	char	nlinks;	/* +2: number of links to file */	char	uid;	/* +3: user ID of owner */	char	gid;	/* +4: group ID of owner */	char	size0;	/* +5: high byte of 24-bit size */	int	size1;	/* +6: low word of 24-bit size */	int	addr[8];	/* +8: block numbers or device number */	int	actime[2];	/* +24: time of last access */	int	modtime[2];	/* +28: time of last modification */};.dt.fi.s3The flags are as follows:.s3.lp +10 9100000	i-node is allocated.lp +10 9060000	2-bit file type:.lp +15 9000000	plain file.lp +15 9040000	directory.lp +15 9020000	character-type special file.lp +15 9060000	block-type special file..lp +10 9010000	large file.lp +10 9004000	set user-ID on execution.lp +10 9002000	set group-ID on execution.lp +10 9000400	read (owner).lp +10 9000200	write (owner).lp +10 9000100	execute (owner).lp +10 9000070	read, write, execute (group).lp +10 9000007	read, write, execute (others).s3.i0Special files are recognized by their flagsand not by i-number.A block-type special file is basically one whichcan potentially be mounted as a file system;a character-type special file cannot, though it isnot necessarily character-oriented.For special files the high byte of the first address wordspecifies the type of device; the low byte specifiesone of several devices ofthat type.The device type numbersof block and character special files overlap..s3The address words of ordinary files and directoriescontain the numbers of the blocks in thefile (if it is small)or the numbers of indirect blocks (if the fileis large).Byte number.it nof a file is accessed as follows..it Nis divided by 512 to find its logical block number(say.it b)in the file.If the file is small (flag 010000 is 0),then.it bmust be less than 8, and the physicalblock number is.it addr[b]..s3If the file is large,.it bis divided by 256 to yield.it i.If.it iis less than 7, then.it addr[i]is the physical block number ofthe indirect block.The remainder from the division yields the word in the indirect blockwhich contains the number of the block forthe sought-for byte..s3If.it iis equal to 7,then the file has become extra-large (huge),and.it addr[7]is the address of a first indirect block.Each word in this blockis the number of a second-level indirect block;each word in the second-level indirect blocks points to a data block.Notice that extra-large files are not marked by any modebit, but only by having.it addr[7]non-zero;and that although this scheme allows for more than256\*X256\*X512 = 33,554,432 bytes per file,the length of files is stored in 24 bitsso in practice a file can be at most16,777,216 bytes long..s3For block.it bin a file to exist,itis not necessary that all blocks less than.it bexist.A zero block number either in the address words ofthe i-node or in an indirect block indicates that thecorresponding block has never been allocated.Such a missing block reads as if it contained all zero words..sh "SEE ALSO"icheck, dcheck (VIII)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -