CVS commit: src/sbin/resize_ffs

2020-05-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun May 24 14:41:27 UTC 2020

Modified Files:
src/sbin/resize_ffs: Makefile resize_ffs.c

Log Message:
Use getfsspecname and getrawdiskname so we can resize by NAME= label.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sbin/resize_ffs/Makefile
cvs rdiff -u -r1.54 -r1.55 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/Makefile
diff -u src/sbin/resize_ffs/Makefile:1.5 src/sbin/resize_ffs/Makefile:1.6
--- src/sbin/resize_ffs/Makefile:1.5	Mon Apr  6 22:44:04 2015
+++ src/sbin/resize_ffs/Makefile	Sun May 24 14:41:26 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.5 2015/04/06 22:44:04 jmcneill Exp $
+#	$NetBSD: Makefile,v 1.6 2020/05/24 14:41:26 jmcneill Exp $
 
 .include 
 
@@ -8,6 +8,9 @@ SRCS=resize_ffs.c ffs_bswap.c progress.c
 
 CPPFLAGS+=-I${NETBSDSRCDIR}/sbin/fsck
 
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+
 .PATH: ${NETBSDSRCDIR}/sys/ufs/ffs
 .PATH: ${NETBSDSRCDIR}/sbin/fsck
 

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.54 src/sbin/resize_ffs/resize_ffs.c:1.55
--- src/sbin/resize_ffs/resize_ffs.c:1.54	Sun Apr 21 11:45:08 2019
+++ src/sbin/resize_ffs/resize_ffs.c	Sun May 24 14:41:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.54 2019/04/21 11:45:08 maya Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.55 2020/05/24 14:41:26 jmcneill Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.54 2019/04/21 11:45:08 maya Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.55 2020/05/24 14:41:26 jmcneill Exp $");
 
 #include 
 #include 
@@ -58,6 +58,7 @@ __RCSID("$NetBSD: resize_ffs.c,v 1.54 20
 #include 
 #include 
 #include 
+#include 
 
 #include "progress.h"
 
@@ -68,7 +69,7 @@ static int64_t newsize;
 static int fd;
 
 /* disk device or file path */
-char *special;
+const char *special;
 
 /* must we break up big I/O operations - see checksmallio() */
 static int smallio;
@@ -2110,7 +2111,7 @@ checkonly(void)
 }
 
 static off_t
-get_dev_size(char *dev_name)
+get_dev_size(const char *dev_name)
 {
 	struct dkwedge_info dkw;
 	struct partition *pp;
@@ -2145,6 +2146,9 @@ main(int argc, char **argv)
 	int ExpertFlag;
 	int SFlag;
 	size_t i;
+	char specname[MAXPATHLEN];
+	char rawname[MAXPATHLEN];
+	const char *raw;
 
 	char reply[5];
 
@@ -2187,7 +2191,12 @@ main(int argc, char **argv)
 		usage();
 	}
 
