summaryrefslogtreecommitdiffstats
path: root/sys/fs/udf/udf_vnops.c
diff options
context:
space:
mode:
authoravg <avg@FreeBSD.org>2009-02-26 18:58:41 +0000
committeravg <avg@FreeBSD.org>2009-02-26 18:58:41 +0000
commit2b666c76d21981720da7ad4acb258421af23d85e (patch)
tree125c079d76bf54373b96a99842f4f442c44d9436 /sys/fs/udf/udf_vnops.c
parentdfd6f02e2ffd77ba010288c4ecd81941adcc4c65 (diff)
downloadFreeBSD-src-2b666c76d21981720da7ad4acb258421af23d85e.zip
FreeBSD-src-2b666c76d21981720da7ad4acb258421af23d85e.tar.gz
udf_readatoffset: read through directory vnode, do not read > MAXBSIZE
Currently bread()-ing through device vnode with (1) VMIO enabled, (2) bo_bsize != DEV_BSIZE (3) more than 1 block results in data being incorrectly cached. So instead a more common approach of using a vnode belonging to fs is now employed. Also, prevent attempt to bread more than MAXBSIZE bytes because of adjustments made to account for offset that doesn't start on block boundary. Add expanded comments to explain the calculations. Also drop unused inline function while here. PR: kern/120967 PR: kern/129084 Reviewed by: scottl, kib Approved by: jhb (mentor)
Diffstat (limited to 'sys/fs/udf/udf_vnops.c')
-rw-r--r--sys/fs/udf/udf_vnops.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c
index 4d5b3a3..5afb038 100644
--- a/sys/fs/udf/udf_vnops.c
+++ b/sys/fs/udf/udf_vnops.c
@@ -1296,16 +1296,20 @@ static int
udf_readatoffset(struct udf_node *node, int *size, off_t offset,
struct buf **bp, uint8_t **data)
{
- struct udf_mnt *udfmp;
- struct file_entry *fentry = NULL;
+ 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;
- udfmp = node->udfmp;
-
- *bp = NULL;
+ /*
+ * 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.
+ */
error = udf_bmap_internal(node, offset, &sector, &max_size);
if (error == UDF_INVALID_BMAP) {
/*
@@ -1323,9 +1327,18 @@ udf_readatoffset(struct udf_node *node, int *size, off_t offset,
/* Adjust the size so that it is within range */
if (*size == 0 || *size > max_size)
*size = max_size;
- *size = min(*size, MAXBSIZE);
- if ((error = udf_readlblks(udfmp, sector, *size + (offset & udfmp->bmask), bp))) {
+ /*
+ * 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.
+ */
+ 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);
/* note: *bp may be non-NULL */
return (error);
OpenPOWER on IntegriCloud