if (flags & BMAPI_IGNSTATE) bmapi_flags |= XFS_BMAPI_IGSTATE; 
xfs_iomap(	xfs_iocore_t	*io,	xfs_off_t	offset,	ssize_t		count,	int		flags,	xfs_iomap_t	*iomapp,	int		*niomaps){	xfs_mount_t	*mp = io->io_mount;	xfs_fileoff_t	offset_fsb, end_fsb;	int		error = 0;	int		lockmode = 0;	xfs_bmbt_irec_t	imap;	int		nimaps = 1;	int		bmapi_flags = 0;	int		iomap_flags = 0;	if (XFS_FORCED_SHUTDOWN(mp))		return XFS_ERROR(EIO);	switch (flags &		(BMAPI_READ | BMAPI_WRITE | BMAPI_ALLOCATE |		 BMAPI_UNWRITTEN | BMAPI_DEVICE)) {	case BMAPI_READ:		xfs_iomap_enter_trace(XFS_IOMAP_READ_ENTER, io, offset, count);		lockmode = XFS_LCK_MAP_SHARED(mp, io);		bmapi_flags = XFS_BMAPI_ENTIRE;		if (flags & BMAPI_IGNSTATE)			bmapi_flags |= XFS_BMAPI_IGSTATE;		break;	case BMAPI_WRITE:		xfs_iomap_enter_trace(XFS_IOMAP_WRITE_ENTER, io, offset, count);		lockmode = XFS_ILOCK_EXCL|XFS_EXTSIZE_WR;		bmapi_flags = 0;		XFS_ILOCK(mp, io, lockmode);		break;	case BMAPI_ALLOCATE:		xfs_iomap_enter_trace(XFS_IOMAP_ALLOC_ENTER, io, offset, count);		lockmode = XFS_ILOCK_SHARED|XFS_EXTSIZE_RD;		bmapi_flags = XFS_BMAPI_ENTIRE;		/* Attempt non-blocking lock */		if (flags & BMAPI_TRYLOCK) {			if (!XFS_ILOCK_NOWAIT(mp, io, lockmode))				return XFS_ERROR(EAGAIN);		} else {			XFS_ILOCK(mp, io, lockmode);		}		break;	case BMAPI_UNWRITTEN:		goto phase2;	case BMAPI_DEVICE:		lockmode = XFS_LCK_MAP_SHARED(mp, io);		iomapp->iomap_target = io->io_flags & XFS_IOCORE_RT ?			mp->m_rtdev_targp : mp->m_ddev_targp;		error = 0;		*niomaps = 1;		goto out;	default:		BUG();	}	ASSERT(offset <= mp->m_maxioffset);	if ((xfs_fsize_t)offset + count > mp->m_maxioffset)		count = mp->m_maxioffset - offset;	end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);	offset_fsb = XFS_B_TO_FSBT(mp, offset);	error = XFS_BMAPI(mp, NULL, io, offset_fsb,			(xfs_filblks_t)(end_fsb - offset_fsb),			bmapi_flags,  NULL, 0, &imap,			&nimaps, NULL);	if (error)		goto out;phase2:	switch (flags & (BMAPI_WRITE|BMAPI_ALLOCATE|BMAPI_UNWRITTEN)) {	case BMAPI_WRITE:		/* If we found an extent, return it */		if (nimaps &&		    (imap.br_startblock != HOLESTARTBLOCK) && 		    (imap.br_startblock != DELAYSTARTBLOCK)) {			xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io,					offset, count, iomapp, &imap, flags);			break;		}		if (flags & (BMAPI_DIRECT|BMAPI_MMAP)) {			error = XFS_IOMAP_WRITE_DIRECT(mp, io, offset,					count, flags, &imap, &nimaps, nimaps);		} else {			error = XFS_IOMAP_WRITE_DELAY(mp, io, offset, count,					flags, &imap, &nimaps);		}		if (!error) {			xfs_iomap_map_trace(XFS_IOMAP_ALLOC_MAP, io,					offset, count, iomapp, &imap, flags);		}		iomap_flags = IOMAP_NEW;		break;	case BMAPI_ALLOCATE:		/* If we found an extent, return it */		XFS_IUNLOCK(mp, io, lockmode);		lockmode = 0;		if (nimaps && !ISNULLSTARTBLOCK(imap.br_startblock)) {			xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io,					offset, count, iomapp, &imap, flags);			break;		}		error = XFS_IOMAP_WRITE_ALLOCATE(mp, io, offset, count,						 &imap, &nimaps);		break;	case BMAPI_UNWRITTEN:		lockmode = 0;		error = XFS_IOMAP_WRITE_UNWRITTEN(mp, io, offset, count);		nimaps = 0;		break;	}	if (nimaps) {		*niomaps = xfs_imap_to_bmap(io, offset, &imap,					    iomapp, nimaps, *niomaps, iomap_flags);	} else if (niomaps) {		*niomaps = 0;	}out:	if (lockmode)		XFS_IUNLOCK(mp, io, lockmode);	return XFS_ERROR(error);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/c31e887807a3eab26614ee142629ba447cbcc0dc/xfs_iomap.c/buggy/fs/xfs/xfs_iomap.c