CVS commit: src/sys/ufs/ffs

2021-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 14 07:24:14 UTC 2021

Modified Files:
src/sys/ufs/ffs: ffs_vnops.c

Log Message:
Hook up ffsext_strategy to fifos. Pointed out by dholland@


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/ufs/ffs/ffs_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vnops.c
diff -u src/sys/ufs/ffs/ffs_vnops.c:1.134 src/sys/ufs/ffs/ffs_vnops.c:1.135
--- src/sys/ufs/ffs/ffs_vnops.c:1.134	Tue Jun 29 18:34:09 2021
+++ src/sys/ufs/ffs/ffs_vnops.c	Wed Jul 14 03:24:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.134 2021/06/29 22:34:09 dholland Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.135 2021/07/14 07:24:14 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.134 2021/06/29 22:34:09 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.135 2021/07/14 07:24:14 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -261,7 +261,7 @@ const struct vnodeopv_entry_desc ffs_fif
 	{ _lock_desc, ufs_lock },			/* lock */
 	{ _unlock_desc, ufs_unlock },		/* unlock */
 	{ _bmap_desc, vn_fifo_bypass },		/* bmap */
-	{ _strategy_desc, vn_fifo_bypass },		/* strategy */
+	{ _strategy_desc, ffsext_strategy },	/* strategy */
 	{ _print_desc, ufs_print },			/* print */
 	{ _islocked_desc, ufs_islocked },		/* islocked */
 	{ _pathconf_desc, vn_fifo_bypass },		/* pathconf */



CVS commit: src/sys/ufs/ffs

2020-07-25 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Jul 26 00:20:14 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
skip the assertions about page-locking when allocating to the extattr bmap,
since extattrs do not use the page cache.


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.167 src/sys/ufs/ffs/ffs_alloc.c:1.168
--- src/sys/ufs/ffs/ffs_alloc.c:1.167	Sat Apr 18 19:18:34 2020
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Jul 26 00:20:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.167 2020/04/18 19:18:34 christos Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.168 2020/07/26 00:20:13 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.167 2020/04/18 19:18:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.168 2020/07/26 00:20:13 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -204,7 +204,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	 */
 
 	struct vnode *vp = ITOV(ip);
-	if (vp->v_type == VREG &&
+	if (vp->v_type == VREG && (flags & IO_EXT) == 0 &&
 	ffs_lblktosize(fs, (voff_t)lbn) < round_page(vp->v_size) &&
 	((vp->v_vflag & VV_MAPPED) != 0 || (size & PAGE_MASK) != 0 ||
 	 ffs_blkoff(fs, size) != 0)) {



CVS commit: src/sys/ufs/ffs

2020-07-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul  5 20:37:40 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
simplify the acl setup, and fix reversed mask in the fs_flags code.


To generate a diff of this commit:
cvs rdiff -u -r1.370 -r1.371 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.370 src/sys/ufs/ffs/ffs_vfsops.c:1.371
--- src/sys/ufs/ffs/ffs_vfsops.c:1.370	Mon May 18 04:28:44 2020
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jul  5 16:37:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.370 2020/05/18 08:28:44 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.371 2020/07/05 20:37:40 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.370 2020/05/18 08:28:44 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.371 2020/07/05 20:37:40 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -404,8 +404,8 @@ ffs_acls(struct mount *mp, int fs_flags)
 			printf("WARNING: %s: ACLs flag on fs conflicts with "
 			"\"posix1eacls\" mount option; option ignored\n",
 			mp->mnt_stat.f_mntonname);
-		mp->mnt_flag &= ~MNT_ACLS;
-		mp->mnt_flag |= MNT_POSIX1EACLS;
+		mp->mnt_flag &= ~MNT_POSIX1EACLS;
+		mp->mnt_flag |= MNT_ACLS;
 
 #else
 		printf("WARNING: %s: ACLs flag on fs but no ACLs support\n",
@@ -418,8 +418,8 @@ ffs_acls(struct mount *mp, int fs_flags)
 			printf("WARNING: %s: NFSv4 ACLs flag on fs conflicts "
 			"with \"acls\" mount option; option ignored\n",
 			mp->mnt_stat.f_mntonname);
-		mp->mnt_flag &= ~MNT_POSIX1EACLS;
-		mp->mnt_flag |= MNT_ACLS;
+		mp->mnt_flag &= ~MNT_ACLS;
+		mp->mnt_flag |= MNT_POSIX1EACLS;
 #else
 		printf("WARNING: %s: POSIX.1e ACLs flag on fs but no "
 		"ACLs support\n", mp->mnt_stat.f_mntonname);
@@ -658,14 +658,13 @@ ffs_mount(struct mount *mp, const char *
 			fs->fs_fmod = 0;
 		}
 
+		ffs_acls(mp, fs->fs_flags);
 		if (mp->mnt_flag & MNT_RELOAD) {
 			error = ffs_reload(mp, l->l_cred, l);
 			if (error) {
 DPRINTF("ffs_reload returned %d", error);
 return error;
 			}
-		} else {
-			ffs_acls(mp, 0);
 		}
 
 		if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
@@ -908,8 +907,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 	}
 	ffs_oldfscompat_read(fs, ump, sblockloc);
 
-	ffs_acls(mp, 0);
-
 	mutex_enter(>um_lock);
 	ump->um_maxfilesize = fs->fs_maxfilesize;
 	if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) {



CVS commit: src/sys/ufs/ffs

2020-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 20 13:16:30 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_extattr.c

Log Message:
remove accmode_t typedef (not needed, breaks llvm) from maxv@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/ufs/ffs/ffs_extattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.5 src/sys/ufs/ffs/ffs_extattr.c:1.6
--- src/sys/ufs/ffs/ffs_extattr.c:1.5	Sat May 16 14:31:53 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Wed May 20 09:16:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.5 2020/05/16 18:31:53 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.6 2020/05/20 13:16:30 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.5 2020/05/16 18:31:53 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.6 2020/05/20 13:16:30 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -121,7 +121,6 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_extattr.
 #define	lblkno(fs, o)		ffs_lblkno(fs, o)
 #define	blkoff(fs, o)		ffs_blkoff(fs, o)
 #define	sblksize(fs, o, lbn)	ffs_sblksize(fs, o, lbn)
-typedef mode_t accmode_t;	/* so that it breaks soon */
 typedef daddr_t ufs_lbn_t;
 #define msleep(chan, mtx, pri, wmesg, timeo) \
 mtsleep((chan), (pri), (wmesg), (timeo), *(mtx))



CVS commit: src/sys/ufs/ffs

2020-05-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat May  2 22:11:16 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_extattr.c ffs_inode.c

Log Message:
Remove the unlock/relock hack by using IO_EXT to indicate that we are already
holding the lock.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/ufs/ffs/ffs_extattr.c
cvs rdiff -u -r1.128 -r1.129 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.3 src/sys/ufs/ffs/ffs_extattr.c:1.4
--- src/sys/ufs/ffs/ffs_extattr.c:1.3	Mon Apr 20 14:10:10 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Sat May  2 18:11:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.4 2020/05/02 22:11:16 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.4 2020/05/02 22:11:16 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -392,10 +392,8 @@ ffs_extwrite(struct vnode *vp, struct ui
 	}
 	if (error) {
 		if (ioflag & IO_UNIT) {
-			genfs_node_unlock(vp);	// XXX: need our own lock
 			(void)ffs_truncate(vp, osize,
 			IO_EXT | (ioflag_SYNC), ucred);
-			genfs_node_wrlock(vp);
 			uio->uio_offset -= resid - uio->uio_resid;
 			uio->uio_resid = resid;
 		}
@@ -561,9 +559,7 @@ ffs_close_ea(struct vnode *vp, int commi
 ffs_unlock_ea(vp);
 return error;
 			}
-			genfs_node_unlock(vp);	// XXX: need our own lock
 			error = ffs_truncate(vp, 0, IO_EXT, cred);
-			genfs_node_wrlock(vp);
 			UFS_WAPBL_END(vp->v_mount);
 		}
 		error = ffs_extwrite(vp, , IO_EXT | IO_SYNC, cred);

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.128 src/sys/ufs/ffs/ffs_inode.c:1.129
--- src/sys/ufs/ffs/ffs_inode.c:1.128	Thu Apr 23 17:47:09 2020
+++ src/sys/ufs/ffs/ffs_inode.c	Sat May  2 18:11:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.128 2020/04/23 21:47:09 ad Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.129 2020/05/02 22:11:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.128 2020/04/23 21:47:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.129 2020/05/02 22:11:16 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -376,7 +376,8 @@ ffs_truncate(struct vnode *ovp, off_t le
 		}
 	}
 
-	genfs_node_wrlock(ovp);
+	if (!(ioflag & IO_EXT))
+		genfs_node_wrlock(ovp);
 	oip->i_size = length;
 	DIP_ASSIGN(oip, size, length);
 	uvm_vnp_setsize(ovp, length);
@@ -585,7 +586,8 @@ out:
 	oip->i_size = length;
 	DIP_ASSIGN(oip, size, length);
 	DIP_ADD(oip, blocks, -blocksreleased);
-	genfs_node_unlock(ovp);
+	if (!(ioflag & IO_EXT))
+		genfs_node_unlock(ovp);
 	oip->i_flag |= IN_CHANGE;
 	UFS_WAPBL_UPDATE(ovp, NULL, NULL, 0);
 #if defined(QUOTA) || defined(QUOTA2)



CVS commit: src/sys/ufs/ffs

2020-04-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 21 15:04:13 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_subr.c

Log Message:
use %s/__func__ so that the strings can be shared.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/ufs/ffs/ffs_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_subr.c
diff -u src/sys/ufs/ffs/ffs_subr.c:1.51 src/sys/ufs/ffs/ffs_subr.c:1.52
--- src/sys/ufs/ffs/ffs_subr.c:1.51	Mon May 27 23:53:28 2019
+++ src/sys/ufs/ffs/ffs_subr.c	Tue Apr 21 11:04:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_subr.c,v 1.51 2019/05/28 03:53:28 kamil Exp $	*/
+/*	$NetBSD: ffs_subr.c,v 1.52 2020/04/21 15:04:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.51 2019/05/28 03:53:28 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.52 2020/04/21 15:04:12 christos Exp $");
 
 #include 
 
@@ -195,7 +195,7 @@ ffs_isblock(struct fs *fs, u_char *cp, i
 		mask = 0x01 << (h & 0x7);
 		return ((cp[h >> 3] & mask) == mask);
 	default:
-		panic("ffs_isblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }
@@ -219,7 +219,7 @@ ffs_isfreeblock(struct fs *fs, u_char *c
 	case 0:
 		return ((cp[h >> 3] & (0x01 << (h & 0x7))) == 0);
 	default:
-		panic("ffs_isfreeblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }
@@ -245,7 +245,7 @@ ffs_clrblock(struct fs *fs, u_char *cp, 
 		cp[h >> 3] &= ~(0x01 << (h & 0x7));
 		return;
 	default:
-		panic("ffs_clrblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }
@@ -271,7 +271,7 @@ ffs_setblock(struct fs *fs, u_char *cp, 
 		cp[h >> 3] |= (0x01 << (h & 0x7));
 		return;
 	default:
-		panic("ffs_setblock: unknown fs_fragshift %d",
+		panic("%s: unknown fs_fragshift %d", __func__,
 		(int)fs->fs_fragshift);
 	}
 }



CVS commit: src/sys/ufs/ffs

2020-04-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 20 18:10:10 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_extattr.c

Log Message:
- Allow root to set system attributes, samba does this
- Fix locking issue, perhaps we should use our own mutex; does not seem worth
  it for this simple case.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/ffs/ffs_extattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.2 src/sys/ufs/ffs/ffs_extattr.c:1.3
--- src/sys/ufs/ffs/ffs_extattr.c:1.2	Sun Apr 19 09:59:13 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Mon Apr 20 14:10:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.3 2020/04/20 18:10:10 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -153,8 +153,8 @@ ffs_extattr_check_cred(struct vnode *vp,
 	 */
 	switch (attrnamespace) {
 	case EXTATTR_NAMESPACE_SYSTEM:
-		/* Potentially with privs */
-		return EPERM;
+		return kauth_authorize_system(cred, KAUTH_SYSTEM_FS_EXTATTR,
+		0, vp->v_mount, NULL, NULL);
 	case EXTATTR_NAMESPACE_USER:
 		return VOP_ACCESS(vp, accmode, cred);
 	default:
@@ -392,8 +392,10 @@ ffs_extwrite(struct vnode *vp, struct ui
 	}
 	if (error) {
 		if (ioflag & IO_UNIT) {
+			genfs_node_unlock(vp);	// XXX: need our own lock
 			(void)ffs_truncate(vp, osize,
 			IO_EXT | (ioflag_SYNC), ucred);
+			genfs_node_wrlock(vp);
 			uio->uio_offset -= resid - uio->uio_resid;
 			uio->uio_resid = resid;
 		}
@@ -559,7 +561,9 @@ ffs_close_ea(struct vnode *vp, int commi
 ffs_unlock_ea(vp);
 return error;
 			}
+			genfs_node_unlock(vp);	// XXX: need our own lock
 			error = ffs_truncate(vp, 0, IO_EXT, cred);
+			genfs_node_wrlock(vp);
 			UFS_WAPBL_END(vp->v_mount);
 		}
 		error = ffs_extwrite(vp, , IO_EXT | IO_SYNC, cred);
@@ -935,7 +939,6 @@ ffs_deleteextattr(void *v)
 	error = ffs_extattr_check_cred(ap->a_vp, ap->a_attrnamespace,
 	ap->a_cred, VWRITE);
 	if (error) {
-
 		/*
 		 * ffs_lock_ea is not needed there, because the vnode
 		 * must be exclusively locked.



CVS commit: src/sys/ufs/ffs

2020-04-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 19 13:59:13 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_extattr.c

Log Message:
- add locking
- wrap wapbl around truncating, ffs_extwrite does it on its own.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/ufs/ffs/ffs_extattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_extattr.c
diff -u src/sys/ufs/ffs/ffs_extattr.c:1.1 src/sys/ufs/ffs/ffs_extattr.c:1.2
--- src/sys/ufs/ffs/ffs_extattr.c:1.1	Sat Apr 18 15:18:34 2020
+++ src/sys/ufs/ffs/ffs_extattr.c	Sun Apr 19 09:59:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extattr.c,v 1.1 2020/04/18 19:18:34 christos Exp $	*/
+/*	$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.1 2020/04/18 19:18:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.2 2020/04/19 13:59:13 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -478,34 +478,13 @@ ffs_rdextattr(u_char **p, struct vnode *
 static void
 ffs_lock_ea(struct vnode *vp)
 {
-#if 0
-	struct inode *ip;
-
-	ip = VTOI(vp);
-	VI_LOCK(vp);
-	while (ip->i_flag & IN_EA_LOCKED) {
-		UFS_INODE_SET_FLAG(ip, IN_EA_LOCKWAIT);
-		msleep(>i_ea_refs, >v_interlock, PINOD + 2, "ufs_ea",
-		0);
-	}
-	UFS_INODE_SET_FLAG(ip, IN_EA_LOCKED);
-	VI_UNLOCK(vp);
-#endif
+	genfs_node_wrlock(vp);
 }
 
 static void
 ffs_unlock_ea(struct vnode *vp)
 {
-#if 0
-	struct inode *ip;
-
-	ip = VTOI(vp);
-	VI_LOCK(vp);
-	if (ip->i_flag & IN_EA_LOCKWAIT)
-		wakeup(>i_ea_refs);
-	ip->i_flag &= ~(IN_EA_LOCKED | IN_EA_LOCKWAIT);
-	VI_UNLOCK(vp);
-#endif
+	genfs_node_unlock(vp);
 }
 
 static int
@@ -573,16 +552,17 @@ ffs_close_ea(struct vnode *vp, int commi
 		luio.uio_resid = ip->i_ea_len;
 		luio.uio_vmspace = vmspace_kernel();
 		luio.uio_rw = UIO_WRITE;
-		if ((error = UFS_WAPBL_BEGIN(vp->v_mount)) != 0) {
-			ffs_unlock_ea(vp);
-			return error;
-		}
 
 		/* XXX: I'm not happy about truncating to zero size */
-		if (ip->i_ea_len < dp->di_extsize)
+		if (ip->i_ea_len < dp->di_extsize) {
+			if ((error = UFS_WAPBL_BEGIN(vp->v_mount)) != 0) {
+ffs_unlock_ea(vp);
+return error;
+			}
 			error = ffs_truncate(vp, 0, IO_EXT, cred);
+			UFS_WAPBL_END(vp->v_mount);
+		}
 		error = ffs_extwrite(vp, , IO_EXT | IO_SYNC, cred);
-		UFS_WAPBL_END(vp->v_mount);
 	}
 	if (--ip->i_ea_refs == 0) {
 		free(ip->i_ea_area, M_TEMP);



CVS commit: src/sys/ufs/ffs

2020-02-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 18 17:50:32 UTC 2020

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Fix non-DIAGNOSTIC build with UVM_PAGE_TRKOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.164 src/sys/ufs/ffs/ffs_alloc.c:1.165
--- src/sys/ufs/ffs/ffs_alloc.c:1.164	Sun Apr 14 15:55:24 2019
+++ src/sys/ufs/ffs/ffs_alloc.c	Tue Feb 18 17:50:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.165 2020/02/18 17:50:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.165 2020/02/18 17:50:32 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -208,7 +208,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	ffs_lblktosize(fs, (voff_t)lbn) < round_page(vp->v_size) &&
 	((vp->v_vflag & VV_MAPPED) != 0 || (size & PAGE_MASK) != 0 ||
 	 ffs_blkoff(fs, size) != 0)) {
-		struct vm_page *pg;
+		struct vm_page *pg __diagused;
 		struct uvm_object *uobj = >v_uobj;
 		voff_t off = trunc_page(ffs_lblktosize(fs, lbn));
 		voff_t endoff = round_page(ffs_lblktosize(fs, lbn) + size);
@@ -328,7 +328,7 @@ ffs_realloccg(struct inode *ip, daddr_t 
 	 */
 
 	if (ITOV(ip)->v_type == VREG) {
-		struct vm_page *pg;
+		struct vm_page *pg __diagused;
 		struct uvm_object *uobj = (ip)->v_uobj;
 		voff_t off = trunc_page(ffs_lblktosize(fs, lbprev));
 		voff_t endoff = round_page(ffs_lblktosize(fs, lbprev) + osize);



CVS commit: src/sys/ufs/ffs

2019-04-14 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Sun Apr 14 15:55:24 UTC 2019

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
PR/53990, PR/52380, PR/52102: UFS2 cylinder group inode allocation botch

Fix rare allocation botch in ffs_nodealloccg().

Conditions:
   a) less than
#_of_initialized_inodes(cg->cg_initediblk)
- inodes_per_filesystem_block
  are allocated in the cylinder group
   b) cg->cg_irotor points to a uninterupted run of
  allocated inodes in the inode bitmap up to the
  end of dynamically initialized inodes
  (cg->cg_initediblk)

In this case the next inode after this run was returned
without initializing the respective inode block. As the
block is not initialized these inodes could trigger panics
on inode consistency due to old (uninitialized) disk data.

In very rare cases data loss could occur when
the uninitialized inode block is initialized via the
normal mechanism.
Further conditions to occur after the above:
   c) no panic
   d) no (forced) fsck
   e) and more than cg->cg_initediblk - inodes_per_filesystem_block
  allocated inodes.

Fix:
Always insure allocation always in initialized inode range
extending the initialized inode range as needed.

Add KASSERTMSG() safeguards.

ok hannken@


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.163 src/sys/ufs/ffs/ffs_alloc.c:1.164
--- src/sys/ufs/ffs/ffs_alloc.c:1.163	Mon Dec 10 20:48:34 2018
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Apr 14 15:55:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.163 2018/12/10 20:48:34 jdolecek Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.163 2018/12/10 20:48:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.164 2019/04/14 15:55:24 kardel Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1259,7 +1259,7 @@ ffs_nodealloccg(struct inode *ip, int cg
 	struct buf *bp, *ibp;
 	u_int8_t *inosused;
 	int error, start, len, loc, map, i;
-	int32_t initediblk;
+	int32_t initediblk, maxiblk, irotor;
 	daddr_t nalloc;
 	struct ufs2_dinode *dp2;
 	const int needswap = UFS_FSNEEDSWAP(fs);
@@ -1271,7 +1271,13 @@ ffs_nodealloccg(struct inode *ip, int cg
 		return (0);
 	mutex_exit(>um_lock);
 	ibp = NULL;
-	initediblk = -1;
+	if (fs->fs_magic == FS_UFS2_MAGIC) {
+		initediblk = -1;
+	} else {
+		initediblk = fs->fs_ipg;
+	}
+	maxiblk = initediblk;
+
 retry:
 	error = bread(ip->i_devvp, FFS_FSBTODB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, B_MODIFY, );
@@ -1291,7 +1297,8 @@ retry:
 	 * Check to see if we need to initialize more inodes.
 	 */
 	if (fs->fs_magic == FS_UFS2_MAGIC && ibp == NULL) {
-		initediblk = ufs_rw32(cgp->cg_initediblk, needswap);
+	initediblk = ufs_rw32(cgp->cg_initediblk, needswap);
+		maxiblk = initediblk;
 		nalloc = fs->fs_ipg - ufs_rw32(cgp->cg_cs.cs_nifree, needswap);
 		if (nalloc + FFS_INOPB(fs) > initediblk &&
 		initediblk < ufs_rw32(cgp->cg_niblk, needswap)) {
@@ -1307,6 +1314,9 @@ retry:
 			FFS_NOBLK, fs->fs_bsize, false, );
 			if (error)
 goto fail;
+
+			maxiblk += FFS_INOPB(fs);
+			
 			goto retry;
 		}
 	}
@@ -1316,14 +1326,22 @@ retry:
 	(fs->fs_old_flags & FS_FLAGS_UPDATED))
 		cgp->cg_time = ufs_rw64(time_second, needswap);
 	inosused = cg_inosused(cgp, needswap);
+	
 	if (ipref) {
 		ipref %= fs->fs_ipg;
-		if (isclr(inosused, ipref))
+		/* safeguard to stay in (to be) allocated range */
+		if (ipref < maxiblk && isclr(inosused, ipref))
 			goto gotit;
 	}
