Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Apr 1997 12:32:38 +0200
From:      Martin Kammerhofer <dada@freepass.tu-graz.ac.at>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/3288: addition of a -f (force) option to "write_mfs_in_kernel.c"
Message-ID:  <199704141032.MAA14186@freepass.tu-graz.ac.at>
Resent-Message-ID: <199704141040.DAA02758@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         3288
>Category:       kern
>Synopsis:       addition of a -f (force) option to "write_mfs_in_kernel.c"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 14 03:40:37 PDT 1997
>Last-Modified:
>Originator:     Martin Kammerhofer
>Organization:
Graz University of Technology
>Release:        FreeBSD 2.2.1-RELEASE i386
>Environment:

>Description:
	I4m a FreeBSD user who (inspired by the handbooks chapter
	FreeBSD internals/The FreeBSD Booting Process/Interesting combinations)
	made myself custom bootfloppies.
	During development the MFS inside the kernel changes frequently
	and therefore altered MFS-images are written into the development
	kernel.
	Unfortunately the (undocumented) utility write_mfs_in_kernel allows
	this only ONCE because there4s a check for all zeroes.
	My proposed patch eliminates the need to relink the kernel every time
	a (non-kernel) file is changed and therefore saves a lot of time.

>How-To-Repeat:

	

>Fix:
Index: write_mfs_in_kernel.c 
--- /usr/src/release/write_mfs_in_kernel.c	Tue Apr 25 05:45:18 1995
+++ mfs2kernel.c	Thu Jan 16 16:29:58 1997
@@ -21,17 +22,33 @@
 #include <sys/stat.h>
 #include <ufs/ffs/fs.h>
 
+static int force = 0;	/* don't check for zeros, may corrupt kernel */
+
+int
 main(int argc, char **argv)
 {
-	unsigned char *buf_kernel, *buf_fs, *p,*q;
-	int fd_kernel, fd_fs;
+	unsigned char *buf_kernel, *buf_fs, *p,*q, *prog;
+	int fd_kernel, fd_fs, ch, errs=0;
 	struct stat st_kernel, st_fs;
 	u_long l;
 
-	if (argc < 3) {
-		fprintf(stderr,"Usage:\n\t%s kernel fs\n");
+	prog= *argv;
+	while ((ch = getopt(argc, argv, "f")) != EOF)
+		switch(ch) {                                                       
+		case 'f':                                                          
+			force = 1 - force;
+			break;   
+		default:
+			errs++;
+		}
+	argc -= optind;
+	argv += optind;
+
+	if (errs || argc != 2) {
+		fprintf(stderr,"Usage:\n\t%s [-f] kernel fs\n", prog);
 		exit(2);
 	}
+	--argv;	/* original prog did not use getopt(3) */
 	fd_kernel = open(argv[1],O_RDWR);
 	if (fd_kernel < 0) { perror(argv[1]); exit(2); }
 	fstat(fd_kernel,&st_kernel);
@@ -51,16 +68,17 @@
 			goto found;
 	fprintf(stderr,"MFS filesystem signature not found in %s\n",argv[1]);
 	exit(1);
-    found:
-	for(l=0,q= p + SBOFF; l < st_fs.st_size - SBOFF ; l++,q++ )
-		if (*q)
-			goto fail;
+found:
+	if (!force)
+		for(l=0,q= p + SBOFF; l < st_fs.st_size - SBOFF ; l++,q++ )
+			if (*q)
+				goto fail;
 	memcpy(p+SBOFF,buf_fs+SBOFF,st_fs.st_size-SBOFF);
 	lseek(fd_kernel,0L,SEEK_SET);
 	if (st_kernel.st_size != write(fd_kernel,buf_kernel,st_kernel.st_size))
 		{ perror(argv[1]); exit(2); }
 	exit(0);
-    fail:
+fail:
 	l += SBOFF;
 	fprintf(stderr,"Obstruction in kernel after %ld bytes (%ld Kbyte)\n",
 		l, l/1024);
@@ -68,3 +86,12 @@
 		(u_long)st_fs.st_size, (u_long)st_fs.st_size/1024);
 	exit(1);
 }
+
+/*
+ * I added a '-f' option to force writing the image into the kernel, even when
+ * there is already data (i.e. not zero) in the written area. This is useful
+ * to rewrite a changed MFS-image. Beware: If the written image is larger than
+ * the space reserved in the kernel (with option MFS_ROOT) then
+ * THIS WILL CORRUPT THE KERNEL!
+ * */
>Audit-Trail:
>Unformatted:



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