qsort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare); 
xfs_sort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare); 
xfs_attr_shortform_list(xfs_attr_list_context_t *context){	attrlist_cursor_kern_t *cursor;	xfs_attr_sf_sort_t *sbuf, *sbp;	xfs_attr_shortform_t *sf;	xfs_attr_sf_entry_t *sfe;	xfs_inode_t *dp;	int sbsize, nsbuf, count, i;	ASSERT(context != NULL);	dp = context->dp;	ASSERT(dp != NULL);	ASSERT(dp->i_afp != NULL);	sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;	ASSERT(sf != NULL);	if (!sf->hdr.count)		return(0);	cursor = context->cursor;	ASSERT(cursor != NULL);	xfs_attr_trace_l_c("sf start", context);	/*	 * If the buffer is large enough, do not bother with sorting.	 * Note the generous fudge factor of 16 overhead bytes per entry.	 */	if ((dp->i_afp->if_bytes + INT_GET(sf->hdr.count, ARCH_CONVERT) * 16)							< context->bufsize) {		for (i = 0, sfe = &sf->list[0];				i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {			attrnames_t	*namesp;			if (((context->flags & ATTR_SECURE) != 0) !=			    ((sfe->flags & XFS_ATTR_SECURE) != 0) &&			    !(context->flags & ATTR_KERNORMALS)) {				sfe = XFS_ATTR_SF_NEXTENTRY(sfe);				continue;			}			if (((context->flags & ATTR_ROOT) != 0) !=			    ((sfe->flags & XFS_ATTR_ROOT) != 0) &&			    !(context->flags & ATTR_KERNROOTLS)) {				sfe = XFS_ATTR_SF_NEXTENTRY(sfe);				continue;			}			namesp = (sfe->flags & XFS_ATTR_SECURE) ? &attr_secure:				((sfe->flags & XFS_ATTR_ROOT) ? &attr_trusted :				  &attr_user);			if (context->flags & ATTR_KERNOVAL) {				ASSERT(context->flags & ATTR_KERNAMELS);				context->count += namesp->attr_namelen +					INT_GET(sfe->namelen, ARCH_CONVERT) + 1;			}			else {				if (xfs_attr_put_listent(context, namesp,						   (char *)sfe->nameval,						   (int)sfe->namelen,						   (int)INT_GET(sfe->valuelen,								ARCH_CONVERT)))					break;			}			sfe = XFS_ATTR_SF_NEXTENTRY(sfe);		}		xfs_attr_trace_l_c("sf big-gulp", context);		return(0);	}	/*	 * It didn't all fit, so we have to sort everything on hashval.	 */	sbsize = INT_GET(sf->hdr.count, ARCH_CONVERT) * sizeof(*sbuf);	sbp = sbuf = kmem_alloc(sbsize, KM_SLEEP);	/*	 * Scan the attribute list for the rest of the entries, storing	 * the relevant info from only those that match into a buffer.	 */	nsbuf = 0;	for (i = 0, sfe = &sf->list[0];			i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {		if (unlikely(		    ((char *)sfe < (char *)sf) ||		    ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) {			XFS_CORRUPTION_ERROR("xfs_attr_shortform_list",					     XFS_ERRLEVEL_LOW,					     context->dp->i_mount, sfe);			xfs_attr_trace_l_c("sf corrupted", context);			kmem_free(sbuf, sbsize);			return XFS_ERROR(EFSCORRUPTED);		}		if (((context->flags & ATTR_SECURE) != 0) !=		    ((sfe->flags & XFS_ATTR_SECURE) != 0) &&		    !(context->flags & ATTR_KERNORMALS)) {			sfe = XFS_ATTR_SF_NEXTENTRY(sfe);			continue;		}		if (((context->flags & ATTR_ROOT) != 0) !=		    ((sfe->flags & XFS_ATTR_ROOT) != 0) &&		    !(context->flags & ATTR_KERNROOTLS)) {			sfe = XFS_ATTR_SF_NEXTENTRY(sfe);			continue;		}		sbp->entno = i;		INT_SET(sbp->hash, ARCH_CONVERT,			xfs_da_hashname((char *)sfe->nameval, sfe->namelen));		sbp->name = (char *)sfe->nameval;		sbp->namelen = sfe->namelen;		/* These are bytes, and both on-disk, don't endian-flip */		sbp->valuelen = sfe->valuelen;		sbp->flags = sfe->flags;		sfe = XFS_ATTR_SF_NEXTENTRY(sfe);		sbp++;		nsbuf++;	}	/*	 * Sort the entries on hash then entno.	 */	qsort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare);	/*	 * Re-find our place IN THE SORTED LIST.	 */	count = 0;	cursor->initted = 1;	cursor->blkno = 0;	for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {		if (INT_GET(sbp->hash, ARCH_CONVERT) == cursor->hashval) {			if (cursor->offset == count) {				break;			}			count++;		} else if (INT_GET(sbp->hash, ARCH_CONVERT) > cursor->hashval) {			break;		}	}	if (i == nsbuf) {		kmem_free(sbuf, sbsize);		xfs_attr_trace_l_c("blk end", context);		return(0);	}	/*	 * Loop putting entries into the user buffer.	 */	for ( ; i < nsbuf; i++, sbp++) {		attrnames_t	*namesp;		namesp = (sbp->flags & XFS_ATTR_SECURE) ? &attr_secure :			((sbp->flags & XFS_ATTR_ROOT) ? &attr_trusted :			  &attr_user);		if (cursor->hashval != INT_GET(sbp->hash, ARCH_CONVERT)) {			cursor->hashval = INT_GET(sbp->hash, ARCH_CONVERT);			cursor->offset = 0;		}		if (context->flags & ATTR_KERNOVAL) {			ASSERT(context->flags & ATTR_KERNAMELS);			context->count += namesp->attr_namelen +						sbp->namelen + 1;		} else {			if (xfs_attr_put_listent(context, namesp,					sbp->name, sbp->namelen,					INT_GET(sbp->valuelen, ARCH_CONVERT)))				break;		}		cursor->offset++;	}	kmem_free(sbuf, sbsize);	xfs_attr_trace_l_c("sf E-O-F", context);	return(0);}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/380b5dc0e59340e7ed36dcc95dd1022aca75bbe2/xfs_attr_leaf.c/buggy/fs/xfs/xfs_attr_leaf.c