-	special = *argv;
+	special = getfsspecname(specname, sizeof(specname), argv[0]);
+	if (special == NULL)
+		err(EXIT_FAILURE, "%s: %s", argv[0], specname);
+	raw = getdiskrawname(rawname, sizeof(rawname), special);
+	if (raw != NULL)
+		special = raw;
 
 	if (ExpertFlag == 0 && CheckOnlyFlag == 0) {
 		printf("It's required to manually run fsck on file system "



CVS commit: src/sbin/resize_ffs

2017-10-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Oct  9 05:24:26 UTC 2017

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Fix computation of left-over fragments also for ufs2.

Fixes PR 52600.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.52 src/sbin/resize_ffs/resize_ffs.c:1.53
--- src/sbin/resize_ffs/resize_ffs.c:1.52	Sun Oct  1 22:59:19 2017
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Oct  9 05:24:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.52 2017/10/01 22:59:19 christos Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.53 2017/10/09 05:24:26 mlelstv Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.52 2017/10/01 22:59:19 christos Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.53 2017/10/09 05:24:26 mlelstv Exp $");
 
 #include 
 #include 
@@ -595,16 +595,17 @@ initcg(int cgn)
 			cg_clustersum(cg, 0)[(n > newsb->fs_contigsumsize) ?
 			newsb->fs_contigsumsize : n]++;
 		}
-		if (is_ufs2 == 0)
-			for (i = n; i > 0; i--) {
+		for (i = n; i > 0; i--) {
+			if (is_ufs2 == 0) {
 old_cg_blktot(cg, 0)[old_cbtocylno(newsb,
 	dhigh)]++;
 old_cg_blks(newsb, cg,
 old_cbtocylno(newsb, dhigh),
 0)[old_cbtorpos(newsb,
 	dhigh)]++;
-dhigh += newsb->fs_frag;
 			}
+			dhigh += newsb->fs_frag;
+		}
 	}
 	/* Deal with any leftover frag at the end of the cg. */
 	i = dmax - dhigh;



CVS commit: src/sbin/resize_ffs

2017-10-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct  1 22:59:19 UTC 2017

Modified Files:
src/sbin/resize_ffs: resize_ffs.8 resize_ffs.c

Log Message:
PR/52590: David H. Gutteridge: Minor documentation improvements


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sbin/resize_ffs/resize_ffs.8
cvs rdiff -u -r1.51 -r1.52 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.17 src/sbin/resize_ffs/resize_ffs.8:1.18
--- src/sbin/resize_ffs/resize_ffs.8:1.17	Mon Sep 12 01:47:21 2016
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Oct  1 18:59:19 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: resize_ffs.8,v 1.17 2016/09/12 05:47:21 sevan Exp $
+.\" $NetBSD: resize_ffs.8,v 1.18 2017/10/01 22:59:19 christos Exp $
 .\"
 .\" As its sole author, I explicitly place this man page in the public
 .\" domain.  Anyone may use it in any way for any purpose (though I would
@@ -9,7 +9,7 @@
 .\"  X  Against HTML   mo...@rodents.montreal.qc.ca
 .\" / \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
 .\"
-.Dd April 6, 2015
+.Dd October 1, 2017
 .Dt RESIZE_FFS 8
 .Os
 .Sh NAME
@@ -128,10 +128,8 @@ command first appeared in
 .Aq r...@netbsd.org
 (Byteswapped file system and UFS2 support)
 .Pp
-A big bug-finding kudos goes to John Kohl for finding the rotational
-layout bug referred to in the
-.Sx WARNING
-section above.
+A big bug-finding kudos goes to John Kohl for finding a significant
+rotational layout bug.
 .Sh BUGS
 Can fail to shrink a file system when there actually is enough space,
 because it does not distinguish between a block allocated as a block

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.51 src/sbin/resize_ffs/resize_ffs.c:1.52
--- src/sbin/resize_ffs/resize_ffs.c:1.51	Sun Oct  1 03:18:39 2017
+++ src/sbin/resize_ffs/resize_ffs.c	Sun Oct  1 18:59:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.51 2017/10/01 07:18:39 mlelstv Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.52 2017/10/01 22:59:19 christos Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.51 2017/10/01 07:18:39 mlelstv Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.52 2017/10/01 22:59:19 christos Exp $");
 
 #include 
 #include 
@@ -2304,7 +2304,7 @@ static void
 usage(void)
 {
 
-	(void)fprintf(stderr, "usage: %s [-cvy] [-s size] special\n",
+	(void)fprintf(stderr, "usage: %s [-cpvy] [-s size] special\n",
 	getprogname());
 	exit(EXIT_FAILURE);
 }



CVS commit: src/sbin/resize_ffs

2017-10-01 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Oct  1 07:18:39 UTC 2017

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.50 src/sbin/resize_ffs/resize_ffs.c:1.51
--- src/sbin/resize_ffs/resize_ffs.c:1.50	Sat Sep 30 18:32:52 2017
+++ src/sbin/resize_ffs/resize_ffs.c	Sun Oct  1 07:18:39 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.50 2017/09/30 18:32:52 kre Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.51 2017/10/01 07:18:39 mlelstv Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.50 2017/09/30 18:32:52 kre Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.51 2017/10/01 07:18:39 mlelstv Exp $");
 
 #include 
 #include 
@@ -478,7 +478,7 @@ initcg(int cgn)
 	dmax = newsb->fs_size - base;
 	if (dmax > newsb->fs_fpg)
 		dmax = newsb->fs_fpg;
-	start = >cg_space[0] - (unsigned char *) cg;
+	start = (unsigned char *)>cg_space[0] - (unsigned char *) cg;
 	/*
  * Clear out the cg - assumes all-0-bytes is the correct way
  * to initialize fields we don't otherwise touch, which is
@@ -606,13 +606,11 @@ initcg(int cgn)
 dhigh += newsb->fs_frag;
 			}
 	}
-	if (is_ufs2 == 0) {
-		/* Deal with any leftover frag at the end of the cg. */
-		i = dmax - dhigh;
-		if (i) {
-			cg->cg_frsum[i]++;
-			cg->cg_cs.cs_nffree += i;
-		}
+	/* Deal with any leftover frag at the end of the cg. */
+	i = dmax - dhigh;
+	if (i) {
+		cg->cg_frsum[i]++;
+		cg->cg_cs.cs_nffree += i;
 	}
 	/* Update the csum info. */
 	csums[cgn] = cg->cg_cs;
@@ -1049,9 +1047,9 @@ grow(void)
 	 * last cg (though possibly not to a full cg!). */
 	if (oldsb->fs_size % oldsb->fs_fpg) {
 		struct cg *cg;
-		int newcgsize;
-		int prevcgtop;
-		int oldcgsize;
+		int64_t newcgsize;
+		int64_t prevcgtop;
+		int64_t oldcgsize;
 		cg = cgs[oldsb->fs_ncg - 1];
 		cgflags[oldsb->fs_ncg - 1] |= CGF_DIRTY | CGF_BLKMAPS;
 		prevcgtop = oldsb->fs_fpg * (oldsb->fs_ncg - 1);
@@ -1124,13 +1122,12 @@ markblk(mark_callback_t fn, union dinode
  * Returns the number of bytes occupied in file, as does markblk().
  * For the sake of update_for_data_move(), we read the indirect block
  * _after_ making the _PRE callback.  The name is historical.  */
-static int
+static off_t
 markiblk(mark_callback_t fn, union dinode * di, off_t bn, off_t o, int lev)
 {
 	int i;
-	int j;
 	unsigned k;
-	int tot;
+	off_t j, tot;
 	static int32_t indirblk1[howmany(MAXBSIZE, sizeof(int32_t))];
 	static int32_t indirblk2[howmany(MAXBSIZE, sizeof(int32_t))];
 	static int32_t indirblk3[howmany(MAXBSIZE, sizeof(int32_t))];
@@ -1141,10 +1138,10 @@ markiblk(mark_callback_t fn, union dinod
 	if (lev < 0)
 		return (markblk(fn, di, bn, o));
 	if (bn == 0) {
-		for (i = newsb->fs_bsize;
+		for (j = newsb->fs_bsize;
 		lev >= 0;
-		i *= FFS_NINDIR(newsb), lev--);
-		return (i);
+		j *= FFS_NINDIR(newsb), lev--);
+		return (j);
 	}
 	(*fn) (bn, newsb->fs_frag, newsb->fs_bsize, MDB_INDIR_PRE);
 	readat(FFS_FSBTODB(newsb, bn), indirblks[lev], newsb->fs_bsize);
@@ -1180,7 +1177,7 @@ static void
 map_inode_data_blocks(union dinode * di, mark_callback_t fn)
 {
 	off_t o;		/* offset within  inode */
-	int inc;		/* increment for o - maybe should be off_t? */
+	off_t inc;		/* increment for o */
 	int b;			/* index within di_db[] and di_ib[] arrays */
 
 	/* Scan the direct blocks... */
@@ -1329,7 +1326,7 @@ mark_move(unsigned int from, unsigned in
  * each block of consecutive allocated frags is moved as a unit.
  */
 static void
-fragmove(struct cg * cg, int base, unsigned int start, unsigned int n)
+fragmove(struct cg * cg, int64_t base, unsigned int start, unsigned int n)
 {
 	unsigned int i;
 	int run;



CVS commit: src/sbin/resize_ffs

2017-09-30 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Sep 30 18:32:52 UTC 2017

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.49 src/sbin/resize_ffs/resize_ffs.c:1.50
--- src/sbin/resize_ffs/resize_ffs.c:1.49	Sat Sep 30 15:25:16 2017
+++ src/sbin/resize_ffs/resize_ffs.c	Sat Sep 30 18:32:52 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.49 2017/09/30 15:25:16 riastradh Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.50 2017/09/30 18:32:52 kre Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.49 2017/09/30 15:25:16 riastradh Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.50 2017/09/30 18:32:52 kre Exp $");
 
 #include 
 #include 
@@ -564,14 +564,16 @@ initcg(int cgn)
 	 * below for the post-inode data area, is that the pre-sb data
 	 * area always starts at 0, and thus is block-aligned, and
 	 * always ends at the sb, which is block-aligned.) */
-	if ((newsb->fs_old_flags & FS_FLAGS_UPDATED) == 0)
+	if ((newsb->fs_old_flags & FS_FLAGS_UPDATED) == 0) {
 		int64_t di;
+
 		for (di = 0; di < dlow; di += newsb->fs_frag) {
 			old_cg_blktot(cg, 0)[old_cbtocylno(newsb, di)]++;
 			old_cg_blks(newsb, cg,
 			old_cbtocylno(newsb, di),
 			0)[old_cbtorpos(newsb, di)]++;
 		}
+	}
 
 	/* Deal with a partial block at the beginning of the post-inode area.
 	 * I'm not convinced this can happen - I think the inodes are always



CVS commit: src/sbin/resize_ffs

2017-09-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep 30 15:25:16 UTC 2017

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Use int64_t for loop index so we don't iterate forever/until trap.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.48 src/sbin/resize_ffs/resize_ffs.c:1.49
--- src/sbin/resize_ffs/resize_ffs.c:1.48	Thu Sep 28 17:07:20 2017
+++ src/sbin/resize_ffs/resize_ffs.c	Sat Sep 30 15:25:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.48 2017/09/28 17:07:20 sborrill Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.49 2017/09/30 15:25:16 riastradh Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.48 2017/09/28 17:07:20 sborrill Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.49 2017/09/30 15:25:16 riastradh Exp $");
 
 #include 
 #include 
@@ -565,11 +565,12 @@ initcg(int cgn)
 	 * area always starts at 0, and thus is block-aligned, and
 	 * always ends at the sb, which is block-aligned.) */
 	if ((newsb->fs_old_flags & FS_FLAGS_UPDATED) == 0)
-		for (i = 0; i < dlow; i += newsb->fs_frag) {
-			old_cg_blktot(cg, 0)[old_cbtocylno(newsb, i)]++;
+		int64_t di;
+		for (di = 0; di < dlow; di += newsb->fs_frag) {
+			old_cg_blktot(cg, 0)[old_cbtocylno(newsb, di)]++;
 			old_cg_blks(newsb, cg,
-			old_cbtocylno(newsb, i),
-			0)[old_cbtorpos(newsb, i)]++;
+			old_cbtocylno(newsb, di),
+			0)[old_cbtorpos(newsb, di)]++;
 		}
 
 	/* Deal with a partial block at the beginning of the post-inode area.



CVS commit: src/sbin/resize_ffs

2017-09-28 Thread Stephen Borrill
Module Name:src
Committed By:   sborrill
Date:   Thu Sep 28 17:07:20 UTC 2017

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@

For example:

# df /data
Filesystem1K-blocks   Used  Avail %Cap Mounted on
/dev/ccd0d   -19974939099004 -19982708701532 -737868756431824584   0% /data

# dumpfs -s /dev/rccd0d
file system: /dev/rccd0d
format  FFSv2
endian  little-endian
location 65536  (-b 128)
magic   19540119timeThu Sep 28 13:18:10 2017
superblock location 65536   id  [ 595fa4a5 3363fe37 ]
cylgrp  dynamic inodes  FFSv2   sblock  FFSv2   fslevel 5
nbfree  242773148   ndir211185  nifree  650798800   nffree
215448
ncg 13933   size2647654400  blocks  -4993734774751
bsize   32768   shift   15  mask0x8000
fsize   4096shift   12  mask0xf000
frag8   shift   3   fsbtodb 3
bpg 23754   fpg 190032  ipg 46848
minfree 5%  optim   timemaxcontig 2 maxbpg  4096
symlinklen 120  contigsumsize 2
maxfilesize 0x000800800805
nindir  4096inopb   128
avgfilesize 16384   avgfpdir 64
sblkno  24  cblkno  32  iblkno  40  dblkno  2968
sbsize  4096cgsize  32768
csaddr  35792   cssize  225280
cgrotor 0   fmod0   ronly   0   clean   0x01
wapbl version 0x1   location 2  flags 0x0
wapbl loc0 6354693888   loc1 131072 loc2 512loc3 3
flags   none
fsmnt   /data
volname swuid   0


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.47 src/sbin/resize_ffs/resize_ffs.c:1.48
--- src/sbin/resize_ffs/resize_ffs.c:1.47	Wed Aug 24 07:44:05 2016
+++ src/sbin/resize_ffs/resize_ffs.c	Thu Sep 28 17:07:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.47 2016/08/24 07:44:05 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.48 2017/09/28 17:07:20 sborrill Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.47 2016/08/24 07:44:05 dholland Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.48 2017/09/28 17:07:20 sborrill Exp $");
 
 #include 
 #include 
@@ -462,10 +462,10 @@ static void
 initcg(int cgn)
 {
 	struct cg *cg;		/* The in-core cg, of course */
-	int base;		/* Disk address of cg base */
-	int dlow;		/* Size of pre-cg data area */
-	int dhigh;		/* Offset of post-inode data area, from base */
-	int dmax;		/* Offset of end of post-inode data area */
+	int64_t base;		/* Disk address of cg base */
+	int64_t dlow;		/* Size of pre-cg data area */
+	int64_t dhigh;		/* Offset of post-inode data area, from base */
+	int64_t dmax;		/* Offset of end of post-inode data area */
 	int i;			/* Generic loop index */
 	int n;			/* Generic count */
 	int start;		/* start of cg maps */
@@ -896,10 +896,10 @@ recompute_fs_dsize(void)
 
 	newsb->fs_dsize = 0;
 	for (i = 0; i < newsb->fs_ncg; i++) {
-		int dlow;	/* size of before-sb data area */
-		int dhigh;	/* offset of post-inode data area */
-		int dmax;	/* total size of cg */
-		int base;	/* base of cg, since cgsblock() etc add it in */
+		int64_t dlow;	/* size of before-sb data area */
+		int64_t dhigh;	/* offset of post-inode data area */
+		int64_t dmax;	/* total size of cg */
+		int64_t base;	/* base of cg, since cgsblock() etc add it in */
 		base = cgbase(newsb, i);
 		dlow = cgsblock(newsb, i) - base;
 		dhigh = cgdmin(newsb, i) - base;
@@ -1365,7 +1365,7 @@ fragmove(struct cg * cg, int base, unsig
 static void
 evict_data(struct cg * cg, unsigned int minfrag, int nfrag)
 {
-	int base;	/* base of cg (in frags from beginning of fs) */
+	int64_t base;	/* base of cg (in frags from beginning of fs) */
 
 	base = cgbase(oldsb, cg->cg_cgx);
 	/* Does the boundary fall in the middle of a block?  To avoid
@@ -1781,10 +1781,10 @@ shrink(void)
 	csum_fixup();
 	/* Evict data from any cgs being wholly eliminated */
 	for (i = newsb->fs_ncg; i < oldsb->fs_ncg; i++) {
-		int base;
-		int dlow;
-		int dhigh;
-		int dmax;
+		int64_t base;
+		int64_t dlow;
+		int64_t dhigh;
+		int64_t dmax;
 		base = cgbase(oldsb, i);
 		dlow = cgsblock(oldsb, i) - base;
 		dhigh = cgdmin(oldsb, i) - base;



CVS commit: src/sbin/resize_ffs

2016-09-11 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Mon Sep 12 05:47:21 UTC 2016

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
Replace contractions.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.16 src/sbin/resize_ffs/resize_ffs.8:1.17
--- src/sbin/resize_ffs/resize_ffs.8:1.16	Mon Apr  6 22:44:04 2015
+++ src/sbin/resize_ffs/resize_ffs.8	Mon Sep 12 05:47:21 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: resize_ffs.8,v 1.16 2015/04/06 22:44:04 jmcneill Exp $
+.\" $NetBSD: resize_ffs.8,v 1.17 2016/09/12 05:47:21 sevan Exp $
 .\"
 .\" As its sole author, I explicitly place this man page in the public
 .\" domain.  Anyone may use it in any way for any purpose (though I would
@@ -38,7 +38,7 @@ assumes this.
 has to copy anything that currently resides in the space being shrunk
 away; there must be enough space free on the file system for this to
 succeed.
-If there isn't,
+If there is not,
 .Nm
 will complain and exit; when this happens, it attempts to always leave
 the file system in a consistent state, but it is probably a good idea to
@@ -90,7 +90,7 @@ with,
 .Nm
 may misbehave, anything from dumping core to completely curdling the
 data.
-It's probably wise to
+It is probably wise to
 .Xr fsck 8
 the file system before and after, just to be safe.
 You should be aware that just because
@@ -143,4 +143,4 @@ when the new size is extremely close to 
 Has no intelligence whatever when it comes to allocating blocks to copy
 data into when shrinking.
 .Pp
-Doesn't currently support shrinking FFSv2 file systems.
+Does not currently support shrinking FFSv2 file systems.



CVS commit: src/sbin/resize_ffs

2016-08-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Aug 24 07:44:05 UTC 2016

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Fix handling of ffsv2 inode initialization. Retires PR 51116.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.46 src/sbin/resize_ffs/resize_ffs.c:1.47
--- src/sbin/resize_ffs/resize_ffs.c:1.46	Thu Mar 17 01:41:54 2016
+++ src/sbin/resize_ffs/resize_ffs.c	Wed Aug 24 07:44:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.46 2016/03/17 01:41:54 christos Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.47 2016/08/24 07:44:05 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.46 2016/03/17 01:41:54 christos Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.47 2016/08/24 07:44:05 dholland Exp $");
 
 #include 
 #include 
@@ -105,7 +105,8 @@ union dinode {
 	} while (0)
 
 /* a cg's worth of brand new squeaky-clean inodes */
-static struct ufs1_dinode *zinodes;
+static struct ufs1_dinode *zinodes1;
+static struct ufs2_dinode *zinodes2;
 
 /* pointers to the in-core cgs, read off disk and possibly modified */
 static struct cg **cgs;
@@ -615,10 +616,15 @@ initcg(int cgn)
 	newsb->fs_cstotal.cs_nffree += cg->cg_cs.cs_nffree;
 	newsb->fs_cstotal.cs_nbfree += cg->cg_cs.cs_nbfree;
 	newsb->fs_cstotal.cs_nifree += cg->cg_cs.cs_nifree;
-	if (is_ufs2 == 0)
+	if (is_ufs2) {
+		/* Write out the cleared inodes. */
+		writeat(FFS_FSBTODB(newsb, cgimin(newsb, cgn)), zinodes2,
+		cg->cg_initediblk * sizeof(*zinodes2));
+	} else {
 		/* Write out the cleared inodes. */
-		writeat(FFS_FSBTODB(newsb, cgimin(newsb, cgn)), zinodes,
-		newsb->fs_ipg * sizeof(*zinodes));
+		writeat(FFS_FSBTODB(newsb, cgimin(newsb, cgn)), zinodes1,
+		newsb->fs_ipg * sizeof(*zinodes1));
+	}
 	/* Dirty the cg. */
 	cgflags[cgn] |= CGF_DIRTY;
 }
@@ -993,8 +999,15 @@ grow(void)
 	/* Update the timestamp. */
 	newsb->fs_time = timestamp();
 	/* Allocate and clear the new-inode area, in case we add any cgs. */
-	zinodes = alloconce(newsb->fs_ipg * sizeof(*zinodes), "zeroed inodes");
-	memset(zinodes, 0, newsb->fs_ipg * sizeof(*zinodes));
+	if (is_ufs2) {
+		zinodes2 = alloconce(newsb->fs_ipg * sizeof(*zinodes2),
+			"zeroed inodes");
+		memset(zinodes2, 0, newsb->fs_ipg * sizeof(*zinodes2));
+	} else {
+		zinodes1 = alloconce(newsb->fs_ipg * sizeof(*zinodes1),
+			"zeroed inodes");
+		memset(zinodes1, 0, newsb->fs_ipg * sizeof(*zinodes1));
+	}
 	
 	/* Check that the new last sector (frag, actually) is writable.  Since
 	 * it's at least one frag larger than it used to be, we know we aren't



CVS commit: src/sbin/resize_ffs

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 17 00:54:53 UTC 2016

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Appease gcc-5 from phone@


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.44 src/sbin/resize_ffs/resize_ffs.c:1.45
--- src/sbin/resize_ffs/resize_ffs.c:1.44	Mon Apr  6 18:44:04 2015
+++ src/sbin/resize_ffs/resize_ffs.c	Wed Mar 16 20:54:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.44 2015/04/06 22:44:04 jmcneill Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.45 2016/03/17 00:54:53 christos Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.44 2015/04/06 22:44:04 jmcneill Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.45 2016/03/17 00:54:53 christos Exp $");
 
 #include 
 #include 
@@ -1262,18 +1262,24 @@ loadinodes(void)
 			if (is_ufs2) {
 if (needswap) {
 	ffs_dinode2_swap(&(dp2[i]), &(dp2[i]));
-	for (j = 0; j < UFS_NDADDR + UFS_NIADDR; j++)
+	for (j = 0; j < UFS_NDADDR; j++)
 		dp2[i].di_db[j] =
 		bswap32(dp2[i].di_db[j]);
+	for (j = 0; j < UFS_NIADDR; j++)
+		dp2[i].di_ib[j] =
+		bswap32(dp2[i].di_ib[j]);
 }
 memcpy([ino].dp2, [i],
 sizeof(inodes[ino].dp2));
 			} else {
 if (needswap) {
 	ffs_dinode1_swap(&(dp1[i]), &(dp1[i]));
-	for (j = 0; j < UFS_NDADDR + UFS_NIADDR; j++)
+	for (j = 0; j < UFS_NIADDR; j++)
 		dp1[i].di_db[j] =
 		bswap32(dp1[i].di_db[j]);
+	for (j = 0; j < UFS_NIADDR; j++)
+		dp1[i].di_ib[j] =
+		bswap32(dp1[i].di_ib[j]);
 }
 memcpy([ino].dp1, [i],
 sizeof(inodes[ino].dp1));
@@ -1555,11 +1561,10 @@ inomove_init(void)
 static void
 flush_inodes(void)
 {
-	int i, j, k, na, ni, m;
+	int i, j, k, ni, m;
 	struct ufs1_dinode *dp1 = NULL;
 	struct ufs2_dinode *dp2 = NULL;
 
-	na = UFS_NDADDR + UFS_NIADDR;
 	ni = newsb->fs_ipg * newsb->fs_ncg;
 	m = FFS_INOPB(newsb) - 1;
 	for (i = 0; i < ni; i++) {
@@ -1575,33 +1580,39 @@ flush_inodes(void)
 		dp1 = (struct ufs1_dinode *)ibuf;
 
 	for (i = 0; i < ni; i += m) {
-		if (iflags[i] & IF_BDIRTY) {
-			if (is_ufs2)
-for (j = 0; j < m; j++) {
-	dp2[j] = inodes[i + j].dp2;
-	if (needswap) {
-		for (k = 0; k < na; k++)
-			dp2[j].di_db[k]=
-			bswap32(dp2[j].di_db[k]);
-		ffs_dinode2_swap([j],
-		[j]);
-	}
+		if ((iflags[i] & IF_BDIRTY) == 0)
+			continue;
+		if (is_ufs2)
+			for (j = 0; j < m; j++) {
+dp2[j] = inodes[i + j].dp2;
+if (needswap) {
+	for (k = 0; k < UFS_NDADDR; k++)
+		dp2[j].di_db[k] =
+		bswap32(dp2[j].di_db[k]);
+	for (k = 0; k < UFS_NIADDR; k++)
+		dp2[j].di_ib[k] =
+		bswap32(dp2[j].di_ib[k]);
+	ffs_dinode2_swap([j],
+	[j]);
 }
-			else
-for (j = 0; j < m; j++) {
-	dp1[j] = inodes[i + j].dp1;
-	if (needswap) {
-		for (k = 0; k < na; k++)
-			dp1[j].di_db[k]=
-			bswap32(dp1[j].di_db[k]);
-		ffs_dinode1_swap([j],
-		[j]);
-	}
+			}
+		else
+			for (j = 0; j < m; j++) {
+dp1[j] = inodes[i + j].dp1;
+if (needswap) {
+	for (k = 0; k < UFS_NDADDR; k++)
+		dp1[j].di_db[k]=
+		bswap32(dp1[j].di_db[k]);
+	for (k = 0; k < UFS_NIADDR; k++)
+		dp1[j].di_ib[k]=
+		bswap32(dp1[j].di_ib[k]);
+	ffs_dinode1_swap([j],
+	[j]);
 }
+			}
 
-			writeat(FFS_FSBTODB(newsb, ino_to_fsba(newsb, i)),
-			ibuf, newsb->fs_bsize);
-		}
+		writeat(FFS_FSBTODB(newsb, ino_to_fsba(newsb, i)),
+		ibuf, newsb->fs_bsize);
 	}
 }
 /*



CVS commit: src/sbin/resize_ffs

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 17 01:41:54 UTC 2016

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
fix pasto


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.45 src/sbin/resize_ffs/resize_ffs.c:1.46
--- src/sbin/resize_ffs/resize_ffs.c:1.45	Wed Mar 16 20:54:53 2016
+++ src/sbin/resize_ffs/resize_ffs.c	Wed Mar 16 21:41:54 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.45 2016/03/17 00:54:53 christos Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.46 2016/03/17 01:41:54 christos Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: resize_ffs.c,v 1.45 2016/03/17 00:54:53 christos Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.46 2016/03/17 01:41:54 christos Exp $");
 
 #include 
 #include 
@@ -1274,7 +1274,7 @@ loadinodes(void)
 			} else {
 if (needswap) {
 	ffs_dinode1_swap(&(dp1[i]), &(dp1[i]));
-	for (j = 0; j < UFS_NIADDR; j++)
+	for (j = 0; j < UFS_NDADDR; j++)
 		dp1[i].di_db[j] =
 		bswap32(dp1[i].di_db[j]);
 	for (j = 0; j < UFS_NIADDR; j++)



CVS commit: src/sbin/resize_ffs

2015-04-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Apr  6 22:44:04 UTC 2015

Modified Files:
src/sbin/resize_ffs: Makefile resize_ffs.8 resize_ffs.c

Log Message:
if the -p flag is specified, display a progress bar while growing the 
file-system


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sbin/resize_ffs/Makefile
cvs rdiff -u -r1.15 -r1.16 src/sbin/resize_ffs/resize_ffs.8
cvs rdiff -u -r1.43 -r1.44 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/Makefile
diff -u src/sbin/resize_ffs/Makefile:1.4 src/sbin/resize_ffs/Makefile:1.5
--- src/sbin/resize_ffs/Makefile:1.4	Mon Aug 15 02:19:50 2011
+++ src/sbin/resize_ffs/Makefile	Mon Apr  6 22:44:04 2015
@@ -1,11 +1,14 @@
-#	$NetBSD: Makefile,v 1.4 2011/08/15 02:19:50 dholland Exp $
+#	$NetBSD: Makefile,v 1.5 2015/04/06 22:44:04 jmcneill Exp $
 
 .include bsd.own.mk
 
 PROG=resize_ffs
 MAN=resize_ffs.8
-SRCS=resize_ffs.c ffs_bswap.c
+SRCS=resize_ffs.c ffs_bswap.c progress.c
+
+CPPFLAGS+=-I${NETBSDSRCDIR}/sbin/fsck
 
 .PATH: ${NETBSDSRCDIR}/sys/ufs/ffs
+.PATH: ${NETBSDSRCDIR}/sbin/fsck
 
 .include bsd.prog.mk

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.15 src/sbin/resize_ffs/resize_ffs.8:1.16
--- src/sbin/resize_ffs/resize_ffs.8:1.15	Sun Mar 29 19:42:15 2015
+++ src/sbin/resize_ffs/resize_ffs.8	Mon Apr  6 22:44:04 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.15 2015/03/29 19:42:15 wiz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.16 2015/04/06 22:44:04 jmcneill Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -9,7 +9,7 @@
 .\  X  Against HTML   mo...@rodents.montreal.qc.ca
 .\ / \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
 .\
-.Dd January 4, 2011
+.Dd April 6, 2015
 .Dt RESIZE_FFS 8
 .Os
 .Sh NAME
@@ -17,7 +17,7 @@
 .Nd resize a file system on disk or in a file
 .Sh SYNOPSIS
 .Nm
-.Op Fl cvy
+.Op Fl cpvy
 .Op Fl s Ar size
 .Ar special
 .Sh DESCRIPTION
@@ -58,6 +58,8 @@ The options are as follows:
 .It Fl c
 Check to see if the new size would change the file system.
 No changes will be made to the file system.
+.It Fl p
+Display a progress meter during the resize process.
 .It Fl s
 Specify the file system size to which the file system should be
 resized.

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.43 src/sbin/resize_ffs/resize_ffs.c:1.44
--- src/sbin/resize_ffs/resize_ffs.c:1.43	Mon Apr  6 13:33:42 2015
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Apr  6 22:44:04 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.43 2015/04/06 13:33:42 mlelstv Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.44 2015/04/06 22:44:04 jmcneill Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.43 2015/04/06 13:33:42 mlelstv Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.44 2015/04/06 22:44:04 jmcneill Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -59,12 +59,17 @@ __RCSID($NetBSD: resize_ffs.c,v 1.43 20
 #include strings.h
 #include unistd.h
 
+#include progress.h
+
 /* new size of file system, in sectors */
 static int64_t newsize;
 
 /* fd open onto disk device or file */
 static int fd;
 
+/* disk device or file path */
+char *special;
+
 /* must we break up big I/O operations - see checksmallio() */
 static int smallio;
 
@@ -153,6 +158,7 @@ static unsigned char *iflags;
 int is_ufs2 = 0;
 int needswap = 0;
 int verbose = 0;
+int progress = 0;
 
 static void usage(void) __dead;
 
@@ -1015,6 +1021,8 @@ grow(void)
 cgs);
 		for (i = oldsb-fs_ncg; i  newsb-fs_ncg; i++) {
 			cgs[i] = (struct cg *) cgp;
+			progress_bar(special, grow cg,
+			i - oldsb-fs_ncg, newsb-fs_ncg - oldsb-fs_ncg);
 			initcg(i);
 			cgp += cgblksz;
 		}
@@ -1043,6 +1051,8 @@ grow(void)
 	csum_fixup();
 	/* Make fs_dsize match the new reality. */
 	recompute_fs_dsize();
+
+	progress_done();
 }
 /*
  * Call (*fn)() for each inode, passing the inode and its inumber.  The
@@ -1990,6 +2000,8 @@ flush_cgs(void)
 	int i;
 
 	for (i = 0; i  newsb-fs_ncg; i++) {
+		progress_bar(special, flush cg,
+		i, newsb-fs_ncg - 1);
 		if (cgflags[i]  CGF_BLKMAPS) {
 			rescan_blkmaps(i);
 		}
@@ -2009,6 +2021,8 @@ flush_cgs(void)
 	if (needswap)
 		ffs_csum_swap(csums,csums,newsb-fs_cssize);
 	writeat(FFS_FSBTODB(newsb, newsb-fs_csaddr), csums, newsb-fs_cssize);
+
+	progress_done();
 }
 /*
  * Write the superblock, both to the main superblock and to each cg's
@@ -2038,8 +2052,12 @@ write_sbs(void)
 		ffs_sb_swap(newsb,newsb);
 	writeat(where /  DEV_BSIZE, newsb, SBLOCKSIZE);
 	for (i = 0; i  oldsb-fs_ncg; i++) {
+		

CVS commit: src/sbin/resize_ffs

2015-04-06 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Apr  6 12:38:21 UTC 2015

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.41 src/sbin/resize_ffs/resize_ffs.c:1.42
--- src/sbin/resize_ffs/resize_ffs.c:1.41	Sun Mar 29 19:33:55 2015
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Apr  6 12:38:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.41 2015/03/29 19:33:55 chopps Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.42 2015/04/06 12:38:21 mlelstv Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.41 2015/03/29 19:33:55 chopps Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.42 2015/04/06 12:38:21 mlelstv Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -959,9 +959,13 @@ grow(void)
 	 * minimal, at most the pre-sb data area. */
 	if (cgdmin(newsb, newsb-fs_ncg - 1)  newsb-fs_size) {
 		newsb-fs_ncg--;
-		newsb-fs_old_ncyl = newsb-fs_ncg * newsb-fs_old_cpg;
-		newsb-fs_size = (newsb-fs_old_ncyl * newsb-fs_old_spc)
-		/ NSPF(newsb);
+		if (is_ufs2)
+			newsb-fs_size = newsb-fs_ncg * newsb-fs_fpg;
+		else {
+			newsb-fs_old_ncyl = newsb-fs_ncg * newsb-fs_old_cpg;
+			newsb-fs_size = (newsb-fs_old_ncyl *
+newsb-fs_old_spc) / NSPF(newsb);
+		}
 		printf(Warning: last cylinder group is too small;\n);
 		printf(dropping it.  New size = %lu.\n,
 		(unsigned long int) FFS_FSBTODB(newsb, newsb-fs_size));
@@ -1699,17 +1703,18 @@ shrink(void)
 		newsb-fs_old_spc);
 		newsb-fs_ncg = howmany(newsb-fs_old_ncyl, newsb-fs_old_cpg);
 	}
+
 	/* Does the (new) last cg end before the end of its inode area?  See
 	 * the similar code in grow() for more on this. */
 	if (cgdmin(newsb, newsb-fs_ncg - 1)  newsb-fs_size) {
 		newsb-fs_ncg--;
-		if (is_ufs2 == 0) {
+		if (is_ufs2)
+			newsb-fs_size = newsb-fs_ncg * newsb-fs_fpg;
+		else {
 			newsb-fs_old_ncyl = newsb-fs_ncg * newsb-fs_old_cpg;
 			newsb-fs_size = (newsb-fs_old_ncyl *
 			newsb-fs_old_spc) / NSPF(newsb);
-		} else
-			newsb-fs_size = newsb-fs_ncg * newsb-fs_fpg;
-
+		}
 		printf(Warning: last cylinder group is too small;\n);
 		printf(dropping it.  New size = %lu.\n,
 		(unsigned long int) FFS_FSBTODB(newsb, newsb-fs_size));



CVS commit: src/sbin/resize_ffs

2015-04-06 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Apr  6 13:33:42 UTC 2015

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.42 src/sbin/resize_ffs/resize_ffs.c:1.43
--- src/sbin/resize_ffs/resize_ffs.c:1.42	Mon Apr  6 12:38:21 2015
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Apr  6 13:33:42 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.42 2015/04/06 12:38:21 mlelstv Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.43 2015/04/06 13:33:42 mlelstv Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.42 2015/04/06 12:38:21 mlelstv Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.43 2015/04/06 13:33:42 mlelstv Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -914,35 +914,17 @@ timestamp(void)
 	time(t);
 	return (t);
 }
+
 /*
- * Grow the file system.
+ * Calculate new filesystem geometry
+ *  return 0 if geometry actually changed
  */
-static void
-grow(void)
+static int
+makegeometry(int chatter)
 {
-	int i;
 
-	/* Update the timestamp. */
-	newsb-fs_time = timestamp();
-	/* Allocate and clear the new-inode area, in case we add any cgs. */
-	zinodes = alloconce(newsb-fs_ipg * sizeof(*zinodes), zeroed inodes);
-	memset(zinodes, 0, newsb-fs_ipg * sizeof(*zinodes));
 	/* Update the size. */
 	newsb-fs_size = FFS_DBTOFSB(newsb, newsize);
-	/* Did we actually not grow?  (This can happen if newsize is less than
-	 * a frag larger than the old size - unlikely, but no excuse to
-	 * misbehave if it happens.) */
-	if (newsb-fs_size == oldsb-fs_size) {
-		printf(New fs size %PRIu64 = old fs size %PRIu64
-		, not growing.\n, newsb-fs_size, oldsb-fs_size);
-		return;
-	}
-	/* Check that the new last sector (frag, actually) is writable.  Since
-	 * it's at least one frag larger than it used to be, we know we aren't
-	 * overwriting anything important by this.  (The choice of sbbuf as
-	 * what to write is irrelevant; it's just something handy that's known
-	 * to be at least one frag in size.) */
-	writeat(FFS_FSBTODB(newsb,newsb-fs_size - 1), sbbuf, newsb-fs_fsize);
 	if (is_ufs2)
 		newsb-fs_ncg = howmany(newsb-fs_size, newsb-fs_fpg);
 	else {
@@ -966,10 +948,55 @@ grow(void)
 			newsb-fs_size = (newsb-fs_old_ncyl *
 newsb-fs_old_spc) / NSPF(newsb);
 		}
-		printf(Warning: last cylinder group is too small;\n);
-		printf(dropping it.  New size = %lu.\n,
-		(unsigned long int) FFS_FSBTODB(newsb, newsb-fs_size));
+		if (chatter || verbose) {
+			printf(Warning: last cylinder group is too small;\n);
+			printf(dropping it.  New size = %lu.\n,
+			(unsigned long int) FFS_FSBTODB(newsb, newsb-fs_size));
+		}
+	}
+
+	/* Did we actually not grow?  (This can happen if newsize is less than
+	 * a frag larger than the old size - unlikely, but no excuse to
+	 * misbehave if it happens.) */
+	if (newsb-fs_size == oldsb-fs_size)
+		return 1;
+
+	return 0;
+}
+
+
+/*
+ * Grow the file system.
+ */
+static void
+grow(void)
+{
+	int i;
+
+	if (makegeometry(1)) {
+		printf(New fs size %PRIu64 = old fs size %PRIu64
+		, not growing.\n, newsb-fs_size, oldsb-fs_size);
+		return;
 	}
+
+	if (verbose) {
+		printf(Growing fs from %PRIu64 blocks to %PRIu64
+		 blocks.\n, oldsb-fs_size, newsb-fs_size);
+	}
+
+	/* Update the timestamp. */
+	newsb-fs_time = timestamp();
+	/* Allocate and clear the new-inode area, in case we add any cgs. */
+	zinodes = alloconce(newsb-fs_ipg * sizeof(*zinodes), zeroed inodes);
+	memset(zinodes, 0, newsb-fs_ipg * sizeof(*zinodes));
+	
+	/* Check that the new last sector (frag, actually) is writable.  Since
+	 * it's at least one frag larger than it used to be, we know we aren't
+	 * overwriting anything important by this.  (The choice of sbbuf as
+	 * what to write is irrelevant; it's just something handy that's known
+	 * to be at least one frag in size.) */
+	writeat(FFS_FSBTODB(newsb,newsb-fs_size - 1), sbbuf, newsb-fs_fsize);
+
 	/* Find out how big the csum area is, and realloc csums if bigger. */
 	newsb-fs_cssize = ffs_fragroundup(newsb,
 	newsb-fs_ncg * sizeof(struct csum));
@@ -1690,39 +1717,28 @@ shrink(void)
 {
 	int i;
 
-	/* Load the inodes off disk - we'll need 'em. */
-	loadinodes();
-	/* Update the timestamp. */
-	newsb-fs_time = timestamp();
-	/* Update the size figures. */
-	newsb-fs_size = FFS_DBTOFSB(newsb, newsize);
-	if (is_ufs2)
-		newsb-fs_ncg = howmany(newsb-fs_size, newsb-fs_fpg);
-	else {
-		newsb-fs_old_ncyl = howmany(newsb-fs_size * NSPF(newsb),
-		

CVS commit: src/sbin/resize_ffs

2015-03-29 Thread Christian E. Hopps
Module Name:src
Committed By:   chopps
Date:   Sun Mar 29 19:33:55 UTC 2015

Modified Files:
src/sbin/resize_ffs: resize_ffs.8 resize_ffs.c

Log Message:
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sbin/resize_ffs/resize_ffs.8
cvs rdiff -u -r1.40 -r1.41 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.13 src/sbin/resize_ffs/resize_ffs.8:1.14
--- src/sbin/resize_ffs/resize_ffs.8:1.13	Sun Aug 28 21:25:11 2011
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Mar 29 19:33:55 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.13 2011/08/28 21:25:11 wiz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.14 2015/03/29 19:33:55 chopps Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -17,7 +17,7 @@
 .Nd resize a file system on disk or in a file
 .Sh SYNOPSIS
 .Nm
-.Op Fl y
+.Op Fl cvy
 .Op Fl s Ar size
 .Ar special
 .Sh DESCRIPTION
@@ -55,6 +55,9 @@ determined from
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl c
+Check to see if the new size would change the file system. No changes
+will be made to the file system.
 .It Fl s
 Specify the file system size to which the file system should be
 resized.
@@ -66,6 +69,8 @@ Mostly used to shrink file systems.
 .It Fl y
 Disable sanity questions made by
 .Nm .
+.It Fl v
+Be more verbose.
 .El
 .Sh WARNING
 .Em Interrupting

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.40 src/sbin/resize_ffs/resize_ffs.c:1.41
--- src/sbin/resize_ffs/resize_ffs.c:1.40	Sat Mar 28 17:25:33 2015
+++ src/sbin/resize_ffs/resize_ffs.c	Sun Mar 29 19:33:55 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.40 2015/03/28 17:25:33 riastradh Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.41 2015/03/29 19:33:55 chopps Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.40 2015/03/28 17:25:33 riastradh Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.41 2015/03/29 19:33:55 chopps Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -152,6 +152,7 @@ static unsigned char *iflags;
 /* global flags */
 int is_ufs2 = 0;
 int needswap = 0;
+int verbose = 0;
 
 static void usage(void) __dead;
 
@@ -2040,7 +2041,7 @@ get_dev_size(char *dev_name)
 		return pp-p_size;
 	}
 	if (fstat(fd, st) != -1  S_ISREG(st.st_mode))
-		return st.st_size;
+		return st.st_size / DEV_BSIZE;
 
 	return 0;
 }
@@ -2052,6 +2053,7 @@ int
 main(int argc, char **argv)
 {
 	int ch;
+	int CheckOnlyFlag;
 	int ExpertFlag;
 	int SFlag;
 	size_t i;
@@ -2062,9 +2064,13 @@ main(int argc, char **argv)
 	newsize = 0;
 	ExpertFlag = 0;
 	SFlag = 0;
+CheckOnlyFlag = 0;
 
-	while ((ch = getopt(argc, argv, s:y)) != -1) {
+	while ((ch = getopt(argc, argv, cs:vy)) != -1) {
 		switch (ch) {
+case 'c':
+			CheckOnlyFlag = 1;
+			break;
 		case 's':
 			SFlag = 1;
 			newsize = strtoll(optarg, NULL, 10);
@@ -2072,6 +2078,9 @@ main(int argc, char **argv)
 usage();
 			}
 			break;
+		case 'v':
+			verbose = 1;
+			break;
 		case 'y':
 			ExpertFlag = 1;
 			break;
@@ -2090,7 +2099,7 @@ main(int argc, char **argv)
 
 	special = *argv;
 
-	if (ExpertFlag == 0) {
+	if (ExpertFlag == 0  CheckOnlyFlag == 0) {
 		printf(It's required to manually run fsck on file system 
 		before you can resize it\n\n
 		 Did you run fsck on your disk (Yes/No) ? );
@@ -2165,6 +2174,25 @@ main(int argc, char **argv)
 	 * just once, so being generous is cheap. */
 	memcpy(newsb, oldsb, SBLOCKSIZE);
 	loadcgs();
+
+if (CheckOnlyFlag) {
+		/* Check to see if the newsize would change the file system. */
+		if (FFS_DBTOFSB(oldsb, newsize) == oldsb-fs_size) {
+			if (verbose) {
+printf(Wouldn't change: already % PRId64
+ blocks\n, newsize);
+			}
+			exit(1);
+		}
+		if (verbose) {
+			printf(Would change: newsize: % PRId64  oldsize: %
+			PRId64  fsdb: % PRId64 \n, FFS_DBTOFSB(oldsb, newsize),
+			(int64_t)oldsb-fs_size,
+			(int64_t)oldsb-fs_fsbtodb);
+		}
+		exit(0);
+}
+
 	if (newsize  FFS_FSBTODB(oldsb, oldsb-fs_size)) {
 		grow();
 	} else if (newsize  FFS_FSBTODB(oldsb, oldsb-fs_size)) {
@@ -2183,7 +2211,7 @@ static void
 usage(void)
 {
 
-	(void)fprintf(stderr, usage: %s [-y] [-s size] special\n,
+	(void)fprintf(stderr, usage: %s [-cvy] [-s size] special\n,
 	getprogname());
 	exit(EXIT_FAILURE);
 }



CVS commit: src/sbin/resize_ffs

2015-03-29 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Mar 29 19:42:15 UTC 2015

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
New sentence, new line. Sort option descriptions.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.14 src/sbin/resize_ffs/resize_ffs.8:1.15
--- src/sbin/resize_ffs/resize_ffs.8:1.14	Sun Mar 29 19:33:55 2015
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Mar 29 19:42:15 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.14 2015/03/29 19:33:55 chopps Exp $
+.\ $NetBSD: resize_ffs.8,v 1.15 2015/03/29 19:42:15 wiz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -56,8 +56,8 @@ determined from
 The options are as follows:
 .Bl -tag -width indent
 .It Fl c
-Check to see if the new size would change the file system. No changes
-will be made to the file system.
+Check to see if the new size would change the file system.
+No changes will be made to the file system.
 .It Fl s
 Specify the file system size to which the file system should be
 resized.
@@ -66,11 +66,11 @@ It will not work correctly for file syst
 To see the
 exact value, have a look at the disk specification or the disklabel.
 Mostly used to shrink file systems.
+.It Fl v
+Be more verbose.
 .It Fl y
 Disable sanity questions made by
 .Nm .
-.It Fl v
-Be more verbose.
 .El
 .Sh WARNING
 .Em Interrupting



CVS commit: src/sbin/resize_ffs

2015-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 28 17:22:46 UTC 2015

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Make get_dev_size work on regular files too.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.38 src/sbin/resize_ffs/resize_ffs.c:1.39
--- src/sbin/resize_ffs/resize_ffs.c:1.38	Sun Jun 23 22:03:34 2013
+++ src/sbin/resize_ffs/resize_ffs.c	Sat Mar 28 17:22:46 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.38 2013/06/23 22:03:34 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.39 2015/03/28 17:22:46 riastradh Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.38 2013/06/23 22:03:34 dholland Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.39 2015/03/28 17:22:46 riastradh Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -2026,22 +2026,23 @@ get_dev_size(char *dev_name)
 	struct dkwedge_info dkw;
 	struct partition *pp;
 	struct disklabel lp;
+	struct stat st;
 	size_t ptn;
 
 	/* Get info about partition/wedge */
-	if (ioctl(fd, DIOCGWEDGEINFO, dkw) == -1) {
-		if (ioctl(fd, DIOCGDINFO, lp) == -1)
-			return 0;
-
+	if (ioctl(fd, DIOCGWEDGEINFO, dkw) == 0)
+		return dkw.dkw_size;
+	if (ioctl(fd, DIOCGDINFO, lp) == 0) {
 		ptn = strchr(dev_name, '\0')[-1] - 'a';
 		if (ptn = lp.d_npartitions)
 			return 0;
-
 		pp = lp.d_partitions[ptn];
 		return pp-p_size;
 	}
+	if (fstat(fd, st) == 0  S_ISREG(st.st_mode))
+		return st.st_size;
 
-	return dkw.dkw_size;
+	return 0;
 }
 
 /*



CVS commit: src/sbin/resize_ffs

2015-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 28 17:25:34 UTC 2015

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Use `!= -1' instead of `== 0' out of paranoia.


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

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.39 src/sbin/resize_ffs/resize_ffs.c:1.40
--- src/sbin/resize_ffs/resize_ffs.c:1.39	Sat Mar 28 17:22:46 2015
+++ src/sbin/resize_ffs/resize_ffs.c	Sat Mar 28 17:25:33 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.39 2015/03/28 17:22:46 riastradh Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.40 2015/03/28 17:25:33 riastradh Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.39 2015/03/28 17:22:46 riastradh Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.40 2015/03/28 17:25:33 riastradh Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -2030,16 +2030,16 @@ get_dev_size(char *dev_name)
 	size_t ptn;
 
 	/* Get info about partition/wedge */
-	if (ioctl(fd, DIOCGWEDGEINFO, dkw) == 0)
+	if (ioctl(fd, DIOCGWEDGEINFO, dkw) != -1)
 		return dkw.dkw_size;
-	if (ioctl(fd, DIOCGDINFO, lp) == 0) {
+	if (ioctl(fd, DIOCGDINFO, lp) != -1) {
 		ptn = strchr(dev_name, '\0')[-1] - 'a';
 		if (ptn = lp.d_npartitions)
 			return 0;
 		pp = lp.d_partitions[ptn];
 		return pp-p_size;
 	}
-	if (fstat(fd, st) == 0  S_ISREG(st.st_mode))
+	if (fstat(fd, st) != -1  S_ISREG(st.st_mode))
 		return st.st_size;
 
 	return 0;



CVS commit: src/sbin/resize_ffs

2013-09-09 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Mon Sep  9 19:37:17 UTC 2013

Modified Files:
src/sbin/resize_ffs: TODO

Log Message:
Add an item to the list (SIGINFO support).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sbin/resize_ffs/TODO

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

Modified files:

Index: src/sbin/resize_ffs/TODO
diff -u src/sbin/resize_ffs/TODO:1.8 src/sbin/resize_ffs/TODO:1.9
--- src/sbin/resize_ffs/TODO:1.8	Wed Jan  5 02:18:15 2011
+++ src/sbin/resize_ffs/TODO	Mon Sep  9 19:37:17 2013
@@ -4,3 +4,4 @@ resize_ffs(8) TODO list
 * Support shrinking UFS2 file systems
 * Make the output a bit more verbose, similar to newfs(8)
 * Expand the testing done in src/tests/sbin/resize_ffs
+* SIGINFO support



CVS commit: src/sbin/resize_ffs

2012-04-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr 20 13:20:39 UTC 2012

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
fix cast in local macro


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.32 src/sbin/resize_ffs/resize_ffs.c:1.33
--- src/sbin/resize_ffs/resize_ffs.c:1.32	Sat Aug 27 12:34:57 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Fri Apr 20 09:20:39 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.32 2011/08/27 16:34:57 christos Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.33 2012/04/20 13:20:39 christos Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.32 2011/08/27 16:34:57 christos Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.33 2012/04/20 13:20:39 christos Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -138,7 +138,7 @@ static unsigned char *iflags;
 
 /* resize_ffs works directly on dinodes, adapt blksize() */
 #define dblksize(fs, dip, lbn, filesize) \
-	(((lbn) = NDADDR || (filesize) = lblktosize(fs, (lbn) + 1)) \
+	(((lbn) = NDADDR || (uint64_t)(filesize) = lblktosize(fs, (lbn) + 1)) \
 	? (fs)-fs_bsize		   \
 	: (fragroundup(fs, blkoff(fs, (filesize)
 



CVS commit: src/sbin/resize_ffs

2011-08-28 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 28 17:15:17 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.11 src/sbin/resize_ffs/resize_ffs.8:1.12
--- src/sbin/resize_ffs/resize_ffs.8:1.11	Sat Aug 27 16:34:57 2011
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Aug 28 17:15:16 2011
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.11 2011/08/27 16:34:57 christos Exp $
+.\ $NetBSD: resize_ffs.8,v 1.12 2011/08/28 17:15:16 wiz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -59,7 +59,8 @@
 .It Fl s
 Specify the file system size to which the file system should be
 resized.
-The size is given as the count of disk sectors, usually 512 bytes. To see the 
+The size is given as the count of disk sectors, usually 512 bytes.
+To see the
 exact value, have a look at the disk specification or the disklabel.
 Mostly used to shrink file systems.
 .It Fl y



CVS commit: src/sbin/resize_ffs

2011-08-28 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 28 21:25:11 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
Move a sentence to where it makes more sense.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.12 src/sbin/resize_ffs/resize_ffs.8:1.13
--- src/sbin/resize_ffs/resize_ffs.8:1.12	Sun Aug 28 17:15:16 2011
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Aug 28 21:25:11 2011
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.12 2011/08/28 17:15:16 wiz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.13 2011/08/28 21:25:11 wiz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -34,7 +34,6 @@
 When shrinking,
 .Nm
 assumes this.
-It will not work correctly for file systems with other sector sizes.)
 .Nm
 has to copy anything that currently resides in the space being shrunk
 away; there must be enough space free on the file system for this to
@@ -60,6 +59,7 @@
 Specify the file system size to which the file system should be
 resized.
 The size is given as the count of disk sectors, usually 512 bytes.
+It will not work correctly for file systems with other sector sizes.
 To see the
 exact value, have a look at the disk specification or the disklabel.
 Mostly used to shrink file systems.



CVS commit: src/sbin/resize_ffs

2011-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 27 16:34:57 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.8 resize_ffs.c

Log Message:
PR/45301: Julian Fagir: make clear that the unit is sectors and fix a typo.
While there, use errx, and sizeof(*var) instead of sizeof(type)


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sbin/resize_ffs/resize_ffs.8
cvs rdiff -u -r1.31 -r1.32 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.10 src/sbin/resize_ffs/resize_ffs.8:1.11
--- src/sbin/resize_ffs/resize_ffs.8:1.10	Tue Jan  4 21:18:15 2011
+++ src/sbin/resize_ffs/resize_ffs.8	Sat Aug 27 12:34:57 2011
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.10 2011/01/05 02:18:15 riz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.11 2011/08/27 16:34:57 christos Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -24,8 +24,7 @@
 .Nm
 resizes a file system.
 .Ar special
-is the name of the raw disk device or file where the file system resides;
-(Sectors are almost always 512 bytes, and
+is the name of the raw disk device or file where the file system resides.
 .Nm
 can both grow and shrink file systems.
 When growing, the disk device
@@ -60,6 +59,8 @@
 .It Fl s
 Specify the file system size to which the file system should be
 resized.
+The size is given as the count of disk sectors, usually 512 bytes. To see the 
+exact value, have a look at the disk specification or the disklabel.
 Mostly used to shrink file systems.
 .It Fl y
 Disable sanity questions made by

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.31 src/sbin/resize_ffs/resize_ffs.c:1.32
--- src/sbin/resize_ffs/resize_ffs.c:1.31	Sun Aug 14 22:22:46 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Sat Aug 27 12:34:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.31 2011/08/15 02:22:46 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.32 2011/08/27 16:34:57 christos Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.31 2011/08/15 02:22:46 dholland Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.32 2011/08/27 16:34:57 christos Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -322,7 +322,7 @@
 	char *cgp;
 
 	cgblksz = roundup(oldsb-fs_cgsize, oldsb-fs_fsize);
-	cgs = nfmalloc(oldsb-fs_ncg * sizeof(struct cg *), cg pointers);
+	cgs = nfmalloc(oldsb-fs_ncg * sizeof(*cgs), cg pointers);
 	cgp = alloconce(oldsb-fs_ncg * cgblksz, cgs);
 	cgflags = nfmalloc(oldsb-fs_ncg, cg flags);
 	csums = nfmalloc(oldsb-fs_cssize, cg summary);
@@ -611,7 +611,7 @@
 	if (is_ufs2 == 0)
 		/* Write out the cleared inodes. */
 		writeat(fsbtodb(newsb, cgimin(newsb, cgn)), zinodes,
-		newsb-fs_ipg * sizeof(struct ufs1_dinode));
+		newsb-fs_ipg * sizeof(*zinodes));
 	/* Dirty the cg. */
 	cgflags[cgn] |= CGF_DIRTY;
 }
@@ -862,10 +862,8 @@
 	 * on disk at this point; the csum info will be written to the
 	 * then-current fs_csaddr as part of the final flush. */
 	newloc = find_freespace(ntot);
-	if (newloc  0) {
-		printf(Sorry, no space available for new csums\n);
-		exit(EXIT_FAILURE);
-	}
+	if (newloc  0)
+		errx(EXIT_FAILURE, Sorry, no space available for new csums);
 	for (i = 0, f = newsb-fs_csaddr, t = newloc; i  ntot; i++, f++, t++) {
 		if (i  nold) {
 			free_frag(f);
@@ -926,16 +924,15 @@
 	/* Update the timestamp. */
 	newsb-fs_time = timestamp();
 	/* Allocate and clear the new-inode area, in case we add any cgs. */
-	zinodes = alloconce(newsb-fs_ipg * sizeof(struct ufs1_dinode),
-zeroed inodes);
-	memset(zinodes, 0, newsb-fs_ipg * sizeof(struct ufs1_dinode));
+	zinodes = alloconce(newsb-fs_ipg * sizeof(*zinodes), zeroed inodes);
+	memset(zinodes, 0, newsb-fs_ipg * sizeof(*zinodes));
 	/* Update the size. */
 	newsb-fs_size = dbtofsb(newsb, newsize);
 	/* Did we actually not grow?  (This can happen if newsize is less than
 	 * a frag larger than the old size - unlikely, but no excuse to
 	 * misbehave if it happens.) */
 	if (newsb-fs_size == oldsb-fs_size) {
-		printf(New fs size %PRIu64 = odl fs size %PRIu64
+		printf(New fs size %PRIu64 = old fs size %PRIu64
 		, not growing.\n, newsb-fs_size, oldsb-fs_size);
 		return;
 	}
@@ -977,7 +974,7 @@
 	   cgs. */
 	if (newsb-fs_ncg  oldsb-fs_ncg) {
 		char *cgp;
-		cgs = nfrealloc(cgs, newsb-fs_ncg * sizeof(struct cg *),
+		cgs = nfrealloc(cgs, newsb-fs_ncg * sizeof(*cgs),
 cg pointers);
 		cgflags = nfrealloc(cgflags, newsb-fs_ncg, cg flags);
 		memset(cgflags + oldsb-fs_ncg, 0,
@@ -1228,7 +1225,7 @@
 		

CVS commit: src/sbin/resize_ffs

2011-08-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 15 00:24:19 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Minor KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.25 src/sbin/resize_ffs/resize_ffs.c:1.26
--- src/sbin/resize_ffs/resize_ffs.c:1.25	Wed Jan  5 02:18:15 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Aug 15 00:24:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.25 2011/01/05 02:18:15 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.26 2011/08/15 00:24:19 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -1050,6 +1050,7 @@
 {
 	int sz;
 	int nb;
+
 	if (o = DIP(di,di_size))
 		return (0);
 	sz = dblksize(newsb, di, lblkno(newsb, o));
@@ -1076,6 +1077,7 @@
 	static int32_t *indirblks[3] = {
 		indirblk1[0], indirblk2[0], indirblk3[0]
 	};
+
 	if (lev  0)
 		return (markblk(fn, di, bn, o));
 	if (bn == 0) {
@@ -1144,6 +1146,7 @@
 dblk_callback(union dinode * di, unsigned int inum, void *arg)
 {
 	mark_callback_t fn;
+
 	fn = (mark_callback_t) arg;
 	switch (DIP(di,di_mode)  IFMT) {
 	case IFLNK:
@@ -1190,7 +1193,6 @@
 	struct ufs1_dinode *dp1 = NULL;
 	struct ufs2_dinode *dp2 = NULL;
 	
-
 	/* read inodes one fs block at a time and copy them */
 
 	inodes = alloconce(oldsb-fs_ncg * oldsb-fs_ipg *
@@ -1262,6 +1264,7 @@
 {
 	int i;
 	int run;
+
 	run = 0;
 	for (i = 0; i = n; i++) {
 		if ((i  n)  bit_is_clr(cg_blksfree(cg, 0), start + i)) {
@@ -1298,7 +1301,6 @@
 {
 	int base;	/* base of cg (in frags from beginning of fs) */
 
-
 	base = cgbase(oldsb, cg-cg_cgx);
 	/* Does the boundary fall in the middle of a block?  To avoid
 	 * breaking between frags allocated as consecutive, we always
@@ -1407,6 +1409,7 @@
 movemap_blocks(int32_t * vec, int n)
 {
 	int rv;
+
 	rv = 0;
 	for (; n  0; n--, vec++) {
 		if (blkmove[*vec] != *vec) {
@@ -1420,6 +1423,7 @@
 moveblocks_callback(union dinode * di, unsigned int inum, void *arg)
 {
 	void *dblkptr, *iblkptr; /* XXX */
+
 	switch (DIP(di,di_mode)  IFMT) {
 	case IFLNK:
 		if (DIP(di,di_size)  oldsb-fs_maxsymlinklen) {
@@ -1432,8 +1436,10 @@
 			dblkptr = (di-dp1.di_db[0]);
 			iblkptr = (di-dp1.di_ib[0]);
 		}
-		/* don't || these two calls; we need their
-		 * side-effects */
+		/*
+		 * Don't || these two calls; we need their
+		 * side-effects.
+		 */
 		if (movemap_blocks(dblkptr, NDADDR)) {
 iflags[inum] |= IF_DIRTY;
 			}
@@ -1450,6 +1456,7 @@
 		   int kind)
 {
 	int i;
+
 	if (kind == MDB_INDIR_PRE) {
 		int32_t blk[howmany(MAXBSIZE, sizeof(int32_t))];
 		readat(fsbtodb(oldsb, off), blk[0], oldsb-fs_bsize);



CVS commit: src/sbin/resize_ffs

2011-08-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 15 00:26:16 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Avoid switch-jumping into the middle of an if. Compiler output is unchanged.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.26 src/sbin/resize_ffs/resize_ffs.c:1.27
--- src/sbin/resize_ffs/resize_ffs.c:1.26	Mon Aug 15 00:24:19 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Aug 15 00:26:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.26 2011/08/15 00:24:19 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.27 2011/08/15 00:26:16 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -1426,7 +1426,10 @@
 
 	switch (DIP(di,di_mode)  IFMT) {
 	case IFLNK:
-		if (DIP(di,di_size)  oldsb-fs_maxsymlinklen) {
+		if (DIP(di,di_size) = oldsb-fs_maxsymlinklen) {
+			break;
+		}
+		/* FALLTHROUGH */
 	case IFDIR:
 	case IFREG:
 		if (is_ufs2) {
@@ -1446,7 +1449,6 @@
 		if (movemap_blocks(iblkptr, NIADDR)) {
 iflags[inum] |= IF_DIRTY;
 			}
-		}
 		break;
 	}
 }



CVS commit: src/sbin/resize_ffs

2011-08-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 15 00:27:51 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.27 src/sbin/resize_ffs/resize_ffs.c:1.28
--- src/sbin/resize_ffs/resize_ffs.c:1.27	Mon Aug 15 00:26:16 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Aug 15 00:27:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.27 2011/08/15 00:26:16 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.28 2011/08/15 00:27:50 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -143,7 +143,7 @@
 
 /*
  * Number of disk sectors per block/fragment
- */ 
+ */
 #define NSPB(fs)	(fsbtodb((fs),1)  (fs)-fs_fragshift)
 #define NSPF(fs)	(fsbtodb((fs),1))
 
@@ -493,8 +493,8 @@
 		cg-cg_old_niblk = cg-cg_niblk;
 		cg-cg_niblk = 0;
 		cg-cg_initediblk = 0;
-	
-	
+
+
 		cg-cg_old_ncyl = newsb-fs_old_cpg;
 		/* Update the cg_old_ncyl value for the last cylinder. */
 		if (cgn == newsb-fs_ncg - 1) {
@@ -545,7 +545,7 @@
 	cg-cg_cs.cs_nifree = newsb-fs_ipg;
 	cg-cg_cs.cs_nbfree = dlow / newsb-fs_frag;
 	cg-cg_cs.cs_nffree = 0;
-	
+
 	/* This is the simplest way of doing this; we perhaps could
 	 * compute the correct cg_blktot()[] and cg_blks()[] values
 	 * other ways, but it would be complicated and hardly seems
@@ -554,7 +554,7 @@
 	 * below for the post-inode data area, is that the pre-sb data
 	 * area always starts at 0, and thus is block-aligned, and
 	 * always ends at the sb, which is block-aligned.) */
-	if ((newsb-fs_old_flags  FS_FLAGS_UPDATED) == 0)	
+	if ((newsb-fs_old_flags  FS_FLAGS_UPDATED) == 0)
 		for (i = 0; i  dlow; i += newsb-fs_frag) {
 			old_cg_blktot(cg, 0)[old_cbtocylno(newsb, i)]++;
 			old_cg_blks(newsb, cg,
@@ -951,7 +951,7 @@
 		newsb-fs_old_spc);
 		newsb-fs_ncg = howmany(newsb-fs_old_ncyl, newsb-fs_old_cpg);
 	}
-	
+
 	/* Does the last cg end before the end of its inode area? There is no
 	 * reason why this couldn't be handled, but it would complicate a lot
 	 * of code (in all file system code - fsck, kernel, etc) because of the
@@ -1192,20 +1192,20 @@
 	int imax, ino, i, j;
 	struct ufs1_dinode *dp1 = NULL;
 	struct ufs2_dinode *dp2 = NULL;
-	
+
 	/* read inodes one fs block at a time and copy them */
 
 	inodes = alloconce(oldsb-fs_ncg * oldsb-fs_ipg *
 	sizeof(union dinode), inodes);
 	iflags = alloconce(oldsb-fs_ncg * oldsb-fs_ipg, inode flags);
 	memset(iflags, 0, oldsb-fs_ncg * oldsb-fs_ipg);
-	
+
 	ibuf = nfmalloc(oldsb-fs_bsize,inode block buf);
 	if (is_ufs2)
 		dp2 = (struct ufs2_dinode *)ibuf;
 	else
 		dp1 = (struct ufs1_dinode *)ibuf;
-	
+
 	for (ino = 0,imax = oldsb-fs_ipg * oldsb-fs_ncg; ino  imax; ) {
 		readat(fsbtodb(oldsb, ino_to_fsba(oldsb, ino)), ibuf,
 		oldsb-fs_bsize);
@@ -1444,11 +1444,11 @@
 		 * side-effects.
 		 */
 		if (movemap_blocks(dblkptr, NDADDR)) {
-iflags[inum] |= IF_DIRTY;
-			}
+			iflags[inum] |= IF_DIRTY;
+		}
 		if (movemap_blocks(iblkptr, NIADDR)) {
-iflags[inum] |= IF_DIRTY;
-			}
+			iflags[inum] |= IF_DIRTY;
+		}
 		break;
 	}
 }
@@ -1525,7 +1525,7 @@
 		dp2 = (struct ufs2_dinode *)ibuf;
 	else
 		dp1 = (struct ufs1_dinode *)ibuf;
-	
+
 	for (i = 0; i  ni; i += m) {
 		if (iflags[i]  IF_BDIRTY) {
 			if (is_ufs2)
@@ -1550,7 +1550,7 @@
 		dp1[j]);
 	}
 }
-
+
 			writeat(fsbtodb(newsb, ino_to_fsba(newsb, i)),
 			ibuf, newsb-fs_bsize);
 		}
@@ -1622,7 +1622,7 @@
 #define d ((struct direct *)buf)
 #define s32(x) (needswap?bswap32((x)):(x))
 #define s16(x) (needswap?bswap16((x)):(x))
-	
+
 	rv = 0;
 	while (nb  0) {
 		if (inomove[s32(d-d_ino)] != s32(d-d_ino)) {
@@ -1704,7 +1704,7 @@
 			newsb-fs_old_spc) / NSPF(newsb);
 		} else
 			newsb-fs_size = newsb-fs_ncg * newsb-fs_fpg;
-		
+
 		printf(Warning: last cylinder group is too small;\n);
 		printf(dropping it.  New size = %lu.\n,
 		(unsigned long int) fsbtodb(newsb, newsb-fs_size));
@@ -2027,7 +2027,7 @@
 	struct partition *pp;
 	struct disklabel lp;
 	size_t ptn;
-	
+
 	/* Get info about partition/wedge */
 	if (ioctl(fd, DIOCGWEDGEINFO, dkw) == -1) {
 		if (ioctl(fd, DIOCGDINFO, lp) == -1)
@@ -2057,11 +2057,11 @@
 
 	char *special;
 	char reply[5];
-	
+
 	newsize = 0;
 	ExpertFlag = 0;
 	SFlag = 0;
-	
+
 	while ((ch = getopt(argc, argv, s:y)) != -1) {
 		switch (ch) {
 		case 's':
@@ -2099,7 +2099,7 @@
 			exit(EXIT_SUCCESS);
 		}
 	}
-	
+
 	fd = open(special, O_RDWR, 0);
 	if (fd  0)
 		err(EXIT_FAILURE, Can't open `%s', special);
@@ -2111,7 +2111,7 @@
 			err(EXIT_FAILURE,
 			Can't resize file system, newsize not known.);
 	}
-	
+
 	oldsb = (struct fs *)  sbbuf;
 	newsb = (struct fs *) 

CVS commit: src/sbin/resize_ffs

2011-08-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 15 00:30:25 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Add missing __RCSID().


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.28 src/sbin/resize_ffs/resize_ffs.c:1.29
--- src/sbin/resize_ffs/resize_ffs.c:1.28	Mon Aug 15 00:27:50 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Aug 15 00:30:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.28 2011/08/15 00:27:50 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.29 2011/08/15 00:30:25 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,6 +36,8 @@
  */
 
 #include sys/cdefs.h
+__RCSID($NetBSD: resize_ffs.c,v 1.29 2011/08/15 00:30:25 dholland Exp $);
+
 #include sys/disk.h
 #include sys/disklabel.h
 #include sys/dkio.h



CVS commit: src/sbin/resize_ffs

2011-08-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 15 02:19:50 UTC 2011

Modified Files:
src/sbin/resize_ffs: Makefile resize_ffs.c

Log Message:
WARNS = 4


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sbin/resize_ffs/Makefile
cvs rdiff -u -r1.29 -r1.30 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/Makefile
diff -u src/sbin/resize_ffs/Makefile:1.3 src/sbin/resize_ffs/Makefile:1.4
--- src/sbin/resize_ffs/Makefile:1.3	Wed Jan  5 02:18:15 2011
+++ src/sbin/resize_ffs/Makefile	Mon Aug 15 02:19:50 2011
@@ -1,9 +1,7 @@
-#	$NetBSD: Makefile,v 1.3 2011/01/05 02:18:15 riz Exp $
+#	$NetBSD: Makefile,v 1.4 2011/08/15 02:19:50 dholland Exp $
 
 .include bsd.own.mk
 
-WARNS?=	3	# XXX: sign-compare issues
-
 PROG=resize_ffs
 MAN=resize_ffs.8
 SRCS=resize_ffs.c ffs_bswap.c

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.29 src/sbin/resize_ffs/resize_ffs.c:1.30
--- src/sbin/resize_ffs/resize_ffs.c:1.29	Mon Aug 15 00:30:25 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Aug 15 02:19:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.29 2011/08/15 00:30:25 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.30 2011/08/15 02:19:50 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.29 2011/08/15 00:30:25 dholland Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.30 2011/08/15 02:19:50 dholland Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -60,7 +60,7 @@
 #include unistd.h
 
 /* new size of file system, in sectors */
-static uint64_t newsize;
+static int64_t newsize;
 
 /* fd open onto disk device or file */
 static int fd;
@@ -137,10 +137,10 @@
  * block. */
 
 /* resize_ffs works directly on dinodes, adapt blksize() */
-#define dblksize(fs, dip, lbn) \
-	(((lbn) = NDADDR || DIP((dip), di_size) = lblktosize(fs, (lbn) + 1)) \
+#define dblksize(fs, dip, lbn, filesize) \
+	(((lbn) = NDADDR || (filesize) = lblktosize(fs, (lbn) + 1)) \
 	? (fs)-fs_bsize		   \
-	: (fragroundup(fs, blkoff(fs, DIP((dip), di_size)
+	: (fragroundup(fs, blkoff(fs, (filesize)
 
 
 /*
@@ -645,7 +645,7 @@
 	int cgn;		/* number of cg hand currently points into */
 	int fwc;		/* frag-within-cg number of frag hand points
  * to */
-	int run;		/* length of run of free frags seen so far */
+	unsigned int run;	/* length of run of free frags seen so far */
 	int secondpass;		/* have we wrapped from end of fs to
  * beginning? */
 	unsigned char *bits;	/* cg_blksfree()[] for cg hand points into */
@@ -1041,22 +1041,24 @@
 #define MDB_INDIR_PRE  2
 #define MDB_INDIR_POST 3
 
-typedef void (*mark_callback_t) (unsigned int blocknum, unsigned int nfrags,
+typedef void (*mark_callback_t) (off_t blocknum, unsigned int nfrags,
  unsigned int blksize, int opcode);
 
 /* Helper function - handles a data block.  Calls the callback
  * function and returns number of bytes occupied in file (actually,
  * rounded up to a frag boundary).  The name is historical.  */
 static int
-markblk(mark_callback_t fn, union dinode * di, int bn, off_t o)
+markblk(mark_callback_t fn, union dinode * di, off_t bn, off_t o)
 {
 	int sz;
 	int nb;
+	off_t filesize;
 
-	if (o = DIP(di,di_size))
+	filesize = DIP(di,di_size);
+	if (o = filesize)
 		return (0);
-	sz = dblksize(newsb, di, lblkno(newsb, o));
-	nb = (sz  DIP(di,di_size) - o) ? DIP(di,di_size) - o : sz;
+	sz = dblksize(newsb, di, lblkno(newsb, o), filesize);
+	nb = (sz  filesize - o) ? filesize - o : sz;
 	if (bn)
 		(*fn) (bn, numfrags(newsb, sz), nb, MDB_DATA);
 	return (sz);
@@ -1068,10 +1070,11 @@
  * For the sake of update_for_data_move(), we read the indirect block
  * _after_ making the _PRE callback.  The name is historical.  */
 static int
-markiblk(mark_callback_t fn, union dinode * di, int bn, off_t o, int lev)
+markiblk(mark_callback_t fn, union dinode * di, off_t bn, off_t o, int lev)
 {
 	int i;
 	int j;
+	unsigned k;
 	int tot;
 	static int32_t indirblk1[howmany(MAXBSIZE, sizeof(int32_t))];
 	static int32_t indirblk2[howmany(MAXBSIZE, sizeof(int32_t))];
@@ -1091,8 +1094,8 @@
 	(*fn) (bn, newsb-fs_frag, newsb-fs_bsize, MDB_INDIR_PRE);
 	readat(fsbtodb(newsb, bn), indirblks[lev], newsb-fs_bsize);
 	if (needswap)
-		for (i = 0; i  howmany(MAXBSIZE, sizeof(int32_t)); i++)
-			indirblks[lev][i] = bswap32(indirblks[lev][i]);
+		for (k = 0; k  howmany(MAXBSIZE, sizeof(int32_t)); k++)
+			indirblks[lev][k] = bswap32(indirblks[lev][k]);
 	tot = 0;
 	for (i = 0; i  NINDIR(newsb); i++) {
 		j = markiblk(fn, di, indirblks[lev][i], o, lev - 1);
@@ -1148,11 +1151,13 @@
 dblk_callback(union dinode * di, unsigned int inum, void *arg)
 {
 	mark_callback_t fn;
+	off_t filesize;
 
+	filesize = 

CVS commit: src/sbin/resize_ffs

2011-08-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 15 02:22:46 UTC 2011

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Fix another dodgy switch-jump.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.30 src/sbin/resize_ffs/resize_ffs.c:1.31
--- src/sbin/resize_ffs/resize_ffs.c:1.30	Mon Aug 15 02:19:50 2011
+++ src/sbin/resize_ffs/resize_ffs.c	Mon Aug 15 02:22:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.30 2011/08/15 02:19:50 dholland Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.31 2011/08/15 02:22:46 dholland Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: resize_ffs.c,v 1.30 2011/08/15 02:19:50 dholland Exp $);
+__RCSID($NetBSD: resize_ffs.c,v 1.31 2011/08/15 02:22:46 dholland Exp $);
 
 #include sys/disk.h
 #include sys/disklabel.h
@@ -1157,11 +1157,13 @@
 	fn = (mark_callback_t) arg;
 	switch (DIP(di,di_mode)  IFMT) {
 	case IFLNK:
-		if (filesize  newsb-fs_maxsymlinklen) {
+		if (filesize = newsb-fs_maxsymlinklen) {
+			break;
+		}
+		/* FALLTHROUGH */
 	case IFDIR:
 	case IFREG:
-			map_inode_data_blocks(di, fn);
-		}
+		map_inode_data_blocks(di, fn);
 		break;
 	}
 }
@@ -1956,7 +1958,7 @@
 			break;
 		case IFDIR:
 			cg-cg_cs.cs_ndir++;
-			/* fall through */
+			/* FALLTHROUGH */
 		default:
 			set_bits(cg_inosused(cg, 0), iwc, 1);
 			break;
@@ -2126,8 +2128,8 @@
 		readat(where / DEV_BSIZE, oldsb, SBLOCKSIZE);
 		switch (oldsb-fs_magic) {
 		case FS_UFS2_MAGIC:
-			/* FALLTHROUGH */
 			is_ufs2 = 1;
+			/* FALLTHROUGH */
 		case FS_UFS1_MAGIC:
 			needswap = 0;
 			break;



CVS commit: src/sbin/resize_ffs

2011-01-04 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Jan  5 02:18:16 UTC 2011

Modified Files:
src/sbin/resize_ffs: Makefile TODO resize_ffs.8 resize_ffs.c

Log Message:
Add support for byteswapped file systems (big-endian on little-endian
host, and vice versa), to fix PR#44203.

Add support for growing (but not yet shrinking) UFS2 file systems.  Partially
addresses PR#44205.

While I'm here, reformat the code for closer adherence to KNF.

Fairly extensive testing was performed, using the shortly-to-be-committed
updated ATF tests.  Patch posted to tech-userlevel on 21 December 2010,
no comments.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sbin/resize_ffs/Makefile
cvs rdiff -u -r1.7 -r1.8 src/sbin/resize_ffs/TODO
cvs rdiff -u -r1.9 -r1.10 src/sbin/resize_ffs/resize_ffs.8
cvs rdiff -u -r1.24 -r1.25 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/Makefile
diff -u src/sbin/resize_ffs/Makefile:1.2 src/sbin/resize_ffs/Makefile:1.3
--- src/sbin/resize_ffs/Makefile:1.2	Sun Apr 26 05:57:48 2009
+++ src/sbin/resize_ffs/Makefile	Wed Jan  5 02:18:15 2011
@@ -1,8 +1,13 @@
-#	$NetBSD: Makefile,v 1.2 2009/04/26 05:57:48 lukem Exp $
+#	$NetBSD: Makefile,v 1.3 2011/01/05 02:18:15 riz Exp $
+
+.include bsd.own.mk
 
 WARNS?=	3	# XXX: sign-compare issues
 
 PROG=resize_ffs
 MAN=resize_ffs.8
+SRCS=resize_ffs.c ffs_bswap.c
+
+.PATH: ${NETBSDSRCDIR}/sys/ufs/ffs
 
 .include bsd.prog.mk

Index: src/sbin/resize_ffs/TODO
diff -u src/sbin/resize_ffs/TODO:1.7 src/sbin/resize_ffs/TODO:1.8
--- src/sbin/resize_ffs/TODO:1.7	Wed Dec  8 15:23:53 2010
+++ src/sbin/resize_ffs/TODO	Wed Jan  5 02:18:15 2011
@@ -1,6 +1,6 @@
 resize_ffs(8) TODO list
 
-* Add support for swapped byte order
-* Fix support for disk blocks of size other than 512 bytes
-* Extend to support UFS2.  Probably growth first, then shrinking separately.
+* Test and likely fix support for disk blocks of size other than 512 bytes
+* Support shrinking UFS2 file systems
+* Make the output a bit more verbose, similar to newfs(8)
 * Expand the testing done in src/tests/sbin/resize_ffs

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.9 src/sbin/resize_ffs/resize_ffs.8:1.10
--- src/sbin/resize_ffs/resize_ffs.8:1.9	Mon Dec 20 00:49:23 2010
+++ src/sbin/resize_ffs/resize_ffs.8	Wed Jan  5 02:18:15 2011
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.9 2010/12/20 00:49:23 riz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.10 2011/01/05 02:18:15 riz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -9,22 +9,22 @@
 .\  X  Against HTML   mo...@rodents.montreal.qc.ca
 .\ / \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
 .\
-.Dd October 30, 2010
+.Dd January 4, 2011
 .Dt RESIZE_FFS 8
 .Os
 .Sh NAME
 .Nm resize_ffs
-.Nd resize an on-disk file system
+.Nd resize a file system on disk or in a file
 .Sh SYNOPSIS
 .Nm
 .Op Fl y
 .Op Fl s Ar size
-.Ar file-system-raw-device
+.Ar special
 .Sh DESCRIPTION
 .Nm
-resizes a file system on disk.
-.Ar file-system-raw-device
-is the name of the raw disk device where the file system resides;
+resizes a file system.
+.Ar special
+is the name of the raw disk device or file where the file system resides;
 (Sectors are almost always 512 bytes, and
 .Nm
 can both grow and shrink file systems.
@@ -53,7 +53,7 @@
 .Nm
 will grow the file system to the underlying device size which is
 determined from
-.Ar file-system-raw-device .
+.Ar special .
 .Pp
 The options are as follows:
 .Bl -tag -width indent
@@ -66,10 +66,6 @@
 .Nm .
 .El
 .Sh WARNING
-.Nm
-should still be considered experimental.
-It still needs to be validated with a rigorous regression test
-suite.
 .Em Interrupting
 .Nm
 .Em may leave your file system in an inconsistent state and require a
@@ -88,16 +84,7 @@
 It's probably wise to
 .Xr fsck 8
 the file system before and after, just to be safe.
-.\ Remove this when (if) fsck gets fixed.
-.Pp
-There is a bug somewhere in
-.Xr fsck 8 ;
-it does not check certain data structures enough.
-A past version of this program had a bug that produced corrupted
-rotation layout summary tables, which would panic the kernel.
-This bug is believed fixed, and there are currently no
-known bugs in the program.
-However, you should be aware that just because
+You should be aware that just because
 .Xr fsck 8
 is happy with the file system does not mean it is intact.
 .Sh EXIT STATUS
@@ -127,15 +114,16 @@
 .Sh AUTHORS
 .An der Mouse
 .Aq mo...@rodents.montreal.qc.ca
+(primary author)
+.An Jeff Rizzo
+.Aq r...@netbsd.org
+(Byteswapped file system and UFS2 support)
 .Pp
 A big bug-finding kudos goes to John Kohl for finding the rotational
 layout bug referred to in the
 .Sx WARNING
 section above.
 .Sh BUGS
-Has not been tested 

CVS commit: src/sbin/resize_ffs

2010-12-19 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Sun Dec 19 23:22:46 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
Add missing .Os macro.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.6 src/sbin/resize_ffs/resize_ffs.8:1.7
--- src/sbin/resize_ffs/resize_ffs.8:1.6	Tue Dec 14 21:49:21 2010
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Dec 19 23:22:46 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.6 2010/12/14 21:49:21 wiz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.7 2010/12/19 23:22:46 njoly Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -11,6 +11,7 @@
 .\
 .Dd October 30, 2010
 .Dt RESIZE_FFS 8
+.Os
 .Sh NAME
 .Nm resize_ffs
 .Nd resize an on-disk file system



CVS commit: src/sbin/resize_ffs

2010-12-19 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Mon Dec 20 00:49:23 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
Revert previous - inadvertant commit to wrong repository.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.8 src/sbin/resize_ffs/resize_ffs.8:1.9
--- src/sbin/resize_ffs/resize_ffs.8:1.8	Mon Dec 20 00:44:53 2010
+++ src/sbin/resize_ffs/resize_ffs.8	Mon Dec 20 00:49:23 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.8 2010/12/20 00:44:53 riz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.9 2010/12/20 00:49:23 riz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -9,12 +9,12 @@
 .\  X  Against HTML   mo...@rodents.montreal.qc.ca
 .\ / \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
 .\
-.Dd December 18, 2010
+.Dd October 30, 2010
 .Dt RESIZE_FFS 8
 .Os
 .Sh NAME
 .Nm resize_ffs
-.Nd resize a file system on disk or in a file
+.Nd resize an on-disk file system
 .Sh SYNOPSIS
 .Nm
 .Op Fl y
@@ -24,7 +24,7 @@
 .Nm
 resizes a file system on disk.
 .Ar file-system-raw-device
-is the name of the raw disk device or file where the file system resides;
+is the name of the raw disk device where the file system resides;
 (Sectors are almost always 512 bytes, and
 .Nm
 can both grow and shrink file systems.
@@ -66,6 +66,10 @@
 .Nm .
 .El
 .Sh WARNING
+.Nm
+should still be considered experimental.
+It still needs to be validated with a rigorous regression test
+suite.
 .Em Interrupting
 .Nm
 .Em may leave your file system in an inconsistent state and require a
@@ -84,7 +88,16 @@
 It's probably wise to
 .Xr fsck 8
 the file system before and after, just to be safe.
-You should be aware that just because
+.\ Remove this when (if) fsck gets fixed.
+.Pp
+There is a bug somewhere in
+.Xr fsck 8 ;
+it does not check certain data structures enough.
+A past version of this program had a bug that produced corrupted
+rotation layout summary tables, which would panic the kernel.
+This bug is believed fixed, and there are currently no
+known bugs in the program.
+However, you should be aware that just because
 .Xr fsck 8
 is happy with the file system does not mean it is intact.
 .Sh EXIT STATUS
@@ -120,6 +133,9 @@
 .Sx WARNING
 section above.
 .Sh BUGS
+Has not been tested and probably won't work on opposite-endian file
+systems.
+.Pp
 Can fail to shrink a file system when there actually is enough space,
 because it does not distinguish between a block allocated as a block
 and a block fully occupied by two or more frags.
@@ -130,4 +146,4 @@
 Has no intelligence whatever when it comes to allocating blocks to copy
 data into when shrinking.
 .Pp
-Doesn't shrink FFSv2 file systems.
+Doesn't work with FFSv2 file systems.



CVS commit: src/sbin/resize_ffs

2010-12-14 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Dec 14 20:45:22 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Be explicit about byteswapped and ffsv2 file systems being currently
unsupported, while catching up to some changes in my local tree which
will hopefully support them at some time in the future.

Also, change device variable to special, to reflect the fact
that resize_ffs will work on a plain file.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.22 src/sbin/resize_ffs/resize_ffs.c:1.23
--- src/sbin/resize_ffs/resize_ffs.c:1.22	Tue Dec 14 04:04:20 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Tue Dec 14 20:45:22 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.22 2010/12/14 04:04:20 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.23 2010/12/14 20:45:22 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -64,7 +64,7 @@
 /* new size of filesystem, in sectors */
 static uint32_t newsize;
 
-/* fd open onto disk device */
+/* fd open onto disk device or file */
 static int fd;
 
 /* must we break up big I/O operations - see checksmallio() */
@@ -131,6 +131,10 @@
 #define NSPB(fs)	((fs)-fs_old_nspf  (fs)-fs_fragshift)
 #define NSPF(fs)	((fs)-fs_old_nspf)
 
+/* global flags */
+int is_ufs2 = 0;
+int needswap = 0;
+
 static void usage(void) __dead;
 
 /*
@@ -1873,7 +1877,7 @@
 	int SFlag;
 	size_t i;
 
-	char *device;
+	char *special;
 	char reply[5];
 	
 	newsize = 0;
@@ -1905,10 +1909,10 @@
 		usage();
 	}
 
-	device = *argv;
+	special = *argv;
 
 	if (ExpertFlag == 0) {
-		printf(It's required to manually run fsck on filesystem device 
+		printf(It's required to manually run fsck on filesystem 
 		before you can resize it\n\n
 		 Did you run fsck on your disk (Yes/No) ? );
 		fgets(reply, (int)sizeof(reply), stdin);
@@ -1918,13 +1922,13 @@
 		}
 	}
 	
-	fd = open(device, O_RDWR, 0);
+	fd = open(special, O_RDWR, 0);
 	if (fd  0)
-		err(EXIT_FAILURE, Can't open `%s', device);
+		err(EXIT_FAILURE, Can't open `%s', special);
 	checksmallio();
 
 	if (SFlag == 0) {
-		newsize = get_dev_size(device);
+		newsize = get_dev_size(special);
 		if (newsize == 0)
 			err(EXIT_FAILURE,
 			Can't resize filesystem, newsize not known.);
@@ -1934,10 +1938,25 @@
 	newsb = (struct fs *) (SBLOCKSIZE + (char *) sbbuf);
 	for (where = search[i = 0]; search[i] != -1; where = search[++i]) {
 		readat(where / DEV_BSIZE, oldsb, SBLOCKSIZE);
-		if (where == SBLOCK_UFS2  (oldsb-fs_magic == FS_UFS1_MAGIC))
-			continue;
-		if (oldsb-fs_magic == FS_UFS1_MAGIC)
+		switch (oldsb-fs_magic) {
+		case FS_UFS2_MAGIC:
+			/* FALLTHROUGH */
+			is_ufs2 = 1;
+		case FS_UFS1_MAGIC:
+			needswap = 0;
+			break;
+		case FS_UFS2_MAGIC_SWAPPED:
+ 			is_ufs2 = 1;
+			/* FALLTHROUGH */
+		case FS_UFS1_MAGIC_SWAPPED:
+			needswap = 1;
 			break;
+		default:
+			continue;
+		}
+		if (!is_ufs2  where == SBLOCK_UFS2)
+			continue;
+		break;
 	}
 	if (where == (off_t)-1)
 		errx(EXIT_FAILURE, Bad magic number);
@@ -1953,6 +1972,11 @@
 		/* any others? */
 		printf(Resizing with ffsv1 superblock\n);
 	}
+	if (is_ufs2)
+		errx(EXIT_FAILURE, ffsv2 file systems currently unsupported.);
+	if (needswap)
+		errx(EXIT_FAILURE, Swapped byte order file system detected
+		 - currently unsupported.);
 	oldsb-fs_qbmask = ~(int64_t) oldsb-fs_bmask;
 	oldsb-fs_qfmask = ~(int64_t) oldsb-fs_fmask;
 	if (oldsb-fs_ipg % INOPB(oldsb)) {
@@ -1982,6 +2006,6 @@
 usage(void)
 {
 
-	(void)fprintf(stderr, usage: %s [-y] [-s size] device\n, getprogname());
+	(void)fprintf(stderr, usage: %s [-y] [-s size] special\n, getprogname());
 	exit(EXIT_FAILURE);
 }



CVS commit: src/sbin/resize_ffs

2010-12-14 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Dec 14 21:49:22 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.8 resize_ffs.c

Log Message:
filesystem - file system.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sbin/resize_ffs/resize_ffs.8
cvs rdiff -u -r1.23 -r1.24 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.5 src/sbin/resize_ffs/resize_ffs.8:1.6
--- src/sbin/resize_ffs/resize_ffs.8:1.5	Sun Oct 31 11:39:46 2010
+++ src/sbin/resize_ffs/resize_ffs.8	Tue Dec 14 21:49:21 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.5 2010/10/31 11:39:46 wiz Exp $
+.\ $NetBSD: resize_ffs.8,v 1.6 2010/12/14 21:49:21 wiz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -145,4 +145,4 @@
 Has no intelligence whatever when it comes to allocating blocks to copy
 data into when shrinking.
 .Pp
-Doesn't work with FFSv2 filesystems.
+Doesn't work with FFSv2 file systems.

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.23 src/sbin/resize_ffs/resize_ffs.c:1.24
--- src/sbin/resize_ffs/resize_ffs.c:1.23	Tue Dec 14 20:45:22 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Tue Dec 14 21:49:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.23 2010/12/14 20:45:22 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.24 2010/12/14 21:49:21 wiz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -13,9 +13,9 @@
 /*
  * resize_ffs:
  *
- * Resize a filesystem.  Is capable of both growing and shrinking.
+ * Resize a file system.  Is capable of both growing and shrinking.
  *
- * Usage: resize_ffs [-s newsize] [-y] filesystem
+ * Usage: resize_ffs [-s newsize] [-y] file_system
  *
  * Example: resize_ffs -s 29574 /dev/rsd1e
  *
@@ -27,7 +27,7 @@
  *  definitions (which in at least a few cases depend on the lexical
  *  scoping gcc provides, so they can't be trivially moved outside).
  *
- * It will not do anything useful with filesystems in other than
+ * It will not do anything useful with file systems in other than
  *  host-native byte order.  This really should be fixed (it's largely
  *  a historical accident; the original version of this program is
  *  older than bi-endian support in FFS).
@@ -61,7 +61,7 @@
 #include strings.h
 #include unistd.h
 
-/* new size of filesystem, in sectors */
+/* new size of file system, in sectors */
 static uint32_t newsize;
 
 /* fd open onto disk device or file */
@@ -584,8 +584,8 @@
  *  takes up more than a whole block (is the csum info allowed to begin
  *  partway through a block and continue into the following block?).
  *
- * If we wrap off the end of the filesystem back to the beginning, we
- *  can end up searching the end of the filesystem twice.  I ignore
+ * If we wrap off the end of the file system back to the beginning, we
+ *  can end up searching the end of the file system twice.  I ignore
  *  this inefficiency, since if that happens we're going to croak with
  *  a no-space error anyway, so it happens at most once.
  */
@@ -782,9 +782,9 @@
 		return;
 	}
 	/* We must be growing.  Check to see that the new csum area fits
-	 * within the filesystem.  I think this can never happen, since for
+	 * within the file system.  I think this can never happen, since for
 	 * the csum area to grow, we must be adding at least one cg, so the
-	 * old csum area can't be this close to the end of the new filesystem.
+	 * old csum area can't be this close to the end of the new file system.
 	 * But it's a cheap check. */
 	/* XXX what if csum info is at end of cg and grows into next cg, what
 	 * if it spills over onto the next cg's backup superblock?  Can this
@@ -867,7 +867,7 @@
 	return (t);
 }
 /*
- * Grow the filesystem.
+ * Grow the file system.
  */
 static void
 grow(void)
@@ -902,7 +902,7 @@
 	newsb-fs_ncg = howmany(newsb-fs_old_ncyl, newsb-fs_old_cpg);
 	/* Does the last cg end before the end of its inode area? There is no
 	 * reason why this couldn't be handled, but it would complicate a lot
-	 * of code (in all filesystem code - fsck, kernel, etc) because of the
+	 * of code (in all file system code - fsck, kernel, etc) because of the
 	 * potential partial inode area, and the gain in space would be
 	 * minimal, at most the pre-sb data area. */
 	if (cgdmin(newsb, newsb-fs_ncg - 1)  newsb-fs_size) {
@@ -962,7 +962,7 @@
 /*
  * Call (*fn)() for each inode, passing the inode and its inumber.  The
  *  number of cylinder groups is pased in, so this can be used to map
- *  over either the old or the new filesystem's set of inodes.
+ *  over either the old or the new file system's set of inodes.
  */
 static void
 map_inodes(void 

CVS commit: src/sbin/resize_ffs

2010-12-13 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Dec 14 04:04:20 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Don't special-case v1 superblocks - especially with an incorrect
calculation.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.21 src/sbin/resize_ffs/resize_ffs.c:1.22
--- src/sbin/resize_ffs/resize_ffs.c:1.21	Sun Dec 12 22:48:59 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Tue Dec 14 04:04:20 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.21 2010/12/12 22:48:59 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.22 2010/12/14 04:04:20 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -948,8 +948,6 @@
 		oldcgsize = oldsb-fs_size % oldsb-fs_fpg;
 		set_bits(cg_blksfree(cg, 0), oldcgsize, newcgsize - oldcgsize);
 		cg-cg_old_ncyl = oldsb-fs_old_cpg;
-		if ((newsb-fs_old_flags  FS_FLAGS_UPDATED) == 0)
-			cg-cg_old_ncyl = newsb-fs_old_ncyl % newsb-fs_old_cpg;
 		cg-cg_ndblk = newcgsize;
 	}
 	/* Fix up the csum info, if necessary. */



CVS commit: src/sbin/resize_ffs

2010-12-12 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Sun Dec 12 22:48:59 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Remove bogus check which is not actually testing anything useful,
and depending on file system data, can actually be a false error.

Fixes what I was actually testing for in bin/44209, though the
actual problem was not what I originally described.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.20 src/sbin/resize_ffs/resize_ffs.c:1.21
--- src/sbin/resize_ffs/resize_ffs.c:1.20	Sun Dec 12 19:53:23 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Sun Dec 12 22:48:59 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.20 2010/12/12 19:53:23 mhitch Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.21 2010/12/12 22:48:59 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -1940,9 +1940,6 @@
 			continue;
 		if (oldsb-fs_magic == FS_UFS1_MAGIC)
 			break;
-		if (oldsb-fs_old_flags  FS_FLAGS_UPDATED)
-			err(EXIT_FAILURE,
-			Can't resize ffsv2 format superblock!);
 	}
 	if (where == (off_t)-1)
 		errx(EXIT_FAILURE, Bad magic number);



CVS commit: src/sbin/resize_ffs

2010-12-08 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Dec  8 15:23:53 UTC 2010

Modified Files:
src/sbin/resize_ffs: TODO

Log Message:
Remove accidentally-resurrected TODO item.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sbin/resize_ffs/TODO

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

Modified files:

Index: src/sbin/resize_ffs/TODO
diff -u src/sbin/resize_ffs/TODO:1.6 src/sbin/resize_ffs/TODO:1.7
--- src/sbin/resize_ffs/TODO:1.6	Wed Dec  8 00:25:54 2010
+++ src/sbin/resize_ffs/TODO	Wed Dec  8 15:23:53 2010
@@ -2,6 +2,5 @@
 
 * Add support for swapped byte order
 * Fix support for disk blocks of size other than 512 bytes
-* Add support for plain files (primarily to ease testing)
 * Extend to support UFS2.  Probably growth first, then shrinking separately.
 * Expand the testing done in src/tests/sbin/resize_ffs



CVS commit: src/sbin/resize_ffs

2010-12-07 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Dec  7 23:29:56 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
As currently written, writeat() expects disk blocks, not fs blocks, so
when testing that the last sector of the new size is writeable, make
sure we're ACTUALLY writing in the new space, instead of possibly
overwriting something in the existing fs.

Discovered while writing tests - tests which uncovered file corruption at
certain block sizes.

XXX should rewrite writeat() to expect fs blocks instead of disk blocks.

OK mlelstv@


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.17 src/sbin/resize_ffs/resize_ffs.c:1.18
--- src/sbin/resize_ffs/resize_ffs.c:1.17	Thu Dec  2 22:00:27 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Tue Dec  7 23:29:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.17 2010/12/02 22:00:27 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.18 2010/12/07 23:29:55 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -880,7 +880,7 @@
 	 * overwriting anything important by this.  (The choice of sbbuf as
 	 * what to write is irrelevant; it's just something handy that's known
 	 * to be at least one frag in size.) */
-	writeat(newsb-fs_size - 1, sbbuf, newsb-fs_fsize);
+	writeat(fsbtodb(newsb,newsb-fs_size - 1), sbbuf, newsb-fs_fsize);
 	/* Update fs_old_ncyl and fs_ncg. */
 	newsb-fs_old_ncyl = howmany(newsb-fs_size * NSPF(newsb),
 	newsb-fs_old_spc);



CVS commit: src/sbin/resize_ffs

2010-12-07 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Dec  8 00:25:54 UTC 2010

Modified Files:
src/sbin/resize_ffs: TODO resize_ffs.c

Log Message:
If we're operating on a plain file instead of a device, ftruncate() it
to ensure it's been properly extended.  Clears up some problems at certain
blocksizes which showed up during creation of atf tests, which is done
using file-backed file systems.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sbin/resize_ffs/TODO
cvs rdiff -u -r1.18 -r1.19 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/TODO
diff -u src/sbin/resize_ffs/TODO:1.5 src/sbin/resize_ffs/TODO:1.6
--- src/sbin/resize_ffs/TODO:1.5	Fri Dec  3 05:23:34 2010
+++ src/sbin/resize_ffs/TODO	Wed Dec  8 00:25:54 2010
@@ -2,5 +2,6 @@
 
 * Add support for swapped byte order
 * Fix support for disk blocks of size other than 512 bytes
+* Add support for plain files (primarily to ease testing)
 * Extend to support UFS2.  Probably growth first, then shrinking separately.
 * Expand the testing done in src/tests/sbin/resize_ffs

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.18 src/sbin/resize_ffs/resize_ffs.c:1.19
--- src/sbin/resize_ffs/resize_ffs.c:1.18	Tue Dec  7 23:29:55 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Wed Dec  8 00:25:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.18 2010/12/07 23:29:55 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.19 2010/12/08 00:25:54 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -149,6 +149,15 @@
 	fstat(fd, stb);
 	smallio = ((stb.st_mode  S_IFMT) == S_IFCHR);
 }
+
+static int
+isplainfile(void)
+{
+	struct stat stb;
+
+	fstat(fd, stb);
+	return S_ISREG(stb.st_mode);
+}
 /*
  * Read size bytes starting at blkno into buf.  blkno is in DEV_BSIZE
  *  units, ie, after fsbtodb(); size is in bytes.
@@ -1942,6 +1951,8 @@
 	}
 	flush_cgs();
 	write_sbs();
+	if (isplainfile())
+		ftruncate(fd,newsize * DEV_BSIZE);
 	return 0;
 }
 



CVS commit: src/sbin/resize_ffs

2010-12-02 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Dec  2 22:00:27 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Use howmany() instead of / to calculate the number of cylinders for
the changed file system, so as to not drop a partial cylinder at the
end.  Fixes PR bin/44177.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.16 src/sbin/resize_ffs/resize_ffs.c:1.17
--- src/sbin/resize_ffs/resize_ffs.c:1.16	Wed Dec  1 17:39:21 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Thu Dec  2 22:00:27 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.16 2010/12/01 17:39:21 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.17 2010/12/02 22:00:27 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -882,7 +882,8 @@
 	 * to be at least one frag in size.) */
 	writeat(newsb-fs_size - 1, sbbuf, newsb-fs_fsize);
 	/* Update fs_old_ncyl and fs_ncg. */
-	newsb-fs_old_ncyl = (newsb-fs_size * NSPF(newsb)) / newsb-fs_old_spc;
+	newsb-fs_old_ncyl = howmany(newsb-fs_size * NSPF(newsb),
+	newsb-fs_old_spc);
 	newsb-fs_ncg = howmany(newsb-fs_old_ncyl, newsb-fs_old_cpg);
 	/* Does the last cg end before the end of its inode area? There is no
 	 * reason why this couldn't be handled, but it would complicate a lot
@@ -1521,7 +1522,8 @@
 	newsb-fs_time = timestamp();
 	/* Update the size figures. */
 	newsb-fs_size = dbtofsb(newsb, newsize);
-	newsb-fs_old_ncyl = (newsb-fs_size * NSPF(newsb)) / newsb-fs_old_spc;
+	newsb-fs_old_ncyl = howmany(newsb-fs_size * NSPF(newsb),
+	newsb-fs_old_spc);
 	newsb-fs_ncg = howmany(newsb-fs_old_ncyl, newsb-fs_old_cpg);
 	/* Does the (new) last cg end before the end of its inode area?  See
 	 * the similar code in grow() for more on this. */



CVS commit: src/sbin/resize_ffs

2010-12-02 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Dec  2 22:04:01 UTC 2010

Modified Files:
src/sbin/resize_ffs: TODO

Log Message:
Knock one off the list.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sbin/resize_ffs/TODO

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

Modified files:

Index: src/sbin/resize_ffs/TODO
diff -u src/sbin/resize_ffs/TODO:1.3 src/sbin/resize_ffs/TODO:1.4
--- src/sbin/resize_ffs/TODO:1.3	Wed Dec  1 17:39:54 2010
+++ src/sbin/resize_ffs/TODO	Thu Dec  2 22:04:01 2010
@@ -1,7 +1,5 @@
 resize_ffs(8) TODO list
 
-* Determine why shrinking a v1 file system gets the free block/frag info
-  wrong, requiring a fsck.
 * Add support for swapped byte order
 * Fix support for disk blocks of size other than 512 bytes
 * Add support for plain files (primarily to ease testing)



CVS commit: src/sbin/resize_ffs

2010-12-01 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Dec  1 17:33:45 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Clean up this file:

- sync usage comment with current reality
- sort includes
- wrap lines
- use EXIT_FAILURE consistently
- make error messages consistent:  Cannot-Can't
- Remove Old FFSv1 macros in favor of system macros in ufs/ffs/fs.h .
  Leave dblksize() because it uses the on-disk dinode structure.

More cleanup is needed.
No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.14 src/sbin/resize_ffs/resize_ffs.c:1.15
--- src/sbin/resize_ffs/resize_ffs.c:1.14	Mon Nov 29 19:54:10 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Wed Dec  1 17:33:45 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.14 2010/11/29 19:54:10 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.15 2010/12/01 17:33:45 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -15,9 +15,9 @@
  *
  * Resize a filesystem.  Is capable of both growing and shrinking.
  *
- * Usage: resize_ffs filesystem newsize
+ * Usage: resize_ffs [-s newsize] [-y] filesystem
  *
- * Example: resize_ffs /dev/rsd1e 29574
+ * Example: resize_ffs -s 29574 /dev/rsd1e
  *
  * newsize is in DEV_BSIZE units (ie, disk sectors, usually 512 bytes
  *  each).
@@ -41,13 +41,6 @@
  */
 
 #include sys/cdefs.h
-#include stdio.h
-#include errno.h
-#include fcntl.h
-#include stdlib.h
-#include unistd.h
-#include strings.h
-#include err.h
 #include sys/disk.h
 #include sys/disklabel.h
 #include sys/dkio.h
@@ -60,6 +53,14 @@
 #include ufs/ufs/dinode.h
 #include ufs/ufs/ufs_bswap.h	/* ufs_rw32 */
 
+#include err.h
+#include errno.h
+#include fcntl.h
+#include stdio.h
+#include stdlib.h
+#include strings.h
+#include unistd.h
+
 /* new size of filesystem, in sectors */
 static uint32_t newsize;
 
@@ -81,7 +82,8 @@
 static struct fs *oldsb;	/* before we started */
 static struct fs *newsb;	/* copy to work with */
 /* Buffer to hold the above.  Make sure it's aligned correctly. */
-static char sbbuf[2 * SBLOCKSIZE] __attribute__((__aligned__(__alignof__(struct fs;
+static char sbbuf[2 * SBLOCKSIZE]
+	__attribute__((__aligned__(__alignof__(struct fs;
 
 /* a cg's worth of brand new squeaky-clean inodes */
 static struct ufs1_dinode *zinodes;
@@ -115,25 +117,7 @@
  * block of inodes, and applies to the whole
  * block. */
 
-/* Old FFS1 macros */
-#define cg_blktot(cgp, ns) \
-(cg_chkmagic(cgp, ns) ? \
-((int32_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)-cg_old_btotoff, (ns \
-: (((struct ocg *)(cgp))-cg_btot))
-#define cg_blks(fs, cgp, cylno, ns) \
-(cg_chkmagic(cgp, ns) ? \
-((int16_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)-cg_old_boff, (ns))) + \
-	(cylno) * (fs)-fs_old_nrpos) \
-: (((struct ocg *)(cgp))-cg_b[cylno]))
-#define cbtocylno(fs, bno) \
-   (fsbtodb(fs, bno) / (fs)-fs_old_spc) 
-#define cbtorpos(fs, bno) \
-((fs)-fs_old_nrpos = 1 ? 0 : \
- (fsbtodb(fs, bno) % (fs)-fs_old_spc / \
-  (fs)-fs_old_nsect * (fs)-fs_old_trackskew + \
-  fsbtodb(fs, bno) % (fs)-fs_old_spc % \
-  (fs)-fs_old_nsect * (fs)-fs_old_interleave) %\
-(fs)-fs_old_nsect * (fs)-fs_old_nrpos / (fs)-fs_old_npsect)
+/* resize_ffs works directly on dinodes, adapt blksize() */
 #define dblksize(fs, dip, lbn) \
 (((lbn) = NDADDR || (dip)-di_size = lblktosize(fs, (lbn) + 1)) \
 ? (fs)-fs_bsize \
@@ -174,7 +158,7 @@
 {
 	/* Seek to the correct place. */
 	if (lseek(fd, blkno * DEV_BSIZE, L_SET)  0)
-		err(1, lseek failed);
+		err(EXIT_FAILURE, lseek failed);
 
 	/* See if we have to break up the transfer... */
 	if (smallio) {
@@ -190,7 +174,8 @@
 			if (rv  0)
 err(EXIT_FAILURE, read failed);
 			if (rv != n)
-errx(1, read: wanted %d, got %d, n, rv);
+errx(EXIT_FAILURE,
+read: wanted %d, got %d, n, rv);
 			bp += n;
 			left -= n;
 		}
@@ -200,7 +185,7 @@
 		if (rv  0)
 			err(EXIT_FAILURE, read failed);
 		if (rv != size)
-			errx(1, read: wanted %d, got %d, size, rv);
+			errx(EXIT_FAILURE, read: wanted %d, got %d, size, rv);
 	}
 }
 /*
@@ -227,7 +212,8 @@
 			if (rv  0)
 err(EXIT_FAILURE, write failed);
 			if (rv != n)
-errx(1, write: wanted %d, got %d, n, rv);
+errx(EXIT_FAILURE,
+write: wanted %d, got %d, n, rv);
 			bp += n;
 			left -= n;
 		}
@@ -237,7 +223,8 @@
 		if (rv  0)
 			err(EXIT_FAILURE, write failed);
 		if (rv != size)
-			errx(1, write: wanted %d, got %d, size, rv);
+			errx(EXIT_FAILURE,
+			write: wanted %d, got %d, size, rv);
 	}
 }
 /*
@@ -458,7 +445,8 @@
 	cg-cg_cgx = cgn;
 	cg-cg_old_ncyl = newsb-fs_old_cpg;
 	/* Update the cg_old_ncyl value for the last cylinder. 

CVS commit: src/sbin/resize_ffs

2010-12-01 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Dec  1 17:39:21 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.c

Log Message:
Do not look for a v1 file system at SBLOCK_UFS2, as this gets the wrong
superblock (first alternate) for a file system with 64k blocks.
Spotted by mhi...@.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sbin/resize_ffs/resize_ffs.c

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.c
diff -u src/sbin/resize_ffs/resize_ffs.c:1.15 src/sbin/resize_ffs/resize_ffs.c:1.16
--- src/sbin/resize_ffs/resize_ffs.c:1.15	Wed Dec  1 17:33:45 2010
+++ src/sbin/resize_ffs/resize_ffs.c	Wed Dec  1 17:39:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_ffs.c,v 1.15 2010/12/01 17:33:45 riz Exp $	*/
+/*	$NetBSD: resize_ffs.c,v 1.16 2010/12/01 17:39:21 riz Exp $	*/
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -1910,10 +1910,10 @@
 	newsb = (struct fs *) (SBLOCKSIZE + (char *) sbbuf);
 	for (where = search[i = 0]; search[i] != -1; where = search[++i]) {
 		readat(where / DEV_BSIZE, oldsb, SBLOCKSIZE);
+		if (where == SBLOCK_UFS2  (oldsb-fs_magic == FS_UFS1_MAGIC))
+			continue;
 		if (oldsb-fs_magic == FS_UFS1_MAGIC)
 			break;
-		if (where == SBLOCK_UFS2)
-			continue;
 		if (oldsb-fs_old_flags  FS_FLAGS_UPDATED)
 			err(EXIT_FAILURE,
 			Can't resize ffsv2 format superblock!);



CVS commit: src/sbin/resize_ffs

2010-12-01 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Dec  1 17:39:54 UTC 2010

Modified Files:
src/sbin/resize_ffs: TODO

Log Message:
Update TODO for resize_ffs(8), adding some stuff and removing some
ancient bits.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sbin/resize_ffs/TODO

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

Modified files:

Index: src/sbin/resize_ffs/TODO
diff -u src/sbin/resize_ffs/TODO:1.2 src/sbin/resize_ffs/TODO:1.3
--- src/sbin/resize_ffs/TODO:1.2	Sun Feb 23 00:27:51 2003
+++ src/sbin/resize_ffs/TODO	Wed Dec  1 17:39:54 2010
@@ -1,15 +1,9 @@
-Preliminary version of resize_ffs, based on der Mouse's fsresize tool.
-I didn't have time to clean it up completely before my legal status
-w.r.t. open source projects goes into limbo for a while.  Other
-developers are encouraged to play with the tool and get it into
-release-worthy shape.
+resize_ffs(8) TODO list
 
-TODO list (see TODO file)
-
-* -current; put it into release lists/etc. and src/sbin/Makefile
-  (built  tested on 1.6.1)
-* make it ask questions before doing any work (confirm)
-* create regression test suite (see discussions on tech-kern and
-  developers) and fix any bugs
-* verify conversion to ANSI C didn't break anything
-* port to UFS2
+* Determine why shrinking a v1 file system gets the free block/frag info
+  wrong, requiring a fsck.
+* Add support for swapped byte order
+* Fix support for disk blocks of size other than 512 bytes
+* Add support for plain files (primarily to ease testing)
+* Extend to support UFS2.  Probably growth first, then shrinking separately.
+* Expand the testing done in src/tests/sbin/resize_ffs



CVS commit: src/sbin/resize_ffs

2010-10-31 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Oct 31 11:39:47 UTC 2010

Modified Files:
src/sbin/resize_ffs: resize_ffs.8

Log Message:
Various improvements.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sbin/resize_ffs/resize_ffs.8

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

Modified files:

Index: src/sbin/resize_ffs/resize_ffs.8
diff -u src/sbin/resize_ffs/resize_ffs.8:1.4 src/sbin/resize_ffs/resize_ffs.8:1.5
--- src/sbin/resize_ffs/resize_ffs.8:1.4	Sat Oct 30 21:16:07 2010
+++ src/sbin/resize_ffs/resize_ffs.8	Sun Oct 31 11:39:46 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: resize_ffs.8,v 1.4 2010/10/30 21:16:07 haad Exp $
+.\ $NetBSD: resize_ffs.8,v 1.5 2010/10/31 11:39:46 wiz Exp $
 .\
 .\ As its sole author, I explicitly place this man page in the public
 .\ domain.  Anyone may use it in any way for any purpose (though I would
@@ -9,7 +9,7 @@
 .\  X  Against HTML   mo...@rodents.montreal.qc.ca
 .\ / \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
 .\
-.Dd February 20, 2003
+.Dd October 30, 2010
 .Dt RESIZE_FFS 8
 .Sh NAME
 .Nm resize_ffs
@@ -24,6 +24,7 @@
 resizes a file system on disk.
 .Ar file-system-raw-device
 is the name of the raw disk device where the file system resides;
+(Sectors are almost always 512 bytes, and
 .Nm
 can both grow and shrink file systems.
 When growing, the disk device
@@ -45,23 +46,29 @@
 check the file system with
 .Xr fsck 8 .
 .Pp
-If there is no
-.Fl s 
-used resize_ffs will grow filesystem to underlyining device size which is get
-from device.
+If no
+.Fl s
+option is provided,
+.Nm
+will grow the file system to the underlying device size which is
+determined from
+.Ar file-system-raw-device .
 .Pp
-The options are as foolows:
+The options are as follows:
 .Bl -tag -width indent
+.It Fl s
+Specify the file system size to which the file system should be
+resized.
+Mostly used to shrink file systems.
 .It Fl y
-option will disable sanity question made by resize_ffs.
-.It Fl s 
-Can be used to specify filesystem size to which we want to resize fs.
-This is only way hot to shrink filesystem now.
+Disable sanity questions made by
+.Nm .
 .El
 .Sh WARNING
 .Nm
-should still be considered experimental.  It still needs to be validated
-with a rigorous regression test suite.
+should still be considered experimental.
+It still needs to be validated with a rigorous regression test
+suite.
 .Em Interrupting
 .Nm
 .Em may leave your file system in an inconsistent state and require a
@@ -82,19 +89,19 @@
 the file system before and after, just to be safe.
 .\ Remove this when (if) fsck gets fixed.
 .Pp
-There is a bug somewhere in fsck; it does not check certain data
-structures enough.
+There is a bug somewhere in
+.Xr fsck 8 ;
+it does not check certain data structures enough.
 A past version of this program had a bug that produced corrupted
 rotation layout summary tables, which would panic the kernel.
 This bug is believed fixed, and there are currently no
 known bugs in the program.
-However, you should be aware that just
-because fsck is happy with the file system does not mean it is intact.
+However, you should be aware that just because
+.Xr fsck 8
+is happy with the file system does not mean it is intact.
 .Sh EXIT STATUS
 .Nm
-exits with
-.Dv 0
-on success.
+exits with 0 on success.
 Any major problems will cause
 .Nm
 to exit with the non-zero
@@ -103,10 +110,10 @@
 intervention is required.
 .Sh EXAMPLES
 .Dl resize_ffs Cm /dev/vg00/rlv1
-.Pp 
-will enlarge filesystem on Logical Volume
+.Pp
+will enlarge the file system on the Logical Volume
 .Pa /dev/vg00/lv1
-from Volume Group vg00 to current device size.
+from Volume Group vg00 to the current device size.
 .Sh SEE ALSO
 .Xr fs 5 ,
 .Xr fsck 8 ,



CVS commit: src/sbin/resize_ffs

2009-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 26 05:57:48 UTC 2009

Modified Files:
src/sbin/resize_ffs: Makefile

Log Message:
set WARNS=3 -- too many -Wsign-compare issues in the kernel ffs code


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sbin/resize_ffs/Makefile

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

Modified files:

Index: src/sbin/resize_ffs/Makefile
diff -u src/sbin/resize_ffs/Makefile:1.1 src/sbin/resize_ffs/Makefile:1.2
--- src/sbin/resize_ffs/Makefile:1.1	Fri Feb 21 04:08:54 2003
+++ src/sbin/resize_ffs/Makefile	Sun Apr 26 05:57:48 2009
@@ -1,4 +1,6 @@
-#	$NetBSD: Makefile,v 1.1 2003/02/21 04:08:54 jtk Exp $
+#	$NetBSD: Makefile,v 1.2 2009/04/26 05:57:48 lukem Exp $
+
+WARNS?=	3	# XXX: sign-compare issues
 
 PROG=resize_ffs
 MAN=resize_ffs.8