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

📄 fs.h

📁 FSD file system driver
💻 H
📖 第 1 页 / 共 2 页
字号:
#define fs_old_csshift	fs_spare1[1]

#define FS_42POSTBLFMT		-1	/* 4.2BSD rotational table format */
#define FS_DYNAMICPOSTBLFMT	1	/* dynamic rotational table format */

#define	old_fs_postbl(fs_, cylno, opostblsave) \
    ((((fs_)->fs_old_postblformat == FS_42POSTBLFMT) || \
     ((fs_)->fs_old_postbloff == offsetof(struct fs, fs_old_postbl_start))) \
    ? ((int16_t *)(opostblsave) + (cylno) * (fs_)->fs_old_nrpos) \
    : ((int16_t *)((uint8_t *)(fs_) + \
	(fs_)->fs_old_postbloff) + (cylno) * (fs_)->fs_old_nrpos))
#define	old_fs_rotbl(fs) \
    (((fs)->fs_old_postblformat == FS_42POSTBLFMT) \
    ? ((uint8_t *)(&(fs)->fs_magic+1)) \
    : ((uint8_t *)((uint8_t *)(fs) + (fs)->fs_old_rotbloff)))

/*
 * File system identification
 */
#define	FS_UFS1_MAGIC	0x011954	/* UFS1 fast file system magic number */
#define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast file system magic number */
#define FS_UFS1_MAGIC_SWAPPED	0x54190100
#define FS_UFS2_MAGIC_SWAPPED	0x19015419
#define	FS_OKAY		0x7c269d38	/* superblock checksum */
#define	FS_42INODEFMT	-1		/* 4.2BSD inode format */
#define	FS_44INODEFMT	2		/* 4.4BSD inode format */

/*
 * File system clean flags
 */
#define	FS_ISCLEAN	0x01
#define	FS_WASCLEAN	0x02

/*
 * Preference for optimization.
 */
#define	FS_OPTTIME	0	/* minimize allocation time */
#define	FS_OPTSPACE	1	/* minimize disk fragmentation */

/*
 * File system flags
 */
#define	FS_UNCLEAN	0x01	/* file system not clean at mount (unused) */
#define	FS_DOSOFTDEP	0x02	/* file system using soft dependencies */
#define FS_NEEDSFSCK	0x04	/* needs sync fsck (FreeBSD compat, unused) */
#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 */

/*
 * File system internal flags, also in fs_flags.
 * (Pick highest number to avoid conflicts with others)
 */
#define	FS_SWAPPED	0x80000000	/* file system is endian swapped */
#define	FS_INTERNAL	0x80000000	/* mask for internal flags */

/*
 * 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_IF(fs, ipg, fpg) \
    /* base cg */	(sizeof(struct cg) + sizeof(int32_t) + \
    /* old btotoff */	(fs)->fs_old_cpg * sizeof(int32_t) + \
    /* old boff */	(fs)->fs_old_cpg * sizeof(u_int16_t) + \
    /* inode map */	howmany((ipg), NBBY) + \
    /* block map */	howmany((fpg), NBBY) +\
    /* if present */	((fs)->fs_contigsumsize <= 0 ? 0 : \
    /* cluster sum */	(fs)->fs_contigsumsize * sizeof(int32_t) + \
    /* cluster map */	howmany(fragstoblks(fs, (fpg)), NBBY)))

#define	CGSIZE(fs) CGSIZE_IF((fs), (fs)->fs_ipg, (fs)->fs_fpg)

/*
 * 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 file system.
 */
#define	CG_MAGIC	0x090255
struct 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;		/* (u_int16) free block positions */
	int32_t	 cg_iusedoff;		/* (u_int8) used inode map */
	int32_t	 cg_freeoff;		/* (u_int8) free block map */
	int32_t	 cg_nextfreeoff;	/* (u_int8) next available space */
	int32_t	 cg_clustersumoff;	/* (u_int32) counts of avail clusters */
	int32_t	 cg_clusteroff;		/* (u_int8) 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 */
	int64_t  cg_time;		/* time last written */
	int64_t  cg_sparecon64[3];	/* reserved for future use */
	u_int8_t cg_space[1];		/* space for cylinder group maps */
/* actually longer */
};

/*
 * The following structure is defined
 * for compatibility with old file systems.
 */
struct ocg {
	int32_t  cg_firstfield;		/* historic linked list of cyl groups */
	int32_t  cg_unused_1;		/*     used for incore cyl groups */
	int32_t  cg_time;		/* time last written */
	int32_t  cg_cgx;		/* we are the cgx'th cylinder group */
	int16_t  cg_ncyl;		/* number of cyl's this cg */
	int16_t  cg_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[8];		/* counts of available frags */
	int32_t  cg_btot[32];		/* block totals per cylinder */
	int16_t  cg_b[32][8];		/* positions of free blocks */
	u_int8_t cg_iused[256];		/* used inode map */
	int32_t  cg_magic;		/* magic number */
	u_int8_t cg_free[1];		/* free block map */
/* actually longer */
};


/*
 * Macros for access to cylinder group array structures.
 */
#define old_cg_blktot_old(cgp, ns) \
    (((struct ocg *)(cgp))->cg_btot)
#define old_cg_blks_old(fs, cgp, cylno, ns) \
    (((struct ocg *)(cgp))->cg_b[cylno])

#define old_cg_blktot_new(cgp, ns) \
    ((int32_t *)((u_int8_t *)(cgp) + \
	ufs_rw32((cgp)->cg_old_btotoff, (ns))))
