CVS commit: src/usr.sbin/dumplfs

2018-06-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun 15 15:16:05 UTC 2018

Modified Files:
src/usr.sbin/dumplfs: Makefile dumplfs.c

Log Message:
PR/53367: Thomas Barabosch: Integer overflow in usr.sbin/dumplfs
While here use the "e" functions to always check for allocation errors.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/dumplfs/Makefile
cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/Makefile
diff -u src/usr.sbin/dumplfs/Makefile:1.17 src/usr.sbin/dumplfs/Makefile:1.18
--- src/usr.sbin/dumplfs/Makefile:1.17	Wed Jun 15 10:08:24 2016
+++ src/usr.sbin/dumplfs/Makefile	Fri Jun 15 11:16:05 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.17 2016/06/15 14:08:24 riastradh Exp $
+#	$NetBSD: Makefile,v 1.18 2018/06/15 15:16:05 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 WARNS?=	3	# XXX -Wsign-compare
@@ -9,5 +9,7 @@ PROG=	dumplfs
 SRCS=	dumplfs.c lfs_cksum.c misc.c
 .PATH:	${NETBSDSRCDIR}/sys/ufs/lfs
 MAN=	dumplfs.8
+LDADD+=	-lutil
+DPADD+= ${LIBUTIL}
 
 .include 

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.63 src/usr.sbin/dumplfs/dumplfs.c:1.64
--- src/usr.sbin/dumplfs/dumplfs.c:1.63	Fri Aug 12 04:22:13 2016
+++ src/usr.sbin/dumplfs/dumplfs.c	Fri Jun 15 11:16:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.63 2016/08/12 08:22:13 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.64 2018/06/15 15:16:05 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.63 2016/08/12 08:22:13 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.64 2018/06/15 15:16:05 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,6 +61,7 @@ __RCSID("$NetBSD: dumplfs.c,v 1.63 2016/
 #include 
 #include 
 #include 
+#include 
 #include "extern.h"
 
 static void	addseg(char *);
@@ -226,10 +227,7 @@ main(int argc, char **argv)
 	if ((fd = open(special, O_RDONLY, 0)) < 0)
 		err(1, "%s", special);
 
-	sbuf = malloc(LFS_SBPAD);
-	if (sbuf == NULL)
-		err(1, "malloc");
-
+	sbuf = emalloc(LFS_SBPAD);
 	if (sbdaddr == 0x0) {
 		/* Read the proto-superblock */
 		__CTASSERT(sizeof(struct dlfs) == sizeof(struct dlfs64));
@@ -332,8 +330,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 	if (!addr)
 		addr = lfs_sb_getidaddr(lfsp);
 
-	if (!(dpage = malloc(psize)))
-		err(1, "malloc");
+	dpage = emalloc(psize);
 	get(fd, fsbtobyte(lfsp, addr), dpage, psize);
 
 	dip = NULL;
@@ -363,8 +360,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 	block_limit = MIN(nblocks, ULFS_NDADDR);
 
 	/* Get the direct block */
-	if ((ipage = malloc(psize)) == NULL)
-		err(1, "malloc");
+	ipage = emalloc(psize);
 	for (inum = 0, i = 0; i < block_limit; i++) {
 		pdb = lfs_dino_getdb(lfsp, dip, i);
 		get(fd, fsbtobyte(lfsp, pdb), ipage, psize);
@@ -395,8 +391,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 		goto e0;
 
 	/* Dump out blocks off of single indirect block */
-	if (!(indir = malloc(psize)))
-		err(1, "malloc");
+	indir = emalloc(psize);
 	get(fd, fsbtobyte(lfsp, lfs_dino_getib(lfsp, dip, 0)), indir, psize);
 	block_limit = MIN(i + lfs_sb_getnindir(lfsp), nblocks);
 	for (offset = 0; i < block_limit; i++, offset++) {
@@ -429,8 +424,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 		goto e1;
 
 	/* Get the double indirect block */
-	if (!(dindir = malloc(psize)))
-		err(1, "malloc");
+	dindir = emalloc(psize);
 	get(fd, fsbtobyte(lfsp, lfs_dino_getib(lfsp, dip, 1)), dindir, psize);
 	for (j = 0; j < lfs_sb_getnindir(lfsp); j++) {
 		thisblock = lfs_iblock_get(lfsp, dindir, j);
@@ -617,7 +611,7 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
 
 	/* Dump out inode disk addresses */
 	iip = SEGSUM_IINFOSTART(lfsp, sp);
-	diblock = malloc(lfs_sb_getbsize(lfsp));
+	diblock = emalloc(lfs_sb_getbsize(lfsp));
 	printf("Inode addresses:");
 	numbytes = 0;
 	numblocks = 0;
@@ -680,11 +674,11 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
 	} else {
 		el_size = sizeof(u_int32_t);
 	}
-	datap = (char *)malloc(el_size * numblocks);
-	memset(datap, 0, el_size * numblocks);
+	datap = ecalloc(numblocks, el_size);
+
 	acc = 0;
 	addr += lfs_btofsb(lfsp, lfs_sb_getsumsize(lfsp));
-	buf = malloc(lfs_sb_getbsize(lfsp));
+	buf = emalloc(lfs_sb_getbsize(lfsp));
 	for (i = 0; i < lfs_ss_getnfinfo(lfsp, sp); i++) {
 		while (addr == lfs_ii_getblock(lfsp, iip2)) {
 			get(fd, fsbtobyte(lfsp, addr), buf, lfs_sb_getibsize(lfsp));
@@ -737,7 +731,7 @@ dump_segment(int fd, int segnum, daddr_t
 	(void)printf("\nSEGMENT %lld (Disk Address 0x%llx)\n",
 		 (long long)lfs_dtosn(lfsp, addr), (long long)addr);
 	sum_offset = fsbtobyte(lfsp, addr);
-	sumblock = malloc(lfs_sb_getsumsize(lfsp));
+	sumblock = emalloc(lfs_sb_getsumsize(lfsp));
 
 	if (lfs_sb_getversion(lfs

CVS commit: src/usr.sbin/dumplfs

2016-08-12 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Aug 12 08:22:13 UTC 2016

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
If the number of inodes per block is zero, bail instead of using
uninitialized stack trash as a dinode pointer. Fixes PR 51409 where
"dumplfs /dev/zero" receives SIGSEGV.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.62 src/usr.sbin/dumplfs/dumplfs.c:1.63
--- src/usr.sbin/dumplfs/dumplfs.c:1.62	Wed Jun 15 14:07:54 2016
+++ src/usr.sbin/dumplfs/dumplfs.c	Fri Aug 12 08:22:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.62 2016/06/15 14:07:54 riastradh Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.63 2016/08/12 08:22:13 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.62 2016/06/15 14:07:54 riastradh Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.63 2016/08/12 08:22:13 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -336,12 +336,19 @@ dump_ifile(int fd, struct lfs *lfsp, int
 		err(1, "malloc");
 	get(fd, fsbtobyte(lfsp, addr), dpage, psize);
 
+	dip = NULL;
 	for (i = LFS_INOPB(lfsp); i-- > 0; ) {
 		dip = DINO_IN_BLOCK(lfsp, dpage, i);
 		if (lfs_dino_getinumber(lfsp, dip) == LFS_IFILE_INUM)
 			break;
 	}
 
+	/* just in case */
+	if (dip == NULL) {
+		warnx("this volume apparently has zero inodes per block");
+		return;
+	}
+
 	if (lfs_dino_getinumber(lfsp, dip) != LFS_IFILE_INUM) {
 		warnx("unable to locate ifile inode at disk address 0x%jx",
 		 (uintmax_t)addr);



CVS commit: src/usr.sbin/dumplfs

2016-06-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jun 15 14:08:24 UTC 2016

Modified Files:
src/usr.sbin/dumplfs: Makefile

Log Message:
Kill another -fno-strict-aliasing.

Generated code is same with/without.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/dumplfs/Makefile

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

Modified files:

Index: src/usr.sbin/dumplfs/Makefile
diff -u src/usr.sbin/dumplfs/Makefile:1.16 src/usr.sbin/dumplfs/Makefile:1.17
--- src/usr.sbin/dumplfs/Makefile:1.16	Sun Aug 11 03:49:24 2013
+++ src/usr.sbin/dumplfs/Makefile	Wed Jun 15 14:08:24 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.16 2013/08/11 03:49:24 dholland Exp $
+#	$NetBSD: Makefile,v 1.17 2016/06/15 14:08:24 riastradh Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 WARNS?=	3	# XXX -Wsign-compare
@@ -10,8 +10,4 @@ SRCS=	dumplfs.c lfs_cksum.c misc.c
 .PATH:	${NETBSDSRCDIR}/sys/ufs/lfs
 MAN=	dumplfs.8
 
-.if defined(HAVE_LLVM)
-COPTS+=	-fno-strict-aliasing
-.endif
-
 .include 



CVS commit: src/usr.sbin/dumplfs

2016-06-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jun 15 14:07:54 UTC 2016

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
 for true and false.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.61 src/usr.sbin/dumplfs/dumplfs.c:1.62
--- src/usr.sbin/dumplfs/dumplfs.c:1.61	Thu Oct 15 06:24:46 2015
+++ src/usr.sbin/dumplfs/dumplfs.c	Wed Jun 15 14:07:54 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.61 2015/10/15 06:24:46 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.62 2016/06/15 14:07:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.61 2015/10/15 06:24:46 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.62 2016/06/15 14:07:54 riastradh Exp $");
 #endif
 #endif /* not lint */
 
@@ -56,6 +56,7 @@ __RCSID("$NetBSD: dumplfs.c,v 1.61 2015/
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/usr.sbin/dumplfs

2015-10-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Oct 15 06:24:46 UTC 2015

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
Enable lfs64 in dumplfs. Print LFS32/64 in the output header.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.60 src/usr.sbin/dumplfs/dumplfs.c:1.61
--- src/usr.sbin/dumplfs/dumplfs.c:1.60	Sat Oct 10 22:34:09 2015
+++ src/usr.sbin/dumplfs/dumplfs.c	Thu Oct 15 06:24:46 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.60 2015/10/10 22:34:09 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.61 2015/10/15 06:24:46 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.60 2015/10/10 22:34:09 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.61 2015/10/15 06:24:46 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -134,6 +134,44 @@ print_ientry(int i, struct lfs *lfsp, IF
 		nextfree == LFS_ORPHAN_NEXTFREE ? "" : "-");
 }
 
+/*
+ * Set the is64 and dobyteswap fields of struct lfs. Note that the
+ * magic number (and version) fields are necessarily at the same place
+ * in all superblock versions, so we can read it via u_32 without
+ * getting confused.
+ */
+static void
+identify(struct lfs *fs)
+{
+	unsigned magic;
+
+	magic = fs->lfs_dlfs_u.u_32.dlfs_magic;
+	switch (magic) {
+	case LFS_MAGIC:
+		fs->lfs_is64 = false;
+		fs->lfs_dobyteswap = false;
+		break;
+	case LFS_MAGIC_SWAPPED:
+		fs->lfs_is64 = false;
+		fs->lfs_dobyteswap = true;
+		break;
+	case LFS64_MAGIC:
+		fs->lfs_is64 = true;
+		fs->lfs_dobyteswap = false;
+		break;
+	case LFS64_MAGIC_SWAPPED:
+		fs->lfs_is64 = true;
+		fs->lfs_dobyteswap = true;
+		break;
+	default:
+		warnx("Superblock magic number 0x%x not known; "
+		  "assuming 32-bit, native-endian", magic);
+		fs->lfs_is64 = false;
+		fs->lfs_dobyteswap = false;
+		break;
+	}
+}
+
 #define fsbtobyte(fs, b)	lfs_fsbtob((fs), (off_t)((b)))
 
 int datasum_check = 0;
@@ -196,12 +234,15 @@ main(int argc, char **argv)
 		__CTASSERT(sizeof(struct dlfs) == sizeof(struct dlfs64));
 		get(fd, LFS_LABELPAD, sbuf, LFS_SBPAD);
 		memcpy(&lfs_sb1.lfs_dlfs_u, sbuf, sizeof(struct dlfs));
+		identify(&lfs_sb1);
 
 		/* If that wasn't the real first sb, get the real first sb */
 		if (lfs_sb_getversion(&lfs_sb1) > 1 &&
-		lfs_sb_getsboff(&lfs_sb1, 0) > lfs_btofsb(&lfs_sb1, LFS_LABELPAD))
+		lfs_sb_getsboff(&lfs_sb1, 0) > lfs_btofsb(&lfs_sb1, LFS_LABELPAD)) {
 			get(fd, lfs_fsbtob(&lfs_sb1, lfs_sb_getsboff(&lfs_sb1, 0)),
 			&lfs_sb1.lfs_dlfs_u, sizeof(struct dlfs));
+			identify(&lfs_sb1);
+		}
 	
 		/*
 	 	* Read the second superblock and figure out which check point is
@@ -211,6 +252,7 @@ main(int argc, char **argv)
 		fsbtobyte(&lfs_sb1, lfs_sb_getsboff(&lfs_sb1, 1)),
 		sbuf, LFS_SBPAD);
 		memcpy(&lfs_sb2.lfs_dlfs_u, sbuf, sizeof(struct dlfs));
+		identify(&lfs_sb2);
 	
 		lfs_master = &lfs_sb1;
 		if (lfs_sb_getversion(&lfs_sb1) > 1) {
@@ -230,6 +272,7 @@ main(int argc, char **argv)
 		/* Read the first superblock */
 		get(fd, dbtob((off_t)sbdaddr), sbuf, LFS_SBPAD);
 		memcpy(&lfs_sb1.lfs_dlfs_u, sbuf, sizeof(struct dlfs));
+		identify(&lfs_sb1);
 		lfs_master = &lfs_sb1;
 	}
 
@@ -244,7 +287,8 @@ main(int argc, char **argv)
 		lfs_sb_setfsbtodb(lfs_master, 0);
 	}
 
-	(void)printf("Master Superblock at 0x%llx:\n", (long long)sbdaddr);
+	(void)printf("Master LFS%d superblock at 0x%llx:\n",
+	lfs_master->lfs_is64 ? 64 : 32, (long long)sbdaddr);
 	dump_super(lfs_master);
 
 	dump_ifile(fd, lfs_master, do_ientries, do_segentries, idaddr);



CVS commit: src/usr.sbin/dumplfs

2015-10-03 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Oct  3 08:28:56 UTC 2015

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
Use accessors for another batch of indirect block accesses, this time
in dumplfs.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.58 src/usr.sbin/dumplfs/dumplfs.c:1.59
--- src/usr.sbin/dumplfs/dumplfs.c:1.58	Sat Oct  3 08:28:46 2015
+++ src/usr.sbin/dumplfs/dumplfs.c	Sat Oct  3 08:28:56 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.58 2015/10/03 08:28:46 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.59 2015/10/03 08:28:56 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.58 2015/10/03 08:28:46 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.59 2015/10/03 08:28:56 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -277,8 +277,9 @@ dump_ifile(int fd, struct lfs *lfsp, int
 	char *ipage;
 	char *dpage;
 	union lfs_dinode *dip = NULL;
-	/* XXX ondisk32 */
-	int32_t *addrp, *dindir, *iaddrp, *indir;
+	void *dindir, *indir;
+	unsigned offset;
+	daddr_t thisblock;
 	daddr_t pdb;
 	int block_limit, i, inum, j, nblocks, psize;
 
@@ -346,10 +347,11 @@ dump_ifile(int fd, struct lfs *lfsp, int
 		err(1, "malloc");
 	get(fd, fsbtobyte(lfsp, lfs_dino_getib(lfsp, dip, 0)), indir, psize);
 	block_limit = MIN(i + lfs_sb_getnindir(lfsp), nblocks);
-	for (addrp = indir; i < block_limit; i++, addrp++) {
-		if (*addrp == LFS_UNUSED_DADDR)
+	for (offset = 0; i < block_limit; i++, offset++) {
+		thisblock = lfs_iblock_get(lfsp, indir, offset);
+		if (thisblock == LFS_UNUSED_DADDR)
 			break;
-		get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
+		get(fd, fsbtobyte(lfsp, thisblock), ipage, psize);
 		if (i < lfs_sb_getcleansz(lfsp)) {
 			dump_cleaner_info(lfsp, ipage);
 			continue;
@@ -378,15 +380,17 @@ dump_ifile(int fd, struct lfs *lfsp, int
 	if (!(dindir = malloc(psize)))
 		err(1, "malloc");
 	get(fd, fsbtobyte(lfsp, lfs_dino_getib(lfsp, dip, 1)), dindir, psize);
-	for (iaddrp = dindir, j = 0; j < lfs_sb_getnindir(lfsp); j++, iaddrp++) {
-		if (*iaddrp == LFS_UNUSED_DADDR)
+	for (j = 0; j < lfs_sb_getnindir(lfsp); j++) {
+		thisblock = lfs_iblock_get(lfsp, dindir, j);
+		if (thisblock == LFS_UNUSED_DADDR)
 			break;
-		get(fd, fsbtobyte(lfsp, *iaddrp), indir, psize);
+		get(fd, fsbtobyte(lfsp, thisblock), indir, psize);
 		block_limit = MIN(i + lfs_sb_getnindir(lfsp), nblocks);
-		for (addrp = indir; i < block_limit; i++, addrp++) {
-			if (*addrp == LFS_UNUSED_DADDR)
+		for (offset = 0; i < block_limit; i++, offset++) {
+			thisblock = lfs_iblock_get(lfsp, indir, offset);
+			if (thisblock == LFS_UNUSED_DADDR)
 break;
-			get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
+			get(fd, fsbtobyte(lfsp, thisblock), ipage, psize);
 			if (i < lfs_sb_getcleansz(lfsp)) {
 dump_cleaner_info(lfsp, ipage);
 continue;



CVS commit: src/usr.sbin/dumplfs

2015-08-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Aug 29 05:33:20 UTC 2015

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
Bypass the ifile's double indirect block if the ifile size in blocks
is less than or equal to NDADDR + NINDIR, the number of blocks mapped
without getting to the double indirect block.

The code here was instead using NINDIR * ifpb (ifile entries per
block); this gives the number of ifile entries the indirect block can
map, but that isn't a useful number.

Caught by mlelstv.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.54 src/usr.sbin/dumplfs/dumplfs.c:1.55
--- src/usr.sbin/dumplfs/dumplfs.c:1.54	Wed Aug 12 18:28:01 2015
+++ src/usr.sbin/dumplfs/dumplfs.c	Sat Aug 29 05:33:20 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.54 2015/08/12 18:28:01 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.55 2015/08/29 05:33:20 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.54 2015/08/12 18:28:01 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.55 2015/08/29 05:33:20 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -371,7 +371,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 			inum = dump_ipage_ifile(lfsp, inum, ipage, lfs_sb_getifpb(lfsp));
 	}
 
-	if (nblocks <= lfs_sb_getnindir(lfsp) * lfs_sb_getifpb(lfsp))
+	if (nblocks <= ULFS_NDADDR + lfs_sb_getnindir(lfsp))
 		goto e1;
 
 	/* Get the double indirect block */



CVS commit: src/usr.sbin/dumplfs

2013-08-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Aug 11 03:49:24 UTC 2013

Modified Files:
src/usr.sbin/dumplfs: Makefile

Log Message:
Turn off -fno-strict-aliasing for HAVE_GCC; it makes no difference to
the compiler output and is therefore ipso facto not necessary. I'll
leave it on for HAVE_LLVM as I can't check that tonight.

(If there is invalid code in here that actually requires it, let me
know so I can fix things properly.)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/dumplfs/Makefile

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

Modified files:

Index: src/usr.sbin/dumplfs/Makefile
diff -u src/usr.sbin/dumplfs/Makefile:1.15 src/usr.sbin/dumplfs/Makefile:1.16
--- src/usr.sbin/dumplfs/Makefile:1.15	Fri Aug 10 12:10:28 2012
+++ src/usr.sbin/dumplfs/Makefile	Sun Aug 11 03:49:24 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.15 2012/08/10 12:10:28 joerg Exp $
+#	$NetBSD: Makefile,v 1.16 2013/08/11 03:49:24 dholland Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 WARNS?=	3	# XXX -Wsign-compare
@@ -10,7 +10,7 @@ SRCS=	dumplfs.c lfs_cksum.c misc.c
 .PATH:	${NETBSDSRCDIR}/sys/ufs/lfs
 MAN=	dumplfs.8
 
-.if defined(HAVE_GCC) || defined(HAVE_LLVM)
+.if defined(HAVE_LLVM)
 COPTS+=	-fno-strict-aliasing
 .endif
 



CVS commit: src/usr.sbin/dumplfs

2013-06-08 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Jun  8 23:27:34 UTC 2013

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
Use struct ulfs1_dinode instead of struct ufs1_dinode.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.39 src/usr.sbin/dumplfs/dumplfs.c:1.40
--- src/usr.sbin/dumplfs/dumplfs.c:1.39	Tue Jan 22 09:39:19 2013
+++ src/usr.sbin/dumplfs/dumplfs.c	Sat Jun  8 23:27:34 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.39 2013/01/22 09:39:19 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.40 2013/06/08 23:27:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.39 2013/01/22 09:39:19 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.40 2013/06/08 23:27:34 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -49,7 +49,6 @@ __RCSID("$NetBSD: dumplfs.c,v 1.39 2013/
 #include 
 #include 
 
-#include 
 #include 
 
 #include 
@@ -64,7 +63,7 @@ __RCSID("$NetBSD: dumplfs.c,v 1.39 2013/
 
 static void	addseg(char *);
 static void	dump_cleaner_info(struct lfs *, void *);
-static void	dump_dinode(struct ufs1_dinode *);
+static void	dump_dinode(struct ulfs1_dinode *);
 static void	dump_ifile(int, struct lfs *, int, int, daddr_t);
 static int	dump_ipage_ifile(struct lfs *, int, char *, int);
 static int	dump_ipage_segusage(struct lfs *, int, char *, int);
@@ -266,7 +265,7 @@ static void
 dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t addr)
 {
 	char *ipage;
-	struct ufs1_dinode *dip, *dpage;
+	struct ulfs1_dinode *dip, *dpage;
 	/* XXX ondisk32 */
 	int32_t *addrp, *dindir, *iaddrp, *indir;
 	int block_limit, i, inum, j, nblocks, psize;
@@ -294,7 +293,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 
 	(void)printf("\nIFILE contents\n");
 	nblocks = dip->di_size >> lfsp->lfs_bshift;
-	block_limit = MIN(nblocks, UFS_NDADDR);
+	block_limit = MIN(nblocks, ULFS_NDADDR);
 
 	/* Get the direct block */
 	if ((ipage = malloc(psize)) == NULL)
@@ -325,7 +324,7 @@ dump_ifile(int fd, struct lfs *lfsp, int
 			inum = dump_ipage_ifile(lfsp, inum, ipage, lfsp->lfs_ifpb);
 	}
 
-	if (nblocks <= UFS_NDADDR)
+	if (nblocks <= ULFS_NDADDR)
 		goto e0;
 
 	/* Dump out blocks off of single indirect block */
@@ -451,7 +450,7 @@ dump_ipage_segusage(struct lfs *lfsp, in
 }
 
 static void
-dump_dinode(struct ufs1_dinode *dip)
+dump_dinode(struct ulfs1_dinode *dip)
 {
 	int i;
 	time_t at, mt, ct;
@@ -472,12 +471,12 @@ dump_dinode(struct ufs1_dinode *dip)
 		"ctime ", ctime(&ct));
 	(void)printf("inum  %d\n", dip->di_inumber);
 	(void)printf("Direct Addresses\n");
-	for (i = 0; i < UFS_NDADDR; i++) {
+	for (i = 0; i < ULFS_NDADDR; i++) {
 		(void)printf("\t0x%x", dip->di_db[i]);
 		if ((i % 6) == 5)
 			(void)printf("\n");
 	}
-	for (i = 0; i < UFS_NIADDR; i++)
+	for (i = 0; i < ULFS_NIADDR; i++)
 		(void)printf("\t0x%x", dip->di_ib[i]);
 	(void)printf("\n");
 }
@@ -491,7 +490,7 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
 	int ck;
 	int numbytes, numblocks;
 	char *datap;
-	struct ufs1_dinode *inop;
+	struct ulfs1_dinode *inop;
 	size_t el_size;
 	u_int32_t datasum;
 	time_t t;



CVS commit: src/usr.sbin/dumplfs

2010-02-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Feb 16 18:57:54 UTC 2010

Modified Files:
src/usr.sbin/dumplfs: dumplfs.c

Log Message:
Read the padded superblocks to avoid problems with disks that have
larger sectors than 512 Bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/usr.sbin/dumplfs/dumplfs.c

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

Modified files:

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.37 src/usr.sbin/dumplfs/dumplfs.c:1.38
--- src/usr.sbin/dumplfs/dumplfs.c:1.37	Mon Jul 21 13:36:58 2008
+++ src/usr.sbin/dumplfs/dumplfs.c	Tue Feb 16 18:57:53 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.37 2008/07/21 13:36:58 lukem Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.38 2010/02/16 18:57:53 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.37 2008/07/21 13:36:58 lukem Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.38 2010/02/16 18:57:53 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -136,6 +136,7 @@
 	struct lfs lfs_sb1, lfs_sb2, *lfs_master;
 	daddr_t seg_addr, idaddr, sbdaddr;
 	int ch, do_allsb, do_ientries, do_segentries, fd, segnum;
+	void *sbuf;
 
 	do_allsb = 0;
 	do_ientries = 0;
@@ -178,9 +179,14 @@
 	if ((fd = open(special, O_RDONLY, 0)) < 0)
 		err(1, "%s", special);
 
+	sbuf = malloc(LFS_SBPAD);
+	if (sbuf == NULL)
+		err(1, "malloc");
+
 	if (sbdaddr == 0x0) {
 		/* Read the proto-superblock */
-		get(fd, LFS_LABELPAD, &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
+		get(fd, LFS_LABELPAD, sbuf, LFS_SBPAD);
+		memcpy(&(lfs_sb1.lfs_dlfs), sbuf, sizeof(struct dlfs));
 
 		/* If that wasn't the real first sb, get the real first sb */
 		if (lfs_sb1.lfs_version > 1 &&
@@ -194,7 +200,8 @@
 	 	*/
 		get(fd,
 		fsbtobyte(&lfs_sb1, lfs_sb1.lfs_sboffs[1]),
-		&(lfs_sb2.lfs_dlfs), sizeof(struct dlfs));
+		sbuf, LFS_SBPAD);
+		memcpy(&(lfs_sb2.lfs_dlfs), sbuf, sizeof(struct dlfs));
 	
 		lfs_master = &lfs_sb1;
 		if (lfs_sb1.lfs_version > 1) {
@@ -212,11 +219,13 @@
 		}
 	} else {
 		/* Read the first superblock */
-		get(fd, dbtob((off_t)sbdaddr), &(lfs_sb1.lfs_dlfs),
-		sizeof(struct dlfs));
+		get(fd, dbtob((off_t)sbdaddr), sbuf, LFS_SBPAD);
+		memcpy(&(lfs_sb1.lfs_dlfs), sbuf, sizeof(struct dlfs));
 		lfs_master = &lfs_sb1;
 	}
 
+	free(sbuf);
+
 	/* Compatibility */
 	if (lfs_master->lfs_version == 1) {
 		lfs_master->lfs_sumsize = LFS_V1_SUMMARY_SIZE;