1N/A * Mach Operating System 1N/A * Copyright (c) 1991,1990 Carnegie Mellon University 1N/A * All Rights Reserved. 1N/A * Permission to use, copy, modify and distribute this software and its 1N/A * documentation is hereby granted, provided that both the copyright 1N/A * notice and this permission notice appear in all copies of the 1N/A * software, derivative works or modified versions, and any portions 1N/A * thereof, and that both notices appear in supporting documentation. 1N/A * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 1N/A * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 1N/A * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 1N/A * Carnegie Mellon requests users of this software to return to 1N/A * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 1N/A * School of Computer Science 1N/A * Carnegie Mellon University 1N/A * Pittsburgh PA 15213-3890 1N/A * any improvements or extensions that they make and grant Carnegie Mellon 1N/A * the rights to redistribute these changes. 1N/A * Copyright (c) 1982, 1986 Regents of the University of California. 1N/A * All rights reserved. 1N/A * Redistribution and use in source and binary forms are permitted 1N/A * provided that the above copyright notice and this paragraph are 1N/A * duplicated in all such forms and that any documentation, 1N/A * advertising materials, and other materials related to such 1N/A * distribution and use acknowledge that the software was developed 1N/A * by the University of California, Berkeley. The name of the 1N/A * University may not be used to endorse or promote products derived 1N/A * from this software without specific prior written permission. 1N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1N/A * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1N/A * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1N/A * Each disk drive contains some number of file systems. 1N/A * A file system consists of a number of cylinder groups. 1N/A * Each cylinder group has inodes and data. 1N/A * A file system is described by its super-block, which in turn 1N/A * describes the cylinder groups. The super-block is critical 1N/A * data and is replicated in each cylinder group to protect against 1N/A * catastrophic loss. This is done at `newfs' time and the critical 1N/A * super-block data does not change, so the copies need not be 1N/A * referenced further unless disaster strikes. 1N/A * For file system fs, the offsets of the various blocks of interest 1N/A * are given in the super block as: 1N/A * [fs->fs_sblkno] Super-block 1N/A * [fs->fs_cblkno] Cylinder group block 1N/A * [fs->fs_iblkno] Inode blocks 1N/A * [fs->fs_dblkno] Data blocks 1N/A * The beginning of cylinder group cg in fs, is given by 1N/A * the ``cgbase(fs, cg)'' macro. 1N/A * The first boot and super blocks are given in absolute disk addresses. 1N/A * The byte-offset forms are preferred, as they don't imply a sector size. 1N/A * Addresses stored in inodes are capable of addressing fragments 1N/A * of `blocks'. File system blocks of at most size MAXBSIZE can 1N/A * be optionally broken into 2, 4, or 8 pieces, each of which is 1N/A * addressible; these pieces may be DEV_BSIZE, or some multiple of 1N/A * Large files consist of exclusively large data blocks. To avoid 1N/A * undue wasted disk space, the last data block of a small file may be 1N/A * allocated as only as many fragments of a large block as are 1N/A * necessary. The file system format retains only a single pointer 1N/A * to such a fragment, which is a piece of a single large block that 1N/A * has been divided. The size of such a fragment is determinable from 1N/A * information in the inode, using the ``blksize(fs, ip, lbn)'' macro. 1N/A * The file system records space availability at the fragment level; 1N/A * to determine block availability, aligned fragments are examined. 1N/A * The root inode is the root of the file system. 1N/A * Inode 0 can't be used for normal purposes and 1N/A * historically bad blocks were linked to inode 1, 1N/A * thus the root inode is 2. (inode 1 is no longer used for 1N/A * this purpose, however numerous dump tapes make this 1N/A * assumption, so we are stuck with it) 1N/A * MINBSIZE is the smallest allowable block size. 1N/A * In order to insure that it is possible to create files of size 1N/A * 2^32 with only two levels of indirection, MINBSIZE is set to 4096. 1N/A * MINBSIZE must be big enough to hold a cylinder group block, 1N/A * thus changes to (struct cg) must keep its size within MINBSIZE. 1N/A * Note that super blocks are always of size SBSIZE, 1N/A * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. 1N/A * The path name on which the file system is mounted is maintained 1N/A * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 1N/A * the super block for this name. 1N/A * The limit on the amount of summary information per file system 1N/A * is defined by MAXCSBUFS. It is currently parameterized for a 1N/A * maximum of two million cylinders. 1N/A * Per cylinder group information; summarized in blocks allocated 1N/A * from first cylinder group data blocks. These blocks have to be 1N/A * read in from fs_csaddr (size fs_cssize) in addition to the 1N/A * N.B. sizeof(struct csum) must be a power of two in order for 1N/A * the ``fs_cs'' macro to work (see below). 1N/A * Super block for a file system. 1N/A int xxx1;
/* struct fs *fs_link; */ 1N/A int xxx2;
/* struct fs *fs_rlink; */ 1N/A int fs_frag;
/* number of frags in a block in fs */ 1N/A/* these are configuration parameters */ 1N/A int fs_rps;
/* disk revolutions per second */ 1N/A/* these fields can be computed from the others */ 1N/A/* these are configuration parameters */ 1N/A/* these fields can be computed from the others */ 1N/A/* yet another configuration parameter */ 1N/A/* these fields are derived from the hardware */ 1N/A/* sizes determined by number of cylinder groups and their sizes */ 1N/A/* these fields are derived from the hardware */ 1N/A/* this comes from the disk driver partitioning */ 1N/A/* these fields can be computed from the others */ 1N/A/* this data must be re-computed after crashes */ 1N/A/* these fields are cleared at mount time */ 1N/A/* these fields retain the current block allocation info */ 1N/A/* actually longer */ 1N/A * Preference for optimization. 1N/A * Rotational layout table format types 1N/A * Macros for access to superblock array structures 1N/A * Convert cylinder group to base address of its global summary info. 1N/A * N.B. This macro assumes that sizeof(struct csum) is a power of two. 1N/A * Cylinder group block for a file system. 1N/A int xxx1;
/* struct cg *cg_link; */ 1N/A int cg_cgx;
/* we are the cgx'th cylinder group */ 1N/A/* actually longer */ 1N/A * Macros for access to cylinder group array structures 1N/A * The following structure is defined 1N/A * for compatibility with old file systems. 1N/A int xxx1;
/* struct ocg *cg_link; */ 1N/A int xxx2;
/* struct ocg *cg_rlink; */ 1N/A int cg_cgx;
/* we are the cgx'th cylinder group */ 1N/A short cg_b[
32][
8];
/* positions of free blocks */ 1N/A/* actually longer */ 1N/A * Turn file system block numbers into disk block addresses. 1N/A * This maps file system blocks to device size blocks. 1N/A * Cylinder group macros to locate things in cylinder groups. 1N/A * They calc file system addresses of cylinder group data structures. 1N/A * Macros for handling inode numbers: 1N/A * inode number to file system block offset. 1N/A * inode number to cylinder group number. 1N/A * inode number to file system block address. 1N/A * Give cylinder group number for a file system block. 1N/A * Give cylinder group block number for a file system block. 1N/A * Extract the bits for a block from a map. 1N/A * Compute the cylinder and rotational position of a cyl block addr. 1N/A * The following macros optimize certain frequently calculated 1N/A * quantities by using shifts and masks in place of divisions 1N/A * modulos and multiplications. 1N/A * Determine the number of available frags given a 1N/A * percentage to hold in reserve 1N/A * Determining the size of a file block in the file system. 1N/A * Number of disk sectors per block; assumes DEV_BSIZE byte sector size. 1N/A * INOPB is the number of inodes in a secondary storage block. 1N/A * NINDIR is the number of indirects in a file system block.