From owner-freebsd-bugs Mon Apr 14 03:40:46 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id DAA02799 for bugs-outgoing; Mon, 14 Apr 1997 03:40:46 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id DAA02758; Mon, 14 Apr 1997 03:40:41 -0700 (PDT) Resent-Date: Mon, 14 Apr 1997 03:40:41 -0700 (PDT) Resent-Message-Id: <199704141040.DAA02758@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, dada@sbox.tu-graz.ac.at Received: from mail.crl.com (mail.crl.com [165.113.1.22]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id DAA02316 for ; Mon, 14 Apr 1997 03:36:29 -0700 (PDT) Received: from freepass.tu-graz.ac.at by mail.crl.com with SMTP id AA01137 (5.65c/IDA-1.5 for ); Mon, 14 Apr 1997 03:34:28 -0700 Received: (from dada@localhost) by freepass.tu-graz.ac.at (8.6.11/8.6.9) id MAA14186; Mon, 14 Apr 1997 12:32:38 +0200 Message-Id: <199704141032.MAA14186@freepass.tu-graz.ac.at> Date: Mon, 14 Apr 1997 12:32:38 +0200 From: Martin Kammerhofer Reply-To: dada@sbox.tu-graz.ac.at To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: kern/3288: addition of a -f (force) option to "write_mfs_in_kernel.c" Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >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 #include +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: