FreeBSD/sys/fs/unionfs/union_subr.c
/*
 * Copy from lvp to uvp.
 * 
 * lvp and uvp should be locked and opened on entry and will be locked and
 * opened on return.
 */
Copy from lvp to uvp.

lvp and uvp should be locked and opened on entry and will be locked and
opened on return.
Copy from lvp to uvp . lvp and uvp should be locked and opened on entry and will be locked and opened on return .
static int
unionfs_copyfile_core(struct vnode *lvp, struct vnode *uvp,
		      struct ucred *cred, struct thread *td)
{
	int		error;
	off_t		offset;
	int		count;
	int		bufoffset;
	char           *buf;
	struct uio	uio;
	struct iovec	iov;
	error = 0;
	memset(&uio, 0, sizeof(uio));
	uio.uio_td = td;
	uio.uio_segflg = UIO_SYSSPACE;
	uio.uio_offset = 0;
	buf = malloc(MAXBSIZE, M_TEMP, M_WAITOK);
	while (error == 0) {
		offset = uio.uio_offset;
		uio.uio_iov = &iov;
		uio.uio_iovcnt = 1;
		iov.iov_base = buf;
		iov.iov_len = MAXBSIZE;
		uio.uio_resid = iov.iov_len;
		uio.uio_rw = UIO_READ;
		if ((error = VOP_READ(lvp, &uio, 0, cred)) != 0)
			break;
		if ((count = MAXBSIZE - uio.uio_resid) == 0)
			break;
		bufoffset = 0;
		while (bufoffset < count) {
			uio.uio_iov = &iov;
			uio.uio_iovcnt = 1;
			iov.iov_base = buf + bufoffset;
			iov.iov_len = count - bufoffset;
			uio.uio_offset = offset + bufoffset;
			uio.uio_resid = iov.iov_len;
			uio.uio_rw = UIO_WRITE;
			if ((error = VOP_WRITE(uvp, &uio, 0, cred)) != 0)
				break;
			bufoffset += (count - bufoffset) - uio.uio_resid;
		}
		uio.uio_offset = offset + bufoffset;
	}
	free(buf, M_TEMP);
	return (error);
}
static int unionfs_copyfile_core ( struct vnode * lvp , struct vnode * uvp , struct ucred * cred , struct thread * td ) { int error ; off_t offset ; int count ; int bufoffset ; char * buf ; struct uio uio ; struct iovec iov ; error = 0 ; memset ( & uio , 0 , sizeof ( uio ) ) ; uio . uio_td = td ; uio . uio_segflg = UIO_SYSSPACE ; uio . uio_offset = 0 ; buf = malloc ( MAXBSIZE , M_TEMP , M_WAITOK ) ; while ( error == 0 ) { offset = uio . uio_offset ; uio . uio_iov = & iov ; uio . uio_iovcnt = 1 ; iov . iov_base = buf ; iov . iov_len = MAXBSIZE ; uio . uio_resid = iov . iov_len ; uio . uio_rw = UIO_READ ; if ( ( error = VOP_READ ( lvp , & uio , 0 , cred ) ) != 0 ) break ; if ( ( count = MAXBSIZE - uio . uio_resid ) == 0 ) break ; bufoffset = 0 ; while ( bufoffset < count ) { uio . uio_iov = & iov ; uio . uio_iovcnt = 1 ; iov . iov_base = buf + bufoffset ; iov . iov_len = count - bufoffset ; uio . uio_offset = offset + bufoffset ; uio . uio_resid = iov . iov_len ; uio . uio_rw = UIO_WRITE ; if ( ( error = VOP_WRITE ( uvp , & uio , 0 , cred ) ) != 0 ) break ; bufoffset += ( count - bufoffset ) - uio . uio_resid ; } uio . uio_offset = offset + bufoffset ; } free ( buf , M_TEMP ) ; return ( error ) ; }
Copy from lvp to uvp.
Copy from lvp to uvp .