qsort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort); 
xfs_sort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort); 
xfs_dir2_sf_to_block(	xfs_da_args_t		*args)		/* operation arguments */{	xfs_dir2_db_t		blkno;		/* dir-relative block # (0) */	xfs_dir2_block_t	*block;		/* block structure */	xfs_dir2_leaf_entry_t	*blp;		/* block leaf entries */	xfs_dabuf_t		*bp;		/* block buffer */	xfs_dir2_block_tail_t	*btp;		/* block tail pointer */	char			*buf;		/* sf buffer */	int			buf_len;	xfs_dir2_data_entry_t	*dep;		/* data entry pointer */	xfs_inode_t		*dp;		/* incore directory inode */	int			dummy;		/* trash */	xfs_dir2_data_unused_t	*dup;		/* unused entry pointer */	int			endoffset;	/* end of data objects */	int			error;		/* error return value */	int			i;		/* index */	xfs_mount_t		*mp;		/* filesystem mount point */	int			needlog;	/* need to log block header */	int			needscan;	/* need to scan block freespc */	int			newoffset;	/* offset from current entry */	int			offset;		/* target block offset */	xfs_dir2_sf_entry_t	*sfep;		/* sf entry pointer */	xfs_dir2_sf_t		*sfp;		/* shortform structure */	xfs_dir2_data_off_t	*tagp;		/* end of data entry */	xfs_trans_t		*tp;		/* transaction pointer */	xfs_dir2_trace_args("sf_to_block", args);	dp = args->dp;	tp = args->trans;	mp = dp->i_mount;	ASSERT(dp->i_df.if_flags & XFS_IFINLINE);	/*	 * Bomb out if the shortform directory is way too short.	 */	if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {		ASSERT(XFS_FORCED_SHUTDOWN(mp));		return XFS_ERROR(EIO);	}	ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);	ASSERT(dp->i_df.if_u1.if_data != NULL);	sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;	ASSERT(dp->i_d.di_size >= XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count));	/*	 * Copy the directory into the stack buffer.	 * Then pitch the incore inode data so we can make extents.	 */	buf_len = dp->i_df.if_bytes;	buf = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);	memcpy(buf, sfp, dp->i_df.if_bytes);	xfs_idata_realloc(dp, -dp->i_df.if_bytes, XFS_DATA_FORK);	dp->i_d.di_size = 0;	xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);	/*	 * Reset pointer - old sfp is gone.	 */	sfp = (xfs_dir2_sf_t *)buf;	/*	 * Add block 0 to the inode.	 */	error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, &blkno);	if (error) {		kmem_free(buf, buf_len);		return error;	}	/*	 * Initialize the data block.	 */	error = xfs_dir2_data_init(args, blkno, &bp);	if (error) {		kmem_free(buf, buf_len);		return error;	}	block = bp->data;	INT_SET(block->hdr.magic, ARCH_CONVERT, XFS_DIR2_BLOCK_MAGIC);	/*	 * Compute size of block "tail" area.	 */	i = (uint)sizeof(*btp) +	    (INT_GET(sfp->hdr.count, ARCH_CONVERT) + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t);	/*	 * The whole thing is initialized to free by the init routine.	 * Say we're using the leaf and tail area.	 */	dup = (xfs_dir2_data_unused_t *)block->u;	needlog = needscan = 0;	xfs_dir2_data_use_free(tp, bp, dup, mp->m_dirblksize - i, i, &needlog,		&needscan);	ASSERT(needscan == 0);	/*	 * Fill in the tail.	 */	btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);	INT_SET(btp->count, ARCH_CONVERT, INT_GET(sfp->hdr.count, ARCH_CONVERT) + 2);	/* ., .. */	btp->stale = 0;	blp = XFS_DIR2_BLOCK_LEAF_P(btp);	endoffset = (uint)((char *)blp - (char *)block);	/*	 * Remove the freespace, we'll manage it.	 */	xfs_dir2_data_use_free(tp, bp, dup,		(xfs_dir2_data_aoff_t)((char *)dup - (char *)block),		INT_GET(dup->length, ARCH_CONVERT), &needlog, &needscan);	/*	 * Create entry for .	 */	dep = (xfs_dir2_data_entry_t *)	      ((char *)block + XFS_DIR2_DATA_DOT_OFFSET);	INT_SET(dep->inumber, ARCH_CONVERT, dp->i_ino);	dep->namelen = 1;	dep->name[0] = '.';	tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);	INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block));	xfs_dir2_data_log_entry(tp, bp, dep);	INT_SET(blp[0].hashval, ARCH_CONVERT, xfs_dir_hash_dot);	INT_SET(blp[0].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp, (char *)dep - (char *)block));	/*	 * Create entry for ..	 */	dep = (xfs_dir2_data_entry_t *)		((char *)block + XFS_DIR2_DATA_DOTDOT_OFFSET);	INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER(sfp, &sfp->hdr.parent));	dep->namelen = 2;	dep->name[0] = dep->name[1] = '.';	tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);	INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block));	xfs_dir2_data_log_entry(tp, bp, dep);	INT_SET(blp[1].hashval, ARCH_CONVERT, xfs_dir_hash_dotdot);	INT_SET(blp[1].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp, (char *)dep - (char *)block));	offset = XFS_DIR2_DATA_FIRST_OFFSET;	/*	 * Loop over existing entries, stuff them in.	 */	if ((i = 0) == INT_GET(sfp->hdr.count, ARCH_CONVERT))		sfep = NULL;	else		sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);	/*	 * Need to preserve the existing offset values in the sf directory.	 * Insert holes (unused entries) where necessary.	 */	while (offset < endoffset) {		/*		 * sfep is null when we reach the end of the list.		 */		if (sfep == NULL)			newoffset = endoffset;		else			newoffset = XFS_DIR2_SF_GET_OFFSET(sfep);		/*		 * There should be a hole here, make one.		 */		if (offset < newoffset) {			dup = (xfs_dir2_data_unused_t *)			      ((char *)block + offset);			INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);			INT_SET(dup->length, ARCH_CONVERT, newoffset - offset);			INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT,				(xfs_dir2_data_off_t)				((char *)dup - (char *)block));			xfs_dir2_data_log_unused(tp, bp, dup);			(void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)block,				dup, &dummy);			offset += INT_GET(dup->length, ARCH_CONVERT);			continue;		}		/*		 * Copy a real entry.		 */		dep = (xfs_dir2_data_entry_t *)((char *)block + newoffset);		INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER(sfp,				XFS_DIR2_SF_INUMBERP(sfep)));		dep->namelen = sfep->namelen;		memcpy(dep->name, sfep->name, dep->namelen);		tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);		INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block));		xfs_dir2_data_log_entry(tp, bp, dep);		INT_SET(blp[2 + i].hashval, ARCH_CONVERT, xfs_da_hashname((char *)sfep->name, sfep->namelen));		INT_SET(blp[2 + i].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp,						 (char *)dep - (char *)block));		offset = (int)((char *)(tagp + 1) - (char *)block);		if (++i == INT_GET(sfp->hdr.count, ARCH_CONVERT))			sfep = NULL;		else			sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);	}	/* Done with the temporary buffer */	kmem_free(buf, buf_len);	/*	 * Sort the leaf entries by hash value.	 */	qsort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort);	/*	 * Log the leaf entry area and tail.	 * Already logged the header in data_init, ignore needlog.	 */	ASSERT(needscan == 0);	xfs_dir2_block_log_leaf(tp, bp, 0, INT_GET(btp->count, ARCH_CONVERT) - 1);	xfs_dir2_block_log_tail(tp, bp);	xfs_dir2_data_check(dp, bp);	xfs_da_buf_done(bp);	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/380b5dc0e59340e7ed36dcc95dd1022aca75bbe2/xfs_dir2_block.c/clean/fs/xfs/xfs_dir2_block.c