Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Feb 2003 17:41:27 -0800 (PST)
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 24953 for review
Message-ID:  <200302110141.h1B1fR0u026413@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=24953

Change 24953 by jmallett@jmallett_dalek on 2003/02/10 17:41:02

	Clean up block-size related code (and mishaps).

Affected files ...

.. //depot/projects/mips/sbin/fxlabel/fxlabel.c#7 edit

Differences ...

==== //depot/projects/mips/sbin/fxlabel/fxlabel.c#7 (text+ko) ====

@@ -43,10 +43,12 @@
 #include <string.h>
 #include <unistd.h>
 
+#define	DEFAULT_BSIZE	512
+
 struct volhdr	label;
 struct volpart	*vhp = &label.vh_part[FX_VOLHDRPART];
 struct volpart	*volp = &label.vh_part[FX_VOLPART];
-static int	bsize = 512;
+static int	bsize = DEFAULT_BSIZE;
 
 /*
  * Boolean returns here indicate true on error.  Some just error to prevent
@@ -98,11 +100,22 @@
 	eflag = pflag = wflag = false;
 	dksize = sflag = 0;
 
-	while ((ch = getopt(argc, argv, "a:d:eg:ps:w")) != -1) {
+	while ((ch = getopt(argc, argv, "a:b:d:eg:ps:w")) != -1) {
 		switch (ch) {
 		case 'a':
 			aflag = optarg;
 			break;
+		case 'b':
+			bsize = atoi(optarg);
+			if (bsize < DEFAULT_BSIZE) {
+				warnx("block size too small)");
+				usage();
+			}
+			/*
+			 * Round to the DEFAULT_BSIZE.
+			 */
+			bsize += bsize % DEFAULT_BSIZE;
+			break;
 		case 'd':
 			dflag = optarg;
 			break;
@@ -367,6 +380,7 @@
 		mediasize = st.st_size;
 
 	rv = mediasize;
+	printf("MEDIA SIZE %d\n", rv);
 
 	return (rv);
 }
@@ -528,12 +542,16 @@
 static void
 newlabel(struct volhdr *vp, int volhdrsize, int dksize)
 {
+	int blocks;
+
 	memset(vp, 0, sizeof *vp);
 	vp->vh_magic = FX_LABEL_MAGIC;
 	if (volhdrsize > dksize)
 		errx(1, "volume header extends beyond volume");
-	setpart(vp, FX_VOLHDRPART, FX_TYPEVOLHDR, 0, volhdrsize);
-	setpart(vp, FX_VOLPART, FX_TYPEVOL, 0, dksize);
+	blocks = bytesround2bsize(volhdrsize) / bsize;
+	setpart(vp, FX_VOLHDRPART, FX_TYPEVOLHDR, 0, blocks);
+	blocks = bytesround2bsize(dksize) / bsize;
+	setpart(vp, FX_VOLPART, FX_TYPEVOL, 0, blocks);
 }
 
 static const char *
@@ -831,11 +849,11 @@
 usage(void)
 {
 	fprintf(stderr,
-"usage: fxlabel [-a file] disk [...]\n"
-"       fxlabel [-d file] disk [...]\n"
-"       fxlabel [-g file] disk [...]\n"
-"       fxlabel [-p] disk [...]\n"
-"       fxlabel [-e] [-s size] disk [...]\n"
-"       fxlabel [-w] [-s size] disk [...]\n");
+"usage: fxlabel [-a file] [-b bsize] disk [...]\n"
+"       fxlabel [-d file] [-b bsize] disk [...]\n"
+"       fxlabel [-g file] [-b bsize] disk [...]\n"
+"       fxlabel [-p] [-b bsize] disk [...]\n"
+"       fxlabel [-e] [-b bsize] [-s size] disk [...]\n"
+"       fxlabel [-w] [-b bsize] [-s size] disk [...]\n");
 	exit(-1);
 }

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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