FreeBSD/sys/kern/vfs_bio.c
/*
 * Map an IO request into kernel virtual address space.
 *
 * All requests are (re)mapped into kernel VA space.
 * Notice that we use b_bufsize for the size of the buffer
 * to be mapped.  b_bcount might be modified by the driver.
 *
 * Note that even if the caller determines that the address space should
 * be valid, a race or a smaller-file mapped into a larger space may
 * actually cause vmapbuf() to fail, so all callers of vmapbuf() MUST
 * check the return value.
 *
 * This function only works with pager buffers.
 */
Map an IO request into kernel virtual address space.
All requests are (re)mapped into kernel VA space.
Notice that we use b_bufsize for the size of the buffer
to be mapped.  b_bcount might be modified by the driver.

Note that even if the caller determines that the address space should
be valid, a race or a smaller-file mapped into a larger space may
actually cause vmapbuf() to fail, so all callers of vmapbuf() MUST
check the return value.

This function only works with pager buffers.
Map an IO request into kernel virtual address space . All requests are ( re ) mapped into kernel VA space . Notice that we use b_bufsize for the size of the buffer to be mapped . b_bcount might be modified by the driver . Note that even if the caller determines that the address space should be valid a race or a smaller - file mapped into a larger space may actually cause vmapbuf () to fail so all callers of vmapbuf () MUST check the return value . This function only works with pager buffers .
int
vmapbuf(struct buf *bp, int mapbuf)
{
	vm_prot_t prot;
	int pidx;
	if (bp->b_bufsize < 0)
		return (-1);
	prot = VM_PROT_READ;
	if (bp->b_iocmd == BIO_READ)
		prot |= VM_PROT_WRITE;	
	if ((pidx = vm_fault_quick_hold_pages(&curproc->p_vmspace->vm_map,
	    (vm_offset_t)bp->b_data, bp->b_bufsize, prot, bp->b_pages,
	    btoc(MAXPHYS))) < 0)
		return (-1);
	bp->b_npages = pidx;
	bp->b_offset = ((vm_offset_t)bp->b_data) & PAGE_MASK;
	if (mapbuf || !unmapped_buf_allowed) {
		pmap_qenter((vm_offset_t)bp->b_kvabase, bp->b_pages, pidx);
		bp->b_data = bp->b_kvabase + bp->b_offset;
	} else
		bp->b_data = unmapped_buf;
	return(0);
}
int vmapbuf ( struct buf * bp , int mapbuf ) { vm_prot_t prot ; int pidx ; if ( bp -> b_bufsize < 0 ) return ( -1 ) ; prot = VM_PROT_READ ; if ( bp -> b_iocmd == BIO_READ ) prot |= VM_PROT_WRITE ; if ( ( pidx = vm_fault_quick_hold_pages ( & curproc -> p_vmspace -> vm_map , ( vm_offset_t ) bp -> b_data , bp -> b_bufsize , prot , bp -> b_pages , btoc ( MAXPHYS ) ) ) < 0 ) return ( -1 ) ; bp -> b_npages = pidx ; bp -> b_offset = ( ( vm_offset_t ) bp -> b_data ) & PAGE_MASK ; if ( mapbuf || ! unmapped_buf_allowed ) { pmap_qenter ( ( vm_offset_t ) bp -> b_kvabase , bp -> b_pages , pidx ) ; bp -> b_data = bp -> b_kvabase + bp -> b_offset ; } else bp -> b_data = unmapped_buf ; return ( 0 ) ; }
Map an IO request into kernel virtual address space.
Map an IO request into kernel virtual address space .
/* Less backwards than it looks */