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

📄 util.h

📁 UnixBSD、SunOs、FreeBSD、NetBSD、OpenBSD和NeXTStep文件系统源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
{	unsigned int index;		index = offset >> uspi->s_fshift;	offset &= ~uspi->s_fmask;	return uspi->s_ubh.bh[index]->b_data + offset;}#define ubh_get_usb_first(uspi) \	((struct ufs_super_block_first *)get_usb_offset((uspi), 0))#define ubh_get_usb_second(uspi) \	((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))#define ubh_get_usb_third(uspi)	\	((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))#define ubh_get_ucg(ubh) \	((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))/* * Extract byte from ufs_buffer_head * Extract the bits for a block from a map inside ufs_buffer_head */#define ubh_get_addr8(ubh,begin) \	((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \	((begin) & ~uspi->s_fmask))#define ubh_get_addr16(ubh,begin) \	(((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \	((begin) & ((uspi->fsize>>1) - 1)))#define ubh_get_addr32(ubh,begin) \	(((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \	((begin) & ((uspi->s_fsize>>2) - 1)))#define ubh_get_addr64(ubh,begin) \	(((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \	((begin) & ((uspi->s_fsize>>3) - 1)))#define ubh_get_addr ubh_get_addr8static inline void *ubh_get_data_ptr(struct ufs_sb_private_info *uspi,				     struct ufs_buffer_head *ubh,				     u64 blk){	if (uspi->fs_magic == UFS2_MAGIC)		return ubh_get_addr64(ubh, blk);	else		return ubh_get_addr32(ubh, blk);}#define ubh_blkmap(ubh,begin,bit) \	((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))/* * Determine the number of available frags given a * percentage to hold in reserve. */static inline u64ufs_freespace(struct ufs_sb_private_info *uspi, int percentreserved){	return ufs_blkstofrags(uspi->cs_total.cs_nbfree) +		uspi->cs_total.cs_nffree -		(uspi->s_dsize * (percentreserved) / 100);}/* * Macros to access cylinder group array structures */#define ubh_cg_blktot(ucpi,cylno) \	(*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))#define ubh_cg_blks(ucpi,cylno,rpos) \	(*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \	(ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))/* * Bitmap operations * These functions work like classical bitmap operations. * The difference is that we don't have the whole bitmap * in one contiguous chunk of memory, but in several buffers. * The parameters of each function are super_block, ufs_buffer_head and * position of the beginning of the bitmap. */#define ubh_setbit(ubh,begin,bit) \	(*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))#define ubh_clrbit(ubh,begin,bit) \	(*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))#define ubh_isset(ubh,begin,bit) \	(*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))#define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))#define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)#define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)static inline unsigned _ubh_find_next_zero_bit_(	struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,	unsigned begin, unsigned size, unsigned offset){	unsigned base, count, pos;	size -= offset;	begin <<= 3;	offset += begin;	base = offset >> uspi->s_bpfshift;	offset &= uspi->s_bpfmask;	for (;;) {		count = min_t(unsigned int, size + offset, uspi->s_bpf);		size -= count - offset;		pos = ext2_find_next_zero_bit (ubh->bh[base]->b_data, count, offset);		if (pos < count || !size)			break;		base++;		offset = 0;	}	return (base << uspi->s_bpfshift) + pos - begin;} 	static inline unsigned find_last_zero_bit (unsigned char * bitmap,	unsigned size, unsigned offset){	unsigned bit, i;	unsigned char * mapp;	unsigned char map;	mapp = bitmap + (size >> 3);	map = *mapp--;	bit = 1 << (size & 7);	for (i = size; i > offset; i--) {		if ((map & bit) == 0)			break;		if ((i & 7) != 0) {			bit >>= 1;		} else {			map = *mapp--;			bit = 1 << 7;		}	}	return i;}#define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)static inline unsigned _ubh_find_last_zero_bit_(	struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,	unsigned begin, unsigned start, unsigned end){	unsigned base, count, pos, size;	size = start - end;	begin <<= 3;	start += begin;	base = start >> uspi->s_bpfshift;	start &= uspi->s_bpfmask;	for (;;) {		count = min_t(unsigned int,			    size + (uspi->s_bpf - start), uspi->s_bpf)			- (uspi->s_bpf - start);		size -= count;		pos = find_last_zero_bit (ubh->bh[base]->b_data,			start, start - count);		if (pos > start - count || !size)			break;		base--;		start = uspi->s_bpf;	}	return (base << uspi->s_bpfshift) + pos - begin;} 	#define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))#define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)static inline int _ubh_isblockset_(struct ufs_sb_private_info * uspi,	struct ufs_buffer_head * ubh, unsigned begin, unsigned block){	switch (uspi->s_fpb) {	case 8:	    	return (*ubh_get_addr (ubh, begin + block) == 0xff);	case 4:		return (*ubh_get_addr (ubh, begin + (block >> 1)) == (0x0f << ((block & 0x01) << 2)));	case 2:		return (*ubh_get_addr (ubh, begin + (block >> 2)) == (0x03 << ((block & 0x03) << 1)));	case 1:		return (*ubh_get_addr (ubh, begin + (block >> 3)) == (0x01 << (block & 0x07)));	}	return 0;	}#define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)static inline void _ubh_clrblock_(struct ufs_sb_private_info * uspi,	struct ufs_buffer_head * ubh, unsigned begin, unsigned block){	switch (uspi->s_fpb) {	case 8:	    	*ubh_get_addr (ubh, begin + block) = 0x00;	    	return; 	case 4:		*ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));		return;	case 2:		*ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));		return;	case 1:		*ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));		return;	}}#define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)static inline void _ubh_setblock_(struct ufs_sb_private_info * uspi,	struct ufs_buffer_head * ubh, unsigned begin, unsigned block){	switch (uspi->s_fpb) {	case 8:	    	*ubh_get_addr(ubh, begin + block) = 0xff;	    	return;	case 4:		*ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));		return;	case 2:		*ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));		return;	case 1:		*ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));		return;	}}static inline void ufs_fragacct (struct super_block * sb, unsigned blockmap,	__fs32 * fraglist, int cnt){	struct ufs_sb_private_info * uspi;	unsigned fragsize, pos;		uspi = UFS_SB(sb)->s_uspi;		fragsize = 0;	for (pos = 0; pos < uspi->s_fpb; pos++) {		if (blockmap & (1 << pos)) {			fragsize++;		}		else if (fragsize > 0) {			fs32_add(sb, &fraglist[fragsize], cnt);			fragsize = 0;		}	}	if (fragsize > 0 && fragsize < uspi->s_fpb)		fs32_add(sb, &fraglist[fragsize], cnt);}static inline void *ufs_get_direct_data_ptr(struct ufs_sb_private_info *uspi,					    struct ufs_inode_info *ufsi,					    unsigned blk){	BUG_ON(blk > UFS_TIND_BLOCK);	return uspi->fs_magic == UFS2_MAGIC ?		(void *)&ufsi->i_u1.u2_i_data[blk] :		(void *)&ufsi->i_u1.i_data[blk];}static inline u64 ufs_data_ptr_to_cpu(struct super_block *sb, void *p){	return UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC ?		fs64_to_cpu(sb, *(__fs64 *)p) :		fs32_to_cpu(sb, *(__fs32 *)p);}static inline void ufs_cpu_to_data_ptr(struct super_block *sb, void *p, u64 val){	if (UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC)		*(__fs64 *)p = cpu_to_fs64(sb, val);	else		*(__fs32 *)p = cpu_to_fs32(sb, val);}static inline void ufs_data_ptr_clear(struct ufs_sb_private_info *uspi,				      void *p){	if (uspi->fs_magic == UFS2_MAGIC)		*(__fs64 *)p = 0;	else		*(__fs32 *)p = 0;}static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,				       void *p){	if (uspi->fs_magic == UFS2_MAGIC)		return *(__fs64 *)p == 0;	else		return *(__fs32 *)p == 0;}

⌨️ 快捷键说明

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