Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Jul 2012 19:04:50 +0000
From:      oleksandr@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r239248 - soc2012/oleksandr/udf-head/sys/fs/udf2
Message-ID:  <20120710190450.651301065676@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: oleksandr
Date: Tue Jul 10 19:04:49 2012
New Revision: 239248
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239248

Log:
  Add determine maximum number of blocks, some comments, debug sections and clean code

Modified:
  soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c
  soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c

Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c
==============================================================================
--- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c	Tue Jul 10 18:57:05 2012	(r239247)
+++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_subr.c	Tue Jul 10 19:04:49 2012	(r239248)
@@ -2412,6 +2412,7 @@
 		l_ea  = le32toh(node->fe->l_ea);
 		eahdr = (struct extattrhdr_desc *) node->fe->data;
 	} else {
+		KASSERT(node->efe, ("Extended File Entry is null"));
 		l_ea  = le32toh(node->efe->l_ea);
 		eahdr = (struct extattrhdr_desc *) node->efe->data;
 	}
@@ -2430,6 +2431,8 @@
 	if (error)
 		return (EINVAL);
 
+	DPRINTF(EXTATTR, ("Found %d bytes of extended attributes\n", l_ea));
+
 	/* looking for Ecma-167 attributes? */
 	offset = sizeof(struct extattrhdr_desc);
 
@@ -2449,16 +2452,22 @@
 	if (l_ea + offset >= sector_size - sizeof(struct extattr_entry))
 		return (EINVAL);
 
