From owner-svn-soc-all@FreeBSD.ORG Tue Jun 26 15:05:21 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id F1800106566B for ; Tue, 26 Jun 2012 15:05:18 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 26 Jun 2012 15:05:18 +0000 Date: Tue, 26 Jun 2012 15:05:18 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120626150518.F1800106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r238337 - soc2012/oleksandr/udf-head/sys/fs/udf2 X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2012 15:05:21 -0000 Author: oleksandr Date: Tue Jun 26 15:05:18 2012 New Revision: 238337 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238337 Log: fix double translation number of blocks in udf_strategy and replace field of some structures Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf.h soc2012/oleksandr/udf-head/sys/fs/udf2/udf_allocation.c soc2012/oleksandr/udf-head/sys/fs/udf2/udf_readwrite.c soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.h soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vfsops.c soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf.h ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf.h Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf.h Tue Jun 26 15:05:18 2012 (r238337) @@ -259,10 +259,6 @@ uint32_t sector_size; struct udf_args mount_args; int flags; - uid_t anon_uid; - gid_t anon_gid; - uid_t nobody_uid; - gid_t nobody_gid; /* iconv */ void *iconv_d2l; /* disk to local */ Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_allocation.c ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_allocation.c Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_allocation.c Tue Jun 26 15:05:18 2012 (r238337) @@ -565,8 +565,11 @@ ext_offset = 0; UDF_UNLOCK_NODE(ump->metadata_node, 0); - if (flags != UDF_EXT_ALLOCATED) + if (flags != UDF_EXT_ALLOCATED) { + DPRINTF(TRANSLATE, ("Metadata partion translation " + "failed: not allocated\n")); return EINVAL; + } /* * vpart and lb_num are updated, translate again since we @@ -623,7 +626,7 @@ uint16_t vpart_num; if (!udf_node) - return ENOENT; + return (ENOENT); KASSERT(num_lb > 0,("num_lb > 0")); @@ -646,7 +649,7 @@ *lsector = UDF_TRANS_INTERN; *maxblks = 1; UDF_UNLOCK_NODE(udf_node, 0); - return 0; + return (0); } /* find first overlapping extent */ @@ -654,7 +657,16 @@ slot = 0; for (;;) { udf_get_adslot(udf_node, slot, &s_ad, &eof); + DPRINTF(ADWLK, ("slot %d, eof = %d, flags = %d, len = %d, " + "lb_num = %d, part = %d\n", slot, eof, + UDF_EXT_FLAGS(le32toh(s_ad.len)), + UDF_EXT_LEN(le32toh(s_ad.len)), + le32toh(s_ad.loc.lb_num), + le16toh(s_ad.loc.part_num))); if (eof) { + DPRINTF(TRANSLATE, + ("Translate file extent " + "failed: can't seek location\n")); UDF_UNLOCK_NODE(udf_node, 0); return EINVAL; } @@ -680,6 +692,8 @@ vpart_num = le16toh(s_ad.loc.part_num); ext_offset = block * lb_size - foffset; + + /* process extent, don't forget to advance on ext_offset! */ lb_num += (ext_offset + lb_size -1) / lb_size; ext_remain = (len - ext_offset + lb_size -1) / lb_size; @@ -707,6 +721,8 @@ *maxblks = MIN(ext_remain, translen); break; default: + DPRINTF(TRANSLATE, ("Translate file extend " + "failed: bad flags %x\n", flags)); UDF_UNLOCK_NODE(udf_node, 0); return EINVAL; } @@ -721,7 +737,6 @@ * Translate an extent (in logical_blocks) into logical block numbers; used * for read and write operations. DOESNT't check extents. */ -#if 0 int udf_translate_file_extent(struct udf_node *udf_node, uint32_t from, uint32_t num_lb, @@ -744,7 +759,7 @@ if (!udf_node) return ENOENT; - KASSERT(num_lb > 0); + KASSERT(num_lb > 0, "num_lb > 0"); UDF_LOCK_NODE(udf_node, 0); @@ -890,6 +905,7 @@ return 0; } +#if 0 /* --------------------------------------------------------------------- */ static int Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_readwrite.c ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_readwrite.c Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_readwrite.c Tue Jun 26 15:05:18 2012 (r238337) @@ -335,9 +335,10 @@ /* off_t lblkno, rblkno; */ uint32_t sector_size, blks; /* buf_offset; */ struct vnode *devvp = ump->devvp; + uint32_t logical_secsize = 2048; sector_size = ump->sector_size; - blks = btodb(sector_size); + blks = btodb(logical_secsize); while (sectors > 0 && error == 0) { if ((error = bread(devvp, start*blks, sector_size, NOCRED, Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c Tue Jun 26 15:05:18 2012 (r238337) @@ -198,7 +198,7 @@ di->disc_flags = MMC_DFLAGS_UNRESTRICTED; /* TODO problem with last_possible_lba on resizable VND; request */ - di->last_possible_lba = psize; + di->last_possible_lba = psize/sector_size; di->sector_size = sector_size; di->num_sessions = 1; @@ -1191,10 +1191,10 @@ udf_read_vds_extent(struct udf_mount *ump, uint32_t loc, uint32_t len) { union dscrptr *dscr; - int error; uint32_t sector_size, dscr_size; + int error; - sector_size = ump->sector_size; + sector_size = ump->discinfo.sector_size; /* loc is sectornr, len is in bytes */ error = EIO; @@ -1222,6 +1222,7 @@ /* dscr is assigned into ump */ error = udf_process_vds_descriptor(ump, dscr); if (error) + free(dscr, M_UDFTEMP); break; /* assert((dscr_size % sector_size) == 0); */ Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.h ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.h Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.h Tue Jun 26 15:05:18 2012 (r238337) @@ -100,8 +100,8 @@ // uint16_t vpart_num, uint64_t *lmapping, uint64_t *pmapping); int udf_bmap_translate(struct udf_node *udf_node, uint32_t block, uint64_t *lsector, uint32_t *maxblks); -//int udf_translate_file_extent(struct udf_node *node, -// uint32_t from, uint32_t num_lb, uint64_t *map); +int udf_translate_file_extent(struct udf_node *node, + uint32_t from, uint32_t num_lb, uint64_t *map); void udf_get_adslot(struct udf_node *udf_node, int slot, struct long_ad *icb, int *eof); int udf_append_adslot(struct udf_node *udf_node, int *slot, struct long_ad *icb); Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vfsops.c ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vfsops.c Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vfsops.c Tue Jun 26 15:05:18 2012 (r238337) @@ -194,6 +194,7 @@ td = curthread; opts = mp->mnt_optnew; DPRINTF(CALL, ("udf_mount called\n")); + /* * Unconditionally mount as read-only. */ @@ -201,20 +202,22 @@ mp->mnt_flag |= MNT_RDONLY; MNT_IUNLOCK(mp); - /* No root filesystem support */ + /* No root filesystem support. Probably not a big deal, since the + * bootloader doesn't understand UDF + */ if (mp->mnt_flag & MNT_ROOTFS) return (ENOTSUP); - /* handle request for updating mount parameters */ - /* TODO can't update my mountpoint yet */ - if (mp->mnt_flag & MNT_UPDATE) - return (0); - fspec = NULL; error = vfs_getopt(opts, "from", (void **)&fspec, &len); if (!error && fspec[len - 1] != '\0') return (EINVAL); + /* handle request for updating mount parameters */ + /* TODO can't update my mountpoint yet */ + if (mp->mnt_flag & MNT_UPDATE) + return (0); + /* Check that the mount device exists */ if (fspec == NULL) return (EINVAL); @@ -225,6 +228,7 @@ return (error); NDFREE(&nd, NDF_ONLY_PNBUF); devvp = nd.ni_vp; + if (vn_isdisk(devvp, &error) == 0) { vput(devvp); return (error); @@ -465,10 +469,10 @@ ump->flags = *udf_flags; /* read in disk info from options */ - ump->anon_uid = 0; - ump->anon_gid = 0; - ump->nobody_uid = -1; - ump->nobody_gid = -1; + ump->mount_args.anon_uid = 0; + ump->mount_args.anon_gid = 0; + ump->mount_args.nobody_uid = -1; + ump->mount_args.nobody_gid = -1; #if 0 optdata = NULL; error = vfs_getopt(opts, "first_trackblank", &optdata, &len); Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c ============================================================================== --- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c Tue Jun 26 14:51:35 2012 (r238336) +++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c Tue Jun 26 15:05:18 2012 (r238337) @@ -419,21 +419,24 @@ struct vnode *vp = ap->a_vp; /* our node */ struct udf_node *udf_node = VTOI(vp); uint64_t lsector; - int error; uint32_t maxblks; + int error; if (ap->a_bop != NULL) - *ap->a_bop = udf_node->ump->bo; + *ap->a_bop = &udf_node->ump->devvp->v_bufobj; if (ap->a_bnp == NULL) - return 0; + return (0); + + if (ap->a_runb) + *ap->a_runb = 0; /* get logical block and run */ error = udf_bmap_translate(udf_node, ap->a_bn, &lsector, &maxblks); if (error) return error; - /* convert to dev blocks */ + /* Translate logical to phisascal sector number*/ if (lsector == UDF_TRANS_INTERN) return EOPNOTSUPP; else if (lsector == UDF_TRANS_ZERO) @@ -443,17 +446,20 @@ /* set runlength of maximum block size */ if (ap->a_runp) - *ap->a_runp = 0; + *ap->a_runp = 0; if (ap->a_runb) *ap->a_runb = 0; /* return success */ - return 0; + return (0); } static int -udf_strategy(struct vop_strategy_args *ap) +udf_strategy(struct vop_strategy_args /* { + struct vnode *a_vp; + struct buf *a_bp; + } */ *ap) { struct vnode *vp = ap->a_vp; struct buf *bp = ap->a_bp; @@ -464,44 +470,64 @@ uint32_t lb_size, from, sectors; uint32_t maxblks; + DPRINTF(STRATEGY, ("udf_strategy called\n")); + + /* check if we ought to be here */ if (vp->v_type == VBLK || vp->v_type == VCHR) panic("udf_strategy: spec"); + /* only filebuffers ought to be read/write by this, no descriptors */ + /* assert(bp->b_blkno >= 0);*/ + /* get sector size */ lb_size = udf_node->ump->sector_size; + + /* calculate sector to start from */ from = bp->b_blkno; + + /* calculate length to fetch/store in sectors */ sectors = bp->b_bcount / lb_size; + /* assert(bp->b_count > 0); */ - /* get logical block and run */ - error = udf_bmap_translate(udf_node, bp->b_lblkno, &lsector, &maxblks); - if (error) { - bp->b_error = error; - bufdone(bp); - return error; - } + /* NEVER assume later that this buffer is already translated */ + /* bp->b_lblkno = bp->b_blkno; */ - if (bp->b_iocmd & BIO_READ) { - if (lsector == UDF_TRANS_ZERO) { - memset(bp->b_data, 0, lb_size); - if ((bp->b_flags & B_ASYNC) == 0) - bufwait(bp); - } else if (lsector == UDF_TRANS_INTERN) { - error = udf_read_internal(udf_node, (uint8_t *) bp->b_data); - if (error) - bp->b_error = error; + /* check assertions: we OUGHT to always get multiples of this */ + /* assert(sectors * lb_size == bp->b_bcount); */ + + if (bp->b_blkno == bp->b_lblkno) { + /* get logical block and run */ + error = udf_bmap_translate(udf_node, bp->b_lblkno, &lsector, &maxblks); + if (error) { + bp->b_error = error; bufdone(bp); - if ((bp->b_flags & B_ASYNC) == 0) - bufwait(bp); + return (error); + } + if (bp->b_iocmd & BIO_READ) { + if (lsector == UDF_TRANS_ZERO) { + /* copy sezo sector */ + memset(bp->b_data, 0, lb_size); + if ((bp->b_flags & B_ASYNC) == 0) + bufwait(bp); + /* pre-check if its an internal */ + } else if (lsector == UDF_TRANS_INTERN) { + error = udf_read_internal(udf_node, (uint8_t *) bp->b_data); + if (error) + bp->b_error = error; + bufdone(bp); + if ((bp->b_flags & B_ASYNC) == 0) + bufwait(bp); + } else { + /* bmap gives sector numbers. bio works with device blocks */ + bp->b_blkno = lsector * (udf_node->ump->sector_size/DEV_BSIZE); + } } else { - bp->b_blkno = lsector * (udf_node->ump->sector_size/DEV_BSIZE); - bp->b_iooffset = dbtob(bp->b_blkno); - BO_STRATEGY(bo, bp); + return (ENOTSUP); } - } else { - return ENOTSUP; } - - return bp->b_error; + bp->b_iooffset = dbtob(bp->b_blkno); + BO_STRATEGY(bo, bp); + return (bp->b_error); } @@ -537,6 +563,8 @@ udf_node = VTOI(vp); ump = udf_node->ump; + DPRINTF(READDIR, ("udf_readdir_called\n")); + /* This operation only makes sense on directory nodes. */ if (vp->v_type != VDIR) return ENOTDIR; @@ -551,6 +579,7 @@ } dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK | M_ZERO); + if (ap->a_ncookies != NULL) { /* is this the max number possible? */ ncookies = uio->uio_resid / 8; @@ -571,6 +600,7 @@ * stream */ if (uio->uio_offset == 0) { + DPRINTF(READDIR, ("\t'.' inserted\n")); memset(dirent, 0, sizeof(struct dirent)); dirent->d_fileno = udf_get_node_id(&udf_node->loc); dirent->d_type = DT_DIR; @@ -678,8 +708,12 @@ } bail: + /* tell the calling layer whether we need to be called again */ *ap->a_eofflag = (uio->uio_offset >= file_size); + if (error < 0) + error = 0; + if (ap->a_ncookies != NULL) { if (error) { free(cookies, M_UDFTEMP); @@ -690,7 +724,7 @@ } free(dirent, M_UDFTEMP); - return error; + return (error); } /* --------------------------------------------------------------------- */ @@ -919,9 +953,9 @@ /* do the uid/gid translation game */ if (uid == (uid_t) -1) - uid = ump->anon_uid; + uid = ump->mount_args.anon_uid; if (gid == (gid_t) -1) - gid = ump->anon_gid; + gid = ump->mount_args.anon_gid; /* * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to add