#define old_cg_blks_new(fs, cgp, cylno, ns) \
    ((int16_t *)((u_int8_t *)(cgp) + \
	ufs_rw32((cgp)->cg_old_boff, (ns))) + (cylno) * (fs)->fs_old_nrpos)

#define old_cg_blktot(cgp, ns) \
    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
      old_cg_blktot_old(cgp, ns) : old_cg_blktot_new(cgp, ns))
#define old_cg_blks(fs, cgp, cylno, ns) \
    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
      old_cg_blks_old(fs, cgp, cylno, ns) : old_cg_blks_new(fs, cgp, cylno, ns))

#define	cg_inosused_new(cgp, ns) \
    ((u_int8_t *)((u_int8_t *)(cgp) + \
	ufs_rw32((cgp)->cg_iusedoff, (ns))))
#define	cg_blksfree_new(cgp, ns) \
    ((u_int8_t *)((u_int8_t *)(cgp) + \
	ufs_rw32((cgp)->cg_freeoff, (ns))))
#define	cg_chkmagic_new(cgp, ns) \
    (ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC)

#define cg_inosused_old(cgp, ns) \
    (((struct ocg *)(cgp))->cg_iused)
#define cg_blksfree_old(cgp, ns) \
    (((struct ocg *)(cgp))->cg_free)
#define cg_chkmagic_old(cgp, ns) \
    (ufs_rw32(((struct ocg *)(cgp))->cg_magic, (ns)) == CG_MAGIC)

#define cg_inosused(cgp, ns) \
    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
      cg_inosused_old(cgp, ns) : cg_inosused_new(cgp, ns))
#define cg_blksfree(cgp, ns) \
    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
      cg_blksfree_old(cgp, ns) : cg_blksfree_new(cgp, ns))
#define cg_chkmagic(cgp, ns) \
    (cg_chkmagic_new(cgp, ns) || cg_chkmagic_old(cgp, ns))

#define	cg_clustersfree(cgp, ns) \
    ((u_int8_t *)((u_int8_t *)(cgp) + \
	ufs_rw32((cgp)->cg_clusteroff, (ns))))
#define	cg_clustersum(cgp, ns) \
    ((int32_t *)((u_int8_t *)(cgp) + \
	ufs_rw32((cgp)->cg_clustersumoff, (ns))))
    

/*
 * Turn file system block numbers into disk block addresses.
 * This maps file system 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 file system addresses of cylinder group data structures.
 */
#define	cgbase(fs, c)	(((daddr_t)(fs)->fs_fpg) * (c))
#define	cgstart_ufs1(fs, c) \
    (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask)))
#define	cgstart_ufs2(fs, c) cgbase((fs), (c))
#define	cgstart(fs, c) ((fs)->fs_magic == FS_UFS2_MAGIC \
			    ? cgstart_ufs2((fs), (c)) : cgstart_ufs1((fs), (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 */

/*
 * Macros for handling inode numbers:
 *     inode number to file system block offset.
 *     inode number to cylinder group number.
 *     inode number to file system block address.
 */
#define	ino_to_cg(fs, x)	((x) / (fs)->fs_ipg)
#define	ino_to_fsba(fs, x)						\
	((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 file system block.
 * Give cylinder group block number for a file system 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)))
#define	old_cbtocylno(fs, bno) \
    (fsbtodb(fs, bno) / (fs)->fs_old_spc)
#define	old_cbtorpos(fs, bno) \
    ((fs)->fs_old_nrpos <= 1 ? 0 : \
     (fsbtodb(fs, bno) % (fs)->fs_old_spc / (fs)->fs_old_nsect * (fs)->fs_old_trackskew + \
      fsbtodb(fs, bno) % (fs)->fs_old_spc % (fs)->fs_old_nsect * (fs)->fs_old_interleave) % \
     (fs)->fs_old_nsect * (fs)->fs_old_nrpos / (fs)->fs_old_npsect)

/*
 * 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)
#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 file system.
 */
#define	blksize(fs, ip, lbn) \
	(((lbn) >= NDADDR || (ip)->i_size >= lblktosize(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 file system block.
 */
#define	NINDIR(fs)	((fs)->fs_nindir)

/*
 * Apple UFS Label:
 *  We check for this to decide to use APPLEUFS_DIRBLKSIZ
 */
#define APPLEUFS_LABEL_MAGIC		0x4c41424c /* LABL */
#define APPLEUFS_LABEL_SIZE		1024
#define APPLEUFS_LABEL_OFFSET	(BBSIZE - APPLEUFS_LABEL_SIZE) /* located at 7k */
#define APPLEUFS_LABEL_VERSION	1
#define APPLEUFS_MAX_LABEL_NAME	512

#if 0
struct appleufslabel {
	u_int32_t	ul_magic;
	u_int16_t	ul_checksum;
	u_int16_t	ul_unused0;
	u_int32_t	ul_version;
	u_int32_t	ul_time;
	u_int16_t	ul_namelen;
	u_char	ul_name[APPLEUFS_MAX_LABEL_NAME]; /* Warning: may not be null terminated */
	u_int16_t	ul_unused1;
	u_int64_t	ul_uuid;	/* Note this is only 4 byte aligned */
	u_char	ul_reserved[24];
	u_char	ul_unused[460];
} __attribute__((__packed__));
#endif


#endif /* !_UFS_FFS_FS_H_ */

⌨️ 快捷键说明

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