ufs_fs.h

来自「BIOS Open Platform!」· C头文件 代码 · 共 636 行 · 第 1/2 页

H
636
字号
	void 	*fs_ocsp[NOCSPTRS];	/* padding; was list of fs_cs buffers */	uint8_t *fs_contigdirs;	/* # of contiguously allocated dirs */	struct	csum *fs_csp;		/* cg summary info buffer for fs_cs */	int32_t	*fs_maxcluster;		/* max cluster in each cyl group */	unsigned int *fs_active;	/* used by snapshots to track fs */	int32_t	 fs_old_cpc;		/* cyl per cycle in postbl */	int32_t	 fs_maxbsize;		/* maximum blocking factor permitted */	int64_t	 fs_sparecon64[17];	/* old rotation block list head */	int64_t	 fs_sblockloc;		/* byte offset of standard superblock */	struct	csum_total fs_cstotal;	/* cylinder summary information */	ufs_time_t fs_time;		/* last time written */	int64_t	 fs_size;		/* number of blocks in fs */	int64_t	 fs_dsize;		/* number of data blocks in fs */	ufs2_daddr_t fs_csaddr;		/* blk addr of cyl grp summary area */	int64_t	 fs_pendingblocks;	/* blocks in process of being freed */	int32_t	 fs_pendinginodes;	/* inodes in process of being freed */	int32_t	 fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */	int32_t	 fs_avgfilesize;	/* expected average file size */	int32_t	 fs_avgfpdir;		/* expected # of files per directory */	int32_t	 fs_save_cgsize;	/* save real cg size to use fs_bsize */	int32_t	 fs_sparecon32[26];	/* reserved for future constants */	int32_t  fs_flags;		/* see FS_ flags below */	int32_t	 fs_contigsumsize;	/* size of cluster summary array */ 	int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */	int32_t	 fs_old_inodefmt;	/* format of on-disk inodes */	uint64_t fs_maxfilesize;	/* maximum representable file size */	int64_t	 fs_qbmask;		/* ~fs_bmask for use with 64-bit size */	int64_t	 fs_qfmask;		/* ~fs_fmask for use with 64-bit size */	int32_t	 fs_state;		/* validate fs_clean field */	int32_t	 fs_old_postblformat;	/* format of positional layout tables */	int32_t	 fs_old_nrpos;		/* number of rotational positions */	int32_t	 fs_spare5[2];		/* old fs_postbloff */					/* old fs_rotbloff */	int32_t	 fs_magic;		/* magic number */};/* Sanity checking. */#ifdef CTASSERTCTASSERT(sizeof(struct fs) == 1376);#endif/* * Filesystem identification */#define	FS_UFS1_MAGIC	0x011954	/* UFS1 fast filesystem magic number */#define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast filesystem magic number */#define	FS_BAD_MAGIC	0x19960408	/* UFS incomplete newfs magic number */#define	FS_OKAY		0x7c269d38	/* superblock checksum */#define FS_42INODEFMT	-1		/* 4.2BSD inode format */#define FS_44INODEFMT	2		/* 4.4BSD inode format *//* * Preference for optimization. */#define FS_OPTTIME	0	/* minimize allocation time */#define FS_OPTSPACE	1	/* minimize disk fragmentation *//* * Filesystem flags. * * The FS_UNCLEAN flag is set by the kernel when the filesystem was * mounted with fs_clean set to zero. The FS_DOSOFTDEP flag indicates * that the filesystem should be managed by the soft updates code. * Note that the FS_NEEDSFSCK flag is set and cleared only by the * fsck utility. It is set when background fsck finds an unexpected * inconsistency which requires a traditional foreground fsck to be * run. Such inconsistencies should only be found after an uncorrectable * disk error. A foreground fsck will clear the FS_NEEDSFSCK flag when * it has successfully cleaned up the filesystem. The kernel uses this * flag to enforce that inconsistent filesystems be mounted read-only. * The FS_INDEXDIRS flag when set indicates that the kernel maintains * on-disk auxiliary indexes (such as B-trees) for speeding directory * accesses. Kernels that do not support auxiliary indicies clear the * flag to indicate that the indicies need to be rebuilt (by fsck) before * they can be used. * * FS_ACLS indicates that ACLs are administratively enabled for the * file system, so they should be loaded from extended attributes, * observed for access control purposes, and be administered by object * owners.  FS_MULTILABEL indicates that the TrustedBSD MAC Framework * should attempt to back MAC labels into extended attributes on the * file system rather than maintain a single mount label for all * objects. */#define FS_UNCLEAN    0x01	/* filesystem not clean at mount */#define FS_DOSOFTDEP  0x02	/* filesystem using soft dependencies */#define FS_NEEDSFSCK  0x04	/* filesystem needs sync fsck before mount */#define FS_INDEXDIRS  0x08	/* kernel supports indexed directories */#define FS_ACLS       0x10	/* file system has ACLs enabled */#define FS_MULTILABEL 0x20	/* file system is MAC multi-label */#define FS_FLAGS_UPDATED 0x80	/* flags have been moved to new location *//* * Macros to access bits in the fs_active array. */#define	ACTIVECGNUM(fs, cg)	((fs)->fs_active[(cg) / (NBBY * sizeof(int))])#define	ACTIVECGOFF(cg)		(1 << ((cg) % (NBBY * sizeof(int))))/* * The size of a cylinder group is calculated by CGSIZE. The maximum size * is limited by the fact that cylinder groups are at most one block. * Its size is derived from the size of the maps maintained in the * cylinder group and the (struct cg) size. */#define CGSIZE(fs) \    /* base cg */	(sizeof(struct cg) + sizeof(int32_t) + \    /* old btotoff */	(fs)->fs_old_cpg * sizeof(int32_t) + \    /* old boff */	(fs)->fs_old_cpg * sizeof(uint16_t) + \    /* inode map */	howmany((fs)->fs_ipg, NBBY) + \    /* block map */	howmany((fs)->fs_fpg, NBBY) +\    /* if present */	((fs)->fs_contigsumsize <= 0 ? 0 : \    /* cluster sum */	(fs)->fs_contigsumsize * sizeof(int32_t) + \    /* cluster map */	howmany(fragstoblks(fs, (fs)->fs_fpg), NBBY)))/* * The minimal number of cylinder groups that should be created. */#define MINCYLGRPS	4/* * Convert cylinder group to base address of its global summary info. */#define fs_cs(fs, indx) fs_csp[indx]/* * Cylinder group block for a filesystem. */#define	CG_MAGIC	0x090255struct cg {	int32_t	 cg_firstfield;		/* historic cyl groups linked list */	int32_t	 cg_magic;		/* magic number */	int32_t  cg_old_time;		/* time last written */	int32_t	 cg_cgx;		/* we are the cgx'th cylinder group */	int16_t	 cg_old_ncyl;		/* number of cyl's this cg */	int16_t  cg_old_niblk;		/* number of inode blocks this cg */	int32_t	 cg_ndblk;		/* number of data blocks this cg */	struct	csum cg_cs;		/* cylinder summary information */	int32_t	 cg_rotor;		/* position of last used block */	int32_t	 cg_frotor;		/* position of last used frag */	int32_t	 cg_irotor;		/* position of last used inode */	int32_t	 cg_frsum[MAXFRAG];	/* counts of available frags */	int32_t	 cg_old_btotoff;	/* (int32) block totals per cylinder */	int32_t	 cg_old_boff;		/* (uint16) free block positions */	int32_t	 cg_iusedoff;		/* (uint8) used inode map */	int32_t	 cg_freeoff;		/* (uint8) free block map */	int32_t	 cg_nextfreeoff;	/* (uint8) next available space */	int32_t	 cg_clustersumoff;	/* (uint32) counts of avail clusters */	int32_t	 cg_clusteroff;		/* (uint8) free cluster map */	int32_t	 cg_nclusterblks;	/* number of clusters this cg */	int32_t  cg_niblk;		/* number of inode blocks this cg */	int32_t	 cg_initediblk;		/* last initialized inode */	int32_t	 cg_sparecon32[3];	/* reserved for future use */	ufs_time_t cg_time;		/* time last written */	int64_t	 cg_sparecon64[3];	/* reserved for future use */	uint8_t cg_space[1];		/* space for cylinder group maps *//* actually longer */};/* * Macros for access to cylinder group array structures */#define cg_chkmagic(cgp) ((cgp)->cg_magic == CG_MAGIC)#define cg_inosused(cgp) \    ((uint8_t *)((uint8_t *)(cgp) + (cgp)->cg_iusedoff))#define cg_blksfree(cgp) \    ((uint8_t *)((uint8_t *)(cgp) + (cgp)->cg_freeoff))#define cg_clustersfree(cgp) \    ((uint8_t *)((uint8_t *)(cgp) + (cgp)->cg_clusteroff))#define cg_clustersum(cgp) \    ((int32_t *)((uintptr_t)(cgp) + (cgp)->cg_clustersumoff))/* * Turn filesystem block numbers into disk block addresses. * This maps filesystem blocks to device size blocks. */#define fsbtodb(fs, b)	((b) << (fs)->fs_fsbtodb)#define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)/* * Cylinder group macros to locate things in cylinder groups. * They calc filesystem addresses of cylinder group data structures. */#define	cgbase(fs, c)	(((ufs2_daddr_t)(fs)->fs_fpg) * (c))#define	cgdmin(fs, c)	(cgstart(fs, c) + (fs)->fs_dblkno)	/* 1st data */#define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno)	/* inode blk */#define	cgsblock(fs, c)	(cgstart(fs, c) + (fs)->fs_sblkno)	/* super blk */#define	cgtod(fs, c)	(cgstart(fs, c) + (fs)->fs_cblkno)	/* cg block */#define cgstart(fs, c)							\       ((fs)->fs_magic == FS_UFS2_MAGIC ? cgbase(fs, c) :		\       (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask))))/* * Macros for handling inode numbers: *     inode number to filesystem block offset. *     inode number to cylinder group number. *     inode number to filesystem block address. */#define	ino_to_cg(fs, x)	((x) / (fs)->fs_ipg)#define	ino_to_fsba(fs, x)						\	((ufs2_daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +			\	    (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))#define	ino_to_fsbo(fs, x)	((x) % INOPB(fs))/* * Give cylinder group number for a filesystem block. * Give cylinder group block number for a filesystem block. */#define	dtog(fs, d)	((d) / (fs)->fs_fpg)#define	dtogd(fs, d)	((d) % (fs)->fs_fpg)/* * Extract the bits for a block from a map. * Compute the cylinder and rotational position of a cyl block addr. */#define blkmap(fs, map, loc) \    (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))/* * The following macros optimize certain frequently calculated * quantities by using shifts and masks in place of divisions * modulos and multiplications. */#define blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \	((loc) & (fs)->fs_qbmask)#define fragoff(fs, loc)	/* calculates (loc % fs->fs_fsize) */ \	((loc) & (fs)->fs_qfmask)#define lfragtosize(fs, frag)	/* calculates ((off_t)frag * fs->fs_fsize) */ \	(((off_t)(frag)) << (fs)->fs_fshift)#define lblktosize(fs, blk)	/* calculates ((off_t)blk * fs->fs_bsize) */ \	(((off_t)(blk)) << (fs)->fs_bshift)/* Use this only when `blk' is known to be small, e.g., < NDADDR. */#define smalllblktosize(fs, blk)    /* calculates (blk * fs->fs_bsize) */ \	((blk) << (fs)->fs_bshift)#define lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \	((loc) >> (fs)->fs_bshift)#define numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \	((loc) >> (fs)->fs_fshift)#define blkroundup(fs, size)	/* calculates roundup(size, fs->fs_bsize) */ \	(((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)#define fragroundup(fs, size)	/* calculates roundup(size, fs->fs_fsize) */ \	(((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)#define fragstoblks(fs, frags)	/* calculates (frags / fs->fs_frag) */ \	((frags) >> (fs)->fs_fragshift)#define blkstofrags(fs, blks)	/* calculates (blks * fs->fs_frag) */ \	((blks) << (fs)->fs_fragshift)#define fragnum(fs, fsb)	/* calculates (fsb % fs->fs_frag) */ \	((fsb) & ((fs)->fs_frag - 1))#define blknum(fs, fsb)		/* calculates rounddown(fsb, fs->fs_frag) */ \	((fsb) &~ ((fs)->fs_frag - 1))/* * Determine the number of available frags given a * percentage to hold in reserve. */#define freespace(fs, percentreserved) \	(blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \	(fs)->fs_cstotal.cs_nffree - \	(((off_t)((fs)->fs_dsize)) * (percentreserved) / 100))/* * Determining the size of a file block in the filesystem. */#define blksize(fs, ip, lbn) \	(((lbn) >= NDADDR || (ip)->i_size >= smalllblktosize(fs, (lbn) + 1)) \	    ? (fs)->fs_bsize \	    : (fragroundup(fs, blkoff(fs, (ip)->i_size))))#define sblksize(fs, size, lbn) \	(((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \	  ? (fs)->fs_bsize \	  : (fragroundup(fs, blkoff(fs, (size)))))/* * Number of inodes in a secondary storage block/fragment. */#define	INOPB(fs)	((fs)->fs_inopb)#define	INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)/* * Number of indirects in a filesystem block. */#define	NINDIR(fs)	((fs)->fs_nindir)extern int inside[], around[];extern char *fragtbl[];struct ufs_dirent {	uint32_t d_fileno;		/* file number of entry */	uint16_t d_reclen;		/* length of this record */	uint8_t  d_type; 		/* file type, see below */	uint8_t  d_namlen;		/* length of string in d_name */#define	MAXNAMLEN	255	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */};/* * File types */#define	DT_UNKNOWN	 0#define	DT_FIFO		 1#define	DT_CHR		 2#define	DT_DIR		 4#define	DT_BLK		 6#define	DT_REG		 8#define	DT_LNK		10#define	DT_SOCK		12#define	DT_WHT		14/* XXX: We hardcode BSIZE and BSIZE_SHIFT here. fsys_ffs seems to do the same, *      so we should get away with it :-) */#define DEV_BSIZE	512#define DEV_BSHIFT 	9		/* 2**9 = 512 */#define MAXBSIZE	8192typedef unsigned int ino_t;#endif

⌨️ 快捷键说明

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