FreeBSD/sys/fs/udf/udf_vnops.c
/*
 * Read the block and then set the data pointer to correspond with the
 * offset passed in.  Only read in at most 'size' bytes, and then set 'size'
 * to the number of bytes pointed to.  If 'size' is zero, try to read in a
 * whole extent.
 *
 * Note that *bp may be assigned error or not.
 *
 */
Read the block and then set the data pointer to correspond with the
offset passed in.  Only read in at most 'size' bytes, and then set 'size'
to the number of bytes pointed to.  If 'size' is zero, try to read in a
whole extent.

Note that *bp may be assigned error or not.
Read the block and then set the data pointer to correspond with the offset passed in . Only read in at most ' size ' bytes and then set ' size ' to the number of bytes pointed to . If ' size ' is zero try to read in a whole extent . Note that * bp may be assigned error or not .
static int
udf_readatoffset(struct udf_node *node, int *size, off_t offset,
    struct buf **bp, uint8_t **data)
{
	struct udf_mnt *udfmp = node->udfmp;
	struct vnode *vp = node->i_vnode;
	struct file_entry *fentry;
	struct buf *bp1;
	uint32_t max_size;
	daddr_t sector;
	off_t off;
	int adj_size;
	int error;
	error = udf_bmap_internal(node, offset, &sector, &max_size);
	if (error == UDF_INVALID_BMAP) {
		fentry = node->fentry;
		*data = &fentry->data[le32toh(fentry->l_ea)];
		*size = le32toh(fentry->l_ad);
		if (offset >= *size)
			*size = 0;
		else {
			*data += offset;
			*size -= offset;
		}
		return (0);
	} else if (error != 0) {
		return (error);
	}
	if (*size == 0 || *size > max_size)
		*size = max_size;
	off = blkoff(udfmp, offset);
	*size = min(*size, MAXBSIZE - off);
	adj_size = (*size + off + udfmp->bmask) & ~udfmp->bmask;
	*bp = NULL;
	if ((error = bread(vp, lblkno(udfmp, offset), adj_size, NOCRED, bp))) {
		printf("warning: udf_readlblks returned error %d\n", error);
		return (error);
	}
	bp1 = *bp;
	*data = (uint8_t *)&bp1->b_data[offset & udfmp->bmask];
	return (0);
}
static int udf_readatoffset ( struct udf_node * node , int * size , off_t offset , struct buf * * bp , uint8_t * * data ) { struct udf_mnt * udfmp = node -> udfmp ; struct vnode * vp = node -> i_vnode ; struct file_entry * fentry ; struct buf * bp1 ; uint32_t max_size ; daddr_t sector ; off_t off ; int adj_size ; int error ; error = udf_bmap_internal ( node , offset , & sector , & max_size ) ; if ( error == UDF_INVALID_BMAP ) { fentry = node -> fentry ; * data = & fentry -> data [ le32toh ( fentry -> l_ea ) ] ; * size = le32toh ( fentry -> l_ad ) ; if ( offset >= * size ) * size = 0 ; else { * data += offset ; * size -= offset ; } return ( 0 ) ; } else if ( error != 0 ) { return ( error ) ; } if ( * size == 0 || * size > max_size ) * size = max_size ; off = blkoff ( udfmp , offset ) ; * size = min ( * size , MAXBSIZE - off ) ; adj_size = ( * size + off + udfmp -> bmask ) & ~ udfmp -> bmask ; * bp = NULL ; if ( ( error = bread ( vp , lblkno ( udfmp , offset ) , adj_size , NOCRED , bp ) ) ) { printf ( " \n " , error ) ; return ( error ) ; } bp1 = * bp ; * data = ( uint8_t * ) & bp1 -> b_data [ offset & udfmp -> bmask ] ; return ( 0 ) ; }
Read the block and then set the data pointer to correspond with the
 offset passed in.
Read the block and then set the data pointer to correspond with the offset passed in .
/*
	 * This call is made *not* only to detect UDF_INVALID_BMAP case,
	 * max_size is used as an ad-hoc read-ahead hint for "normal" case.
	 */ /*
		 * This error means that the file *data* is stored in the
		 * allocation descriptor field of the file entry.
		 */ /* Adjust the size so that it is within range */ /*
	 * Because we will read starting at block boundary, we need to adjust
	 * how much we need to read so that all promised data is in.
	 * Also, we can't promise to read more than MAXBSIZE bytes starting
	 * from block boundary, so adjust what we promise too.
	 */ /* note: *bp may be non-NULL */