Add a "I know it points to my foot!" -f option.
PR: 3288 Reviewed by: phk Submitted by: Martin Kammerhofer <dada@freepass.tu-graz.ac.at>
This commit is contained in:
parent
0d150bcf0b
commit
f8bb3e895f
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id$
|
||||
* $Id: write_mfs_in_kernel.c,v 1.3 1997/02/22 14:10:31 peter Exp $
|
||||
*
|
||||
* This program patches a filesystem into a kernel made with MFS_ROOT
|
||||
* option.
|
||||
@ -21,17 +21,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 +67,17 @@ main(int argc, char **argv)
|
||||
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 +85,12 @@ main(int argc, char **argv)
|
||||
(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!
|
||||
*
|
||||
*/
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id$
|
||||
* $Id: write_mfs_in_kernel.c,v 1.3 1997/02/22 14:10:31 peter Exp $
|
||||
*
|
||||
* This program patches a filesystem into a kernel made with MFS_ROOT
|
||||
* option.
|
||||
@ -21,17 +21,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 +67,17 @@ main(int argc, char **argv)
|
||||
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 +85,12 @@ main(int argc, char **argv)
|
||||
(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!
|
||||
*
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user