-	start = ufs_rw32(cgp->cg_irotor, needswap) / NBBY;
-	len = howmany(fs->fs_ipg - ufs_rw32(cgp->cg_irotor, needswap),
-		NBBY);
+
+	irotor = ufs_rw32(cgp->cg_irotor, needswap); 
+
+	KASSERTMSG(irotor < initediblk, "%s: allocation botch: cg=%d, irotor %d"
+		   " out of bounds, initediblk=%d",
+		   __func__, cg, irotor, initediblk);
+
+	start = irotor / NBBY;
+	len = howmany(maxiblk - irotor, NBBY);
 	loc = skpc(0xff, len, [start]);
 	if (loc == 0) {
 		len = start + 1;
@@ -1341,9 +1359,17 @@ retry:
 	if (map == 0) {
 		panic("%s: block not in map: fs=%s", __func__, fs->fs_fsmnt);
 	}
+	
 	ipref = i * NBBY + ffs(map) - 1;
+
 	cgp->cg_irotor = ufs_rw32(ipref, needswap);
+
 gotit:
+	KASSERTMSG(ipref < maxiblk, "%s: allocation botch: cg=%d attempt to "
+		   "allocate inode index %d beyond max allocated index %d"
+		   " of %d inodes/cg",
+		   __func__, cg, (int)ipref, maxiblk, cgp->cg_niblk);
+
 	UFS_WAPBL_REGISTER_INODE(ip->i_ump->um_mountp, cg * fs->fs_ipg + ipref,
 	mode);
 	/*



CVS commit: src/sys/ufs/ffs

2018-07-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jul 19 05:09:34 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Avoid using magic numbers for arguments of workqueue_create (NFC)


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.159 src/sys/ufs/ffs/ffs_alloc.c:1.160
--- src/sys/ufs/ffs/ffs_alloc.c:1.159	Thu Dec  7 21:53:41 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Thu Jul 19 05:09:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.160 2018/07/19 05:09:34 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.160 2018/07/19 05:09:34 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1641,7 +1641,7 @@ ffs_discard_init(struct vnode *devvp, st
 
 	ts = kmem_zalloc(sizeof (*ts), KM_SLEEP);
 	error = workqueue_create(>wq, "trimwq", ffs_discardcb, ts,
- 0, 0, 0);
+ PRI_USER, IPL_NONE, 0);
 	if (error) {
 		kmem_free(ts, sizeof (*ts));
 		return NULL;



CVS commit: src/sys/ufs/ffs

2018-07-18 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jul 18 22:40:56 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate - check fs_old_size too.

Now I can mount OpenWindows Version 3 CD from 1991.


To generate a diff of this commit:
cvs rdiff -u -r1.357 -r1.358 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.357 src/sys/ufs/ffs/ffs_vfsops.c:1.358
--- src/sys/ufs/ffs/ffs_vfsops.c:1.357	Mon May 28 21:04:38 2018
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Jul 18 22:40:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.357 2018/05/28 21:04:38 chs Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.358 2018/07/18 22:40:56 uwe Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.357 2018/05/28 21:04:38 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.358 2018/07/18 22:40:56 uwe Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -971,7 +971,7 @@ ffs_superblock_validate(struct fs *fs)
 	 * XXX: these values are just zero-checked to prevent obvious
 	 * bugs. We need more strict checks.
 	 */
-	if (fs->fs_size == 0)
+	if (fs->fs_size == 0 && fs->fs_old_size == 0)
 		return 0;
 	if (fs->fs_cssize == 0)
 		return 0;



CVS commit: src/sys/ufs/ffs

2018-07-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jul  4 02:02:15 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_subr.c

Log Message:
Avoid Undefined Behavior in ffs_clusteracct()

Change the type of 'bit' variable from int to unsigned int and use unsigned
values consistently.

sys/ufs/ffs/ffs_subr.c:336:10, shift exponent -1 is negative

Detected with Kernel Undefined Behavior Sanitizer.

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/ufs/ffs/ffs_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_subr.c
diff -u src/sys/ufs/ffs/ffs_subr.c:1.49 src/sys/ufs/ffs/ffs_subr.c:1.50
--- src/sys/ufs/ffs/ffs_subr.c:1.49	Sat May  7 11:59:08 2016
+++ src/sys/ufs/ffs/ffs_subr.c	Wed Jul  4 02:02:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $	*/
+/*	$NetBSD: ffs_subr.c,v 1.50 2018/07/04 02:02:15 kamil Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.50 2018/07/04 02:02:15 kamil Exp $");
 
 #include 
 
@@ -287,7 +287,8 @@ ffs_clusteracct(struct fs *fs, struct cg
 	int32_t *sump;
 	int32_t *lp;
 	u_char *freemapp, *mapp;
-	int i, start, end, forw, back, map, bit;
+	int i, start, end, forw, back, map;
+	unsigned int bit;
 	const int needswap = UFS_FSNEEDSWAP(fs);
 
 	/* KASSERT(mutex_owned(>um_lock)); */
@@ -312,7 +313,7 @@ ffs_clusteracct(struct fs *fs, struct cg
 		end = ufs_rw32(cgp->cg_nclusterblks, needswap);
 	mapp = [start / NBBY];
 	map = *mapp++;
-	bit = 1 << (start % NBBY);
+	bit = 1U << (start % NBBY);
 	for (i = start; i < end; i++) {
 		if ((map & bit) == 0)
 			break;
@@ -333,7 +334,7 @@ ffs_clusteracct(struct fs *fs, struct cg
 		end = -1;
 	mapp = [start / NBBY];
 	map = *mapp--;
-	bit = 1 << (start % NBBY);
+	bit = 1U << (start % NBBY);
 	for (i = start; i > end; i--) {
 		if ((map & bit) == 0)
 			break;
@@ -341,7 +342,7 @@ ffs_clusteracct(struct fs *fs, struct cg
 			bit >>= 1;
 		} else {
 			map = *mapp--;
-			bit = 1 << (NBBY - 1);
+			bit = 1U << (NBBY - 1);
 		}
 	}
 	back = start - i;



CVS commit: src/sys/ufs/ffs

2018-01-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jan 28 10:02:01 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Prevent use-after-free where genfs_node_destroy() would destroy
a lock residing in the just freed inode data.


To generate a diff of this commit:
cvs rdiff -u -r1.355 -r1.356 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.355 src/sys/ufs/ffs/ffs_vfsops.c:1.356
--- src/sys/ufs/ffs/ffs_vfsops.c:1.355	Wed Nov 15 21:21:18 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jan 28 10:02:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.356 2018/01/28 10:02:00 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.356 2018/01/28 10:02:00 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2024,14 +2024,14 @@ ffs_deinit_vnode(struct ufsmount *ump, s
 {
 	struct inode *ip = VTOI(vp);
 
+	genfs_node_destroy(vp);
+	vp->v_data = NULL;
+
 	if (ump->um_fstype == UFS1)
 		pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
 	else
 		pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
 	pool_cache_put(ffs_inode_cache, ip);
-
-	genfs_node_destroy(vp);
-	vp->v_data = NULL;
 }
 
 /*



CVS commit: src/sys/ufs/ffs

2017-12-07 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Thu Dec  7 21:53:41 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
fix the UVM_PAGE_TRKOWN page-locking assertion at the top of ffs_alloc()
to work right for multi-threaded processes.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.158 src/sys/ufs/ffs/ffs_alloc.c:1.159
--- src/sys/ufs/ffs/ffs_alloc.c:1.158	Sun Aug 13 21:00:58 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Thu Dec  7 21:53:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -203,10 +203,12 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	 * be locked by the current thread.
 	 */
 
-	if (ITOV(ip)->v_type == VREG &&
-	ffs_lblktosize(fs, (voff_t)lbn) < round_page(ITOV(ip)->v_size)) {
+	struct vnode *vp = ITOV(ip);
+	if (vp->v_type == VREG &&
+	ffs_lblktosize(fs, (voff_t)lbn) < round_page(vp->v_size) &&
+	((vp->v_vflag & VV_MAPPED) != 0 || (size & PAGE_MASK) != 0 ||
+	 ffs_blkoff(fs, size) != 0)) {
 		struct vm_page *pg;
-		struct vnode *vp = ITOV(ip);
 		struct uvm_object *uobj = >v_uobj;
 		voff_t off = trunc_page(ffs_lblktosize(fs, lbn));
 		voff_t endoff = round_page(ffs_lblktosize(fs, lbn) + size);
@@ -214,10 +216,8 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 		mutex_enter(uobj->vmobjlock);
 		while (off < endoff) {
 			pg = uvm_pagelookup(uobj, off);
-			KASSERT((pg == NULL && (vp->v_vflag & VV_MAPPED) == 0 &&
- (size & PAGE_MASK) == 0 && 
- ffs_blkoff(fs, size) == 0) ||
-(pg != NULL && pg->owner == curproc->p_pid &&
+			KASSERT((pg != NULL && pg->owner_tag != NULL &&
+ pg->owner == curproc->p_pid &&
  pg->lowner == curlwp->l_lid));
 			off += PAGE_SIZE;
 		}



CVS commit: src/sys/ufs/ffs

2017-11-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 15 21:21:18 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
PR/52728: Izumi Tsutsui: "mount -u /dev/ /" triggers kernel panic
Simplify the control flow of the mount code and make sure that the
mountfrom argument can be converted to a block device in the update
case.
XXX: pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.354 -r1.355 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.354 src/sys/ufs/ffs/ffs_vfsops.c:1.355
--- src/sys/ufs/ffs/ffs_vfsops.c:1.354	Sun Aug 20 08:51:38 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Nov 15 16:21:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.355 2017/11/15 21:21:18 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -418,12 +418,13 @@ ffs_mount(struct mount *mp, const char *
 		return EINVAL;
 	}
 
+	ump = VFSTOUFS(mp);
+	if ((mp->mnt_flag & (MNT_GETARGS|MNT_UPDATE)) && ump == NULL) {
+		DPRINTF("no ump");
+		return EIO;
+	}
+
 	if (mp->mnt_flag & MNT_GETARGS) {
-		ump = VFSTOUFS(mp);
-		if (ump == NULL) {
-			DPRINTF("no ump");
-			return EIO;
-		}
 		args->fspec = NULL;
 		*data_len = sizeof *args;
 		return 0;
@@ -432,7 +433,13 @@ ffs_mount(struct mount *mp, const char *
 	update = mp->mnt_flag & MNT_UPDATE;
 
 	/* Check arguments */
-	if (args->fspec != NULL) {
+	if (args->fspec == NULL) {
+		if (!update) {
+			/* New mounts must have a filename for the device */
+			DPRINTF("no filename for mount");
+			return EINVAL;
+		}
+	} else {
 		/*
 		 * Look up the name and verify that it's sane.
 		 */
@@ -443,48 +450,43 @@ ffs_mount(struct mount *mp, const char *
 			return error;
 		}
 
-		if (!update) {
-			/*
-			 * Be sure this is a valid block device
-			 */
-			if (devvp->v_type != VBLK) {
-DPRINTF("non block device %d", devvp->v_type);
-error = ENOTBLK;
-			} else if (bdevsw_lookup(devvp->v_rdev) == NULL) {
-DPRINTF("can't find block device 0x%jx",
-devvp->v_rdev);
-error = ENXIO;
-			}
-		} else {
+		/*
+		 * Be sure this is a valid block device
+		 */
+		if (devvp->v_type != VBLK) {
+			DPRINTF("non block device %d", devvp->v_type);
+			error = ENOTBLK;
+			goto fail;
+		}
+
+		if (bdevsw_lookup(devvp->v_rdev) == NULL) {
+			DPRINTF("can't find block device 0x%jx",
+			devvp->v_rdev);
+			error = ENXIO;
+			goto fail;
+		}
+
+		if (update) {
 			/*
 			 * Be sure we're still naming the same device
 			 * used for our initial mount
 			 */
-			ump = VFSTOUFS(mp);
-			if (devvp != ump->um_devvp) {
-if (devvp->v_rdev != ump->um_devvp->v_rdev) {
-	DPRINTF("wrong device 0x%jx != 0x%jx",
-	(uintmax_t)devvp->v_rdev,
-	(uintmax_t)ump->um_devvp->v_rdev);
-	error = EINVAL;
-} else {
-	vrele(devvp);
-	devvp = ump->um_devvp;
-	vref(devvp);
-}
+			if (devvp != ump->um_devvp &&
+			devvp->v_rdev != ump->um_devvp->v_rdev) {
+DPRINTF("wrong device 0x%jx != 0x%jx",
+(uintmax_t)devvp->v_rdev,
+(uintmax_t)ump->um_devvp->v_rdev);
+error = EINVAL;
+goto fail;
 			}
+			vrele(devvp);
+			devvp = NULL;
 		}
-	} else {
-		if (!update) {
-			/* New mounts must have a filename for the device */
-			DPRINTF("no filename for mount");
-			return EINVAL;
-		} else {
-			/* Use the extant mount */
-			ump = VFSTOUFS(mp);
-			devvp = ump->um_devvp;
-			vref(devvp);
-		}
+	}
+
+	if (devvp == NULL) {
+		devvp = ump->um_devvp;
+		vref(devvp);
 	}
 
 	/*
@@ -495,25 +497,17 @@ ffs_mount(struct mount *mp, const char *
 	 * updating the mount is okay (for example, as far as securelevel goes)
 	 * which leaves us with the normal check.
 	 */
-	if (error == 0) {
-		accessmode = VREAD;
-		if (update ?
-		(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
-		(mp->mnt_flag & MNT_RDONLY) == 0)
-			accessmode |= VWRITE;
-		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
-		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
-		KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
-		KAUTH_ARG(accessmode));
-		if (error) {
-			DPRINTF("kauth returned %d", error);
-		}
-		VOP_UNLOCK(devvp);
-	}
-
+	accessmode = VREAD;
+	if (update ? (mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
+	(mp->mnt_flag & MNT_RDONLY) == 0)
+		accessmode |= VWRITE;
+	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
+	error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
+	KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(accessmode));
+	VOP_UNLOCK(devvp);
 	if (error) {
-		

CVS commit: src/sys/ufs/ffs

2017-08-20 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Aug 20 12:51:39 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
print mode as octal for readability


To generate a diff of this commit:
cvs rdiff -u -r1.353 -r1.354 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.353 src/sys/ufs/ffs/ffs_vfsops.c:1.354
--- src/sys/ufs/ffs/ffs_vfsops.c:1.353	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Aug 20 12:51:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.353 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.353 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.354 2017/08/20 12:51:38 maya Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2132,7 +2132,7 @@ ffs_newvnode(struct mount *mp, struct vn
 
 	ip = VTOI(vp);
 	if (ip->i_mode) {
-		panic("%s: dup alloc ino=%" PRId64 " on %s: mode %x/%x "
+		panic("%s: dup alloc ino=%" PRId64 " on %s: mode %o/%o "
 		"gen %x/%x size %" PRIx64 " blocks %" PRIx64,
 		__func__, ino, fs->fs_fsmnt, DIP(ip, mode), ip->i_mode,
 		DIP(ip, gen), ip->i_gen, DIP(ip, size), DIP(ip, blocks));



CVS commit: src/sys/ufs/ffs

2017-08-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Aug 13 21:00:58 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Don't time out the discard work queue here. Either destroying a work queue
with pending work items panics or accessing freed resources from the work
item will crash. The timeout needs to be handled gracefully by the driver
that implements the discard operation.

Fixes parts of PR 50725.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.157 src/sys/ufs/ffs/ffs_alloc.c:1.158
--- src/sys/ufs/ffs/ffs_alloc.c:1.157	Wed Jul 12 09:30:16 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Aug 13 21:00:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.158 2017/08/13 21:00:58 mlelstv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1659,17 +1659,14 @@ ffs_discard_finish(void *vts, int flags)
 {
 	struct discarddata *ts = vts;
 	struct discardopdata *td = NULL;
-	int res = 0;
 
 	/* wait for workqueue to drain */
 	mutex_enter(>wqlk);
 	if (ts->wqcnt) {
 		ts->wqdraining = 1;
-		res = cv_timedwait(>wqcv, >wqlk, mstohz(5000));
+		cv_wait(>wqcv, >wqlk);
 	}
 	mutex_exit(>wqlk);
-	if (res)
-		printf("ffs_discarddata drain timeout\n");
 
 	mutex_enter(>entrylk);
 	if (ts->entry) {



CVS commit: src/sys/ufs/ffs

2017-07-12 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Jul 12 09:30:16 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
When initializing more inodes make sure to write them to disk
before writing the cylinder group with updated cg_initediblk.


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.156 src/sys/ufs/ffs/ffs_alloc.c:1.157
--- src/sys/ufs/ffs/ffs_alloc.c:1.156	Sat Mar 18 05:20:04 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Wed Jul 12 09:30:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.157 2017/07/12 09:30:16 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1379,8 +1379,8 @@ gotit:
 	}
 	mutex_exit(>um_lock);
 	if (ibp != NULL) {
+		bwrite(ibp);
 		bwrite(bp);
-		bawrite(ibp);
 	} else
 		bdwrite(bp);
 	return (cg * fs->fs_ipg + ipref);



CVS commit: src/sys/ufs/ffs

2017-05-28 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun May 28 16:37:55 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
No need to call vgone() on the just created in file system log vnode,
vput() is sufficient.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.40 src/sys/ufs/ffs/ffs_wapbl.c:1.41
--- src/sys/ufs/ffs/ffs_wapbl.c:1.40	Wed Mar 22 21:30:59 2017
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sun May 28 16:37:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.40 2017/03/22 21:30:59 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.41 2017/05/28 16:37:55 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.40 2017/03/22 21:30:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.41 2017/05/28 16:37:55 hannken Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -686,8 +686,7 @@ wapbl_create_infs_log(struct mount *mp, 
 		 */
 		ip->i_nlink = 0;
 		DIP_ASSIGN(ip, nlink, 0);
-		VOP_UNLOCK(vp);
-		vgone(vp);
+		vput(vp);
 
 		return error;
 	}
@@ -696,8 +695,7 @@ wapbl_create_infs_log(struct mount *mp, 
 	 * Now that we have the place-holder inode for the journal,
 	 * we don't need the vnode ever again.
 	 */
-	VOP_UNLOCK(vp);
-	vgone(vp);
+	vput(vp);
 
 	return 0;
 }



CVS commit: src/sys/ufs/ffs

2017-03-22 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Mar 22 21:31:00 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
move the ffs_sync() after wapbl_log_position() call, since that can still
create delayed writes with MNT_ASYNC when log is created


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.39 src/sys/ufs/ffs/ffs_wapbl.c:1.40
--- src/sys/ufs/ffs/ffs_wapbl.c:1.39	Thu Mar 16 22:09:19 2017
+++ src/sys/ufs/ffs/ffs_wapbl.c	Wed Mar 22 21:30:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.39 2017/03/16 22:09:19 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.40 2017/03/22 21:30:59 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.39 2017/03/16 22:09:19 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.40 2017/03/22 21:30:59 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -338,6 +338,11 @@ ffs_wapbl_start(struct mount *mp)
 return EINVAL;
 			}
 
+			error = wapbl_log_position(mp, fs, devvp, ,
+			, , );
+			if (error)
+return error;
+
 			/*
 			 * Make sure we don't carry over any delayed write
 			 * buffers when updating to log. Need to turn off
@@ -351,11 +356,6 @@ ffs_wapbl_start(struct mount *mp)
 mp->mnt_flag |= saveflag;
 			}
 
-			error = wapbl_log_position(mp, fs, devvp, ,
-			, , );
-			if (error)
-return error;
-
 			error = wapbl_start(>mnt_wapbl, mp, devvp, off,
 			count, blksize, mp->mnt_wapbl_replay,
 			ffs_wapbl_sync_metadata,



CVS commit: src/sys/ufs/ffs

2017-03-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 18 05:29:16 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_snapshot.c

Log Message:
#if DIAGNOSTIC panic ---> KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/ufs/ffs/ffs_snapshot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.146 src/sys/ufs/ffs/ffs_snapshot.c:1.147
--- src/sys/ufs/ffs/ffs_snapshot.c:1.146	Wed Mar  1 10:42:45 2017
+++ src/sys/ufs/ffs/ffs_snapshot.c	Sat Mar 18 05:29:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.146 2017/03/01 10:42:45 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.147 2017/03/18 05:29:16 riastradh Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.146 2017/03/01 10:42:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.147 2017/03/18 05:29:16 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1993,10 +1993,9 @@ retry:
 			if (gen != si->si_gen)
 goto retry;
 		}
-#ifdef DIAGNOSTIC
-		if (blkno == BLK_SNAP && bp->b_lblkno >= 0)
-			panic("ffs_copyonwrite: bad copy block");
-#endif
+		KASSERTMSG((blkno != BLK_SNAP || bp->b_lblkno < 0),
+		"ffs_copyonwrite: bad copy block: blkno %jd, lblkno %jd",
+		(intmax_t)blkno, (intmax_t)bp->b_lblkno);
 		if (blkno != 0)
 			continue;
 



CVS commit: src/sys/ufs/ffs

2017-03-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 18 05:26:40 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_inode.c

Log Message:
#if DIAGNOSTIC panic ---> KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.123 src/sys/ufs/ffs/ffs_inode.c:1.124
--- src/sys/ufs/ffs/ffs_inode.c:1.123	Fri Nov 11 10:50:16 2016
+++ src/sys/ufs/ffs/ffs_inode.c	Sat Mar 18 05:26:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.123 2016/11/11 10:50:16 hannken Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.124 2017/03/18 05:26:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.123 2016/11/11 10:50:16 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.124 2017/03/18 05:26:40 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -527,17 +527,19 @@ ffs_truncate(struct vnode *ovp, off_t le
 	}
 
 done:
-#ifdef DIAGNOSTIC
 	for (level = SINGLE; level <= TRIPLE; level++)
-		if (blks[UFS_NDADDR + level] != DIP(oip, ib[level]))
-			panic("itrunc1");
+		KASSERTMSG((blks[UFS_NDADDR + level] == DIP(oip, ib[level])),
+		"itrunc1 blk mismatch: %jx != %jx",
+		(uintmax_t)blks[UFS_NDADDR + level],
+		(uintmax_t)DIP(oip, ib[level]));
 	for (i = 0; i < UFS_NDADDR; i++)
-		if (blks[i] != DIP(oip, db[i]))
-			panic("itrunc2");
-	if (length == 0 &&
-	(!LIST_EMPTY(>v_cleanblkhd) || !LIST_EMPTY(>v_dirtyblkhd)))
-		panic("itrunc3");
-#endif /* DIAGNOSTIC */
+		KASSERTMSG((blks[i] == DIP(oip, db[i])),
+		"itrunc2 blk mismatch: %jx != %jx",
+		(uintmax_t)blks[i], (uintmax_t)DIP(oip, db[i]));
+	KASSERTMSG((length != 0 || LIST_EMPTY(>v_cleanblkhd)),
+	"itrunc3: zero length and nonempty cleanblkhd");
+	KASSERTMSG((length != 0 || LIST_EMPTY(>v_dirtyblkhd)),
+	"itrunc3: zero length and nonempty dirtyblkhd");
 
 out:
 	/*



CVS commit: src/sys/ufs/ffs

2017-03-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 18 05:20:04 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
#if DIAGNOSTIC panic ---> KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.155 src/sys/ufs/ffs/ffs_alloc.c:1.156
--- src/sys/ufs/ffs/ffs_alloc.c:1.155	Wed Mar  1 10:42:45 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Sat Mar 18 05:20:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.155 2017/03/01 10:42:45 hannken Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.155 2017/03/01 10:42:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.156 2017/03/18 05:20:04 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -226,15 +226,15 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 #endif
 
 	*bnp = 0;
-#ifdef DIAGNOSTIC
-	if (cred == NOCRED)
-		panic("%s: missing credential", __func__);
-	if ((u_int)size > fs->fs_bsize || ffs_fragoff(fs, size) != 0) {
-		panic("%s: bad size: dev = 0x%llx, bsize = %d, size = %d, "
-		"fs = %s", __func__, (unsigned long long)ip->i_dev,
-		fs->fs_bsize, size, fs->fs_fsmnt);
-	}
-#endif /* DIAGNOSTIC */
+
+	KASSERTMSG((cred != NOCRED), "missing credential");
+	KASSERTMSG(((u_int)size <= fs->fs_bsize),
+	"bad size: dev = 0x%llx, bsize = %d, size = %d, fs = %s",
+	(unsigned long long)ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
+	KASSERTMSG((ffs_fragoff(fs, size) == 0),
+	"bad size: dev = 0x%llx, bsize = %d, size = %d, fs = %s",
+	(unsigned long long)ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
+
 	if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
 		goto nospace;
 	if (freespace(fs, fs->fs_minfree) <= 0 &&
@@ -344,17 +344,24 @@ ffs_realloccg(struct inode *ip, daddr_t 
 	}
 #endif
 
-#ifdef DIAGNOSTIC
-	if (cred == NOCRED)
-		panic("%s: missing credential", __func__);
-	if ((u_int)osize > fs->fs_bsize || ffs_fragoff(fs, osize) != 0 ||
-	(u_int)nsize > fs->fs_bsize || ffs_fragoff(fs, nsize) != 0) {
-		panic("%s: bad size: dev = 0x%llx, bsize = %d, osize = %d, "
-		"nsize = %d, fs = %s", __func__,
-		(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
-		fs->fs_fsmnt);
-	}
-#endif /* DIAGNOSTIC */
+	KASSERTMSG((cred != NOCRED), "missing credential");
+	KASSERTMSG(((u_int)osize <= fs->fs_bsize),
+	"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
+	(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
+	fs->fs_fsmnt);
+	KASSERTMSG((ffs_fragoff(fs, osize) == 0),
+	"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
+	(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
+	fs->fs_fsmnt);
+	KASSERTMSG(((u_int)nsize <= fs->fs_bsize),
+	"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
+	(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
+	fs->fs_fsmnt);
+	KASSERTMSG((ffs_fragoff(fs, nsize) == 0),
+	"bad size: dev=0x%llx, bsize=%d, osize=%d, nsize=%d, fs=%s",
+	(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
+	fs->fs_fsmnt);
+
 	if (freespace(fs, fs->fs_minfree) <= 0 &&
 	kauth_authorize_system(cred, KAUTH_SYSTEM_FS_RESERVEDSPACE, 0, NULL,
 	NULL, NULL) != 0) {



CVS commit: src/sys/ufs/ffs

2017-03-16 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Mar 16 22:09:19 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
need to turn off async during ffs_sync(), otherwise its bwrite() calls are
themselves turned to bdwrite(), creating dirty delayed writes

fixes panic for 'mount -o log,async ...' reported by Masanobu SAITOH
on current-users; fix help by hannken@, thank you


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.38 src/sys/ufs/ffs/ffs_wapbl.c:1.39
--- src/sys/ufs/ffs/ffs_wapbl.c:1.38	Fri Mar 10 22:43:03 2017
+++ src/sys/ufs/ffs/ffs_wapbl.c	Thu Mar 16 22:09:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.38 2017/03/10 22:43:03 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.39 2017/03/16 22:09:19 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.38 2017/03/10 22:43:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.39 2017/03/16 22:09:19 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -340,10 +340,16 @@ ffs_wapbl_start(struct mount *mp)
 
 			/*
 			 * Make sure we don't carry over any delayed write
-			 * buffers when updating to log.
+			 * buffers when updating to log. Need to turn off
+			 * async termporarily, to prevent ffs_sync() writes
+			 * themselves being turned into delayed writes.
 			 */
-			if (mp->mnt_flag & MNT_UPDATE)
+			if (mp->mnt_flag & MNT_UPDATE) {
+int saveflag = mp->mnt_flag & MNT_ASYNC;
+mp->mnt_flag &= ~MNT_ASYNC;
 ffs_sync(mp, MNT_WAIT, FSCRED);
+mp->mnt_flag |= saveflag;
+			}
 
 			error = wapbl_log_position(mp, fs, devvp, ,
 			, , );



CVS commit: src/sys/ufs/ffs

2017-03-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Mar 10 22:43:03 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
sync any delayed writes when updating filesystem to log

Adresses PR kern/52056 by Martin Husemann, fix helped by Juergen Hannken, thanks


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.37 src/sys/ufs/ffs/ffs_wapbl.c:1.38
--- src/sys/ufs/ffs/ffs_wapbl.c:1.37	Thu Nov 10 22:19:23 2016
+++ src/sys/ufs/ffs/ffs_wapbl.c	Fri Mar 10 22:43:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.37 2016/11/10 22:19:23 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.38 2017/03/10 22:43:03 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.37 2016/11/10 22:19:23 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.38 2017/03/10 22:43:03 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -338,6 +338,13 @@ ffs_wapbl_start(struct mount *mp)
 return EINVAL;
 			}
 
+			/*
+			 * Make sure we don't carry over any delayed write
+			 * buffers when updating to log.
+			 */
+			if (mp->mnt_flag & MNT_UPDATE)
+ffs_sync(mp, MNT_WAIT, FSCRED);
+
 			error = wapbl_log_position(mp, fs, devvp, ,
 			, , );
 			if (error)



CVS commit: src/sys/ufs/ffs

2017-03-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Mar 10 20:38:28 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
slightly rearrange the code for IMNT_WANTRDONLY + MNT_UPDATE case for
better readability, no functional change


To generate a diff of this commit:
cvs rdiff -u -r1.349 -r1.350 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.349 src/sys/ufs/ffs/ffs_vfsops.c:1.350
--- src/sys/ufs/ffs/ffs_vfsops.c:1.349	Mon Mar  6 10:12:00 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Mar 10 20:38:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.349 2017/03/06 10:12:00 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.350 2017/03/10 20:38:28 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.349 2017/03/06 10:12:00 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.350 2017/03/10 20:38:28 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -573,20 +573,23 @@ ffs_mount(struct mount *mp, const char *
 			if (mp->mnt_flag & MNT_FORCE)
 flags |= FORCECLOSE;
 			error = ffs_flushfiles(mp, flags, l);
-			if (error == 0)
-error = UFS_WAPBL_BEGIN(mp);
-			if (error == 0 &&
-			ffs_cgupdate(ump, MNT_WAIT) == 0 &&
+			if (error)
+return error;
+
+			error = UFS_WAPBL_BEGIN(mp);
+			if (error) {
+DPRINTF("wapbl %d", error);
+return error;
+			}
+
+			if (ffs_cgupdate(ump, MNT_WAIT) == 0 &&
 			fs->fs_clean & FS_WASCLEAN) {
 if (mp->mnt_flag & MNT_SOFTDEP)
 	fs->fs_flags &= ~FS_DOSOFTDEP;
 fs->fs_clean = FS_ISCLEAN;
 (void) ffs_sbupdate(ump, MNT_WAIT);
 			}
-			if (error) {
-DPRINTF("wapbl %d", error);
-return error;
-			}
+
 			UFS_WAPBL_END(mp);
 		}
 



CVS commit: src/sys/ufs/ffs

2017-03-06 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Mar  6 10:12:00 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Adapt the test "enable WAPBL on rw mounts only" to the recent change of
the protocol to update a mounted file.

Should fix PR kern/52031 (FFS mount update doesn't play nice with WAPBL)


To generate a diff of this commit:
cvs rdiff -u -r1.348 -r1.349 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.348 src/sys/ufs/ffs/ffs_vfsops.c:1.349
--- src/sys/ufs/ffs/ffs_vfsops.c:1.348	Wed Mar  1 10:46:43 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon Mar  6 10:12:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.348 2017/03/01 10:46:43 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.349 2017/03/06 10:12:00 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.348 2017/03/01 10:46:43 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.349 2017/03/06 10:12:00 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -518,7 +518,8 @@ ffs_mount(struct mount *mp, const char *
 
 #ifdef WAPBL
 	/* WAPBL can only be enabled on a r/w mount. */
-	if ((mp->mnt_flag & MNT_RDONLY) && !(mp->mnt_iflag & IMNT_WANTRDWR)) {
+	if (((mp->mnt_flag & MNT_RDONLY) && !(mp->mnt_iflag & IMNT_WANTRDWR)) ||
+	(mp->mnt_iflag & IMNT_WANTRDONLY)) {
 		mp->mnt_flag &= ~MNT_LOG;
 	}
 #else /* !WAPBL */



CVS commit: src/sys/ufs/ffs

2017-03-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar  2 00:43:40 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vnops.c

Log Message:
ifdef reduction


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/ufs/ffs/ffs_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vnops.c
diff -u src/sys/ufs/ffs/ffs_vnops.c:1.127 src/sys/ufs/ffs/ffs_vnops.c:1.128
--- src/sys/ufs/ffs/ffs_vnops.c:1.127	Wed Mar  1 16:55:07 2017
+++ src/sys/ufs/ffs/ffs_vnops.c	Wed Mar  1 19:43:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.127 2017/03/01 21:55:07 hannken Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.128 2017/03/02 00:43:40 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.127 2017/03/01 21:55:07 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.128 2017/03/02 00:43:40 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -283,9 +283,6 @@ ffs_spec_fsync(void *v)
 	} */ *ap = v;
 	int error, flags, uflags;
 	struct vnode *vp;
-#ifdef WAPBL
-	struct mount *mp;
-#endif /* WAPBL */
 
 	flags = ap->a_flags;
 	uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
@@ -296,7 +293,8 @@ ffs_spec_fsync(void *v)
 		goto out;
 
 #ifdef WAPBL
-	mp = vp->v_mount;
+	struct mount *mp = vp->v_mount;
+
 	if (mp && mp->mnt_wapbl) {
 		/*
 		 * Don't bother writing out metadata if the syncer is
@@ -462,6 +460,7 @@ ffs_full_fsync(struct vnode *vp, int fla
 
 #ifdef WAPBL
 	struct mount *mp = vp->v_mount;
+
 	if (mp && mp->mnt_wapbl) {
 
 		/*



CVS commit: src/sys/ufs/ffs

2017-03-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Mar  1 21:55:07 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vnops.c

Log Message:
Make compile again without "options WAPBL".

>From John D. Baker via current-users@, slightly modified by me.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/ufs/ffs/ffs_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vnops.c
diff -u src/sys/ufs/ffs/ffs_vnops.c:1.126 src/sys/ufs/ffs/ffs_vnops.c:1.127
--- src/sys/ufs/ffs/ffs_vnops.c:1.126	Wed Mar  1 10:42:45 2017
+++ src/sys/ufs/ffs/ffs_vnops.c	Wed Mar  1 21:55:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.126 2017/03/01 10:42:45 hannken Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.127 2017/03/01 21:55:07 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.126 2017/03/01 10:42:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.127 2017/03/01 21:55:07 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -283,18 +283,20 @@ ffs_spec_fsync(void *v)
 	} */ *ap = v;
 	int error, flags, uflags;
 	struct vnode *vp;
+#ifdef WAPBL
 	struct mount *mp;
+#endif /* WAPBL */
 
 	flags = ap->a_flags;
 	uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
 	vp = ap->a_vp;
-	mp = vp->v_mount;
 
 	error = spec_fsync(v);
 	if (error)
 		goto out;
 
 #ifdef WAPBL
+	mp = vp->v_mount;
 	if (mp && mp->mnt_wapbl) {
 		/*
 		 * Don't bother writing out metadata if the syncer is



CVS commit: src/sys/ufs/ffs

2017-03-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Mar  1 10:46:43 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Bring back read-write to read-only mount update for ffs.


To generate a diff of this commit:
cvs rdiff -u -r1.347 -r1.348 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.347 src/sys/ufs/ffs/ffs_vfsops.c:1.348
--- src/sys/ufs/ffs/ffs_vfsops.c:1.347	Wed Mar  1 10:42:45 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Mar  1 10:46:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.347 2017/03/01 10:42:45 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.348 2017/03/01 10:46:43 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.347 2017/03/01 10:42:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.348 2017/03/01 10:46:43 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -564,7 +564,7 @@ ffs_mount(struct mount *mp, const char *
 
 		ump = VFSTOUFS(mp);
 		fs = ump->um_fs;
-		if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
+		if (fs->fs_ronly == 0 && (mp->mnt_iflag & IMNT_WANTRDONLY)) {
 			/*
 			 * Changing from r/w to r/o
 			 */
@@ -599,7 +599,7 @@ ffs_mount(struct mount *mp, const char *
 		}
 #endif /* WAPBL */
 
-		if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
+		if (fs->fs_ronly == 0 && (mp->mnt_iflag & IMNT_WANTRDONLY)) {
 			/*
 			 * Finish change from r/w to r/o
 			 */
@@ -1455,7 +1455,7 @@ ffs_mountfs(struct vnode *devvp, struct 
 	mp->mnt_fs_bshift = fs->fs_bshift;
 	mp->mnt_dev_bshift = DEV_BSHIFT;	/* XXX */
 	mp->mnt_flag |= MNT_LOCAL;
-	mp->mnt_iflag |= IMNT_MPSAFE;
+	mp->mnt_iflag |= IMNT_MPSAFE | IMNT_CAN_RWTORO;
 #ifdef FFS_EI
 	if (needswap)
 		ump->um_flags |= UFS_NEEDSWAP;



CVS commit: src/sys/ufs/ffs

2017-02-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 17 08:26:41 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Flush the log to disk when ffs_sync() gets called with MNT_WAIT.


To generate a diff of this commit:
cvs rdiff -u -r1.342 -r1.343 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.342 src/sys/ufs/ffs/ffs_vfsops.c:1.343
--- src/sys/ufs/ffs/ffs_vfsops.c:1.342	Tue Dec 27 10:54:38 2016
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 17 08:26:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.342 2016/12/27 10:54:38 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.343 2017/02/17 08:26:41 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.342 2016/12/27 10:54:38 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.343 2017/02/17 08:26:41 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1973,7 +1973,7 @@ ffs_sync(struct mount *mp, int waitfor, 
 
 #ifdef WAPBL
 	if (mp->mnt_wapbl) {
-		error = wapbl_flush(mp->mnt_wapbl, 0);
+		error = wapbl_flush(mp->mnt_wapbl, (waitfor == MNT_WAIT));
 		if (error)
 			allerror = error;
 	}



CVS commit: src/sys/ufs/ffs

2017-02-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Feb  9 04:37:35 UTC 2017

Modified Files:
src/sys/ufs/ffs: ffs_bswap.c ffs_extern.h

Log Message:
Sprinkle in a pinch of const, not too much, just enough
to add a little strength without affecting the overall balance...


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/ufs/ffs/ffs_bswap.c
cvs rdiff -u -r1.83 -r1.84 src/sys/ufs/ffs/ffs_extern.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_bswap.c
diff -u src/sys/ufs/ffs/ffs_bswap.c:1.39 src/sys/ufs/ffs/ffs_bswap.c:1.40
--- src/sys/ufs/ffs/ffs_bswap.c:1.39	Wed May 20 18:21:17 2015
+++ src/sys/ufs/ffs/ffs_bswap.c	Thu Feb  9 04:37:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_bswap.c,v 1.39 2015/05/20 18:21:17 riastradh Exp $	*/
+/*	$NetBSD: ffs_bswap.c,v 1.40 2017/02/09 04:37:35 kre Exp $	*/
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.
@@ -30,7 +30,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_bswap.c,v 1.39 2015/05/20 18:21:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_bswap.c,v 1.40 2017/02/09 04:37:35 kre Exp $");
 
 #include 
 #if defined(_KERNEL)
@@ -52,17 +52,18 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_bswap.c,
 #endif
 
 void
-ffs_sb_swap(struct fs *o, struct fs *n)
+ffs_sb_swap(const struct fs *o, struct fs *n)
 {
 	size_t i;
-	u_int32_t *o32, *n32;
+	const u_int32_t *o32;
+	u_int32_t *n32;
 
 	/*
 	 * In order to avoid a lot of lines, as the first N fields (52)
 	 * of the superblock up to fs_fmod are u_int32_t, we just loop
 	 * here to convert them.
 	 */
-	o32 = (u_int32_t *)o;
+	o32 = (const u_int32_t *)o;
 	n32 = (u_int32_t *)n;
 	for (i = 0; i < offsetof(struct fs, fs_fmod) / sizeof(u_int32_t); i++)
 		n32[i] = bswap32(o32[i]);
@@ -178,7 +179,7 @@ ffs_csum_swap(struct csum *o, struct csu
 }
 
 void
-ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n)
+ffs_csumtotal_swap(const struct csum_total *o, struct csum_total *n)
 {
 	n->cs_ndir = bswap64(o->cs_ndir);
 	n->cs_nbfree = bswap64(o->cs_nbfree);

Index: src/sys/ufs/ffs/ffs_extern.h
diff -u src/sys/ufs/ffs/ffs_extern.h:1.83 src/sys/ufs/ffs/ffs_extern.h:1.84
--- src/sys/ufs/ffs/ffs_extern.h:1.83	Sat Oct  1 13:15:45 2016
+++ src/sys/ufs/ffs/ffs_extern.h	Thu Feb  9 04:37:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_extern.h,v 1.83 2016/10/01 13:15:45 jdolecek Exp $	*/
+/*	$NetBSD: ffs_extern.h,v 1.84 2017/02/09 04:37:35 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -186,13 +186,13 @@ void	ffs_appleufs_set(struct appleufslab
 			 uint64_t);
 
 /* ffs_bswap.c */
-void	ffs_sb_swap(struct fs*, struct fs *);
+void	ffs_sb_swap(const struct fs *, struct fs *);
 void	ffs_dinode1_swap(struct ufs1_dinode *, struct ufs1_dinode *);
 void	ffs_dinode2_swap(struct ufs2_dinode *, struct ufs2_dinode *);
 struct csum;
 void	ffs_csum_swap(struct csum *, struct csum *, int);
 struct csum_total;
-void	ffs_csumtotal_swap(struct csum_total *, struct csum_total *);
+void	ffs_csumtotal_swap(const struct csum_total *, struct csum_total *);
 void	ffs_cg_swap(struct cg *, struct cg *, struct fs *);
 
 /* ffs_subr.c */



CVS commit: src/sys/ufs/ffs

2016-12-27 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Dec 27 10:54:38 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Fix a bug introduced with Rev. 1.294:  use LK_NOWAIT when called with MNT_LAZY.


To generate a diff of this commit:
cvs rdiff -u -r1.341 -r1.342 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.341 src/sys/ufs/ffs/ffs_vfsops.c:1.342
--- src/sys/ufs/ffs/ffs_vfsops.c:1.341	Thu Oct 20 19:31:32 2016
+++ src/sys/ufs/ffs/ffs_vfsops.c	Tue Dec 27 10:54:38 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.341 2016/10/20 19:31:32 jdolecek Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.342 2016/12/27 10:54:38 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.341 2016/10/20 19:31:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.342 2016/12/27 10:54:38 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1917,7 +1917,8 @@ ffs_sync(struct mount *mp, int waitfor, 
 	ctx.is_suspending = is_suspending;
 	while ((vp = vfs_vnode_iterator_next(marker, ffs_sync_selector, )))
 	{
-		error = vn_lock(vp, LK_EXCLUSIVE);
+		error = vn_lock(vp,
+		LK_EXCLUSIVE | (waitfor == MNT_LAZY ? LK_NOWAIT : 0));
 		if (error) {
 			vrele(vp);
 			continue;



CVS commit: src/sys/ufs/ffs

2016-11-11 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Nov 11 10:50:16 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_inode.c

Log Message:
Fix a "slight tweak" from Rev. 1.121:  bap1/bap2 must be valid
before using BAP_ASSIGN().

Prevents NULL pointer dereference when "lastbn >= 0".


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.122 src/sys/ufs/ffs/ffs_inode.c:1.123
--- src/sys/ufs/ffs/ffs_inode.c:1.122	Thu Nov 10 20:56:32 2016
+++ src/sys/ufs/ffs/ffs_inode.c	Fri Nov 11 10:50:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.122 2016/11/10 20:56:32 jdolecek Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.123 2016/11/11 10:50:16 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.122 2016/11/10 20:56:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.123 2016/11/11 10:50:16 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -659,6 +659,10 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 	 * This assumes the truncate process would not fail, contrary
 	 * to the wapbl case.
 	 */
+	if (ip->i_ump->um_fstype == UFS1)
+		bap1 = (int32_t *)bp->b_data;
+	else
+		bap2 = (int64_t *)bp->b_data;
 	if (lastbn >= 0 && !wapbl) {
 		copy = kmem_alloc(fs->fs_bsize, KM_SLEEP);
 		memcpy((void *)copy, bp->b_data, (u_int)fs->fs_bsize);
@@ -672,11 +676,6 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 			bap1 = (int32_t *)copy;
 		else
 			bap2 = (int64_t *)copy;
-	} else {
-		if (ip->i_ump->um_fstype == UFS1)
-			bap1 = (int32_t *)bp->b_data;
-		else
-			bap2 = (int64_t *)bp->b_data;
 	}
 
 	/*



CVS commit: src/sys/ufs/ffs

2016-11-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Nov 10 22:19:23 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
disable discard when log is enabled to preserve log consistency promise

PR kern/50725


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.36 src/sys/ufs/ffs/ffs_wapbl.c:1.37
--- src/sys/ufs/ffs/ffs_wapbl.c:1.36	Thu Nov 10 20:56:32 2016
+++ src/sys/ufs/ffs/ffs_wapbl.c	Thu Nov 10 22:19:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.36 2016/11/10 20:56:32 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.37 2016/11/10 22:19:23 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.36 2016/11/10 20:56:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.37 2016/11/10 22:19:23 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -371,6 +371,23 @@ ffs_wapbl_start(struct mount *mp)
 if (error)
 	goto out;
 			}
+
+			/*
+			 * XXX discard interferes with block deallocation
+			 * registration and hence log consistency
+			 */
+			if (mp->mnt_flag & MNT_DISCARD) {
+CLR(mp->mnt_flag, MNT_DISCARD);
+printf("%s: %s: disabling discard to preserve log consistency\n", __func__,
+fs->fs_fsmnt);
+
+if (ump->um_discarddata != NULL) {
+			ffs_discard_finish(ump->um_discarddata,
+	0);
+			ump->um_discarddata = NULL;
+}
+			}
+
 		} else if (fs->fs_flags & FS_DOWAPBL) {
 			fs->fs_fmod = 1;
 			fs->fs_flags &= ~FS_DOWAPBL;



CVS commit: src/sys/ufs/ffs

2016-11-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Nov 10 19:10:05 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_inode.c

Log Message:
ffs_indirtrunc(): for !wapbl, restore rev 1.117 behavior of writing the zeroed
(indirect) block before freeing the referenced blocks; it's necessary for
fsck to recover the filesystem, if system goes down during truncate

patch courtesy of hannken@ with only sligh tweaks


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.120 src/sys/ufs/ffs/ffs_inode.c:1.121
--- src/sys/ufs/ffs/ffs_inode.c:1.120	Mon Nov  7 21:14:23 2016
+++ src/sys/ufs/ffs/ffs_inode.c	Thu Nov 10 19:10:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.120 2016/11/07 21:14:23 jdolecek Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.121 2016/11/10 19:10:05 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.120 2016/11/07 21:14:23 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.121 2016/11/10 19:10:05 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -533,6 +533,8 @@ out:
 	 * blocks were deallocated creating a hole, but that is okay.
 	 */
 	if (error == EAGAIN) {
+		if (!allerror)
+			allerror = error;
 		length = osize;
 		uvm_vnp_setsize(ovp, length);
 	}
@@ -573,10 +575,12 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 	int64_t *bap2 = NULL;
 	struct vnode *vp;
 	daddr_t nb, nlbn, last;
+	char *copy = NULL;
 	int64_t factor;
 	int64_t nblocks;
-	int error = 0;
+	int error = 0, allerror = 0;
 	const int needswap = UFS_FSNEEDSWAP(fs);
+	const int wapbl = (ip->i_ump->um_mountp->mnt_wapbl != NULL);
 
 #define RBAP(ip, i) (((ip)->i_ump->um_fstype == UFS1) ? \
 	ufs_rw32(bap1[i], needswap) : ufs_rw64(bap2[i], needswap))
@@ -602,7 +606,7 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 	nblocks = btodb(fs->fs_bsize);
 	/*
 	 * Get buffer of block pointers, zero those entries corresponding
-	 * to blocks to be free'd, and update on disk copy.  Since
+	 * to blocks to be free'd, and update on disk copy first.  Since
 	 * double(triple) indirect before single(double) indirect, calls
 	 * to bmap on these blocks will fail.  However, we already have
 	 * the on disk address, so we have to set the b_blkno field
@@ -635,13 +639,35 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 		return error;
 	}
 
-	if (ip->i_ump->um_fstype == UFS1)
-		bap1 = (int32_t *)bp->b_data;
-	else
-		bap2 = (int64_t *)bp->b_data;
+	/*
+	 * Clear reference to blocks to be removed on disk, before actually
+	 * reclaiming them, so that fsck is more likely to be able to recover
+	 * the filesystem if system goes down during the truncate process.
+	 * This assumes the truncate process would not fail, contrary
+	 * to the wapbl case.
+	 */
+	if (lastbn >= 0 && !wapbl) {
+		copy = kmem_alloc(fs->fs_bsize, KM_SLEEP);
+		memcpy((void *)copy, bp->b_data, (u_int)fs->fs_bsize);
+		for (i = last + 1; i < FFS_NINDIR(fs); i++)
+			BAP_ASSIGN(ip, i, 0);
+		error = bwrite(bp);
+		if (error)
+			allerror = error;
+
+		if (ip->i_ump->um_fstype == UFS1)
+			bap1 = (int32_t *)copy;
+		else
+			bap2 = (int64_t *)copy;
+	} else {
+		if (ip->i_ump->um_fstype == UFS1)
+			bap1 = (int32_t *)bp->b_data;
+		else
+			bap2 = (int64_t *)bp->b_data;
+	}
 
 	/*
-	 * Recursively free totally unused blocks, starting from first.
+	 * Recursively free totally unused blocks.
 	 */
 	for (i = FFS_NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
 	i--, nlbn += factor) {
@@ -686,15 +712,22 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 	}
 
 out:
-	if (lastbn < 0 && error == 0) {
+ 	if (error && !allerror)
+ 		allerror = error;
+
+ 	if (copy != NULL) {
+ 		kmem_free(copy, fs->fs_bsize);
+ 	} else if (lastbn < 0 && error == 0) {
 		/* all freed, release without writing back */
 		brelse(bp, BC_INVAL);
-	} else {
-		/* only partially freed, write the updated block */
-		(void) bwrite(bp);
+	} else if (wapbl) {
+ 		/* only partially freed, write the updated block */
+ 		error = bwrite(bp);
+ 		if (!allerror)
+ 			allerror = error;
 	}
 
-	return (error);
+	return (allerror);
 }
 
 void



CVS commit: src/sys/ufs/ffs

2016-11-07 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Nov  7 21:14:23 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_inode.c

Log Message:
fix broken test for partial truncate, introduced in rev 1.118

PR kern/51601 kern/51602


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.119 src/sys/ufs/ffs/ffs_inode.c:1.120
--- src/sys/ufs/ffs/ffs_inode.c:1.119	Mon Nov  7 21:05:38 2016
+++ src/sys/ufs/ffs/ffs_inode.c	Mon Nov  7 21:14:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.119 2016/11/07 21:05:38 jdolecek Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.120 2016/11/07 21:14:23 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.119 2016/11/07 21:05:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.120 2016/11/07 21:14:23 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -686,7 +686,7 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 	}
 
 out:
-	if (RBAP(ip, 0) == 0) {
+	if (lastbn < 0 && error == 0) {
 		/* all freed, release without writing back */
 		brelse(bp, BC_INVAL);
 	} else {



CVS commit: src/sys/ufs/ffs

2016-11-07 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Nov  7 21:05:38 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_inode.c

Log Message:
reduce diff vs 1.117, no functional change


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.118 src/sys/ufs/ffs/ffs_inode.c:1.119
--- src/sys/ufs/ffs/ffs_inode.c:1.118	Fri Oct 28 20:38:12 2016
+++ src/sys/ufs/ffs/ffs_inode.c	Mon Nov  7 21:05:38 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.118 2016/10/28 20:38:12 jdolecek Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.119 2016/11/07 21:05:38 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.118 2016/10/28 20:38:12 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.119 2016/11/07 21:05:38 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -675,11 +675,11 @@ ffs_indirtrunc(struct inode *ip, daddr_t
 	 * Recursively free blocks on the now last partial indirect block.
 	 */
 	if (level > SINGLE && lastbn >= 0) {
-		nb = RBAP(ip, last);
+		last = lastbn % factor;
+		nb = RBAP(ip, i);
 		if (nb != 0) {
 			error = ffs_indirtrunc(ip, nlbn, FFS_FSBTODB(fs, nb),
-	   lastbn % factor, level - 1,
-	   countp);
+	   last, level - 1, countp);
 			if (error)
 goto out;
 		}



CVS commit: src/sys/ufs/ffs

2016-10-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 30 15:01:46 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Tidy up panic messages, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.153 src/sys/ufs/ffs/ffs_alloc.c:1.154
--- src/sys/ufs/ffs/ffs_alloc.c:1.153	Fri Oct 28 16:38:12 2016
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Oct 30 11:01:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.153 2016/10/28 20:38:12 jdolecek Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.154 2016/10/30 15:01:46 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.153 2016/10/28 20:38:12 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.154 2016/10/30 15:01:46 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -136,14 +136,13 @@ ffs_check_bad_allocation(const char *fun
 {
 	if ((u_int)size > fs->fs_bsize || ffs_fragoff(fs, size) != 0 ||
 	ffs_fragnum(fs, bno) + ffs_numfrags(fs, size) > fs->fs_frag) {
-		printf("dev = 0x%llx, bno = %" PRId64 " bsize = %d, "
-		"size = %ld, fs = %s\n",
+		panic("%s: bad size: dev = 0x%llx, bno = %" PRId64 
+		" bsize = %d, size = %ld, fs = %s", func,
 		(long long)dev, bno, fs->fs_bsize, size, fs->fs_fsmnt);
-		panic("%s: bad size", func);
 	}
 
 	if (bno >= fs->fs_size) {
-		printf("bad block %" PRId64 ", ino %llu\n", bno,
+		printf("%s: bad block %" PRId64 ", ino %llu\n", func, bno,
 		(unsigned long long)inum);
 		ffs_fserr(fs, NOCRED, "bad block");
 		return EINVAL;
@@ -229,14 +228,13 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 
 	*bnp = 0;
 #ifdef DIAGNOSTIC
+	if (cred == NOCRED)
+		panic("%s: missing credential", __func__);
 	if ((u_int)size > fs->fs_bsize || ffs_fragoff(fs, size) != 0) {
-		printf("dev = 0x%llx, bsize = %d, size = %d, fs = %s\n",
-		(unsigned long long)ip->i_dev, fs->fs_bsize, size,
-		fs->fs_fsmnt);
-		panic("ffs_alloc: bad size");
+		panic("%s: bad size: dev = 0x%llx, bsize = %d, size = %d, "
+		"fs = %s", __func__, (unsigned long long)ip->i_dev,
+		fs->fs_bsize, size, fs->fs_fsmnt);
 	}
-	if (cred == NOCRED)
-		panic("ffs_alloc: missing credential");
 #endif /* DIAGNOSTIC */
 	if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
 		goto nospace;
@@ -348,16 +346,15 @@ ffs_realloccg(struct inode *ip, daddr_t 
 #endif
 
 #ifdef DIAGNOSTIC
+	if (cred == NOCRED)
+		panic("%s: missing credential", __func__);
 	if ((u_int)osize > fs->fs_bsize || ffs_fragoff(fs, osize) != 0 ||
 	(u_int)nsize > fs->fs_bsize || ffs_fragoff(fs, nsize) != 0) {
-		printf(
-		"dev = 0x%llx, bsize = %d, osize = %d, nsize = %d, fs = %s\n",
+		panic("%s: bad size: dev = 0x%llx, bsize = %d, osize = %d, "
+		"nsize = %d, fs = %s", __func__,
 		(unsigned long long)ip->i_dev, fs->fs_bsize, osize, nsize,
 		fs->fs_fsmnt);
-		panic("ffs_realloccg: bad size");
 	}
-	if (cred == NOCRED)
-		panic("ffs_realloccg: missing credential");
 #endif /* DIAGNOSTIC */
 	if (freespace(fs, fs->fs_minfree) <= 0 &&
 	kauth_authorize_system(cred, KAUTH_SYSTEM_FS_RESERVEDSPACE, 0, NULL,
@@ -371,10 +368,10 @@ ffs_realloccg(struct inode *ip, daddr_t 
 		bprev = ufs_rw32(ip->i_ffs1_db[lbprev], UFS_FSNEEDSWAP(fs));
 
 	if (bprev == 0) {
-		printf("dev = 0x%llx, bsize = %d, bprev = %" PRId64 ", fs = %s\n",
+		panic("%s: bad bprev: dev = 0x%llx, bsize = %d, bprev = %"
+		PRId64 ", fs = %s", __func__,
 		(unsigned long long)ip->i_dev, fs->fs_bsize, bprev,
 		fs->fs_fsmnt);
-		panic("ffs_realloccg: bad bprev");
 	}
 	mutex_exit(>um_lock);
 
@@ -403,8 +400,11 @@ ffs_realloccg(struct inode *ip, daddr_t 
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
 
 		if (bpp != NULL) {
-			if (bp->b_blkno != FFS_FSBTODB(fs, bno))
-panic("bad blockno");
+			if (bp->b_blkno != FFS_FSBTODB(fs, bno)) {
+panic("%s: bad blockno %#llx != %#llx",
+__func__, (unsigned long long) bp->b_blkno,
+(unsigned long long)FFS_FSBTODB(fs, bno));
+			}
 			allocbuf(bp, nsize, 1);
 			memset((char *)bp->b_data + osize, 0, nsize - osize);
 			mutex_enter(bp->b_objlock);
@@ -471,9 +471,9 @@ ffs_realloccg(struct inode *ip, daddr_t 
 		fs->fs_optim = FS_OPTSPACE;
 		break;
 	default:
-		printf("dev = 0x%llx, optim = %d, fs = %s\n",
-		(unsigned long long)ip->i_dev, fs->fs_optim, fs->fs_fsmnt);
-		panic("ffs_realloccg: bad optim");
+		panic("%s: bad optim: dev = 0x%llx, optim = %d, fs = %s",
+		__func__, (unsigned long long)ip->i_dev, fs->fs_optim,
+		fs->fs_fsmnt);
 		/* NOTREACHED */
 	}
 	bno = ffs_hashalloc(ip, cg, bpref, request, nsize, 0, ffs_alloccg);
@@ -1324,18 +1324,16 @@ retry:
 		start = 0;
 		loc = skpc(0xff, len, [0]);

CVS commit: src/sys/ufs/ffs

2016-10-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Oct 21 19:28:03 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_snapshot.c

Log Message:
revert 1.141 - the second ffs_truncate() can't really fail

requested by hannken@


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/ufs/ffs/ffs_snapshot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.141 src/sys/ufs/ffs/ffs_snapshot.c:1.142
--- src/sys/ufs/ffs/ffs_snapshot.c:1.141	Thu Oct 20 20:17:46 2016
+++ src/sys/ufs/ffs/ffs_snapshot.c	Fri Oct 21 19:28:03 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.141 2016/10/20 20:17:46 jdolecek Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.142 2016/10/21 19:28:03 jdolecek Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.141 2016/10/20 20:17:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.142 2016/10/21 19:28:03 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -402,10 +402,6 @@ out:
 	}
 	if (error) {
 		if (UFS_WAPBL_BEGIN(mp) == 0) {
-			/*
-			 * This is okay to fail, we'll simply reuse the blocks
-			 * later.
-			 */
 			(void) ffs_truncate(vp, (off_t)0, 0, NOCRED);
 			UFS_WAPBL_END(mp);
 		}
@@ -441,13 +437,9 @@ snapshot_setup(struct mount *mp, struct 
 		return EACCES;
 
 	if (vp->v_size != 0) {
-		if (UFS_WAPBL_BEGIN(mp) == 0) {
-			/*
-			 * This is okay to fail, we'll simply reuse the blocks
-			 */
-			(void) ffs_truncate(vp, 0, 0, NOCRED);
-			UFS_WAPBL_END(mp);
-		}
+		error = ffs_truncate(vp, 0, 0, NOCRED);
+		if (error)
+			return error;
 	}
 
 	/* Change inode to snapshot type file. */
@@ -456,7 +448,6 @@ snapshot_setup(struct mount *mp, struct 
 		return error;
 #if defined(QUOTA) || defined(QUOTA2)
 	/* shapshot inodes are not accounted in quotas */
-	chkdq(ip, -DIP(ip, blocks), l->l_cred, 0);
 	chkiq(ip, -1, l->l_cred, 0);
 #endif
 	ip->i_flags |= (SF_SNAPSHOT | SF_SNAPINVAL);



CVS commit: src/sys/ufs/ffs

2016-10-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Oct 20 20:17:46 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_snapshot.c

Log Message:
allow also the snapshot_setup()'s call to ffs_truncate() fail, the code
should simply reuse the file blocks in that case; also make sure the
ffs_truncate() call is run within transaction if log is on


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/ufs/ffs/ffs_snapshot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.140 src/sys/ufs/ffs/ffs_snapshot.c:1.141
--- src/sys/ufs/ffs/ffs_snapshot.c:1.140	Sun Jun 28 10:04:32 2015
+++ src/sys/ufs/ffs/ffs_snapshot.c	Thu Oct 20 20:17:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.140 2015/06/28 10:04:32 maxv Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.141 2016/10/20 20:17:46 jdolecek Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.140 2015/06/28 10:04:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.141 2016/10/20 20:17:46 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -402,6 +402,10 @@ out:
 	}
 	if (error) {
 		if (UFS_WAPBL_BEGIN(mp) == 0) {
+			/*
+			 * This is okay to fail, we'll simply reuse the blocks
+			 * later.
+			 */
 			(void) ffs_truncate(vp, (off_t)0, 0, NOCRED);
 			UFS_WAPBL_END(mp);
 		}
@@ -437,9 +441,13 @@ snapshot_setup(struct mount *mp, struct 
 		return EACCES;
 
 	if (vp->v_size != 0) {
-		error = ffs_truncate(vp, 0, 0, NOCRED);
-		if (error)
-			return error;
+		if (UFS_WAPBL_BEGIN(mp) == 0) {
+			/*
+			 * This is okay to fail, we'll simply reuse the blocks
+			 */
+			(void) ffs_truncate(vp, 0, 0, NOCRED);
+			UFS_WAPBL_END(mp);
+		}
 	}
 
 	/* Change inode to snapshot type file. */
@@ -448,6 +456,7 @@ snapshot_setup(struct mount *mp, struct 
 		return error;
 #if defined(QUOTA) || defined(QUOTA2)
 	/* shapshot inodes are not accounted in quotas */
+	chkdq(ip, -DIP(ip, blocks), l->l_cred, 0);
 	chkiq(ip, -1, l->l_cred, 0);
 #endif
 	ip->i_flags |= (SF_SNAPSHOT | SF_SNAPINVAL);



CVS commit: src/sys/ufs/ffs

2016-10-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Oct 20 19:31:32 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
add assertion to ensure ffs_cgupdate() is always called from
within a WAPBL transaction (if logging is on)


To generate a diff of this commit:
cvs rdiff -u -r1.340 -r1.341 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.340 src/sys/ufs/ffs/ffs_vfsops.c:1.341
--- src/sys/ufs/ffs/ffs_vfsops.c:1.340	Thu Jul 28 08:24:58 2016
+++ src/sys/ufs/ffs/ffs_vfsops.c	Thu Oct 20 19:31:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.340 2016/07/28 08:24:58 martin Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.341 2016/10/20 19:31:32 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.340 2016/07/28 08:24:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.341 2016/10/20 19:31:32 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2351,6 +2351,8 @@ ffs_cgupdate(struct ufsmount *mp, int wa
 	void *space;
 	int i, size, error = 0, allerror = 0;
 
+	UFS_WAPBL_JLOCK_ASSERT(mp);
+
 	allerror = ffs_sbupdate(mp, waitfor);
 	blks = howmany(fs->fs_cssize, fs->fs_fsize);
 	space = fs->fs_csp;



CVS commit: src/sys/ufs/ffs

2016-10-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct  2 19:02:57 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
use __func__ and print the filesystem we are printing the message for.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.34 src/sys/ufs/ffs/ffs_wapbl.c:1.35
--- src/sys/ufs/ffs/ffs_wapbl.c:1.34	Sat Oct  1 09:15:45 2016
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sun Oct  2 15:02:57 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.34 2016/10/01 13:15:45 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.35 2016/10/02 19:02:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.34 2016/10/01 13:15:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.35 2016/10/02 19:02:57 christos Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -126,16 +126,17 @@ ffs_wapbl_replay_finish(struct mount *mp
 		struct inode *ip;
 		error = VFS_VGET(mp, wr->wr_inodes[i].wr_inumber, );
 		if (error) {
-			printf("ffs_wapbl_replay_finish: "
-			"unable to cleanup inode %" PRIu32 "\n",
+			printf("%s: %s: unable to cleanup inode %" PRIu32 "\n",
+			__func__, VFSTOUFS(mp)->um_fs->fs_fsmnt,
 			wr->wr_inodes[i].wr_inumber);
 			continue;
 		}
 		ip = VTOI(vp);
 		KDASSERT(wr->wr_inodes[i].wr_inumber == ip->i_number);
 #ifdef WAPBL_DEBUG
-		printf("ffs_wapbl_replay_finish: "
-		"cleaning inode %" PRIu64 " size=%" PRIu64 " mode=%o nlink=%d\n",
+		printf("%s%s: %s: cleaning inode %" PRIu64 " size=%" PRIu64
+		" mode=%o nlink=%d\n",
+		__func__, VFSTOUFS(mp)->um_fs->fs_fsmnt,
 		ip->i_number, ip->i_size, ip->i_mode, ip->i_nlink);
 #endif
 		KASSERT(ip->i_nlink == 0);
@@ -149,8 +150,9 @@ ffs_wapbl_replay_finish(struct mount *mp
 		if (ip->i_mode == 0) {
 			error = UFS_WAPBL_BEGIN(mp);
 			if (error) {
-printf("ffs_wapbl_replay_finish: "
+printf("%s: %s: "
 "unable to cleanup inode %" PRIu32 "\n",
+__func__, VFSTOUFS(mp)->um_fs->fs_fsmnt,
 wr->wr_inodes[i].wr_inumber);
 			} else {
 ffs_vfree(vp, ip->i_number,
@@ -177,7 +179,7 @@ ffs_wapbl_sync_metadata(struct mount *mp
 	UFS_WAPBL_JLOCK_ASSERT(mp);
 
 #ifdef WAPBL_DEBUG_INODES
-	ufs_wapbl_verify_inodes(mp, "ffs_wapbl_sync_metadata");
+	ufs_wapbl_verify_inodes(mp, __func__);
 #endif
 
 	for (wd = fdealloc; wd != NULL; wd = SIMPLEQ_NEXT(wd, wd_entries)) {
@@ -254,16 +256,16 @@ wapbl_remove_log(struct mount *mp)
 			goto done;
 		error = VFS_VGET(mp, log_ino, );
 		if (error != 0) {
-			printf("ffs_wapbl: vget failed %d\n",
-			error);
+			printf("%s: %s: vget failed %d\n", __func__,
+			fs->fs_fsmnt, error);
 			/* clear out log info on error */
 			goto done;
 		}
 		ip = VTOI(vp);
 		KASSERT(log_ino == ip->i_number);
 		if ((ip->i_flags & SF_LOG) == 0) {
-			printf("ffs_wapbl: try to clear non-log inode "
-			"%" PRId64 "\n", log_ino);
+			printf("%s: %s: try to clear non-log inode "
+			"%" PRId64 "\n", __func__, fs->fs_fsmnt, log_ino);
 			vput(vp);
 			/* clear out log info on error */
 			goto done;
@@ -284,8 +286,8 @@ wapbl_remove_log(struct mount *mp)
 		break;
 
 	default:
-		printf("ffs_wapbl: unknown journal type %d\n",
-		fs->fs_journal_location);
+		printf("%s: %s: unknown journal type %d\n", __func__,
+		fs->fs_fsmnt, fs->fs_journal_location);
 		break;
 	}
 
@@ -329,8 +331,8 @@ ffs_wapbl_start(struct mount *mp)
 
 			/* WAPBL needs UFS2 format super block */
 			if (ffs_superblock_layout(fs) < 2) {
-printf("%s fs superblock in old format, "
-   "not journaling\n",
+printf("%s: %s: fs superblock in old format, "
+   "not journaling\n", __func__,
    VFSTOUFS(mp)->um_fs->fs_fsmnt);
 mp->mnt_flag &= ~MNT_LOG;
 return EINVAL;
@@ -351,7 +353,8 @@ ffs_wapbl_start(struct mount *mp)
 			mp->mnt_wapbl_op = _ops;
 
 #ifdef WAPBL_DEBUG
-			printf("%s: enabling logging\n", fs->fs_fsmnt);
+			printf("%s: %s: enabling logging\n", __func__,
+			fs->fs_fsmnt);
 #endif
 
 			if ((fs->fs_flags & FS_DOWAPBL) == 0) {
@@ -440,7 +443,7 @@ ffs_wapbl_stop(struct mount *mp, int for
 		mp->mnt_wapbl = NULL;
 
 #ifdef WAPBL_DEBUG
-		printf("%s: disabled logging\n", fs->fs_fsmnt);
+		printf("%s: %s: disabled logging\n", __func__, fs->fs_fsmnt);
 #endif
 	}
 
@@ -533,8 +536,8 @@ wapbl_log_position(struct mount *mp, str
 			return 0;
 
 		default:
-			printf("ffs_wapbl: unknown journal type %d\n",
-			fs->fs_journal_location);
+			printf("%s: %s: unknown journal type %d\n", __func__,
+			fs->fs_fsmnt, fs->fs_journal_location);
 			return EINVAL;
 		}
 	}
@@ -687,14 +690,14 @@ wapbl_allocate_log_file(struct mount *mp
 		logsize = fs->fs_journallocs[UFS_WAPBL_INFS_COUNT];
 
 	if 

CVS commit: src/sys/ufs/ffs

2016-10-01 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Oct  1 13:06:20 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
wapbl_remove_log(): add missing break; harmless, fallthrough just printed
extra debug message


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.32 src/sys/ufs/ffs/ffs_wapbl.c:1.33
--- src/sys/ufs/ffs/ffs_wapbl.c:1.32	Sat Sep 24 21:00:54 2016
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sat Oct  1 13:06:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.32 2016/09/24 21:00:54 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.33 2016/10/01 13:06:20 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.32 2016/09/24 21:00:54 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.33 2016/10/01 13:06:20 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -277,6 +277,7 @@ wapbl_remove_log(struct mount *mp)
 		ip->i_nlink = 0;
 		DIP_ASSIGN(ip, nlink, 0);
 		vput(vp);
+		break;
 
 	case UFS_WAPBL_JOURNALLOC_END_PARTITION:
 		DPRINTF("end-of-partition log\n");



CVS commit: src/sys/ufs/ffs

2016-09-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Sep 25 17:14:59 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
adjust ffs_realloccg() so that the logic about allocating full
contiguous block for future fragment expansion doesn't need to
UFS_WAPBL_REGISTER_DEALLOCATION() or ffs_blkfree(); the free blocks
are now immediatelly available for use by the expanding file in further i/o

primary driver is safe removal of the deallocation registration and
hence failure point, but this also fixes degenerate case for wapbl,
and similar also for discard - if the file would be actually expanded
before wapbl commit, or before discard queue would be processed,
the filesystem would not yet see the contiguous free blocks, and
would be forced to allocate another fragment elsewhere


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.151 src/sys/ufs/ffs/ffs_alloc.c:1.152
--- src/sys/ufs/ffs/ffs_alloc.c:1.151	Wed Aug 12 14:52:35 2015
+++ src/sys/ufs/ffs/ffs_alloc.c	Sun Sep 25 17:14:59 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.151 2015/08/12 14:52:35 riastradh Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.152 2016/09/25 17:14:59 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.151 2015/08/12 14:52:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.152 2016/09/25 17:14:59 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -107,14 +107,14 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,
 #include 
 #endif
 
-static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int, int);
-static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int);
+static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int, int, int);
+static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int, int);
 static ino_t ffs_dirpref(struct inode *);
 static daddr_t ffs_fragextend(struct inode *, int, daddr_t, int, int);
 static void ffs_fserr(struct fs *, kauth_cred_t, const char *);
-static daddr_t ffs_hashalloc(struct inode *, int, daddr_t, int, int,
-daddr_t (*)(struct inode *, int, daddr_t, int, int));
-static daddr_t ffs_nodealloccg(struct inode *, int, daddr_t, int, int);
+static daddr_t ffs_hashalloc(struct inode *, int, daddr_t, int, int, int,
+daddr_t (*)(struct inode *, int, daddr_t, int, int, int));
+static daddr_t ffs_nodealloccg(struct inode *, int, daddr_t, int, int, int);
 static int32_t ffs_mapsearch(struct fs *, struct cg *,
   daddr_t, int);
 static void ffs_blkfree_common(struct ufsmount *, struct fs *, dev_t, struct buf *,
@@ -174,8 +174,8 @@ ffs_check_bad_allocation(const char *fun
  * => releases um_lock before returning
  */
 int
-ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size, int flags,
-kauth_cred_t cred, daddr_t *bnp)
+ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
+int flags, kauth_cred_t cred, daddr_t *bnp)
 {
 	struct ufsmount *ump;
 	struct fs *fs;
@@ -257,7 +257,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 		cg = ino_to_cg(fs, ip->i_number);
 	else
 		cg = dtog(fs, bpref);
-	bno = ffs_hashalloc(ip, cg, bpref, size, flags, ffs_alloccg);
+	bno = ffs_hashalloc(ip, cg, bpref, size, 0, flags, ffs_alloccg);
 	if (bno > 0) {
 		DIP_ADD(ip, blocks, btodb(size));
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
@@ -476,7 +476,7 @@ ffs_realloccg(struct inode *ip, daddr_t 
 		panic("ffs_realloccg: bad optim");
 		/* NOTREACHED */
 	}
-	bno = ffs_hashalloc(ip, cg, bpref, request, 0, ffs_alloccg);
+	bno = ffs_hashalloc(ip, cg, bpref, request, nsize, 0, ffs_alloccg);
 	if (bno > 0) {
 		if ((ip->i_ump->um_mountp->mnt_wapbl) &&
 		(ITOV(ip)->v_type != VREG)) {
@@ -487,18 +487,6 @@ ffs_realloccg(struct inode *ip, daddr_t 
 			ffs_blkfree(fs, ip->i_devvp, bprev, (long)osize,
 			ip->i_number);
 		}
-		if (nsize < request) {
-			if ((ip->i_ump->um_mountp->mnt_wapbl) &&
-			(ITOV(ip)->v_type != VREG)) {
-UFS_WAPBL_REGISTER_DEALLOCATION(
-ip->i_ump->um_mountp,
-FFS_FSBTODB(fs, (bno + ffs_numfrags(fs, nsize))),
-request - nsize);
-			} else
-ffs_blkfree(fs, ip->i_devvp,
-bno + ffs_numfrags(fs, nsize),
-(long)(request - nsize), ip->i_number);
-		}
 		DIP_ADD(ip, blocks, btodb(nsize - osize));
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
 		if (bpp != NULL) {
@@ -595,7 +583,7 @@ ffs_valloc(struct vnode *pvp, int mode, 
 		if (fs->fs_contigdirs[cg] > 0)
 			fs->fs_contigdirs[cg]--;
 	}
-	ino = (ino_t)ffs_hashalloc(pip, cg, ipref, mode, 0, ffs_nodealloccg);
+	ino = (ino_t)ffs_hashalloc(pip, cg, ipref, mode, 0, 0, ffs_nodealloccg);
 	if (ino == 0)
 		goto noinodes;
 	

CVS commit: src/sys/ufs/ffs

2016-09-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Sep 25 11:45:39 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_balloc.c

Log Message:
fix typo in #ifdef notyet part


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/ufs/ffs/ffs_balloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_balloc.c
diff -u src/sys/ufs/ffs/ffs_balloc.c:1.61 src/sys/ufs/ffs/ffs_balloc.c:1.62
--- src/sys/ufs/ffs/ffs_balloc.c:1.61	Sat Mar 28 19:24:04 2015
+++ src/sys/ufs/ffs/ffs_balloc.c	Sun Sep 25 11:45:39 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_balloc.c,v 1.61 2015/03/28 19:24:04 maxv Exp $	*/
+/*	$NetBSD: ffs_balloc.c,v 1.62 2016/09/25 11:45:39 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2002 Networks Associates Technology, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_balloc.c,v 1.61 2015/03/28 19:24:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_balloc.c,v 1.62 2016/09/25 11:45:39 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -636,7 +636,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t 
 			if (error)
 return (error);
 			error = ffs_getblk(vp, -1 - lbn, FFS_FSBTODB(fs, newb),
-			nsize, (flags & BA_CLRBUF) != 0, );
+			nsize, (flags & B_CLRBUF) != 0, );
 			if (error)
 return error;
 			bp->b_xflags |= BX_ALTDATA;



CVS commit: src/sys/ufs/ffs

2016-09-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Sep 24 21:00:54 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
fix swapped KASSERT()


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.31 src/sys/ufs/ffs/ffs_wapbl.c:1.32
--- src/sys/ufs/ffs/ffs_wapbl.c:1.31	Sat Sep 24 20:59:51 2016
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sat Sep 24 21:00:54 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.31 2016/09/24 20:59:51 jdolecek Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.32 2016/09/24 21:00:54 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.31 2016/09/24 20:59:51 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.32 2016/09/24 21:00:54 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -193,7 +193,7 @@ ffs_wapbl_sync_metadata(struct mount *mp
 		fs->fs_fmod = 0;
 		fs->fs_time = time_second;
 		error = ffs_cgupdate(ump, 0);
-		KASSERT(error != 0);
+		KASSERT(error == 0);
 	}
 }
 



CVS commit: src/sys/ufs/ffs

2016-09-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Sep 24 20:59:51 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
i/o optimization for wapbl flush - only sync superblock and cgs when
they were actually changed


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.30 src/sys/ufs/ffs/ffs_wapbl.c:1.31
--- src/sys/ufs/ffs/ffs_wapbl.c:1.30	Sat Mar 28 19:24:04 2015
+++ src/sys/ufs/ffs/ffs_wapbl.c	Sat Sep 24 20:59:51 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.30 2015/03/28 19:24:04 maxv Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.31 2016/09/24 20:59:51 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.30 2015/03/28 19:24:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_wapbl.c,v 1.31 2016/09/24 20:59:51 jdolecek Exp $");
 
 #define WAPBL_INTERNAL
 
@@ -174,6 +174,8 @@ ffs_wapbl_sync_metadata(struct mount *mp
 	struct fs *fs = ump->um_fs;
 	int i, error __diagused;
 
+	UFS_WAPBL_JLOCK_ASSERT(mp);
+
 #ifdef WAPBL_DEBUG_INODES
 	ufs_wapbl_verify_inodes(mp, "ffs_wapbl_sync_metadata");
 #endif
@@ -187,10 +189,12 @@ ffs_wapbl_sync_metadata(struct mount *mp
 		FFS_DBTOFSB(fs, deallocblks[i]), dealloclens[i], -1);
 	}
 
-	fs->fs_fmod = 0;
-	fs->fs_time = time_second;
-	error = ffs_cgupdate(ump, 0);
-	KASSERT(error == 0);
+	if (fs->fs_fmod != 0) {
+		fs->fs_fmod = 0;
+		fs->fs_time = time_second;
+		error = ffs_cgupdate(ump, 0);
+		KASSERT(error != 0);
+	}
 }
 
 void



CVS commit: src/sys/ufs/ffs

2016-06-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 22:41:31 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Relax the dup alloc tests to not include the on-disk data for ffsv2, since
nothing checks that the lazy-initialized inodes are correct and if they happen
to get corrupted, there is no way to fix them.


To generate a diff of this commit:
cvs rdiff -u -r1.338 -r1.339 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.338 src/sys/ufs/ffs/ffs_vfsops.c:1.339
--- src/sys/ufs/ffs/ffs_vfsops.c:1.338	Wed Dec 23 18:31:28 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jun 19 18:41:31 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.338 2015/12/23 23:31:28 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.339 2016/06/19 22:41:31 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.338 2015/12/23 23:31:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.339 2016/06/19 22:41:31 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -765,7 +765,7 @@ ffs_reload(struct mount *mp, kauth_cred_
 	error = vinvalbuf(devvp, 0, cred, l, 0, 0);
 	VOP_UNLOCK(devvp);
 	if (error)
-		panic("ffs_reload: dirty1");
+		panic("%s: dirty1", __func__);
 
 	/*
 	 * Step 2: re-read superblock from disk. XXX: We don't handle
@@ -922,7 +922,7 @@ ffs_reload(struct mount *mp, kauth_cred_
 			continue;
 		}
 		if (vinvalbuf(vp, 0, cred, l, 0, 0))
-			panic("ffs_reload: dirty2");
+			panic("%s: dirty2", __func__);
 		/*
 		 * Step 6: re-read inode data for all active vnodes.
 		 */
@@ -1902,8 +1902,7 @@ ffs_sync(struct mount *mp, int waitfor, 
 
 	fs = ump->um_fs;
 	if (fs->fs_fmod != 0 && fs->fs_ronly != 0) {		/* XXX */
-		printf("fs = %s\n", fs->fs_fsmnt);
-		panic("update: rofs mod");
+		panic("%s: rofs mod, fs=%s", __func__, fs->fs_fsmnt);
 	}
 
 	fstrans_start(mp, FSTRANS_SHARED);
@@ -2141,14 +2140,22 @@ ffs_newvnode(struct mount *mp, struct vn
 	}
 
 	ip = VTOI(vp);
-	if (ip->i_mode || DIP(ip, size) || DIP(ip, blocks)) {
-		printf("free ino %" PRId64 " on %s:\n", ino, fs->fs_fsmnt);
-		printf("dmode %x mode %x dgen %x gen %x\n",
-		DIP(ip, mode), ip->i_mode,
-		DIP(ip, gen), ip->i_gen);
-		printf("size %" PRIx64 " blocks %" PRIx64 "\n",
-		DIP(ip, size), DIP(ip, blocks));
-		panic("ffs_init_vnode: dup alloc");
+	if (ip->i_mode) {
+		panic("%s: dup alloc ino=%" PRId64 " on %s: mode %x/%x "
+		"gen %x/%x size %" PRIx64 " blocks %" PRIx64,
+		__func__, ino, fs->fs_fsmnt, DIP(ip, mode), ip->i_mode,
+		DIP(ip, gen), ip->i_gen, DIP(ip, size), DIP(ip, blocks));
+	}
+	if (DIP(ip, size) || DIP(ip, blocks)) {
+		printf("%s: ino=%" PRId64 " on %s: "
+		"gen %x/%x has non zero blocks %" PRIx64 " or size %"
+		PRIx64 "\n",
+		__func__, ino, fs->fs_fsmnt, DIP(ip, gen), ip->i_gen,
+		DIP(ip, blocks), DIP(ip, size));
+		if ((ip)->i_ump->um_fstype == UFS1)
+			panic("%s: dirty filesystem?", __func__);
+		DIP_ASSIGN(ip, blocks, 0);
+		DIP_ASSIGN(ip, size, 0);
 	}
 
 	/* Set uid / gid. */



CVS commit: src/sys/ufs/ffs

2016-05-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May  7 11:59:09 UTC 2016

Modified Files:
src/sys/ufs/ffs: ffs_subr.c

Log Message:
uaf


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/ufs/ffs/ffs_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_subr.c
diff -u src/sys/ufs/ffs/ffs_subr.c:1.48 src/sys/ufs/ffs/ffs_subr.c:1.49
--- src/sys/ufs/ffs/ffs_subr.c:1.48	Sun Oct 20 00:29:10 2013
+++ src/sys/ufs/ffs/ffs_subr.c	Sat May  7 11:59:08 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_subr.c,v 1.48 2013/10/20 00:29:10 htodd Exp $	*/
+/*	$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.48 2013/10/20 00:29:10 htodd Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $");
 
 #include 
 
@@ -127,8 +127,10 @@ ffs_getblk(struct vnode *vp, daddr_t lbl
 		(*bpp)->b_blkno = blkno;
 	if (clearbuf)
 		clrbuf(*bpp);
-	if ((*bpp)->b_blkno >= 0 && (error = fscow_run(*bpp, false)) != 0)
+	if ((*bpp)->b_blkno >= 0 && (error = fscow_run(*bpp, false)) != 0) {
 		brelse(*bpp, BC_INVAL);
+		*bpp = NULL;
+	}
 	return error;
 }
 



CVS commit: src/sys/ufs/ffs

2015-12-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec 23 23:31:28 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
We need to check if the inode is initialized for ffsv2 when we translate a
filehandle to a vnode. This can come from nfs and it could be out of range.
In that case we read garbage from the disk, end up trying to free bogus data
when we put the vnode back and we crash.
XXX: pullup-7


To generate a diff of this commit:
cvs rdiff -u -r1.337 -r1.338 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.337 src/sys/ufs/ffs/ffs_vfsops.c:1.338
--- src/sys/ufs/ffs/ffs_vfsops.c:1.337	Sat Nov 14 20:39:23 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Dec 23 18:31:28 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.337 2015/11/15 01:39:23 pgoyette Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.338 2015/12/23 23:31:28 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.337 2015/11/15 01:39:23 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.338 2015/12/23 23:31:28 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -192,6 +192,54 @@ static const struct ufs_ops ffs_ufsops =
 };
 
 static int
+ffs_checkrange(struct mount *mp, uint32_t ino)
+{
+	struct fs *fs = VFSTOUFS(mp)->um_fs;
+
+	if (ino < UFS_ROOTINO || ino >= fs->fs_ncg * fs->fs_ipg) {
+		DPRINTF("out of range %u\n", ino);
+		return ESTALE;
+	}
+
+	/*
+	 * Need to check if inode is initialized because ffsv2 does 
+	 * lazy initialization and we can get here from nfs_fhtovp
+	 */
+	if (fs->fs_magic != FS_UFS2_MAGIC)
+		return 0;
+
+	struct buf *bp;
+	int cg = ino_to_cg(fs, ino);
+	struct ufsmount *ump = VFSTOUFS(mp);
+
+	int error = bread(ump->um_devvp, FFS_FSBTODB(fs, cgtod(fs, cg)),
+	(int)fs->fs_cgsize, B_MODIFY, );
+	if (error) {
+		DPRINTF("error %d reading cg %d ino %u\n", error, cg, ino);
+		return error;
+	}
+
+	const int needswap = UFS_FSNEEDSWAP(fs);
+
+	struct cg *cgp = (struct cg *)bp->b_data;
+	if (!cg_chkmagic(cgp, needswap)) {
+		brelse(bp, 0);
+		DPRINTF("bad cylinder group magic cg %d ino %u\n", cg, ino);
+		return ESTALE;
+	}
+
+	int32_t initediblk = ufs_rw32(cgp->cg_initediblk, needswap);
+	brelse(bp, 0);
+
+	if (cg * fs->fs_ipg + initediblk < ino) {
+		DPRINTF("cg=%d fs->fs_ipg=%d initediblk=%d ino=%u\n",
+		cg, fs->fs_ipg, initediblk, ino);
+		return ESTALE;
+	}
+	return 0;
+}
+
+static int
 ffs_snapshot_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
 void *arg0, void *arg1, void *arg2, void *arg3)
 {
@@ -2181,16 +2229,15 @@ int
 ffs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
 {
 	struct ufid ufh;
-	struct fs *fs;
+	int error;
 
 	if (fhp->fid_len != sizeof(struct ufid))
 		return EINVAL;
 
 	memcpy(, fhp, sizeof(ufh));
-	fs = VFSTOUFS(mp)->um_fs;
-	if (ufh.ufid_ino < UFS_ROOTINO ||
-	ufh.ufid_ino >= fs->fs_ncg * fs->fs_ipg)
-		return (ESTALE);
+	if ((error = ffs_checkrange(mp, ufh.ufid_ino)) != 0)
+		return error;
+
 	return (ufs_fhtovp(mp, , vpp));
 }
 



CVS commit: src/sys/ufs/ffs

2015-11-14 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Nov 15 01:39:23 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
If file system ffs is built with WAPBL defined, make sure that the
module depends on the wapbl module.

No impact to users of built-in ffs file system code, as the WAPBL
#define will cause inclusion of the code in the kernel.

A standard build of the modular ffs file system code will #define
WAPBL, so the module will only work on a kernel which was also
built with WAPBL defined (or, once I commit it, with a dynamically-
loaded wapbl module).


To generate a diff of this commit:
cvs rdiff -u -r1.336 -r1.337 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.336 src/sys/ufs/ffs/ffs_vfsops.c:1.337
--- src/sys/ufs/ffs/ffs_vfsops.c:1.336	Thu Oct 22 11:31:31 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Nov 15 01:39:23 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.336 2015/10/22 11:31:31 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.337 2015/11/15 01:39:23 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.336 2015/10/22 11:31:31 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.337 2015/11/15 01:39:23 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -109,7 +109,11 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c
 #include 
 #include 
 
+#ifdef WAPBL
+MODULE(MODULE_CLASS_VFS, ffs, "wapbl");
+#else
 MODULE(MODULE_CLASS_VFS, ffs, NULL);
+#endif
 
 static int ffs_vfs_fsync(vnode_t *, int);
 static int ffs_superblock_validate(struct fs *);



CVS commit: src/sys/ufs/ffs

2015-10-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Oct 22 11:31:31 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Fix PR 50070. From hannken@.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.335 src/sys/ufs/ffs/ffs_vfsops.c:1.336
--- src/sys/ufs/ffs/ffs_vfsops.c:1.335	Fri Jul 24 13:02:52 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Thu Oct 22 11:31:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.335 2015/07/24 13:02:52 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.336 2015/10/22 11:31:31 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.335 2015/07/24 13:02:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.336 2015/10/22 11:31:31 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -899,7 +899,7 @@ static int
 ffs_superblock_validate(struct fs *fs)
 {
 	int32_t i, fs_bshift = 0, fs_fshift = 0, fs_fragshift = 0, fs_frag;
-	int32_t fs_inopb, fs_cgsize;
+	int32_t fs_inopb;
 
 	/* Check the superblock size */
 	if (fs->fs_sbsize > SBLOCKSIZE || fs->fs_sbsize < sizeof(struct fs))
@@ -981,23 +981,9 @@ ffs_superblock_validate(struct fs *fs)
 		return 0;
 
 	/* Check the size of cylinder groups */
-	fs_cgsize = ffs_fragroundup(fs, CGSIZE(fs));
-	if (fs->fs_cgsize != fs_cgsize) {
-		if (fs->fs_cgsize+1 == CGSIZE(fs)) {
-			printf("CGSIZE(fs) miscalculated by one - this file "
-			"system may have been created by\n"
-			"  an old (buggy) userland, see\n"
-			"  http://www.NetBSD.org/;
-			"docs/ffsv1badsuperblock.html\n");
-		} else {
-			printf("ERROR: cylinder group size mismatch: "
-			"fs_cgsize = 0x%zx, "
-			"fs->fs_cgsize = 0x%zx, CGSIZE(fs) = 0x%zx\n",
-			(size_t)fs_cgsize, (size_t)fs->fs_cgsize,
-			(size_t)CGSIZE(fs));
-			return 0;
-		}
-	}
+	if ((fs->fs_cgsize < sizeof(struct cg)) ||
+	(fs->fs_cgsize > fs->fs_bsize))
+		return 0;
 
 	return 1;
 }



CVS commit: src/sys/ufs/ffs

2015-08-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 12 14:52:35 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Need wapbl transaction around ffs_blkfree_cg.  Fixes wapbl+discard.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.150 src/sys/ufs/ffs/ffs_alloc.c:1.151
--- src/sys/ufs/ffs/ffs_alloc.c:1.150	Sat Aug  8 08:18:52 2015
+++ src/sys/ufs/ffs/ffs_alloc.c	Wed Aug 12 14:52:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.150 2015/08/08 08:18:52 mlelstv Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.151 2015/08/12 14:52:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.150 2015/08/08 08:18:52 mlelstv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.151 2015/08/12 14:52:35 riastradh Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1553,12 +1553,21 @@ struct discarddata {
 static void
 ffs_blkfree_td(struct fs *fs, struct discardopdata *td)
 {
+	struct mount *mp = spec_node_getmountedfs(td-devvp);
 	long todo;
+	int error;
 
 	while (td-size) {
 		todo = min(td-size,
 		  ffs_lfragtosize(fs, (fs-fs_frag - ffs_fragnum(fs, td-bno;
+		error = UFS_WAPBL_BEGIN(mp);
+		if (error) {
+			printf(ffs: failed to begin wapbl transaction
+			 for discard: %d\n, error);
+			break;
+		}
 		ffs_blkfree_cg(fs, td-devvp, td-bno, todo);
+		UFS_WAPBL_END(mp);
 		td-bno += ffs_numfrags(fs, todo);
 		td-size -= todo;
 	}



CVS commit: src/sys/ufs/ffs

2015-08-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Aug  8 08:18:52 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
don't crash when printing error messages when there are no credentials.
don't abuse the printed uid to log the inode number.

The printing/logging of error messages should be simplified.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.149 src/sys/ufs/ffs/ffs_alloc.c:1.150
--- src/sys/ufs/ffs/ffs_alloc.c:1.149	Sat Mar 28 19:24:04 2015
+++ src/sys/ufs/ffs/ffs_alloc.c	Sat Aug  8 08:18:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.149 2015/03/28 19:24:04 maxv Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.150 2015/08/08 08:18:52 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.149 2015/03/28 19:24:04 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.150 2015/08/08 08:18:52 mlelstv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -111,7 +111,7 @@ static daddr_t ffs_alloccg(struct inode 
 static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int);
 static ino_t ffs_dirpref(struct inode *);
 static daddr_t ffs_fragextend(struct inode *, int, daddr_t, int, int);
-static void ffs_fserr(struct fs *, u_int, const char *);
+static void ffs_fserr(struct fs *, kauth_cred_t, const char *);
 static daddr_t ffs_hashalloc(struct inode *, int, daddr_t, int, int,
 daddr_t (*)(struct inode *, int, daddr_t, int, int));
 static daddr_t ffs_nodealloccg(struct inode *, int, daddr_t, int, int);
@@ -145,7 +145,7 @@ ffs_check_bad_allocation(const char *fun
 	if (bno = fs-fs_size) {
 		printf(bad block % PRId64 , ino %llu\n, bno,
 		(unsigned long long)inum);
-		ffs_fserr(fs, inum, bad block);
+		ffs_fserr(fs, NOCRED, bad block);
 		return EINVAL;
 	}
 	return 0;
@@ -286,7 +286,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn,
 	}
 nospace:
 	mutex_exit(ump-um_lock);
-	ffs_fserr(fs, kauth_cred_geteuid(cred), file system full);
+	ffs_fserr(fs, cred, file system full);
 	uprintf(\n%s: write failed, file system is full\n, fs-fs_fsmnt);
 	return (ENOSPC);
 }
@@ -532,7 +532,7 @@ nospace:
 	/*
 	 * no space available
 	 */
-	ffs_fserr(fs, kauth_cred_geteuid(cred), file system full);
+	ffs_fserr(fs, cred, file system full);
 	uprintf(\n%s: write failed, file system is full\n, fs-fs_fsmnt);
 	return (ENOSPC);
 }
@@ -605,7 +605,7 @@ ffs_valloc(struct vnode *pvp, int mode, 
 noinodes:
 	mutex_exit(ump-um_lock);
 	UFS_WAPBL_END(pvp-v_mount);
-	ffs_fserr(fs, kauth_cred_geteuid(cred), out of inodes);
+	ffs_fserr(fs, cred, out of inodes);
 	uprintf(\n%s: create/symlink failed, no inodes free\n, fs-fs_fsmnt);
 	return ENOSPC;
 }
@@ -2159,9 +2159,17 @@ ffs_mapsearch(struct fs *fs, struct cg *
  *	fs: error message
  */
 static void
-ffs_fserr(struct fs *fs, u_int uid, const char *cp)
+ffs_fserr(struct fs *fs, kauth_cred_t cred, const char *cp)
 {
+	KASSERT(cred != NULL);
 
-	log(LOG_ERR, uid %d, pid %d, command %s, on %s: %s\n,
-	uid, curproc-p_pid, curproc-p_comm, fs-fs_fsmnt, cp);
+	if (cred == NOCRED || cred == FSCRED) {
+		log(LOG_ERR, pid %d, command %s, on %s: %s\n,
+		curproc-p_pid, curproc-p_comm,
+		fs-fs_fsmnt, cp);
+	} else {
+		log(LOG_ERR, uid %d, pid %d, command %s, on %s: %s\n,
+		kauth_cred_getuid(cred), curproc-p_pid, curproc-p_comm,
+		fs-fs_fsmnt, cp);
+	}
 }



CVS commit: src/sys/ufs/ffs

2015-06-28 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jun 28 10:04:32 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_snapshot.c

Log Message:
Small fixes.

ok hannken@


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/ufs/ffs/ffs_snapshot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.139 src/sys/ufs/ffs/ffs_snapshot.c:1.140
--- src/sys/ufs/ffs/ffs_snapshot.c:1.139	Sat Mar 28 19:24:04 2015
+++ src/sys/ufs/ffs/ffs_snapshot.c	Sun Jun 28 10:04:32 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.139 2015/03/28 19:24:04 maxv Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.140 2015/06/28 10:04:32 maxv Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.139 2015/03/28 19:24:04 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.140 2015/06/28 10:04:32 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -82,7 +82,7 @@ TAILQ_HEAD(inodelst, inode);			/* List o
 struct snap_info {
 	kmutex_t si_lock;			/* Lock this snapinfo */
 	kmutex_t si_snaplock;			/* Snapshot vnode common lock */
-	lwp_t *si_owner;			/* Sanplock owner */
+	lwp_t *si_owner;			/* Snaplock owner */
 	struct inodelst si_snapshots;		/* List of active snapshots */
 	daddr_t *si_snapblklist;		/* Snapshot block hints list */
 	uint32_t si_gen;			/* Incremented on change */
@@ -198,12 +198,12 @@ ffs_snapshot(struct mount *mp, struct vn
 	/*
 	 * If the vnode already is a snapshot, return.
 	 */
-	if ((VTOI(vp)-i_flags  SF_SNAPSHOT)) {
-		if ((VTOI(vp)-i_flags  SF_SNAPINVAL))
+	if ((ip-i_flags  SF_SNAPSHOT)) {
+		if ((ip-i_flags  SF_SNAPINVAL))
 			return EINVAL;
 		if (ctime) {
-			ctime-tv_sec = DIP(VTOI(vp), mtime);
-			ctime-tv_nsec = DIP(VTOI(vp), mtimensec);
+			ctime-tv_sec = DIP(ip, mtime);
+			ctime-tv_nsec = DIP(ip, mtimensec);
 		}
 		return 0;
 	}
@@ -269,9 +269,9 @@ ffs_snapshot(struct mount *mp, struct vn
 	 * Create a copy of the superblock and its summary information.
 	 */
 	error = snapshot_copyfs(mp, vp, sbbuf);
-	copy_fs = (struct fs *)((char *)sbbuf + ffs_blkoff(fs, fs-fs_sblockloc));
 	if (error)
 		goto out;
+	copy_fs = (struct fs *)((char *)sbbuf + ffs_blkoff(fs, fs-fs_sblockloc));
 	/*
 	 * Expunge unlinked files from our view.
 	 */



CVS commit: src/sys/ufs/ffs

2015-05-23 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 23 16:59:13 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Add a missing goto.

(was here before my changes)

ok christos@


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.333 src/sys/ufs/ffs/ffs_vfsops.c:1.334
--- src/sys/ufs/ffs/ffs_vfsops.c:1.333	Tue May 19 06:44:42 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat May 23 16:59:13 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.333 2015/05/19 06:44:42 martin Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.334 2015/05/23 16:59:13 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.333 2015/05/19 06:44:42 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.334 2015/05/23 16:59:13 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1332,6 +1332,8 @@ ffs_mountfs(struct vnode *devvp, struct 
 			DPRINTF(bcount %x != fsize %x, bp-b_bcount,
 			fs-fs_fsize);
 			error = EINVAL;
+			bset = BC_INVAL;
+			goto out;
 		}
 		brelse(bp, BC_INVAL);
 		bp = NULL;



CVS commit: src/sys/ufs/ffs

2015-05-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 20 18:19:09 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_bswap.c

Log Message:
Don't (harmlessly) overrun di_db array; copy di_ib separately.

Noted by Coverity, CID 974635.

While here, simplify size calculation for memcpy.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/ufs/ffs/ffs_bswap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_bswap.c
diff -u src/sys/ufs/ffs/ffs_bswap.c:1.37 src/sys/ufs/ffs/ffs_bswap.c:1.38
--- src/sys/ufs/ffs/ffs_bswap.c:1.37	Sun Jun  9 17:55:46 2013
+++ src/sys/ufs/ffs/ffs_bswap.c	Wed May 20 18:19:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_bswap.c,v 1.37 2013/06/09 17:55:46 dholland Exp $	*/
+/*	$NetBSD: ffs_bswap.c,v 1.38 2015/05/20 18:19:09 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.
@@ -30,7 +30,7 @@
 #endif
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_bswap.c,v 1.37 2013/06/09 17:55:46 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_bswap.c,v 1.38 2015/05/20 18:19:09 riastradh Exp $);
 
 #include sys/param.h
 #if defined(_KERNEL)
@@ -128,7 +128,8 @@ ffs_dinode1_swap(struct ufs1_dinode *o, 
 	n-di_mtimensec = bswap32(o-di_mtimensec);
 	n-di_ctime = bswap32(o-di_ctime);
 	n-di_ctimensec = bswap32(o-di_ctimensec);
-	memcpy(n-di_db, o-di_db, (UFS_NDADDR + UFS_NIADDR) * sizeof(u_int32_t));
+	memcpy(n-di_db, o-di_db, sizeof(n-di_db));
+	memcpy(n-di_ib, o-di_ib, sizeof(n-di_ib));
 	n-di_flags = bswap32(o-di_flags);
 	n-di_blocks = bswap32(o-di_blocks);
 	n-di_gen = bswap32(o-di_gen);



CVS commit: src/sys/ufs/ffs

2015-05-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 20 18:21:17 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_bswap.c

Log Message:
memcpy di_extb/db/ib separately.  Noted by Coverity, CID 974636.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/ufs/ffs/ffs_bswap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_bswap.c
diff -u src/sys/ufs/ffs/ffs_bswap.c:1.38 src/sys/ufs/ffs/ffs_bswap.c:1.39
--- src/sys/ufs/ffs/ffs_bswap.c:1.38	Wed May 20 18:19:09 2015
+++ src/sys/ufs/ffs/ffs_bswap.c	Wed May 20 18:21:17 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_bswap.c,v 1.38 2015/05/20 18:19:09 riastradh Exp $	*/
+/*	$NetBSD: ffs_bswap.c,v 1.39 2015/05/20 18:21:17 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.
@@ -30,7 +30,7 @@
 #endif
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_bswap.c,v 1.38 2015/05/20 18:19:09 riastradh Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_bswap.c,v 1.39 2015/05/20 18:21:17 riastradh Exp $);
 
 #include sys/param.h
 #if defined(_KERNEL)
@@ -159,7 +159,9 @@ ffs_dinode2_swap(struct ufs2_dinode *o, 
 	n-di_kernflags = bswap32(o-di_kernflags);
 	n-di_flags = bswap32(o-di_flags);
 	n-di_extsize = bswap32(o-di_extsize);
-	memcpy(n-di_extb, o-di_extb, (UFS_NXADDR + UFS_NDADDR + UFS_NIADDR) * 8);
+	memcpy(n-di_extb, o-di_extb, sizeof(n-di_extb));
+	memcpy(n-di_db, o-di_db, sizeof(n-di_db));
+	memcpy(n-di_ib, o-di_ib, sizeof(n-di_ib));
 }
 
 void



CVS commit: src/sys/ufs/ffs

2015-05-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 19 06:44:42 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Cosmetics: fix netbsd.org spelling


To generate a diff of this commit:
cvs rdiff -u -r1.332 -r1.333 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.332 src/sys/ufs/ffs/ffs_vfsops.c:1.333
--- src/sys/ufs/ffs/ffs_vfsops.c:1.332	Mon May 18 08:33:29 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Tue May 19 06:44:42 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.332 2015/05/18 08:33:29 martin Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.333 2015/05/19 06:44:42 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.332 2015/05/18 08:33:29 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.333 2015/05/19 06:44:42 martin Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -987,7 +987,7 @@ ffs_superblock_validate(struct fs *fs)
 			printf(CGSIZE(fs) miscalculated by one - this file 
 			system may have been created by\n
 			  an old (buggy) userland, see\n
-			  http://www.netbsd.org/;
+			  http://www.NetBSD.org/;
 			docs/ffsv1badsuperblock.html\n);
 		} else {
 			printf(ERROR: cylinder group size mismatch: 



CVS commit: src/sys/ufs/ffs

2015-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 08:07:30 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Make the recently added fs_cgsize test less strict, as it prevents existing
installs from booting.
Catch the common case and warn about it, pointing to a web page describing
the issue - but allow mounting. In all other cases, print more details about
the inconsistency and fail the mount.


To generate a diff of this commit:
cvs rdiff -u -r1.330 -r1.331 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.330 src/sys/ufs/ffs/ffs_vfsops.c:1.331
--- src/sys/ufs/ffs/ffs_vfsops.c:1.330	Sun Apr 26 06:19:36 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon May 18 08:07:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.330 2015/04/26 06:19:36 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.331 2015/05/18 08:07:29 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.330 2015/04/26 06:19:36 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.331 2015/05/18 08:07:29 martin Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -982,8 +982,21 @@ ffs_superblock_validate(struct fs *fs)
 
 	/* Check the size of cylinder groups */
 	fs_cgsize = ffs_fragroundup(fs, CGSIZE(fs));
-	if (fs-fs_cgsize != fs_cgsize)
-		return 0;
+	if (fs-fs_cgsize != fs_cgsize) {
+		if (fs-fs_cgsize+1 == CGSIZE(fs)) {
+			printf(CGSIZE(fs) miscalculated by one - this file 
+			system may have been created by\n
+			  an old (buggy) userland, see\n
+			  http://www.netbsd.org/;
+			docs/ffsv1badsuperblock.html\n);
+		} else {
+			printf(ERROR: cylinder group size mismatch: 
+			fs_cgsize = 0x%x, 
+			fs-fs_cgsize = 0x%x, CGSIZE(fs) = 0x%lx\n,
+			fs_cgsize, fs-fs_cgsize, CGSIZE(fs));
+			return 0;
+		}
+	}
 
 	return 1;
 }



CVS commit: src/sys/ufs/ffs

2015-04-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Apr 26 06:19:36 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): check the size of cylinder groups.


To generate a diff of this commit:
cvs rdiff -u -r1.329 -r1.330 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.329 src/sys/ufs/ffs/ffs_vfsops.c:1.330
--- src/sys/ufs/ffs/ffs_vfsops.c:1.329	Wed Apr 22 07:27:09 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Apr 26 06:19:36 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.329 2015/04/22 07:27:09 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.330 2015/04/26 06:19:36 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.329 2015/04/22 07:27:09 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.330 2015/04/26 06:19:36 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -899,7 +899,7 @@ static int
 ffs_superblock_validate(struct fs *fs)
 {
 	int32_t i, fs_bshift = 0, fs_fshift = 0, fs_fragshift = 0, fs_frag;
-	int32_t fs_inopb;
+	int32_t fs_inopb, fs_cgsize;
 
 	/* Check the superblock size */
 	if (fs-fs_sbsize  SBLOCKSIZE || fs-fs_sbsize  sizeof(struct fs))
@@ -980,6 +980,11 @@ ffs_superblock_validate(struct fs *fs)
 	if (fs-fs_frag != fs_frag)
 		return 0;
 
+	/* Check the size of cylinder groups */
+	fs_cgsize = ffs_fragroundup(fs, CGSIZE(fs));
+	if (fs-fs_cgsize != fs_cgsize)
+		return 0;
+
 	return 1;
 }
 



CVS commit: src/sys/ufs/ffs

2015-04-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Apr 22 07:27:09 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Instead of duplicating code, create ffs_is_appleufs(): returns 1 if the
device is an AppleUFS FS, 0 otherwise.

This changes the behavior a bit: if the kernel cannot determine whether the
disk is an AppleUFS one or not, it now considers it as a normal UFS rather
than returning an error and not mounting/reloading it.

No particular comment on tech-kern@


To generate a diff of this commit:
cvs rdiff -u -r1.328 -r1.329 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.328 src/sys/ufs/ffs/ffs_vfsops.c:1.329
--- src/sys/ufs/ffs/ffs_vfsops.c:1.328	Sat Apr  4 06:00:12 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Wed Apr 22 07:27:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.328 2015/04/04 06:00:12 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.329 2015/04/22 07:27:09 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.328 2015/04/04 06:00:12 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.329 2015/04/22 07:27:09 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -113,6 +113,7 @@ MODULE(MODULE_CLASS_VFS, ffs, NULL);
 
 static int ffs_vfs_fsync(vnode_t *, int);
 static int ffs_superblock_validate(struct fs *);
+static int ffs_is_appleufs(struct vnode *, struct fs *);
 
 static int ffs_init_vnode(struct ufsmount *, struct vnode *, ino_t);
 static void ffs_deinit_vnode(struct ufsmount *, struct vnode *);
@@ -693,7 +694,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 	void *space;
 	struct buf *bp;
 	struct fs *fs, *newfs;
-	struct dkwedge_info dkw;
 	int i, bsize, blks, error;
 	int32_t *lp, fs_sbsize;
 	struct ufsmount *ump;
@@ -776,41 +776,18 @@ ffs_reload(struct mount *mp, kauth_cred_
 	memcpy(fs, newfs, (u_int)fs_sbsize);
 	kmem_free(newfs, fs_sbsize);
 
-	/* Recheck for apple UFS filesystem */
-	ump-um_flags = ~UFS_ISAPPLEUFS;
-	/* First check to see if this is tagged as an Apple UFS filesystem
-	 * in the disklabel
+	/*
+	 * Recheck for Apple UFS filesystem.
 	 */
-	if (getdiskinfo(devvp, dkw) == 0 
-	strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
-		ump-um_flags |= UFS_ISAPPLEUFS;
+	ump-um_flags = ~UFS_ISAPPLEUFS;
+	if (ffs_is_appleufs(devvp, fs)) {
 #ifdef APPLE_UFS
-	else {
-		/* Manually look for an apple ufs label, and if a valid one
-		 * is found, then treat it like an Apple UFS filesystem anyway
-		 *
-		 * EINVAL is most probably a blocksize or alignment problem,
-		 * it is unlikely that this is an Apple UFS filesystem then.
-		 */
-		error = bread(devvp,
-		(daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
-		APPLEUFS_LABEL_SIZE, 0, bp);
-		if (error  error != EINVAL) {
-			return error;
-		}
-		if (error == 0) {
-			error = ffs_appleufs_validate(fs-fs_fsmnt,
-(struct appleufslabel *)bp-b_data, NULL);
-			if (error == 0)
-ump-um_flags |= UFS_ISAPPLEUFS;
-			brelse(bp, 0);
-		}
-		bp = NULL;
-	}
+		ump-um_flags |= UFS_ISAPPLEUFS;
 #else
-	if (ump-um_flags  UFS_ISAPPLEUFS)
-		return (EIO);
+		DPRINTF(AppleUFS not supported);
+		return (EIO); /* XXX: really? */
 #endif
+	}
 
 	if (UFS_MPISAPPLEUFS(ump)) {
 		/* see comment about NeXT below */
@@ -1006,6 +983,46 @@ ffs_superblock_validate(struct fs *fs)
 	return 1;
 }
 
+static int
+ffs_is_appleufs(struct vnode *devvp, struct fs *fs)
+{
+	struct dkwedge_info dkw;
+	int ret = 0;
+
+	/*
+	 * First check to see if this is tagged as an Apple UFS filesystem
+	 * in the disklabel.
+	 */
+	if (getdiskinfo(devvp, dkw) == 0 
+	strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
+		ret = 1;
+#ifdef APPLE_UFS
+	else {
+		struct appleufslabel *applefs;
+		struct buf *bp;
+		daddr_t blkno = APPLEUFS_LABEL_OFFSET / DEV_BSIZE;
+		int error;
+
+		/*
+		 * Manually look for an Apple UFS label, and if a valid one
+		 * is found, then treat it like an Apple UFS filesystem anyway.
+		 */
+		error = bread(devvp, blkno, APPLEUFS_LABEL_SIZE, 0, bp);
+		if (error) {
+			DPRINTF(bread@0x%jx returned %d, (intmax_t)blkno, error);
+			return 0;
+		}
+		applefs = (struct appleufslabel *)bp-b_data;
+		error = ffs_appleufs_validate(fs-fs_fsmnt, applefs, NULL);
+		if (error == 0)
+			ret = 1;
+		brelse(bp, 0);
+	}
+#endif
+
+	return ret;
+}
+
 /*
  * Common code for mount and mountroot
  */
@@ -1016,7 +1033,6 @@ ffs_mountfs(struct vnode *devvp, struct 
 	struct buf *bp = NULL;
 	struct fs *fs = NULL;
 	dev_t dev;
-	struct dkwedge_info dkw;
 	void *space;
 	daddr_t sblockloc = 0;
 	int blks, fstype = 0;
@@ -1239,42 +1255,15 @@ ffs_mountfs(struct vnode *devvp, struct 
 		brelse(bp, 0);
 	bp = NULL;
 
-	/*
-	 * First check to see if this is tagged as an Apple UFS filesystem
-	 * in the disklabel
-	 */

CVS commit: src/sys/ufs/ffs

2015-04-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Apr  4 06:00:12 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): ensure fs_ncg!=0 and fs_maxbpg!=0 to prevent
several divisions by zero.


To generate a diff of this commit:
cvs rdiff -u -r1.327 -r1.328 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.327 src/sys/ufs/ffs/ffs_vfsops.c:1.328
--- src/sys/ufs/ffs/ffs_vfsops.c:1.327	Sat Mar 28 19:24:04 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Apr  4 06:00:12 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.327 2015/03/28 19:24:04 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.328 2015/04/04 06:00:12 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.327 2015/03/28 19:24:04 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.328 2015/04/04 06:00:12 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -952,6 +952,10 @@ ffs_superblock_validate(struct fs *fs)
 		return 0;
 	if (fs-fs_fpg == 0)
 		return 0;
+	if (fs-fs_ncg == 0)
+		return 0;
+	if (fs-fs_maxbpg == 0)
+		return 0;
 
 	/* Check the number of inodes per block */
 	if (fs-fs_magic == FS_UFS1_MAGIC)



CVS commit: src/sys/ufs/ffs

2015-03-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Mar 15 09:21:01 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_reload(): fix a bug that prevents Big Endian FSes from being reloaded.
'newfs' should be tagged as FS_SWAPPED, not 'fs'.

Was here before my changes.

While here, also KNF a bit.


To generate a diff of this commit:
cvs rdiff -u -r1.323 -r1.324 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.323 src/sys/ufs/ffs/ffs_vfsops.c:1.324
--- src/sys/ufs/ffs/ffs_vfsops.c:1.323	Sat Mar 14 19:52:54 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Mar 15 09:21:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.323 2015/03/14 19:52:54 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.324 2015/03/15 09:21:01 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.323 2015/03/14 19:52:54 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.324 2015/03/15 09:21:01 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -727,16 +727,16 @@ ffs_reload(struct mount *mp, kauth_cred_
 
 #ifdef FFS_EI
 	if (ump-um_flags  UFS_NEEDSWAP) {
-		ffs_sb_swap((struct fs*)bp-b_data, newfs);
-		fs-fs_flags |= FS_SWAPPED;
+		ffs_sb_swap((struct fs *)bp-b_data, newfs);
+		newfs-fs_flags |= FS_SWAPPED;
 	} else
 #endif
-		fs-fs_flags = ~FS_SWAPPED;
+		newfs-fs_flags = ~FS_SWAPPED;
 
 	brelse(bp, 0);
 
-	if ((newfs-fs_magic != FS_UFS1_MAGIC 
-	 newfs-fs_magic != FS_UFS2_MAGIC)) {
+	if ((newfs-fs_magic != FS_UFS1_MAGIC) 
+	(newfs-fs_magic != FS_UFS2_MAGIC)) {
 		kmem_free(newfs, fs_sbsize);
 		return (EIO);		/* XXX needs translation */
 	}
@@ -757,7 +757,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 		return (EINVAL);
 	}
 
-
 	/* Store off old fs_sblockloc for fs_oldfscompat_read. */
 	sblockloc = fs-fs_sblockloc;
 	/*



CVS commit: src/sys/ufs/ffs

2015-03-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Mar 14 19:52:54 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): ensure fs_ipg and fs_fpg are != 0. Otherwise
division by zero in several places.


To generate a diff of this commit:
cvs rdiff -u -r1.322 -r1.323 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.322 src/sys/ufs/ffs/ffs_vfsops.c:1.323
--- src/sys/ufs/ffs/ffs_vfsops.c:1.322	Tue Mar 10 12:59:32 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Mar 14 19:52:54 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.322 2015/03/10 12:59:32 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.323 2015/03/14 19:52:54 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.322 2015/03/10 12:59:32 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.323 2015/03/14 19:52:54 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -937,10 +937,18 @@ ffs_superblock_validate(struct fs *fs)
 	if (fs-fs_fsize == 0)
 		return 0;
 
+	/*
+	 * XXX: these values are just zero-checked to prevent obvious
+	 * bugs. We need more strict checks.
+	 */
 	if (fs-fs_size == 0)
 		return 0;
 	if (fs-fs_cssize == 0)
 		return 0;
+	if (fs-fs_ipg == 0)
+		return 0;
+	if (fs-fs_fpg == 0)
+		return 0;
 
 	/* Check the number of inodes per block */
 	if (fs-fs_magic == FS_UFS1_MAGIC)



CVS commit: src/sys/ufs/ffs

2015-03-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Mar 10 12:59:32 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): check the number of inodes per block. Otherwise
a malformed value could panic the system.


To generate a diff of this commit:
cvs rdiff -u -r1.321 -r1.322 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.321 src/sys/ufs/ffs/ffs_vfsops.c:1.322
--- src/sys/ufs/ffs/ffs_vfsops.c:1.321	Tue Mar  3 17:56:51 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Tue Mar 10 12:59:32 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.321 2015/03/03 17:56:51 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.322 2015/03/10 12:59:32 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.321 2015/03/03 17:56:51 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.322 2015/03/10 12:59:32 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -919,6 +919,7 @@ static int
 ffs_superblock_validate(struct fs *fs)
 {
 	int32_t i, fs_bshift = 0, fs_fshift = 0, fs_fragshift = 0, fs_frag;
+	int32_t fs_inopb;
 
 	/* Check the superblock size */
 	if (fs-fs_sbsize  SBLOCKSIZE || fs-fs_sbsize  sizeof(struct fs))
@@ -941,6 +942,14 @@ ffs_superblock_validate(struct fs *fs)
 	if (fs-fs_cssize == 0)
 		return 0;
 
+	/* Check the number of inodes per block */
+	if (fs-fs_magic == FS_UFS1_MAGIC)
+		fs_inopb = fs-fs_bsize / sizeof(struct ufs1_dinode);
+	else /* fs-fs_magic == FS_UFS2_MAGIC */
+		fs_inopb = fs-fs_bsize / sizeof(struct ufs2_dinode);
+	if (fs-fs_inopb != fs_inopb)
+		return 0;
+
 	/* Block size cannot be smaller than fragment size */
 	if (fs-fs_bsize  fs-fs_fsize)
 		return 0;



CVS commit: src/sys/ufs/ffs

2015-03-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Mar  3 17:56:51 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_reload(): release 'bp' earlier


To generate a diff of this commit:
cvs rdiff -u -r1.320 -r1.321 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.320 src/sys/ufs/ffs/ffs_vfsops.c:1.321
--- src/sys/ufs/ffs/ffs_vfsops.c:1.320	Tue Mar  3 17:46:39 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Tue Mar  3 17:56:51 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.320 2015/03/03 17:46:39 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.321 2015/03/03 17:56:51 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.320 2015/03/03 17:46:39 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.321 2015/03/03 17:56:51 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -733,14 +733,14 @@ ffs_reload(struct mount *mp, kauth_cred_
 #endif
 		fs-fs_flags = ~FS_SWAPPED;
 
+	brelse(bp, 0);
+
 	if ((newfs-fs_magic != FS_UFS1_MAGIC 
 	 newfs-fs_magic != FS_UFS2_MAGIC)) {
-		brelse(bp, 0);
 		kmem_free(newfs, fs_sbsize);
 		return (EIO);		/* XXX needs translation */
 	}
 	if (!ffs_superblock_validate(newfs)) {
-		brelse(bp, 0);
 		kmem_free(newfs, fs_sbsize);
 		return (EINVAL);
 	}
@@ -753,7 +753,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 	(newfs-fs_cssize != fs-fs_cssize) ||
 	(newfs-fs_contigsumsize != fs-fs_contigsumsize) ||
 	(newfs-fs_ncg != fs-fs_ncg)) {
-		brelse(bp, 0);
 		kmem_free(newfs, fs_sbsize);
 		return (EINVAL);
 	}
@@ -772,7 +771,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 	newfs-fs_ronly = fs-fs_ronly;
 	newfs-fs_active = fs-fs_active;
 	memcpy(fs, newfs, (u_int)fs_sbsize);
-	brelse(bp, 0);
 	kmem_free(newfs, fs_sbsize);
 
 	/* Recheck for apple UFS filesystem */



CVS commit: src/sys/ufs/ffs

2015-03-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Mar  3 17:46:39 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_reload(): the current implementation blindly guesses critical fields
of the superblock didn't change. Add checks to ensure they didn't change
for real. This prevents several memory corruptions.


To generate a diff of this commit:
cvs rdiff -u -r1.319 -r1.320 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.319 src/sys/ufs/ffs/ffs_vfsops.c:1.320
--- src/sys/ufs/ffs/ffs_vfsops.c:1.319	Mon Feb 23 13:38:54 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Tue Mar  3 17:46:39 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.319 2015/02/23 13:38:54 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.320 2015/03/03 17:46:39 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.319 2015/02/23 13:38:54 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.320 2015/03/03 17:46:39 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -733,12 +733,6 @@ ffs_reload(struct mount *mp, kauth_cred_
 #endif
 		fs-fs_flags = ~FS_SWAPPED;
 
-	/* We don't want the superblock size to change. */
-	if (newfs-fs_sbsize != fs_sbsize) {
-		brelse(bp, 0);
-		kmem_free(newfs, fs_sbsize);
-		return (EINVAL);
-	}
 	if ((newfs-fs_magic != FS_UFS1_MAGIC 
 	 newfs-fs_magic != FS_UFS2_MAGIC)) {
 		brelse(bp, 0);
@@ -751,6 +745,20 @@ ffs_reload(struct mount *mp, kauth_cred_
 		return (EINVAL);
 	}
 
+	/*
+	 * The current implementation doesn't handle the possibility that
+	 * these values may have changed.
+	 */
+	if ((newfs-fs_sbsize != fs_sbsize) ||
+	(newfs-fs_cssize != fs-fs_cssize) ||
+	(newfs-fs_contigsumsize != fs-fs_contigsumsize) ||
+	(newfs-fs_ncg != fs-fs_ncg)) {
+		brelse(bp, 0);
+		kmem_free(newfs, fs_sbsize);
+		return (EINVAL);
+	}
+
+
 	/* Store off old fs_sblockloc for fs_oldfscompat_read. */
 	sblockloc = fs-fs_sblockloc;
 	/*



CVS commit: src/sys/ufs/ffs

2015-02-23 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Feb 23 13:38:54 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Small changes:
 - instead of always calling DPRINTF with __func__, put __func__ directly
   in the macro
 - ffs_mountfs(): rename fsblockloc - fs_sblockloc, initialize fs_sbsize
   to zero
No real functional change


To generate a diff of this commit:
cvs rdiff -u -r1.318 -r1.319 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.318 src/sys/ufs/ffs/ffs_vfsops.c:1.319
--- src/sys/ufs/ffs/ffs_vfsops.c:1.318	Sun Feb 22 14:22:34 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Mon Feb 23 13:38:54 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.318 2015/02/22 14:22:34 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.319 2015/02/23 13:38:54 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.318 2015/02/22 14:22:34 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.319 2015/02/23 13:38:54 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -122,9 +122,9 @@ static kauth_listener_t ffs_snapshot_lis
 int ffs_initcount = 0;
 
 #ifdef DEBUG_FFS_MOUNT
-#define DPRINTF(a)	printf a
+#define DPRINTF(_fmt, args...)	printf(%s:  _fmt \n, __func__, ##args)
 #else
-#define DPRINTF(a)	do {} while (/*CONSTCOND*/0)
+#define DPRINTF(_fmt, args...)	do {} while (/*CONSTCOND*/0)
 #endif
 
 extern const struct vnodeopv_desc ffs_vnodeop_opv_desc;
@@ -354,19 +354,18 @@ ffs_mount(struct mount *mp, const char *
 	mode_t accessmode;
 
 	if (args == NULL) {
-		DPRINTF((%s: NULL args\n, __func__));
+		DPRINTF(NULL args);
 		return EINVAL;
 	}
 	if (*data_len  sizeof(*args)) {
-		DPRINTF((%s: bad size args %zu != %zu\n,
-		__func__, *data_len, sizeof(*args)));
+		DPRINTF(bad size args %zu != %zu, *data_len, sizeof(*args));
 		return EINVAL;
 	}
 
 	if (mp-mnt_flag  MNT_GETARGS) {
 		ump = VFSTOUFS(mp);
 		if (ump == NULL) {
-			DPRINTF((%s: no ump\n, __func__));
+			DPRINTF(no ump);
 			return EIO;
 		}
 		args-fspec = NULL;
@@ -384,8 +383,7 @@ ffs_mount(struct mount *mp, const char *
 		error = namei_simple_user(args-fspec,
 		NSM_FOLLOW_NOEMULROOT, devvp);
 		if (error != 0) {
-			DPRINTF((%s: namei_simple_user %d\n, __func__,
-			error));
+			DPRINTF(namei_simple_user returned %d, error);
 			return error;
 		}
 
@@ -394,12 +392,11 @@ ffs_mount(struct mount *mp, const char *
 			 * Be sure this is a valid block device
 			 */
 			if (devvp-v_type != VBLK) {
-DPRINTF((%s: non block device %d\n,
-__func__, devvp-v_type));
+DPRINTF(non block device %d, devvp-v_type);
 error = ENOTBLK;
 			} else if (bdevsw_lookup(devvp-v_rdev) == NULL) {
-DPRINTF((%s: can't find block device 0x%jx\n,
-__func__, devvp-v_rdev));
+DPRINTF(can't find block device 0x%jx,
+devvp-v_rdev);
 error = ENXIO;
 			}
 		} else {
@@ -410,10 +407,9 @@ ffs_mount(struct mount *mp, const char *
 			ump = VFSTOUFS(mp);
 			if (devvp != ump-um_devvp) {
 if (devvp-v_rdev != ump-um_devvp-v_rdev) {
-	DPRINTF((%s: wrong device 0x%jx
-	 != 0x%jx\n, __func__,
+	DPRINTF(wrong device 0x%jx != 0x%jx,
 	(uintmax_t)devvp-v_rdev,
-	(uintmax_t)ump-um_devvp-v_rdev));
+	(uintmax_t)ump-um_devvp-v_rdev);
 	error = EINVAL;
 } else {
 	vrele(devvp);
@@ -425,7 +421,7 @@ ffs_mount(struct mount *mp, const char *
 	} else {
 		if (!update) {
 			/* New mounts must have a filename for the device */
-			DPRINTF((%s: no filename for mount\n, __func__));
+			DPRINTF(no filename for mount);
 			return EINVAL;
 		} else {
 			/* Use the extant mount */
@@ -454,7 +450,7 @@ ffs_mount(struct mount *mp, const char *
 		KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
 		KAUTH_ARG(accessmode));
 		if (error) {
-			DPRINTF((%s: kauth %d\n, __func__, error));
+			DPRINTF(kauth returned %d, error);
 		}
 		VOP_UNLOCK(devvp);
 	}
@@ -484,12 +480,12 @@ ffs_mount(struct mount *mp, const char *
 		error = VOP_OPEN(devvp, xflags, FSCRED);
 		VOP_UNLOCK(devvp);
 		if (error) {	
-			DPRINTF((%s: VOP_OPEN %d\n, __func__, error));
+			DPRINTF(VOP_OPEN returned %d, error);
 			goto fail;
 		}
 		error = ffs_mountfs(devvp, mp, l);
 		if (error) {
-			DPRINTF((%s: ffs_mountfs %d\n, __func__, error));
+			DPRINTF(ffs_mountfs returned %d, error);
 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
 			(void)VOP_CLOSE(devvp, xflags, NOCRED);
 			VOP_UNLOCK(devvp);
@@ -531,7 +527,7 @@ ffs_mount(struct mount *mp, const char *
 (void) ffs_sbupdate(ump, MNT_WAIT);
 			}
 			if (error) {
-DPRINTF((%s: wapbl %d\n, __func__, error));
+DPRINTF(wapbl %d, error);
 return error;
 			}
 			UFS_WAPBL_END(mp);
@@ -541,8 +537,7 @@ ffs_mount(struct mount *mp, const 

CVS commit: src/sys/ufs/ffs

2015-02-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Feb 22 14:12:48 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_quota2.c

Log Message:
KNF, and simplify a bit.

No functional change


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/ufs/ffs/ffs_quota2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_quota2.c
diff -u src/sys/ufs/ffs/ffs_quota2.c:1.4 src/sys/ufs/ffs/ffs_quota2.c:1.5
--- src/sys/ufs/ffs/ffs_quota2.c:1.4	Sun Jun 12 03:36:00 2011
+++ src/sys/ufs/ffs/ffs_quota2.c	Sun Feb 22 14:12:48 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp $ */
+/* $NetBSD: ffs_quota2.c,v 1.5 2015/02/22 14:12:48 maxv Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,14 +26,13 @@
   */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_quota2.c,v 1.5 2015/02/22 14:12:48 maxv Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
 #include sys/systm.h
 #include sys/namei.h
 #include sys/file.h
-#include sys/proc.h
 #include sys/vnode.h
 #include sys/mount.h
 #include sys/kauth.h
@@ -44,13 +43,12 @@ __KERNEL_RCSID(0, $NetBSD: ffs_quota2.c
 #include ufs/ffs/ffs_extern.h
 #include ufs/ffs/fs.h
 
-
 int
 ffs_quota2_mount(struct mount *mp)
 {
 	struct ufsmount *ump = VFSTOUFS(mp);
 	struct fs *fs = ump-um_fs;
-	int error = 0;
+	int error;
 	struct vnode *vp;
 	struct lwp *l = curlwp;
 
@@ -61,26 +59,24 @@ ffs_quota2_mount(struct mount *mp)
 	ump-umq2_bsize = fs-fs_bsize;
 	ump-umq2_bmask = fs-fs_qbmask;
 	if (fs-fs_quota_magic != Q2_HEAD_MAGIC) {
-		printf(%s: Invalid quota magic number\n,
+		printf(%s: invalid quota magic number\n,
 		mp-mnt_stat.f_mntonname);
 		return EINVAL;
 	}
-if ((fs-fs_quota_flags  FS_Q2_DO_TYPE(USRQUOTA)) 
-fs-fs_quotafile[USRQUOTA] == 0) {
-printf(%s: no user quota inode\n,
+	if ((fs-fs_quota_flags  FS_Q2_DO_TYPE(USRQUOTA)) 
+	fs-fs_quotafile[USRQUOTA] == 0) {
+		printf(%s: no user quota inode\n,
 		mp-mnt_stat.f_mntonname); 
-error = EINVAL;
-}
-if ((fs-fs_quota_flags  FS_Q2_DO_TYPE(GRPQUOTA)) 
-fs-fs_quotafile[GRPQUOTA] == 0) {
-printf(%s: no group quota inode\n,
+		return EINVAL;
+	}
+	if ((fs-fs_quota_flags  FS_Q2_DO_TYPE(GRPQUOTA)) 
+	fs-fs_quotafile[GRPQUOTA] == 0) {
+		printf(%s: no group quota inode\n,
 		mp-mnt_stat.f_mntonname);
-error = EINVAL;
-}
-	if (error)
-		return error;
+		return EINVAL;
+	}
 
-if (fs-fs_quota_flags  FS_Q2_DO_TYPE(USRQUOTA) 
+	if (fs-fs_quota_flags  FS_Q2_DO_TYPE(USRQUOTA) 
 	ump-um_quotas[USRQUOTA] == NULLVP) {
 		error = VFS_VGET(mp, fs-fs_quotafile[USRQUOTA], vp);
 		if (error) {
@@ -95,7 +91,7 @@ ffs_quota2_mount(struct mount *mp)
 		mutex_exit(vp-v_interlock);
 		VOP_UNLOCK(vp);
 	}
-if (fs-fs_quota_flags  FS_Q2_DO_TYPE(GRPQUOTA) 
+	if (fs-fs_quota_flags  FS_Q2_DO_TYPE(GRPQUOTA) 
 	ump-um_quotas[GRPQUOTA] == NULLVP) {
 		error = VFS_VGET(mp, fs-fs_quotafile[GRPQUOTA], vp);
 		if (error) {
@@ -113,6 +109,7 @@ ffs_quota2_mount(struct mount *mp)
 		mutex_exit(vp-v_interlock);
 		VOP_UNLOCK(vp);
 	}
+
 	mp-mnt_flag |= MNT_QUOTA;
 	return 0;
 }



CVS commit: src/sys/ufs/ffs

2015-02-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Feb 22 14:22:34 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): sanitize fs_fragshift, fs_bmask and fs_fmask.


To generate a diff of this commit:
cvs rdiff -u -r1.317 -r1.318 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.317 src/sys/ufs/ffs/ffs_vfsops.c:1.318
--- src/sys/ufs/ffs/ffs_vfsops.c:1.317	Fri Feb 20 17:10:17 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Feb 22 14:22:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.317 2015/02/20 17:10:17 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.318 2015/02/22 14:22:34 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.317 2015/02/20 17:10:17 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.318 2015/02/22 14:22:34 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -922,7 +922,7 @@ static const int sblock_try[] = SBLOCKSE
 static int
 ffs_superblock_validate(struct fs *fs)
 {
-	int32_t i, fs_bshift = 0, fs_fshift = 0, fs_frag;
+	int32_t i, fs_bshift = 0, fs_fshift = 0, fs_fragshift = 0, fs_frag;
 
 	/* Check the superblock size */
 	if (fs-fs_sbsize  SBLOCKSIZE || fs-fs_sbsize  sizeof(struct fs))
@@ -937,6 +937,8 @@ ffs_superblock_validate(struct fs *fs)
 	/* Check the size of frag blocks */
 	if (!powerof2(fs-fs_fsize))
 		return 0;
+	if (fs-fs_fsize == 0)
+		return 0;
 
 	if (fs-fs_size == 0)
 		return 0;
@@ -959,7 +961,21 @@ ffs_superblock_validate(struct fs *fs)
 	if (fs-fs_fshift != fs_fshift)
 		return 0;
 
-	/* Now that the shifts are sanitized, we can use the ffs_ API */
+	/* Compute fs_fragshift and ensure it is consistent */
+	for (i = fs-fs_frag; i  1; i = 1)
+		fs_fragshift++;
+	if (fs-fs_fragshift != fs_fragshift)
+		return 0;
+
+	/* Check the masks */
+	if (fs-fs_bmask != ~(fs-fs_bsize - 1))
+		return 0;
+	if (fs-fs_fmask != ~(fs-fs_fsize - 1))
+		return 0;
+
+	/*
+	 * Now that the shifts and masks are sanitized, we can use the ffs_ API.
+	 */
 
 	/* Check the number of frag blocks */
 	if ((fs_frag = ffs_numfrags(fs, fs-fs_bsize))  MAXFRAG)
@@ -1205,7 +1221,8 @@ ffs_mountfs(struct vnode *devvp, struct 
 		brelse(bp, 0);
 	bp = NULL;
 
-	/* First check to see if this is tagged as an Apple UFS filesystem
+	/*
+	 * First check to see if this is tagged as an Apple UFS filesystem
 	 * in the disklabel
 	 */
 	if (getdiskinfo(devvp, dkw) == 0 
@@ -1213,7 +1230,8 @@ ffs_mountfs(struct vnode *devvp, struct 
 		ump-um_flags |= UFS_ISAPPLEUFS;
 #ifdef APPLE_UFS
 	else {
-		/* Manually look for an apple ufs label, and if a valid one
+		/*
+		 * Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
 		 */
 		error = bread(devvp,
@@ -1346,12 +1364,14 @@ ffs_mountfs(struct vnode *devvp, struct 
 	fs-fs_contigdirs = space;
 	space = (char *)space + bsize;
 	memset(fs-fs_contigdirs, 0, bsize);
-		/* Compatibility for old filesystems - XXX */
+
+	/* Compatibility for old filesystems - XXX */
 	if (fs-fs_avgfilesize = 0)
 		fs-fs_avgfilesize = AVFILESIZ;
 	if (fs-fs_avgfpdir = 0)
 		fs-fs_avgfpdir = AFPDIR;
 	fs-fs_active = NULL;
+
 	mp-mnt_data = ump;
 	mp-mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
 	mp-mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FFS);



CVS commit: src/sys/ufs/ffs

2015-02-20 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 20 17:10:17 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Style, and fix a DPRINTF

No functional change


To generate a diff of this commit:
cvs rdiff -u -r1.316 -r1.317 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.316 src/sys/ufs/ffs/ffs_vfsops.c:1.317
--- src/sys/ufs/ffs/ffs_vfsops.c:1.316	Sat Feb 14 13:43:28 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 20 17:10:17 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.316 2015/02/14 13:43:28 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.317 2015/02/20 17:10:17 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.316 2015/02/14 13:43:28 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.317 2015/02/20 17:10:17 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -111,11 +111,8 @@ __KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c
 
 MODULE(MODULE_CLASS_VFS, ffs, NULL);
 
-static int
-ffs_vfs_fsync(vnode_t *, int);
-
-static int
-ffs_superblock_validate(struct fs *fs);
+static int ffs_vfs_fsync(vnode_t *, int);
+static int ffs_superblock_validate(struct fs *);
 
 static struct sysctllog *ffs_sysctl_log;
 
@@ -1039,7 +1036,7 @@ ffs_mountfs(struct vnode *devvp, struct 
 			bp = NULL;
 		}
 		if (sblock_try[i] == -1) {
-			DPRINTF((%s: sblock_try\n, __func__));
+			DPRINTF((%s: no superblock found\n, __func__));
 			error = EINVAL;
 			fs = NULL;
 			goto out;



CVS commit: src/sys/ufs/ffs

2015-02-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Feb 15 11:04:44 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_appleufs.c

Log Message:
Revert a change in my previous commit that broke the checksum calculation.
Noted by dholland@


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/ufs/ffs/ffs_appleufs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_appleufs.c
diff -u src/sys/ufs/ffs/ffs_appleufs.c:1.14 src/sys/ufs/ffs/ffs_appleufs.c:1.15
--- src/sys/ufs/ffs/ffs_appleufs.c:1.14	Sat Feb 14 08:07:39 2015
+++ src/sys/ufs/ffs/ffs_appleufs.c	Sun Feb 15 11:04:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_appleufs.c,v 1.14 2015/02/14 08:07:39 maxv Exp $	*/
+/*	$NetBSD: ffs_appleufs.c,v 1.15 2015/02/15 11:04:43 maxv Exp $	*/
 
 /*
  * Copyright (c) 2002 Darrin B. Jewell
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.14 2015/02/14 08:07:39 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.15 2015/02/15 11:04:43 maxv Exp $);
 
 #include sys/param.h
 #include sys/time.h
@@ -89,6 +89,7 @@ ffs_appleufs_validate(const char *name, 
 		return EINVAL;
 
 	*n = *o;
+	n-ul_checksum = 0;
 	n-ul_checksum = ffs_appleufs_cksum(n);
 	n-ul_magic = be32toh(o-ul_magic);
 	n-ul_version = be32toh(o-ul_version);



CVS commit: src/sys/ufs/ffs

2015-02-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 10:21:29 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): compute fs_bshift and fs_fshift, and ensure
they are consistent with what is indicated in the superblock. This allows
us to safely use some ffs_ macros.


To generate a diff of this commit:
cvs rdiff -u -r1.314 -r1.315 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.314 src/sys/ufs/ffs/ffs_vfsops.c:1.315
--- src/sys/ufs/ffs/ffs_vfsops.c:1.314	Sat Feb 14 09:55:53 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 10:21:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.314 2015/02/14 09:55:53 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.315 2015/02/14 10:21:29 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.314 2015/02/14 09:55:53 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.315 2015/02/14 10:21:29 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -925,6 +925,8 @@ static const int sblock_try[] = SBLOCKSE
 static int
 ffs_superblock_validate(struct fs *fs)
 {
+	int32_t i, fs_bshift = 0, fs_fshift = 0;
+
 	/* Check the superblock size */
 	if (fs-fs_sbsize  SBLOCKSIZE || fs-fs_sbsize  sizeof(struct fs))
 		return 0;
@@ -948,8 +950,22 @@ ffs_superblock_validate(struct fs *fs)
 	if (fs-fs_bsize  fs-fs_fsize)
 		return 0;
 
+	/* Compute fs_bshift and ensure it is consistent */
+	for (i = fs-fs_bsize; i  1; i = 1)
+		fs_bshift++;
+	if (fs-fs_bshift != fs_bshift)
+		return 0;
+
+	/* Compute fs_fshift and ensure it is consistent */
+	for (i = fs-fs_fsize; i  1; i = 1)
+		fs_fshift++;
+	if (fs-fs_fshift != fs_fshift)
+		return 0;
+
+	/* Now that the shifts are sanitized, we can use the ffs_ API */
+
 	/* Check the number of frag blocks */
-	if ((fs-fs_bsize / fs-fs_fsize)  MAXFRAG)
+	if (ffs_numfrags(fs, fs-fs_bsize)  MAXFRAG)
 		return 0;
 
 	return 1;



CVS commit: src/sys/ufs/ffs

2015-02-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 09:55:53 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
In fact, we need to sanitize the superblock *after* swapping it. Therefore,
move the swap code inside the loop.

'fs-fs_sbsize' is swapped twice: the first time in order to get the
correct superblock size, and later when swapping the whole superblock
structure. As a result, we need to check 'fs-fs_sbsize' twice.

This:
 - fixes my previous changes for swapped FSes
 - allows the kernel to look for other superblock locations if the
   current superblock is not validated

And now:
 - ffs_superblock_validate() takes only one argument: the fs structure
 - 'fs_bsize' is unused, so delete it

Add some comments to explain a bit what we are doing.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.313 src/sys/ufs/ffs/ffs_vfsops.c:1.314
--- src/sys/ufs/ffs/ffs_vfsops.c:1.313	Sat Feb 14 09:00:12 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 09:55:53 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.313 2015/02/14 09:00:12 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.314 2015/02/14 09:55:53 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.313 2015/02/14 09:00:12 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.314 2015/02/14 09:55:53 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -115,7 +115,7 @@ static int
 ffs_vfs_fsync(vnode_t *, int);
 
 static int
-ffs_superblock_validate(struct fs *fs, u_int32_t fs_sbsize, int32_t fs_bsize);
+ffs_superblock_validate(struct fs *fs);
 
 static struct sysctllog *ffs_sysctl_log;
 
@@ -758,7 +758,7 @@ ffs_reload(struct mount *mp, kauth_cred_
 		kmem_free(newfs, fs_sbsize);
 		return (EIO);		/* XXX needs translation */
 	}
-	if (!ffs_superblock_validate(newfs, newfs-fs_sbsize, newfs-fs_bsize)) {
+	if (!ffs_superblock_validate(newfs)) {
 		brelse(bp, 0);
 		kmem_free(newfs, fs_sbsize);
 		return (EINVAL);
@@ -923,16 +923,16 @@ static const int sblock_try[] = SBLOCKSE
 
 
 static int
-ffs_superblock_validate(struct fs *fs, u_int32_t fs_sbsize, int32_t fs_bsize)
+ffs_superblock_validate(struct fs *fs)
 {
 	/* Check the superblock size */
-	if (fs_sbsize  SBLOCKSIZE || fs_sbsize  sizeof(struct fs))
+	if (fs-fs_sbsize  SBLOCKSIZE || fs-fs_sbsize  sizeof(struct fs))
 		return 0;
 
 	/* Check the file system blocksize */
-	if (fs_bsize  MAXBSIZE || fs_bsize  MINBSIZE)
+	if (fs-fs_bsize  MAXBSIZE || fs-fs_bsize  MINBSIZE)
 		return 0;
-	if (!powerof2(fs_bsize))
+	if (!powerof2(fs-fs_bsize))
 		return 0;
 
 	/* Check the size of frag blocks */
@@ -945,11 +945,11 @@ ffs_superblock_validate(struct fs *fs, u
 		return 0;
 
 	/* Block size cannot be smaller than fragment size */
-	if (fs_bsize  fs-fs_fsize)
+	if (fs-fs_bsize  fs-fs_fsize)
 		return 0;
 
 	/* Check the number of frag blocks */
-	if ((fs_bsize / fs-fs_fsize)  MAXFRAG)
+	if ((fs-fs_bsize / fs-fs_fsize)  MAXFRAG)
 		return 0;
 
 	return 1;
@@ -1015,7 +1015,6 @@ ffs_mountfs(struct vnode *devvp, struct 
 	 */
 	for (i = 0; ; i++) {
 		daddr_t fsblockloc;
-		int32_t fs_bsize;
 
 		if (bp != NULL) {
 			brelse(bp, BC_NOCACHE);
@@ -1040,28 +1039,30 @@ ffs_mountfs(struct vnode *devvp, struct 
 
 		fsblockloc = sblockloc = sblock_try[i];
 		DPRINTF((%s: fs_magic 0x%x\n, __func__, fs-fs_magic));
+
+		/*
+		 * Swap: here, we swap fs-fs_sbsize in order to get the correct
+		 * size to read the superblock. Once read, we swap the whole
+		 * superblock structure.
+		 */
 		if (fs-fs_magic == FS_UFS1_MAGIC) {
 			fs_sbsize = fs-fs_sbsize;
 			fstype = UFS1;
-			fs_bsize = fs-fs_bsize;
 #ifdef FFS_EI
 			needswap = 0;
 		} else if (fs-fs_magic == FS_UFS1_MAGIC_SWAPPED) {
 			fs_sbsize = bswap32(fs-fs_sbsize);
 			fstype = UFS1;
-			fs_bsize = bswap32(fs-fs_bsize);
 			needswap = 1;
 #endif
 		} else if (fs-fs_magic == FS_UFS2_MAGIC) {
 			fs_sbsize = fs-fs_sbsize;
 			fstype = UFS2;
-			fs_bsize = fs-fs_bsize;
 #ifdef FFS_EI
 			needswap = 0;
 		} else if (fs-fs_magic == FS_UFS2_MAGIC_SWAPPED) {
 			fs_sbsize = bswap32(fs-fs_sbsize);
 			fstype = UFS2;
-			fs_bsize = bswap32(fs-fs_bsize);
 			needswap = 1;
 #endif
 		} else
@@ -1089,25 +1090,36 @@ ffs_mountfs(struct vnode *devvp, struct 
 		if (fsblockloc != sblockloc)
 			continue;
 
-		if (!ffs_superblock_validate(fs, fs_sbsize, fs_bsize))
+		/* Check the superblock size */
+		if (fs_sbsize  SBLOCKSIZE || fs_sbsize  sizeof(struct fs))
 			continue;
+		fs = kmem_alloc((u_long)fs_sbsize, KM_SLEEP);
+		memcpy(fs, bp-b_data, fs_sbsize);
+
+		/* Swap the whole superblock structure, if necessary. */
+#ifdef FFS_EI
+		if (needswap) {
+			ffs_sb_swap((struct 

CVS commit: src/sys/ufs/ffs

2015-02-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 13:43:28 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): when checking the number of frag blocks, also
make sure it matches fs-fs_frag. This also prevents an infinite loop if
fs-fs_frag=0.


To generate a diff of this commit:
cvs rdiff -u -r1.315 -r1.316 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.315 src/sys/ufs/ffs/ffs_vfsops.c:1.316
--- src/sys/ufs/ffs/ffs_vfsops.c:1.315	Sat Feb 14 10:21:29 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 13:43:28 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.315 2015/02/14 10:21:29 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.316 2015/02/14 13:43:28 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.315 2015/02/14 10:21:29 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.316 2015/02/14 13:43:28 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -925,7 +925,7 @@ static const int sblock_try[] = SBLOCKSE
 static int
 ffs_superblock_validate(struct fs *fs)
 {
-	int32_t i, fs_bshift = 0, fs_fshift = 0;
+	int32_t i, fs_bshift = 0, fs_fshift = 0, fs_frag;
 
 	/* Check the superblock size */
 	if (fs-fs_sbsize  SBLOCKSIZE || fs-fs_sbsize  sizeof(struct fs))
@@ -965,7 +965,9 @@ ffs_superblock_validate(struct fs *fs)
 	/* Now that the shifts are sanitized, we can use the ffs_ API */
 
 	/* Check the number of frag blocks */
-	if (ffs_numfrags(fs, fs-fs_bsize)  MAXFRAG)
+	if ((fs_frag = ffs_numfrags(fs, fs-fs_bsize))  MAXFRAG)
+		return 0;
+	if (fs-fs_frag != fs_frag)
 		return 0;
 
 	return 1;



CVS commit: src/sys/ufs/ffs

2015-02-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 08:07:39 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_appleufs.c

Log Message:
ffs_appleufs_validate():
 - remove superfluous printfs
 - ensure ul_namelen!=0, otherwise the kernel accesses ul_name[-1] and
   overwrites the previous field in the structure.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/ufs/ffs/ffs_appleufs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_appleufs.c
diff -u src/sys/ufs/ffs/ffs_appleufs.c:1.13 src/sys/ufs/ffs/ffs_appleufs.c:1.14
--- src/sys/ufs/ffs/ffs_appleufs.c:1.13	Sat Feb 14 07:56:31 2015
+++ src/sys/ufs/ffs/ffs_appleufs.c	Sat Feb 14 08:07:39 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_appleufs.c,v 1.13 2015/02/14 07:56:31 maxv Exp $	*/
+/*	$NetBSD: ffs_appleufs.c,v 1.14 2015/02/14 08:07:39 maxv Exp $	*/
 
 /*
  * Copyright (c) 2002 Darrin B. Jewell
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.13 2015/02/14 07:56:31 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.14 2015/02/14 08:07:39 maxv Exp $);
 
 #include sys/param.h
 #include sys/time.h
@@ -89,28 +89,19 @@ ffs_appleufs_validate(const char *name, 
 		return EINVAL;
 
 	*n = *o;
-	n-ul_checksum = 0;
 	n-ul_checksum = ffs_appleufs_cksum(n);
-	if (n-ul_checksum != o-ul_checksum) {
-#if defined(DIAGNOSTIC) || !defined(_KERNEL)
-		printf(%s: invalid APPLE UFS checksum. found 0x%x, expecting 0x%x,
-		name, o-ul_checksum, n-ul_checksum);
-#endif
-		return EINVAL;
-	}
 	n-ul_magic = be32toh(o-ul_magic);
 	n-ul_version = be32toh(o-ul_version);
 	n-ul_time = be32toh(o-ul_time);
 	n-ul_namelen = be16toh(o-ul_namelen);
 
-	if (n-ul_namelen  APPLEUFS_MAX_LABEL_NAME) {
-#if defined(DIAGNOSTIC) || !defined(_KERNEL)
-		printf(%s: APPLE UFS label name too long, truncated.\n,
-		name);
-#endif
+	if (n-ul_checksum != o-ul_checksum)
+		return EINVAL;
+	if (n-ul_namelen == 0)
+		return EINVAL;
+	if (n-ul_namelen  APPLEUFS_MAX_LABEL_NAME)
 		n-ul_namelen = APPLEUFS_MAX_LABEL_NAME;
-	}
-	/* if len is max, will set ul_unused1 */
+
 	n-ul_name[n-ul_namelen - 1] = '\0';
 
 #ifdef DEBUG



CVS commit: src/sys/ufs/ffs

2015-02-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 09:00:12 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): sanitize the number of frag blocks.


To generate a diff of this commit:
cvs rdiff -u -r1.312 -r1.313 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.312 src/sys/ufs/ffs/ffs_vfsops.c:1.313
--- src/sys/ufs/ffs/ffs_vfsops.c:1.312	Sat Feb 14 07:41:40 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 09:00:12 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.312 2015/02/14 07:41:40 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.313 2015/02/14 09:00:12 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.312 2015/02/14 07:41:40 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.313 2015/02/14 09:00:12 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -948,6 +948,10 @@ ffs_superblock_validate(struct fs *fs, u
 	if (fs_bsize  fs-fs_fsize)
 		return 0;
 
+	/* Check the number of frag blocks */
+	if ((fs_bsize / fs-fs_fsize)  MAXFRAG)
+		return 0;
+
 	return 1;
 }
 



CVS commit: src/sys/ufs/ffs

2015-02-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 09:06:11 UTC 2015

Modified Files:
src/sys/ufs/ffs: fs.h

Log Message:
Two typos:
 - preferrably - preferably
 - overriden - overridden
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/ufs/ffs/fs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/fs.h
diff -u src/sys/ufs/ffs/fs.h:1.65 src/sys/ufs/ffs/fs.h:1.66
--- src/sys/ufs/ffs/fs.h:1.65	Tue Sep  3 02:24:01 2013
+++ src/sys/ufs/ffs/fs.h	Sat Feb 14 09:06:11 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fs.h,v 1.65 2013/09/03 02:24:01 dholland Exp $	*/
+/*	$NetBSD: fs.h,v 1.66 2015/02/14 09:06:11 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -72,7 +72,7 @@
  *
  * Unfortunately the UFS2/FFSv2 change was done without adequate consideration
  * of backward compatibility.  In particular 'newfs' for a FFSv2 partition
- * must overwrite any old FFSv1 superblock at 8k, and preferrably as many
+ * must overwrite any old FFSv1 superblock at 8k, and preferably as many
  * of the alternates as it can find - otherwise attempting to mount on a
  * system that only supports FFSv1 is likely to succeed!.
  * For a small FFSv1 filesystem, an old FFSv2 superblock can be left on
@@ -210,7 +210,7 @@
  * is run at between 95% and 100% full; thus the minimum default
  * value of fs_minfree is 5%. However, to get good clustering
  * performance, 10% is a better choice. This value is used only
- * when creating a file system and can be overriden from the
+ * when creating a file system and can be overridden from the
  * command line. By default we choose to optimize for time.
  */
 #define	MINFREE		5



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 13 15:28:56 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Make this a bit more readable. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.305 src/sys/ufs/ffs/ffs_vfsops.c:1.306
--- src/sys/ufs/ffs/ffs_vfsops.c:1.305	Fri Jan 16 03:57:52 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 13 15:28:56 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.305 2015/01/16 03:57:52 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.306 2015/02/13 15:28:56 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.305 2015/01/16 03:57:52 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.306 2015/02/13 15:28:56 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -909,23 +909,22 @@ static const int sblock_try[] = SBLOCKSE
 int
 ffs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
 {
-	struct ufsmount *ump;
-	struct buf *bp;
-	struct fs *fs;
+	struct ufsmount *ump = NULL;
+	struct buf *bp = NULL;
+	struct fs *fs = NULL;
 	dev_t dev;
 	struct dkwedge_info dkw;
 	void *space;
-	daddr_t sblockloc, fsblockloc;
-	int blks, fstype;
+	daddr_t sblockloc = 0;
+	int blks, fstype = 0;
 	int error, i, bsize, ronly, bset = 0;
 #ifdef FFS_EI
 	int needswap = 0;		/* keep gcc happy */
 #endif
 	int32_t *lp;
 	kauth_cred_t cred;
-	u_int32_t sbsize = 8192;	/* keep gcc happy*/
+	u_int32_t fs_sbsize = 8192;	/* keep gcc happy*/
 	u_int32_t allocsbsize;
-	int32_t fsbsize;
 
 	dev = devvp-v_rdev;
 	cred = l ? l-l_cred : NOCRED;
@@ -941,12 +940,6 @@ ffs_mountfs(struct vnode *devvp, struct 
 
 	ronly = (mp-mnt_flag  MNT_RDONLY) != 0;
 
-	bp = NULL;
-	ump = NULL;
-	fs = NULL;
-	sblockloc = 0;
-	fstype = 0;
-
 	error = fstrans_mount(mp);
 	if (error) {
 		DPRINTF((%s: fstrans_mount %d\n, __func__, error));
@@ -969,6 +962,9 @@ ffs_mountfs(struct vnode *devvp, struct 
 	 * Try reading the superblock in each of its possible locations.
 	 */
 	for (i = 0; ; i++) {
+		daddr_t fsblockloc;
+		int32_t fs_bsize;
+
 		if (bp != NULL) {
 			brelse(bp, BC_NOCACHE);
 			bp = NULL;
@@ -979,6 +975,7 @@ ffs_mountfs(struct vnode *devvp, struct 
 			fs = NULL;
 			goto out;
 		}
+
 		error = bread(devvp, sblock_try[i] / DEV_BSIZE, SBLOCKSIZE,
 		cred, 0, bp);
 		if (error) {
@@ -988,36 +985,36 @@ ffs_mountfs(struct vnode *devvp, struct 
 			goto out;
 		}
 		fs = (struct fs*)bp-b_data;
+
 		fsblockloc = sblockloc = sblock_try[i];
 		DPRINTF((%s: fs_magic 0x%x\n, __func__, fs-fs_magic));
 		if (fs-fs_magic == FS_UFS1_MAGIC) {
-			sbsize = fs-fs_sbsize;
+			fs_sbsize = fs-fs_sbsize;
 			fstype = UFS1;
-			fsbsize = fs-fs_bsize;
+			fs_bsize = fs-fs_bsize;
 #ifdef FFS_EI
 			needswap = 0;
 		} else if (fs-fs_magic == FS_UFS1_MAGIC_SWAPPED) {
-			sbsize = bswap32(fs-fs_sbsize);
+			fs_sbsize = bswap32(fs-fs_sbsize);
 			fstype = UFS1;
-			fsbsize = bswap32(fs-fs_bsize);
+			fs_bsize = bswap32(fs-fs_bsize);
 			needswap = 1;
 #endif
 		} else if (fs-fs_magic == FS_UFS2_MAGIC) {
-			sbsize = fs-fs_sbsize;
+			fs_sbsize = fs-fs_sbsize;
 			fstype = UFS2;
-			fsbsize = fs-fs_bsize;
+			fs_bsize = fs-fs_bsize;
 #ifdef FFS_EI
 			needswap = 0;
 		} else if (fs-fs_magic == FS_UFS2_MAGIC_SWAPPED) {
-			sbsize = bswap32(fs-fs_sbsize);
+			fs_sbsize = bswap32(fs-fs_sbsize);
 			fstype = UFS2;
-			fsbsize = bswap32(fs-fs_bsize);
+			fs_bsize = bswap32(fs-fs_bsize);
 			needswap = 1;
 #endif
 		} else
 			continue;
 
-
 		/* fs-fs_sblockloc isn't defined for old filesystems */
 		if (fstype == UFS1  !(fs-fs_old_flags  FS_FLAGS_UPDATED)) {
 			if (sblockloc == SBLOCK_UFS2)
@@ -1041,13 +1038,13 @@ ffs_mountfs(struct vnode *devvp, struct 
 			continue;
 
 		/* Validate size of superblock */
-		if (sbsize  SBLOCKSIZE || sbsize  sizeof(struct fs))
+		if (fs_sbsize  SBLOCKSIZE || fs_sbsize  sizeof(struct fs))
 			continue;
 
 		/* Check that we can handle the file system blocksize */
-		if (fsbsize  MAXBSIZE) {
+		if (fs_bsize  MAXBSIZE) {
 			printf(ffs_mountfs: block size (%d)  MAXBSIZE (%d)\n,
-			fsbsize, MAXBSIZE);
+			fs_bsize, MAXBSIZE);
 			continue;
 		}
 
@@ -1055,8 +1052,8 @@ ffs_mountfs(struct vnode *devvp, struct 
 		break;
 	}
 
-	fs = kmem_alloc((u_long)sbsize, KM_SLEEP);
-	memcpy(fs, bp-b_data, sbsize);
+	fs = kmem_alloc((u_long)fs_sbsize, KM_SLEEP);
+	memcpy(fs, bp-b_data, fs_sbsize);
 	ump-um_fs = fs;
 
 #ifdef FFS_EI
@@ -1098,7 +1095,7 @@ ffs_mountfs(struct vnode *devvp, struct 
 			/* Force a re-read of the superblock */
 			brelse(bp, BC_INVAL);
 			bp = NULL;
-			kmem_free(fs, sbsize);
+			kmem_free(fs, fs_sbsize);
 			fs = NULL;
 			goto sbagain;
 		}

CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 13 17:13:20 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_superblock_validate(): ensure fs-fs_cssize!=0, otherwise the kernel
panics with kmem_alloc(0).


To generate a diff of this commit:
cvs rdiff -u -r1.308 -r1.309 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.308 src/sys/ufs/ffs/ffs_vfsops.c:1.309
--- src/sys/ufs/ffs/ffs_vfsops.c:1.308	Fri Feb 13 16:59:52 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 13 17:13:20 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.308 2015/02/13 16:59:52 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.309 2015/02/13 17:13:20 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.308 2015/02/13 16:59:52 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.309 2015/02/13 17:13:20 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -923,6 +923,8 @@ ffs_superblock_validate(struct fs *fs, u
 
 	if (fs-fs_size == 0)
 		return 0;
+	if (fs-fs_cssize == 0)
+		return 0;
 
 	/* Block size cannot be smaller than fragment size */
 	if (fs_bsize  fs-fs_fsize)



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 13 15:52:29 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Add a new function: ffs_superblock_validate(). And add a new check to
ensure fs_size!=0; otherwise the kernel panics with a division by zero.


To generate a diff of this commit:
cvs rdiff -u -r1.306 -r1.307 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.306 src/sys/ufs/ffs/ffs_vfsops.c:1.307
--- src/sys/ufs/ffs/ffs_vfsops.c:1.306	Fri Feb 13 15:28:56 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 13 15:52:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.306 2015/02/13 15:28:56 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.307 2015/02/13 15:52:29 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.306 2015/02/13 15:28:56 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.307 2015/02/13 15:52:29 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -903,6 +903,24 @@ ffs_reload(struct mount *mp, kauth_cred_
  */
 static const int sblock_try[] = SBLOCKSEARCH;
 
+
+static int
+ffs_superblock_validate(struct fs *fs, u_int32_t fs_sbsize, int32_t fs_bsize)
+{
+	/* Check the superblock size */
+	if (fs_sbsize  SBLOCKSIZE || fs_sbsize  sizeof(struct fs))
+		return 0;
+
+	/* Check the file system blocksize */
+	if (fs_bsize  MAXBSIZE)
+		return 0;
+
+	if (fs-fs_size == 0)
+		return 0;
+
+	return 1;
+}
+
 /*
  * Common code for mount and mountroot
  */
@@ -1037,17 +1055,9 @@ ffs_mountfs(struct vnode *devvp, struct 
 		if (fsblockloc != sblockloc)
 			continue;
 
-		/* Validate size of superblock */
-		if (fs_sbsize  SBLOCKSIZE || fs_sbsize  sizeof(struct fs))
+		if (!ffs_superblock_validate(fs, fs_sbsize, fs_bsize))
 			continue;
 
-		/* Check that we can handle the file system blocksize */
-		if (fs_bsize  MAXBSIZE) {
-			printf(ffs_mountfs: block size (%d)  MAXBSIZE (%d)\n,
-			fs_bsize, MAXBSIZE);
-			continue;
-		}
-
 		/* Ok seems to be a good superblock */
 		break;
 	}



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 13 16:59:53 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Add some checks in ffs_superblock_validate():
 - fs_bsize  MINBSIZE
 - !powerof2(fs_bsize)
 - !powerof2(fs-fs_fsize)
 - fs_bsize  fs-fs_fsize

Based on makefs/ffs.


To generate a diff of this commit:
cvs rdiff -u -r1.307 -r1.308 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.307 src/sys/ufs/ffs/ffs_vfsops.c:1.308
--- src/sys/ufs/ffs/ffs_vfsops.c:1.307	Fri Feb 13 15:52:29 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 13 16:59:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.307 2015/02/13 15:52:29 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.308 2015/02/13 16:59:52 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.307 2015/02/13 15:52:29 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.308 2015/02/13 16:59:52 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -912,12 +912,22 @@ ffs_superblock_validate(struct fs *fs, u
 		return 0;
 
 	/* Check the file system blocksize */
-	if (fs_bsize  MAXBSIZE)
+	if (fs_bsize  MAXBSIZE || fs_bsize  MINBSIZE)
+		return 0;
+	if (!powerof2(fs_bsize))
+		return 0;
+
+	/* Check the size of frag blocks */
+	if (!powerof2(fs-fs_fsize))
 		return 0;
 
 	if (fs-fs_size == 0)
 		return 0;
 
+	/* Block size cannot be smaller than fragment size */
+	if (fs_bsize  fs-fs_fsize)
+		return 0;
+
 	return 1;
 }
 



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 07:11:34 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
ffs_reload(): call ffs_superblock_validate() with the new superblock.


To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.309 src/sys/ufs/ffs/ffs_vfsops.c:1.310
--- src/sys/ufs/ffs/ffs_vfsops.c:1.309	Fri Feb 13 17:13:20 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 07:11:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.309 2015/02/13 17:13:20 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.310 2015/02/14 07:11:34 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.309 2015/02/13 17:13:20 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.310 2015/02/14 07:11:34 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -111,7 +111,11 @@ __KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c
 
 MODULE(MODULE_CLASS_VFS, ffs, NULL);
 
-static int	ffs_vfs_fsync(vnode_t *, int);
+static int
+ffs_vfs_fsync(vnode_t *, int);
+
+static int
+ffs_superblock_validate(struct fs *fs, u_int32_t fs_sbsize, int32_t fs_bsize);
 
 static struct sysctllog *ffs_sysctl_log;
 
@@ -738,14 +742,19 @@ ffs_reload(struct mount *mp, kauth_cred_
 	} else
 #endif
 		fs-fs_flags = ~FS_SWAPPED;
+
 	if ((newfs-fs_magic != FS_UFS1_MAGIC 
-	 newfs-fs_magic != FS_UFS2_MAGIC)||
-	 newfs-fs_bsize  MAXBSIZE ||
-	 newfs-fs_bsize  sizeof(struct fs)) {
+	 newfs-fs_magic != FS_UFS2_MAGIC)) {
 		brelse(bp, 0);
 		kmem_free(newfs, fs-fs_sbsize);
 		return (EIO);		/* XXX needs translation */
 	}
+	if (!ffs_superblock_validate(newfs, newfs-fs_sbsize, newfs-fs_bsize)) {
+		brelse(bp, 0);
+		kmem_free(newfs, fs-fs_sbsize);
+		return (EINVAL);
+	}
+
 	/* Store off old fs_sblockloc for fs_oldfscompat_read. */
 	sblockloc = fs-fs_sblockloc;
 	/*



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 07:20:11 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Style. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.310 src/sys/ufs/ffs/ffs_vfsops.c:1.311
--- src/sys/ufs/ffs/ffs_vfsops.c:1.310	Sat Feb 14 07:11:34 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 07:20:11 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.310 2015/02/14 07:11:34 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.311 2015/02/14 07:20:11 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.310 2015/02/14 07:11:34 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.311 2015/02/14 07:20:11 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -713,6 +713,7 @@ ffs_reload(struct mount *mp, kauth_cred_
 		return (EINVAL);
 
 	ump = VFSTOUFS(mp);
+
 	/*
 	 * Step 1: invalidate all cached meta-data.
 	 */
@@ -722,19 +723,19 @@ ffs_reload(struct mount *mp, kauth_cred_
 	VOP_UNLOCK(devvp);
 	if (error)
 		panic(ffs_reload: dirty1);
+
 	/*
-	 * Step 2: re-read superblock from disk.
+	 * Step 2: re-read superblock from disk. XXX: We don't handle
+	 * possibility that superblock moved.
 	 */
 	fs = ump-um_fs;
-
-	/* XXX we don't handle possibility that superblock moved. */
 	error = bread(devvp, fs-fs_sblockloc / DEV_BSIZE, fs-fs_sbsize,
 		  NOCRED, 0, bp);
-	if (error) {
+	if (error)
 		return (error);
-	}
 	newfs = kmem_alloc(fs-fs_sbsize, KM_SLEEP);
 	memcpy(newfs, bp-b_data, fs-fs_sbsize);
+
 #ifdef FFS_EI
 	if (ump-um_flags  UFS_NEEDSWAP) {
 		ffs_sb_swap((struct fs*)bp-b_data, newfs);



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 07:41:40 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Currently, in ffs_reload(), we don't handle the possibility that the
superblock location may have changed. But that implies that we don't
handle the possibility that its size may have changed either.

Therefore: add a check to ensure the size hasn't changed. Otherwise the
mismatch leads to a memory corruption with kmem.


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.311 src/sys/ufs/ffs/ffs_vfsops.c:1.312
--- src/sys/ufs/ffs/ffs_vfsops.c:1.311	Sat Feb 14 07:20:11 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Feb 14 07:41:40 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.311 2015/02/14 07:20:11 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.312 2015/02/14 07:41:40 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.311 2015/02/14 07:20:11 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.312 2015/02/14 07:41:40 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -704,7 +704,7 @@ ffs_reload(struct mount *mp, kauth_cred_
 	struct fs *fs, *newfs;
 	struct dkwedge_info dkw;
 	int i, bsize, blks, error;
-	int32_t *lp;
+	int32_t *lp, fs_sbsize;
 	struct ufsmount *ump;
 	daddr_t sblockloc;
 	struct vnode_iterator *marker;
@@ -726,15 +726,17 @@ ffs_reload(struct mount *mp, kauth_cred_
 
 	/*
 	 * Step 2: re-read superblock from disk. XXX: We don't handle
-	 * possibility that superblock moved.
+	 * possibility that superblock moved. Which implies that we don't
+	 * want its size to change either.
 	 */
 	fs = ump-um_fs;
-	error = bread(devvp, fs-fs_sblockloc / DEV_BSIZE, fs-fs_sbsize,
+	fs_sbsize = fs-fs_sbsize;
+	error = bread(devvp, fs-fs_sblockloc / DEV_BSIZE, fs_sbsize,
 		  NOCRED, 0, bp);
 	if (error)
 		return (error);
-	newfs = kmem_alloc(fs-fs_sbsize, KM_SLEEP);
-	memcpy(newfs, bp-b_data, fs-fs_sbsize);
+	newfs = kmem_alloc(fs_sbsize, KM_SLEEP);
+	memcpy(newfs, bp-b_data, fs_sbsize);
 
 #ifdef FFS_EI
 	if (ump-um_flags  UFS_NEEDSWAP) {
@@ -744,15 +746,21 @@ ffs_reload(struct mount *mp, kauth_cred_
 #endif
 		fs-fs_flags = ~FS_SWAPPED;
 
+	/* We don't want the superblock size to change. */
+	if (newfs-fs_sbsize != fs_sbsize) {
+		brelse(bp, 0);
+		kmem_free(newfs, fs_sbsize);
+		return (EINVAL);
+	}
 	if ((newfs-fs_magic != FS_UFS1_MAGIC 
 	 newfs-fs_magic != FS_UFS2_MAGIC)) {
 		brelse(bp, 0);
-		kmem_free(newfs, fs-fs_sbsize);
+		kmem_free(newfs, fs_sbsize);
 		return (EIO);		/* XXX needs translation */
 	}
 	if (!ffs_superblock_validate(newfs, newfs-fs_sbsize, newfs-fs_bsize)) {
 		brelse(bp, 0);
-		kmem_free(newfs, fs-fs_sbsize);
+		kmem_free(newfs, fs_sbsize);
 		return (EINVAL);
 	}
 
@@ -768,9 +776,9 @@ ffs_reload(struct mount *mp, kauth_cred_
 	newfs-fs_contigdirs = fs-fs_contigdirs;
 	newfs-fs_ronly = fs-fs_ronly;
 	newfs-fs_active = fs-fs_active;
-	memcpy(fs, newfs, (u_int)fs-fs_sbsize);
+	memcpy(fs, newfs, (u_int)fs_sbsize);
 	brelse(bp, 0);
-	kmem_free(newfs, fs-fs_sbsize);
+	kmem_free(newfs, fs_sbsize);
 
 	/* Recheck for apple UFS filesystem */
 	ump-um_flags = ~UFS_ISAPPLEUFS;



CVS commit: src/sys/ufs/ffs

2015-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 14 07:56:31 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_appleufs.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/ufs/ffs/ffs_appleufs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_appleufs.c
diff -u src/sys/ufs/ffs/ffs_appleufs.c:1.12 src/sys/ufs/ffs/ffs_appleufs.c:1.13
--- src/sys/ufs/ffs/ffs_appleufs.c:1.12	Sat Nov 19 22:51:31 2011
+++ src/sys/ufs/ffs/ffs_appleufs.c	Sat Feb 14 07:56:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_appleufs.c,v 1.12 2011/11/19 22:51:31 tls Exp $	*/
+/*	$NetBSD: ffs_appleufs.c,v 1.13 2015/02/14 07:56:31 maxv Exp $	*/
 
 /*
  * Copyright (c) 2002 Darrin B. Jewell
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.12 2011/11/19 22:51:31 tls Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_appleufs.c,v 1.13 2015/02/14 07:56:31 maxv Exp $);
 
 #include sys/param.h
 #include sys/time.h
@@ -52,7 +52,7 @@ __KERNEL_RCSID(0, $NetBSD: ffs_appleufs
 #endif
 
 /*
- * this is the same calculation as in_cksum
+ * This is the same calculation as in_cksum.
  */
 u_int16_t
 ffs_appleufs_cksum(const struct appleufslabel *appleufs)
@@ -73,26 +73,28 @@ ffs_appleufs_cksum(const struct appleufs
 	return (~res);
 }
 
-/* copies o to n, validating and byteswapping along the way
- * returns 0 if ok, EINVAL if not valid
+/*
+ * Copies o to n, validating and byteswapping along the way. Returns 0 if ok,
+ * EINVAL if not valid.
  */
 int
 ffs_appleufs_validate(const char *name, const struct appleufslabel *o,
 struct appleufslabel *n)
 {
 	struct appleufslabel tmp;
-	if (!n) n = tmp;
 
-	if (o-ul_magic != be32toh(APPLEUFS_LABEL_MAGIC)) {
+	if (!n)
+		n = tmp;
+	if (o-ul_magic != be32toh(APPLEUFS_LABEL_MAGIC))
 		return EINVAL;
-	}
+
 	*n = *o;
 	n-ul_checksum = 0;
 	n-ul_checksum = ffs_appleufs_cksum(n);
 	if (n-ul_checksum != o-ul_checksum) {
 #if defined(DIAGNOSTIC) || !defined(_KERNEL)
 		printf(%s: invalid APPLE UFS checksum. found 0x%x, expecting 0x%x,
-			name,o-ul_checksum,n-ul_checksum);
+		name, o-ul_checksum, n-ul_checksum);
 #endif
 		return EINVAL;
 	}
@@ -104,7 +106,7 @@ ffs_appleufs_validate(const char *name, 
 	if (n-ul_namelen  APPLEUFS_MAX_LABEL_NAME) {
 #if defined(DIAGNOSTIC) || !defined(_KERNEL)
 		printf(%s: APPLE UFS label name too long, truncated.\n,
-name);
+		name);
 #endif
 		n-ul_namelen = APPLEUFS_MAX_LABEL_NAME;
 	}
@@ -112,8 +114,8 @@ ffs_appleufs_validate(const char *name, 
 	n-ul_name[n-ul_namelen - 1] = '\0';
 
 #ifdef DEBUG
-	printf(%s: found APPLE UFS label v%d: \%s\\n,
-	name,n-ul_version,n-ul_name);
+	printf(%s: found APPLE UFS label v%d: \%s\\n, name,
+	n-ul_version, n-ul_name);
 #endif
 	n-ul_uuid = be64toh(o-ul_uuid);
 
@@ -125,7 +127,9 @@ ffs_appleufs_set(struct appleufslabel *a
 uint64_t uuid)
 {
 	size_t namelen;
-	if (!name) name = untitled;
+
+	if (!name)
+		name = untitled;
 	if (t == ((time_t)-1)) {
 #if defined(_KERNEL)
 		t = time_second;
@@ -148,7 +152,7 @@ ffs_appleufs_set(struct appleufslabel *a
 	appleufs-ul_version = htobe32(APPLEUFS_LABEL_VERSION);
 	appleufs-ul_time= htobe32((u_int32_t)t);
 	appleufs-ul_namelen = htobe16(namelen);
-	strncpy(appleufs-ul_name,name,namelen);
+	strncpy(appleufs-ul_name, name, namelen);
 	appleufs-ul_uuid= htobe64(uuid);
 	appleufs-ul_checksum = ffs_appleufs_cksum(appleufs);
 }



CVS commit: src/sys/ufs/ffs

2015-01-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 16 03:57:52 UTC 2015

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
PR/39371: Tobias Nygren: Don't fail mounting root if WAPBL log is corrupt.
Patch from Sergio L. Pascual.
XXX: pullup-7


To generate a diff of this commit:
cvs rdiff -u -r1.304 -r1.305 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.304 src/sys/ufs/ffs/ffs_vfsops.c:1.305
--- src/sys/ufs/ffs/ffs_vfsops.c:1.304	Sat Dec 13 20:13:57 2014
+++ src/sys/ufs/ffs/ffs_vfsops.c	Thu Jan 15 22:57:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.304 2014/12/14 01:13:57 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.305 2015/01/16 03:57:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.304 2014/12/14 01:13:57 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.305 2015/01/16 03:57:52 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -585,14 +585,19 @@ ffs_mount(struct mount *mp, const char *
 			fs-fs_fmod = 1;
 #ifdef WAPBL
 			if (fs-fs_flags  FS_DOWAPBL) {
-printf(%s: replaying log to disk\n,
-mp-mnt_stat.f_mntonname);
-KDASSERT(mp-mnt_wapbl_replay);
+const char *nm = mp-mnt_stat.f_mntonname;
+if (!mp-mnt_wapbl_replay) {
+	printf(%s: log corrupted;
+	 replay cancelled\n, nm);
+	return EFTYPE;
+}
+printf(%s: replaying log to disk\n, nm);
 error = wapbl_replay_write(mp-mnt_wapbl_replay,
-			   devvp);
+devvp);
 if (error) {
-	DPRINTF((%s: wapbl_replay_write %d\n,
-	__func__, error));
+	DPRINTF((
+	%s: %s: wapbl_replay_write %d\n,
+	__func__, nm, error));
 	return error;
 }
 wapbl_replay_stop(mp-mnt_wapbl_replay);



CVS commit: src/sys/ufs/ffs

2014-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 14 00:36:07 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
- Add debugging for mount...
- Merge some error returns
- Check more errors


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.302 src/sys/ufs/ffs/ffs_vfsops.c:1.303
--- src/sys/ufs/ffs/ffs_vfsops.c:1.302	Fri Nov 14 05:09:50 2014
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Dec 13 19:36:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.302 2014/11/14 10:09:50 manu Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.303 2014/12/14 00:36:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.302 2014/11/14 10:09:50 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.303 2014/12/14 00:36:07 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -120,6 +120,12 @@ static kauth_listener_t ffs_snapshot_lis
 /* how many times ffs_init() was called */
 int ffs_initcount = 0;
 
+#ifdef DEBUG_FFS_MOUNT
+#define DPRINTF(a)	printf a
+#else
+#define DPRINTF(a)	do {} while (/*CONSTCOND*/0)
+#endif
+
 extern const struct vnodeopv_desc ffs_vnodeop_opv_desc;
 extern const struct vnodeopv_desc ffs_specop_opv_desc;
 extern const struct vnodeopv_desc ffs_fifoop_opv_desc;
@@ -346,15 +352,22 @@ ffs_mount(struct mount *mp, const char *
 	int error = 0, flags, update;
 	mode_t accessmode;
 
-	if (args == NULL)
+	if (args == NULL) {
+		DPRINTF((%s: NULL args\n, __func__));
 		return EINVAL;
-	if (*data_len  sizeof *args)
+	}
+	if (*data_len  sizeof(*args)) {
+		DPRINTF((%s: bad size args %zu != %zu\n,
+		__func__, *data_len, sizeof(*args)));
 		return EINVAL;
+	}
 
 	if (mp-mnt_flag  MNT_GETARGS) {
 		ump = VFSTOUFS(mp);
-		if (ump == NULL)
+		if (ump == NULL) {
+			DPRINTF((%s: no ump\n, __func__));
 			return EIO;
+		}
 		args-fspec = NULL;
 		*data_len = sizeof *args;
 		return 0;
@@ -368,18 +381,26 @@ ffs_mount(struct mount *mp, const char *
 		 * Look up the name and verify that it's sane.
 		 */
 		error = namei_simple_user(args-fspec,
-	NSM_FOLLOW_NOEMULROOT, devvp);
-		if (error != 0)
-			return (error);
+		NSM_FOLLOW_NOEMULROOT, devvp);
+		if (error != 0) {
+			DPRINTF((%s: namei_simple_user %d\n, __func__,
+			error));
+			return error;
+		}
 
 		if (!update) {
 			/*
 			 * Be sure this is a valid block device
 			 */
-			if (devvp-v_type != VBLK)
+			if (devvp-v_type != VBLK) {
+DPRINTF((%s: non block device %d\n,
+__func__, devvp-v_type));
 error = ENOTBLK;
-			else if (bdevsw_lookup(devvp-v_rdev) == NULL)
+			} else if (bdevsw_lookup(devvp-v_rdev) == NULL) {
+DPRINTF((%s: can't find block device 0x%jx\n,
+__func__, devvp-v_rdev));
 error = ENXIO;
+			}
 		} else {
 			/*
 			 * Be sure we're still naming the same device
@@ -387,9 +408,13 @@ ffs_mount(struct mount *mp, const char *
 			 */
 			ump = VFSTOUFS(mp);
 			if (devvp != ump-um_devvp) {
-if (devvp-v_rdev != ump-um_devvp-v_rdev)
+if (devvp-v_rdev != ump-um_devvp-v_rdev) {
+	DPRINTF((%s: wrong device 0x%jx
+	 != 0x%jx\n, __func__,
+	(uintmax_t)devvp-v_rdev,
+	(uintmax_t)ump-um_devvp-v_rdev));
 	error = EINVAL;
-else {
+} else {
 	vrele(devvp);
 	devvp = ump-um_devvp;
 	vref(devvp);
@@ -399,7 +424,8 @@ ffs_mount(struct mount *mp, const char *
 	} else {
 		if (!update) {
 			/* New mounts must have a filename for the device */
-			return (EINVAL);
+			DPRINTF((%s: no filename for mount\n, __func__));
+			return EINVAL;
 		} else {
 			/* Use the extant mount */
 			ump = VFSTOUFS(mp);
@@ -426,6 +452,9 @@ ffs_mount(struct mount *mp, const char *
 		error = kauth_authorize_system(l-l_cred, KAUTH_SYSTEM_MOUNT,
 		KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
 		KAUTH_ARG(accessmode));
+		if (error) {
+			DPRINTF((%s: kauth %d\n, __func__, error));
+		}
 		VOP_UNLOCK(devvp);
 	}
 
@@ -453,10 +482,13 @@ ffs_mount(struct mount *mp, const char *
 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
 		error = VOP_OPEN(devvp, xflags, FSCRED);
 		VOP_UNLOCK(devvp);
-		if (error)
+		if (error) {	
+			DPRINTF((%s: VOP_OPEN %d\n, __func__, error));
 			goto fail;
+		}
 		error = ffs_mountfs(devvp, mp, l);
 		if (error) {
+			DPRINTF((%s: ffs_mountfs %d\n, __func__, error));
 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
 			(void)VOP_CLOSE(devvp, xflags, NOCRED);
 			VOP_UNLOCK(devvp);
@@ -497,17 +529,21 @@ ffs_mount(struct mount *mp, const char *
 fs-fs_clean = FS_ISCLEAN;
 (void) ffs_sbupdate(ump, MNT_WAIT);
 			}
-			if (error == 0)
-UFS_WAPBL_END(mp);
-			if (error)
-return (error);
+			if (error) {
+DPRINTF((%s: wapbl %d\n, 

CVS commit: src/sys/ufs/ffs

2014-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 14 01:13:57 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Restore apple ufs error handling.


To generate a diff of this commit:
cvs rdiff -u -r1.303 -r1.304 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.303 src/sys/ufs/ffs/ffs_vfsops.c:1.304
--- src/sys/ufs/ffs/ffs_vfsops.c:1.303	Sat Dec 13 19:36:07 2014
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sat Dec 13 20:13:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.303 2014/12/14 00:36:07 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.304 2014/12/14 01:13:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.303 2014/12/14 00:36:07 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.304 2014/12/14 01:13:57 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -773,10 +773,11 @@ ffs_reload(struct mount *mp, kauth_cred_
 		 * EINVAL is most probably a blocksize or alignment problem,
 		 * it is unlikely that this is an Apple UFS filesystem then.
 		 */
-		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
-			APPLEUFS_LABEL_SIZE, cred, 0, bp);
+		error = bread(devvp,
+		(daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
+		APPLEUFS_LABEL_SIZE, cred, 0, bp);
 		if (error  error != EINVAL) {
-			return (error);
+			return error;
 		}
 		if (error == 0) {
 			error = ffs_appleufs_validate(fs-fs_fsmnt,
@@ -1153,15 +1154,10 @@ ffs_mountfs(struct vnode *devvp, struct 
 		}
 		error = ffs_appleufs_validate(fs-fs_fsmnt,
 		(struct appleufslabel *)bp-b_data, NULL);
-			(struct appleufslabel *)bp-b_data, NULL);
+		if (error == 0)
 			ump-um_flags |= UFS_ISAPPLEUFS;
 		brelse(bp, 0);
 		bp = NULL;
-		if (error) {
-			DPRINTF((%s: ffs_appleufs_validate %d\n, __func__,
-			error));
-			goto out;
-		}
 	}
 #else
 	if (ump-um_flags  UFS_ISAPPLEUFS) {



CVS commit: src/sys/ufs/ffs

2014-10-30 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Oct 30 17:13:41 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Limit the superblock size to SBLOCKSIZE, not MAXBSIZE. Otherwise memcpy
will read beyond the allocated buffer.

Discussed a bit on tech-kern@.


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.300 src/sys/ufs/ffs/ffs_vfsops.c:1.301
--- src/sys/ufs/ffs/ffs_vfsops.c:1.300	Fri Oct 24 13:18:51 2014
+++ src/sys/ufs/ffs/ffs_vfsops.c	Thu Oct 30 17:13:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.300 2014/10/24 13:18:51 njoly Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.301 2014/10/30 17:13:41 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.300 2014/10/24 13:18:51 njoly Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.301 2014/10/30 17:13:41 maxv Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -974,7 +974,7 @@ ffs_mountfs(struct vnode *devvp, struct 
 			continue;
 
 		/* Validate size of superblock */
-		if (sbsize  MAXBSIZE || sbsize  sizeof(struct fs))
+		if (sbsize  SBLOCKSIZE || sbsize  sizeof(struct fs))
 			continue;
 
 		/* Check that we can handle the file system blocksize */



CVS commit: src/sys/ufs/ffs

2014-10-24 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Fri Oct 24 13:18:51 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
One semicolon is enough.


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.299 src/sys/ufs/ffs/ffs_vfsops.c:1.300
--- src/sys/ufs/ffs/ffs_vfsops.c:1.299	Sat May 24 16:34:04 2014
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Oct 24 13:18:51 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.299 2014/05/24 16:34:04 christos Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.300 2014/10/24 13:18:51 njoly Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.299 2014/05/24 16:34:04 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vfsops.c,v 1.300 2014/10/24 13:18:51 njoly Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -180,7 +180,7 @@ ffs_snapshot_cb(kauth_cred_t cred, kauth
 void *arg0, void *arg1, void *arg2, void *arg3)
 {
 	vnode_t *vp = arg2;
-	int result = KAUTH_RESULT_DEFER;;
+	int result = KAUTH_RESULT_DEFER;
 
 	if (action != KAUTH_SYSTEM_FS_SNAPSHOT)
 		return result;



CVS commit: src/sys/ufs/ffs

2014-09-08 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Sep  8 20:52:37 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Prefer cprng_fast32 over random. A good distribution even in the lower
bits beat any minor performance advantage randomo(9) might have,
especially given the disk IO involved.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.146 src/sys/ufs/ffs/ffs_alloc.c:1.147
--- src/sys/ufs/ffs/ffs_alloc.c:1.146	Fri Jul 25 08:24:31 2014
+++ src/sys/ufs/ffs/ffs_alloc.c	Mon Sep  8 20:52:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.146 2014/07/25 08:24:31 dholland Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.147 2014/09/08 20:52:37 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.146 2014/07/25 08:24:31 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.147 2014/09/08 20:52:37 joerg Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -90,6 +90,7 @@ __KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,
 #include sys/syslog.h
 #include sys/vnode.h
 #include sys/wapbl.h
+#include sys/cprng.h
 
 #include miscfs/specfs/specdev.h
 #include ufs/ufs/quota.h
@@ -697,7 +698,7 @@ ffs_dirpref(struct inode *pip)
 	 * Force allocation in another cg if creating a first level dir.
 	 */
 	if (ITOV(pip)-v_vflag  VV_ROOT) {
-		prefcg = random() % fs-fs_ncg;
+		prefcg = cprng_fast32() % fs-fs_ncg;
 		mincg = prefcg;
 		minndir = fs-fs_ipg;
 		for (cg = prefcg; cg  fs-fs_ncg; cg++)



CVS commit: src/sys/ufs/ffs

2014-09-05 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Fri Sep  5 06:10:08 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_snapshot.c

Log Message:
Don't nest structure definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/ufs/ffs/ffs_snapshot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.136 src/sys/ufs/ffs/ffs_snapshot.c:1.137
--- src/sys/ufs/ffs/ffs_snapshot.c:1.136	Thu Jul 10 06:02:40 2014
+++ src/sys/ufs/ffs/ffs_snapshot.c	Fri Sep  5 06:10:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.136 2014/07/10 06:02:40 dholland Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.137 2014/09/05 06:10:07 matt Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.136 2014/07/10 06:02:40 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.137 2014/09/05 06:10:07 matt Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -77,11 +77,13 @@ __KERNEL_RCSID(0, $NetBSD: ffs_snapshot
 
 #include uvm/uvm.h
 
+TAILQ_HEAD(inodelst, inode);			/* List of active snapshots */
+
 struct snap_info {
 	kmutex_t si_lock;			/* Lock this snapinfo */
 	kmutex_t si_snaplock;			/* Snapshot vnode common lock */
 	lwp_t *si_owner;			/* Sanplock owner */
-	TAILQ_HEAD(inodelst, inode) si_snapshots; /* List of active snapshots */
+	struct inodelst si_snapshots;		/* List of active snapshots */
 	daddr_t *si_snapblklist;		/* Snapshot block hints list */
 	uint32_t si_gen;			/* Incremented on change */
 };



CVS commit: src/sys/ufs/ffs

2014-07-25 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Jul 25 08:24:31 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Switch the FFS code for discarding free blocks to use VOP_FDISCARD.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/ufs/ffs/ffs_alloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.145 src/sys/ufs/ffs/ffs_alloc.c:1.146
--- src/sys/ufs/ffs/ffs_alloc.c:1.145	Tue Nov 12 03:29:22 2013
+++ src/sys/ufs/ffs/ffs_alloc.c	Fri Jul 25 08:24:31 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.145 2013/11/12 03:29:22 dholland Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.146 2014/07/25 08:24:31 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.145 2013/11/12 03:29:22 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_alloc.c,v 1.146 2014/07/25 08:24:31 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -1621,17 +1621,22 @@ ffs_discardcb(struct work *wk, void *arg
 	struct discardopdata *td = (void *)wk;
 	struct discarddata *ts = arg;
 	struct fs *fs = ts-fs;
-	struct disk_discard_range ta;
+	off_t start, len;
 #ifdef TRIMDEBUG
 	int error;
 #endif
 
-	ta.bno = FFS_FSBTODB(fs, td-bno);
-	ta.size = td-size  DEV_BSHIFT;
+/* like FSBTODB but emits bytes; XXX move to fs.h */
+#ifndef FFS_FSBTOBYTES
+#define FFS_FSBTOBYTES(fs, b) ((b)  (fs)-fs_fshift)
+#endif
+
+	start = FFS_FSBTOBYTES(fs, td-bno);
+	len = td-size;
 #ifdef TRIMDEBUG
 	error =
 #endif
-		VOP_IOCTL(td-devvp, DIOCDISCARD, ta, FWRITE, FSCRED);
+		VOP_FDISCARD(td-devvp, start, len);
 #ifdef TRIMDEBUG
 	printf(trim(% PRId64 ,%ld):%d\n, td-bno, td-size, error);
 #endif
@@ -1648,20 +1653,9 @@ ffs_discardcb(struct work *wk, void *arg
 void *
 ffs_discard_init(struct vnode *devvp, struct fs *fs)
 {
-	struct disk_discard_params tp;
 	struct discarddata *ts;
 	int error;
 
-	error = VOP_IOCTL(devvp, DIOCGDISCARDPARAMS, tp, FREAD, FSCRED);
-	if (error) {
-		printf(DIOCGDISCARDPARAMS: %d\n, error);
-		return NULL;
-	}
-	if (tp.maxsize * DEV_BSIZE  fs-fs_bsize) {
-		printf(tp.maxsize=%ld, fs_bsize=%d\n, tp.maxsize, fs-fs_bsize);
-		return NULL;
-	}
-
 	ts = kmem_zalloc(sizeof (*ts), KM_SLEEP);
 	error = workqueue_create(ts-wq, trimwq, ffs_discardcb, ts,
  0, 0, 0);
@@ -1672,7 +1666,7 @@ ffs_discard_init(struct vnode *devvp, st
 	mutex_init(ts-entrylk, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(ts-wqlk, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(ts-wqcv, trimwqcv);
-	ts-maxsize = max(tp.maxsize * DEV_BSIZE, 100*1024); /* XXX */
+	ts-maxsize = 100*1024; /* XXX */
 	ts-fs = fs;
 	return ts;
 }



CVS commit: src/sys/ufs/ffs

2014-07-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jul 11 16:17:29 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
move the flag setting higher to avoid KASSERT (dholland)


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.27 src/sys/ufs/ffs/ffs_wapbl.c:1.28
--- src/sys/ufs/ffs/ffs_wapbl.c:1.27	Thu Jul 10 11:15:54 2014
+++ src/sys/ufs/ffs/ffs_wapbl.c	Fri Jul 11 12:17:29 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.27 2014/07/10 15:15:54 christos Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.28 2014/07/11 16:17:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.27 2014/07/10 15:15:54 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.28 2014/07/11 16:17:29 christos Exp $);
 
 #define WAPBL_INTERNAL
 
@@ -351,9 +351,9 @@ ffs_wapbl_start(struct mount *mp)
 #endif
 
 			if ((fs-fs_flags  FS_DOWAPBL) == 0) {
+fs-fs_flags |= FS_DOWAPBL;
 if ((error = UFS_WAPBL_BEGIN(mp)) != 0)
 	goto out;
-fs-fs_flags |= FS_DOWAPBL;
 error = ffs_sbupdate(ump, MNT_WAIT);
 if (error) {
 	UFS_WAPBL_END(mp);



CVS commit: src/sys/ufs/ffs

2014-07-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Jul 10 06:02:40 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_snapshot.c

Log Message:
Use an explicit compare to 0 for an immediate error result, not !.
Using ! is perfectly clear on variables like error or result,
but directly on a function call it tends to look like a mistake.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/sys/ufs/ffs/ffs_snapshot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.135 src/sys/ufs/ffs/ffs_snapshot.c:1.136
--- src/sys/ufs/ffs/ffs_snapshot.c:1.135	Fri May 30 08:40:09 2014
+++ src/sys/ufs/ffs/ffs_snapshot.c	Thu Jul 10 06:02:40 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_snapshot.c,v 1.135 2014/05/30 08:40:09 hannken Exp $	*/
+/*	$NetBSD: ffs_snapshot.c,v 1.136 2014/07/10 06:02:40 dholland Exp $	*/
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.135 2014/05/30 08:40:09 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_snapshot.c,v 1.136 2014/07/10 06:02:40 dholland Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -399,7 +399,7 @@ out:
 #endif
 	}
 	if (error) {
-		if (!UFS_WAPBL_BEGIN(mp)) {
+		if (UFS_WAPBL_BEGIN(mp) == 0) {
 			(void) ffs_truncate(vp, (off_t)0, 0, NOCRED);
 			UFS_WAPBL_END(mp);
 		}



CVS commit: src/sys/ufs/ffs

2014-07-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Jul 10 06:27:15 UTC 2014

Modified Files:
src/sys/ufs/ffs: ffs_wapbl.c

Log Message:
Fix unchecked UFS_WAPBL_BEGIN. Coverity 975226.
Unfortunately it looks like all we can do on error here is printf.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/ufs/ffs/ffs_wapbl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_wapbl.c
diff -u src/sys/ufs/ffs/ffs_wapbl.c:1.25 src/sys/ufs/ffs/ffs_wapbl.c:1.26
--- src/sys/ufs/ffs/ffs_wapbl.c:1.25	Fri Oct 25 11:35:55 2013
+++ src/sys/ufs/ffs/ffs_wapbl.c	Thu Jul 10 06:27:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_wapbl.c,v 1.25 2013/10/25 11:35:55 martin Exp $	*/
+/*	$NetBSD: ffs_wapbl.c,v 1.26 2014/07/10 06:27:15 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.25 2013/10/25 11:35:55 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_wapbl.c,v 1.26 2014/07/10 06:27:15 dholland Exp $);
 
 #define WAPBL_INTERNAL
 
@@ -147,9 +147,16 @@ ffs_wapbl_replay_finish(struct mount *mp
 		 * initialized in ufs_makeinode.  If so, just dallocate them.
 		 */
 		if (ip-i_mode == 0) {
-			UFS_WAPBL_BEGIN(mp);
-			ffs_vfree(vp, ip-i_number, wr-wr_inodes[i].wr_imode);
-			UFS_WAPBL_END(mp);
+			error = UFS_WAPBL_BEGIN(mp);
+			if (error) {
+printf(ffs_wapbl_replay_finish: 
+unable to cleanup inode % PRIu32 \n,
+wr-wr_inodes[i].wr_inumber);
+			} else {
+ffs_vfree(vp, ip-i_number,
+wr-wr_inodes[i].wr_imode);
+UFS_WAPBL_END(mp);
+			}
 		}
 		vput(vp);
 	}



  1   2   >