+	DPRINTF(EXTATTR, ("Starting at offset %d\n", offset));
+
 	/* find our extended attribute  */
 	l_ea -= offset;
 	pos = (uint8_t *) eahdr + offset;
 
 	while (l_ea >= sizeof(struct extattr_entry)) {
+		DPRINTF(EXTATTR, ("%d extended attr bytes left\n", l_ea));
 		attrhdr = (struct extattr_entry *) pos;
 		implext = (struct impl_extattr_entry *) pos;
 
 		/* get complete attribute length and check for roque values */
 		a_l = le32toh(attrhdr->a_l);
+		DPRINTF(EXTATTR, ("attribute %d:%d, len %d/%d\n",
+				le32toh(attrhdr->type),
+				attrhdr->subtype, a_l, l_ea));
 		if ((a_l == 0) || (a_l > l_ea))
 			return (EINVAL);
 
@@ -2479,6 +2488,7 @@
 		 * we need to check
 		 */
 
+		DPRINTF(EXTATTR, ("named attribute %s\n", implext->imp_id.id));
 		if (strcmp(implext->imp_id.id, sattrname) == 0) {
 			/* we have found our appl/implementation attribute */
 			*offsetp = offset;
@@ -4350,7 +4360,7 @@
 		icbftype = fe->icbtag.file_type;
 		icbflags = le16toh(fe->icbtag.flags);
 	} else {
-		/*assert(udf_node->efe); */
+		KASSERT(udf_node->efe, ("Extended File Entry is null")); 
 		udf_perm = le32toh(efe->perm);
 		icbftype = efe->icbtag.file_type;
 		icbflags = le16toh(efe->icbtag.flags);

Modified: soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c
==============================================================================
--- soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c	Tue Jul 10 18:57:05 2012	(r239247)
+++ soc2012/oleksandr/udf-head/sys/fs/udf2/udf_vnops.c	Tue Jul 10 19:04:49 2012	(r239248)
@@ -100,6 +100,8 @@
 int
 udf_getanode(struct mount *mp, struct vnode **vpp)
 {
+	DPRINTF(CALL, ("udf_getanode called\n"));
+
 	return (getnewvnode("udf2", mp, &udf_vnodeops, vpp));
 }
 
@@ -214,6 +216,8 @@
 	int on, n, lbn; 
 	int error = 0;
 
+	DPRINTF(READ, ("udf_read called\n"));
+
 	/* can this happen? some filingsystems have this check */
 	if (uio->uio_offset < 0)
 		return (EINVAL);
@@ -226,10 +230,14 @@
 		panic("udf_read: type %d",  vp->v_type);
 #endif
 
+	KASSERT(udf_node, ("udf_read: udf_node is null"));
+	KASSERT(udf_noed->fe || udf_node->efe, ("udf_read: Extended File Entry or File Entry is null"));
+
 	/* get file/directory filesize */
 	if (udf_node->fe)
 		file_size = le64toh(udf_node->fe->inf_len);
 	else 
+		KASSERT(udf_node->efe, ("Extended File Entry is null"));
 		file_size = le64toh(udf_node->efe->inf_len);
 
 	/* read contents using buffercache */
@@ -454,10 +462,19 @@
 	else
 		*ap->a_bnp = lsector * (udf_node->ump->discinfo.sector_size/DEV_BSIZE);
 
-	/* set runlength of maximum block size */
-	if (ap->a_runp)
-		*ap->a_runp = 0; 
-
+	/*
+	 * Determine maximum number of readahead blocks following the 
+	 * requested block.
+	 */
+	if (ap->a_runp) {
+		if (maxblks <= 1) 		
+			*ap->a_runp = 0; 
+		else if (maxblks - 1 >= MAXBSIZE)
+			*ap->a_runp = MAXBSIZE - 1; 
+		else 
+			*ap->a_runp = maxblks - 1; 
+	
+	}
 	if (ap->a_runb) 
 		*ap->a_runb = 0;
 
@@ -487,7 +504,7 @@
 		panic("udf_strategy: spec");
 
 	/* only filebuffers ought to be read/write by this, no descriptors */
-	/* assert(bp->b_blkno >= 0);*/
+	KASSERT(bp->b_blkno >= 0, ("udf_strategy: nonexistent physical block number"));
 
 	/* get sector size */
 	lb_size = udf_node->ump->discinfo.sector_size;
@@ -497,14 +514,14 @@
 
 	/* calculate length to fetch/store in sectors */
 	sectors = bp->b_bcount / lb_size;
-	/* assert(bp->b_count > 0); */
+	KASSERT(bp->b_bcount > 0, ("udf_strategy: no valid bytes in buffer")); 
 
 	/* NEVER assume later that this buffer is already translated */
 	/* bp->b_lblkno = bp->b_blkno; */
 
 	/* check assertions: we OUGHT to always get multiples of this */
-	/* assert(sectors * lb_size == bp->b_bcount); */
-
+	KASSERT(sectors * lb_size == bp->b_bcount, ("udf_strategy: wrong length 
+				to fetch/store in sectors")); 
 	if (bp->b_blkno == bp->b_lblkno) {
 		/* get logical block and run */
 		error = udf_bmap_translate(udf_node, bp->b_lblkno, &lsector, &maxblks);
@@ -515,6 +532,10 @@
 		 }
 	}	
 	if (bp->b_iocmd & BIO_READ) {
+		DPRINTF(STRATEGY, ("\tread vp %p buf %p (blk no %llu)"
+		    ", sector %d for %d sectors\n",
+		    vp, bp, bp->b_blkno, from, sectors));
+
 		if (lsector == UDF_TRANS_ZERO) {
 			/* copy sezo sector */
 			memset(bp->b_data, 0, lb_size);
@@ -535,6 +556,10 @@
 			BO_STRATEGY(bo, bp);
 		}
 	} else {
+		DPRINTF(STRATEGY, ("\twrite vp %p buf %p (blk no %llu)"
+		    ", sector %d for %d sectors\n",
+		    vp, bp, bp->b_blkno, from, sectors));
+
 		return (ENOTSUP);
 	}
 	return (bp->b_error);
@@ -591,7 +616,11 @@
 	dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK | M_ZERO);
 
 	if (ap->a_ncookies != NULL) {
-		/* is this the max number possible? */
+		/*
+		 * Guess how many entries are needed. If we run out, this 
+		 * function will be called again and thing will pick up
+		 * were it left off.
+		 */
 		ncookies = uio->uio_resid / 8;
 		cookies = malloc(sizeof(u_long) * ncookies, M_UDFTEMP, 
 		    M_WAITOK | M_ZERO);
@@ -643,8 +672,11 @@
 		diroffset   = uio->uio_offset;
 		transoffset = diroffset;
 		while (diroffset < file_size) {
+			DPRINTF(READDIR, ("\tread in fid stream\n"));
 			/* transfer a new fid/dirent */
 			error = udf_read_fid_stream(vp, &diroffset, fid);
+			DPRINTFIF(READDIR, error, ("read error in read fid "
+			    "stream : %d\n", error));
 			if (error) {
 				printf("Read error in read fid: %d\n", error);
 				break;
@@ -698,6 +730,8 @@
 				continue;
 
 			/* copy dirent to the caller */
+			DPRINTF(READDIR, ("\tread dirent `%s', type %d\n",
+			    dirent->d_name, dirent->d_type));
 			if (cookiesp) {
 				/*
 				if (++acookies >= ncookies)
@@ -732,6 +766,17 @@
 			//*ap->a_cookies = cookies;
 		}
 	}
+
+#ifdef DEBUG
+	if (udf_verbose & UDF_DEBUG_READDIR) {
+		printf("returning offset %d\n", (uint32_t) uio->uio_offset);
+		if (ap->a_eofflag)
+			printf("returning EOF ? %d\n", *ap->a_eofflag);
+		if (error)
+			printf("readdir returning error %d\n", error);
+	}
+#endif
+
 	free(dirent, M_UDFTEMP);
 
 	return (error);
@@ -936,12 +981,13 @@
 	struct timestamp *atime, *mtime, *attrtime, *creatime;
 	struct udf_mount *ump = udf_node->ump;
 	uint64_t filesize, blkssize;
+	uint32_t nlink, offset, a_l;
+	uint8_t *filedata;
+	uid_t uid;
 	gid_t gid;
 	int error;
-	uid_t uid;
-	uint32_t nlink;
-	uint32_t offset, a_l;
-	uint8_t *filedata;
+
+	DPRINTF(CALL, ("udf_getattr called\n"));
 
 	/* update times before we returning values */ 
 #if 0
@@ -973,6 +1019,7 @@
 				creatime = &ft_extattr->times[0];
 		}
 	} else {
+		KASSERT(udf_node->efe, ("Extended File Entry is null"));
 		nlink    = le16toh(efe->link_cnt);
 		uid      = (uid_t)le32toh(efe->uid);
 		gid      = (gid_t)le32toh(efe->gid);
@@ -1253,10 +1300,11 @@
 /*	struct udf_mount *ump = udf_node->ump; */
 /*	kauth_cred_t cred = ap->a_cred; */
 	struct vattr *vap = ap->a_vap;
-	int error;
+	int error = 0;
+
+	DPRINTF(CALL, ("udf_setattr called\n"));
 
 	/* Abort if any unsettable attribute is given. */
-	error = 0;
 	if (vap->va_type != VNON ||
 	    vap->va_nlink != VNOVAL ||
 	    vap->va_fsid != VNOVAL ||
@@ -1274,12 +1322,15 @@
 	    vap->va_bytes != VNOVAL)
 		error = EINVAL;
 
+	DPRINTF(ATTR, ("setattr changing:\n"));
 	if (error == 0 && (vap->va_flags != VNOVAL)) {
+		DPRINTF(ATTR, ("\tchflags\n"));
 		return (EROFS);
 /*		error = udf_chflags(vp, vap->va_flags, cred); */
 	}
 
 	if (error == 0 && (vap->va_size != VNOVAL)) {
+		DPRINTF(ATTR, ("\tchsize\n"));
 		if (vap->va_type == VDIR)
 			return (EISDIR);
 		if (vap->va_type == VLNK || vap->va_type == VREG)
@@ -1288,11 +1339,13 @@
 	}
 
 	if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL)) {
+		DPRINTF(ATTR, ("\tchown\n"));
 		return (EROFS);
 /*		error = udf_chown(vp, vap->va_uid, vap->va_gid, cred); */
 	}
 
 	if (error == 0 && (vap->va_mode != (mode_t)VNOVAL)) {
+		DPRINTF(ATTR, ("\tchmod\n"));
 		return (EROFS);
 /*		error = udf_chmod(vp, vap->va_mode, cred); */
 	}
@@ -1303,9 +1356,10 @@
 	     (vap->va_mtime.tv_sec != VNOVAL &&
 	      vap->va_mtime.tv_nsec != VNOVAL))
 	    ) {
+		DPRINTF(ATTR, ("\tchimes\n"));
 		return (EROFS);
-/*		error = udf_chtimes(vp, &vap->va_atime, &vap->va_mtime, */
-/*		    &vap->va_birthtime, vap->va_vaflags, cred); */
+/*		error = udf_chtimes(vp, &vap->va_atime, &vap->va_mtime, 
+		    &vap->va_birthtime, vap->va_vaflags, cred); */
 	}
 /*	VN_KNOTE(vp, NOTE_ATTRIB); */
 
@@ -1322,6 +1376,8 @@
 {
 	uint32_t bits;
 
+	DPRINTF(CALL, ("udf_pathconf called\n"));
+
 	switch (ap->a_name) {
 	case _PC_LINK_MAX:
 		*ap->a_retval = (1<<16)-1;	/* 16 bits */
@@ -1347,10 +1403,7 @@
 	case _PC_FILESIZEBITS:
 		/* 64 bit file offsets -> 2+floor(2log(2^64-1)) = 2 + 63 = 65 */
 		bits = 64; /* XXX ought to deliver 65 */
-#if 0
-		if (udf_node)
-			bits = 64 * vp->v_mount->mnt_dev_bshift;
-#endif
+
 		*ap->a_retval = bits;
 		return (0);
 	}
@@ -1364,11 +1417,11 @@
 static int
 udf_open(struct vop_open_args *ap)
 {
-	struct udf_node *udf_node;
+	struct udf_node *udf_node = VTOI(ap->a_vp);
 	off_t file_size;
 	/* int flags; */
 
-	udf_node = VTOI(ap->a_vp);
+	DPRINTF(CALL, ("udf_open called\n"));
 
 	/*
 	 * Files marked append-only must be opened for appending.
@@ -1427,16 +1480,15 @@
 static int
 udf_access(struct vop_access_args *ap)
 {
-	struct vnode *vp;
-	struct udf_node *udf_node;
-	accmode_t accmode;
+	struct vnode *vp = ap->a_vp;
+	struct udf_node *udf_node = VTOI(vp);
+	accmode_t accmode = ap->a_accmode;
 	gid_t gid;
 	mode_t mode;
 	uid_t uid;
+	/* int flags = 0; */
 
-	vp = ap->a_vp;
-	udf_node = VTOI(vp);
-	accmode = ap->a_accmode;
+	DPRINTF(CALL, ("udf_access called\n"));
 
 	/* check if we are allowed to write */
 	switch (vp->v_type) {
@@ -1448,7 +1500,7 @@
 		 * filingsystem and bomb out if we're trying to write.
 		 */
 		if ((accmode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY))
-			return (EROFS); /* check that this works */
+			return (EROFS); 
 		break;
 	case VBLK:
 	case VCHR:
@@ -1466,8 +1518,7 @@
 
 	/* noone may write immutable files */
 	/* TODO: get chflags(2) flags from extened attribute. */
-#if 0
-	flags = 0;
+#if 0	
 	if ((mode & VWRITE) && (flags & IMMUTABLE))
 		return (EPERM);
 #endif
@@ -1796,14 +1847,14 @@
 	struct vnode *vp = ap->a_vp;
 	struct uio *uio = ap->a_uio;
 	struct pathcomp pathcomp;
-	struct udf_node *udf_node;
+	struct udf_node *udf_node = VTOI(vp);
 	int pathlen, targetlen, namelen, mntonnamelen, len, l_ci, filelen;
 	int first, error;
 	char *mntonname;
 	uint8_t *pathbuf, *targetbuf, *tmpname;
 	uint8_t *pathpos, *targetpos;
 
-	udf_node = VTOI(vp);
+	DPRINTF(CALL, ("udf_readlink called\n"));	
 
 	if (udf_node->efe)
 		filelen = le64toh(udf_node->efe->inf_len);
@@ -2407,9 +2458,13 @@
 }
 #endif
 
+/*
+ * File specific ioctls.
+ */
 static int
 udf_ioctl(struct vop_ioctl_args *ap)
 {
+	printf("%s called\n", __func__);
 	return (ENOTTY);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120710190450.651301065676>