CVS commit: src/distrib/utils/edlabel

2010-03-10 Thread David Brownlee
Module Name:src
Committed By:   abs
Date:   Wed Mar 10 23:16:16 UTC 2010

Added Files:
src/distrib/utils/edlabel: Makefile edlabel.c

Log Message:
Relegate edlabel to use in extremely memory constrained install
ramdisks and prefer disklabel elsewhere.
Based on discussion on affected port lists (port-sparc port-sparc64
port-sun3 port-sun2 port-atari port-mvme68k).
All listed ports plus amd64 test built after change


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/distrib/utils/edlabel/Makefile \
src/distrib/utils/edlabel/edlabel.c

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

Added files:

Index: src/distrib/utils/edlabel/Makefile
diff -u /dev/null src/distrib/utils/edlabel/Makefile:1.1
--- /dev/null	Wed Mar 10 23:16:16 2010
+++ src/distrib/utils/edlabel/Makefile	Wed Mar 10 23:16:16 2010
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile,v 1.1 2010/03/10 23:16:16 abs Exp $
+# edlabel (Edit Disk LABEL)
+
+NOMAN=	# defined
+
+PROG=	edlabel
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
+.include bsd.prog.mk
Index: src/distrib/utils/edlabel/edlabel.c
diff -u /dev/null src/distrib/utils/edlabel/edlabel.c:1.1
--- /dev/null	Wed Mar 10 23:16:16 2010
+++ src/distrib/utils/edlabel/edlabel.c	Wed Mar 10 23:16:16 2010
@@ -0,0 +1,535 @@
+/*	$NetBSD: edlabel.c,v 1.1 2010/03/10 23:16:16 abs Exp $	*/
+
+/*
+ * Copyright (c) 1995 Gordon W. Ross
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+#include sys/types.h
+#include sys/param.h
+#include sys/ioctl.h
+#define FSTYPENAMES
+#include sys/disklabel.h
+
+#include fcntl.h
+#include stdio.h
+#include ctype.h
+#include string.h
+#include errno.h
+#include unistd.h
+#include util.h
+#include stdlib.h
+
+/*
+ * Machine dependent constants you want to retrieve only once...
+ */
+int rawpartition, maxpartitions;
+
+/*
+ * This is a data-driven program
+ */
+struct field {
+	const char *f_name;
+	int f_offset;
+	int f_type;	/* 1:char, 2:short, 4:int, 4:string */
+};
+
+/* Table describing fields in the head of a disklabel. */
+#define	dloff(f) (int)(((struct disklabel *)0)-f)
+struct field label_head[] = {
+  { type_num, dloff(d_type), 2 },
+  { sub_type, dloff(d_subtype), 2 },
+  {type_name, dloff(d_typename), 16 },
+  {pack_name, dloff(d_packname),  16 },
+  { bytes/sector, dloff(d_secsize), 4 },
+  {sectors/track, dloff(d_nsectors), 4 },
+  {  tracks/cylinder, dloff(d_ntracks),  4 },
+  {cylinders, dloff(d_ncylinders), 4 },
+  { sectors/cylinder, dloff(d_secpercyl), 4 },
+  /* Don't care about the others until later... */
+  { .f_name = NULL },
+};
+#undef dloff
+
+void	check_divisors(struct disklabel *);
+u_short	dkcksum(struct disklabel *);
+void	edit_geo(struct disklabel *);
+void	edit_head_all(struct disklabel *, int);
+void	edit_head_field(void *, struct field *, int);
+void	edit_partition(struct disklabel *, int, int);
+void	get_fstype(char *, u_int8_t *);
+void	get_val_cts(struct disklabel *, char *, u_int32_t *);
+void	label_modify(struct disklabel *, char *);
+void	label_print(struct disklabel *, char *);
+void	label_quit(struct disklabel *, char *);
+void	label_read(struct disklabel *, char *);
+void	label_write(struct disklabel *, char *);
+void	menu(void);
+void	print_val_cts(struct disklabel *, u_long val);
+
+char	tmpbuf[64];
+
+void
+edit_head_field(void *v, struct field *f, int modify /* also modify */)
+{
+	u_int8_t  *cp;
+	u_int tmp;
+
+	cp = v;
+	cp += f-f_offset;
+
+	printf(%s: , f-f_name);
+
+	/* Print current value... */
+	switch (f-f_type) {
+	case 1:
+		tmp = *cp;
+		printf(%d, tmp);
+		break;
+	case 2:
+		tmp = *((u_int16_t *)cp);
+		printf(%d, tmp);
+		break;
+	case 4:
+		

CVS commit: src/distrib/utils/edlabel

2010-03-10 Thread David Brownlee
Module Name:src
Committed By:   abs
Date:   Wed Mar 10 23:16:16 UTC 2010

Added Files:
src/distrib/utils/edlabel: Makefile edlabel.c

Log Message:
Relegate edlabel to use in extremely memory constrained install
ramdisks and prefer disklabel elsewhere.
Based on discussion on affected port lists (port-sparc port-sparc64
port-sun3 port-sun2 port-atari port-mvme68k).
All listed ports plus amd64 test built after change


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/distrib/utils/edlabel/Makefile \
src/distrib/utils/edlabel/edlabel.c

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