mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-20 00:33:57 +00:00
Add rcsid. Remove unused #includes. Use err(3) and check spelling. Reorganize
man page.
This commit is contained in:
parent
750f6fe391
commit
61d20ca30f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37278
|
@ -1,40 +1,31 @@
|
||||||
.\" $Id: nextboot.8,v 1.6 1997/02/22 14:32:31 peter Exp $
|
.\" $Id: nextboot.8,v 1.7 1997/04/23 04:46:38 danny Exp $
|
||||||
.Dd July 9, 1996
|
.Dd July 9, 1996
|
||||||
.Dt NEXTBOOT 8
|
.Dt NEXTBOOT 8
|
||||||
.\".Os BSD 4
|
.\".Os BSD 4
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm nextboot
|
.Nm nextboot
|
||||||
.Nd Install a default bootstring block on the boot disk
|
.Nd install a default bootstring block on the boot disk
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm nextboot
|
||||||
.Op Fl b
|
.Op Fl b
|
||||||
.Ar filename bootstring ...
|
.Ar filename bootstring
|
||||||
.Pp
|
.Ar
|
||||||
.Nm
|
.Nm nextboot
|
||||||
.Op Fl ed
|
.Op Fl ed
|
||||||
.Ar filename
|
.Ar filename
|
||||||
.Bl -tag -width time
|
.Sh DESCRIPTION
|
||||||
.It Fl b
|
The
|
||||||
Is used for bootstrapping (initially configuring) the nameblock. Without
|
.Bx Free
|
||||||
this,
|
program
|
||||||
.Nm
|
|
||||||
will refuse to write to a block that does not already contain the magic
|
|
||||||
number.
|
|
||||||
.It Fl d
|
|
||||||
temporarily disables an existing name block by changing a bit
|
|
||||||
in the magic number.
|
|
||||||
.It Fl e
|
|
||||||
restores the good magic number on a block disabled by -d.
|
|
||||||
.El
|
|
||||||
.Sh PROLOGUE
|
|
||||||
The FreeBSD program
|
|
||||||
.Nm
|
.Nm
|
||||||
controls the actions of the boot blocks at the time of the next boot.
|
controls the actions of the boot blocks at the time of the next boot.
|
||||||
If compiled with the correct option,
|
If compiled with the correct option,
|
||||||
the boot blocks will check the nameblock for a magic number and a
|
the boot blocks will check the nameblock for a magic number and a
|
||||||
default name to use for booting. If compiled to do so they will also
|
default name to use for booting. If compiled to do so they will also
|
||||||
delete the name from the block, ensuring that if the boot should fail,
|
delete the name from the block, ensuring that if the boot should fail,
|
||||||
then it will not be tried again. It is the job of /etc/rc to use
|
then it will not be tried again. It is the job of
|
||||||
|
.Pa /etc/rc
|
||||||
|
to use
|
||||||
.Nm
|
.Nm
|
||||||
to re-install the string if that boot is found to have succeeded.
|
to re-install the string if that boot is found to have succeeded.
|
||||||
This allows a one-time only boot string to be used for such applications
|
This allows a one-time only boot string to be used for such applications
|
||||||
|
@ -42,8 +33,29 @@ as remote debugging, and installation of new, untrusted kernels.
|
||||||
The nameblock is defined at compile time to be the second physical block
|
The nameblock is defined at compile time to be the second physical block
|
||||||
on the disk.
|
on the disk.
|
||||||
.Pp
|
.Pp
|
||||||
.Sh DESCRIPTION
|
The following options are available:
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl b
|
||||||
|
Is used for bootstrapping (initially configuring) the nameblock. Without
|
||||||
|
this,
|
||||||
.Nm
|
.Nm
|
||||||
|
will refuse to write to a block that does not already contain the magic
|
||||||
|
number.
|
||||||
|
.It Fl d
|
||||||
|
Disable (temporarily) an existing name block by changing a bit
|
||||||
|
in the magic number.
|
||||||
|
.It Fl e
|
||||||
|
Restore the good magic number on a block disabled by
|
||||||
|
.Fl d .
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fl e
|
||||||
|
and
|
||||||
|
.Fl d
|
||||||
|
flags are mutually exclusive.
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm Nextboot
|
||||||
first checks that the disk has an fdisk table and checks that none of the
|
first checks that the disk has an fdisk table and checks that none of the
|
||||||
partitions defined in that table include the nameblock. If the name block is
|
partitions defined in that table include the nameblock. If the name block is
|
||||||
shown to be unused, it will install the bootstrings given as arguments,
|
shown to be unused, it will install the bootstrings given as arguments,
|
||||||
|
@ -61,18 +73,20 @@ An example of usage might be:
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Which would instruct the boot blocks at the next boot,
|
Which would instruct the boot blocks at the next boot,
|
||||||
to try boot the experimental kernel off the scsi disk.
|
to try boot the experimental kernel off the SCSI disk.
|
||||||
If for any reason this failed, the next boot attempt would
|
If for any reason this failed, the next boot attempt would
|
||||||
boot the kernel
|
boot the kernel
|
||||||
.Em /kernel.old
|
.Pa /kernel.old
|
||||||
off the IDE drive. (assuming the write-back option were enabled) If this
|
off the IDE drive. (Assuming the write-back option were enabled) If this
|
||||||
in turn failed. the compiled in default would be used.
|
in turn failed. The compiled in default would be used.
|
||||||
.Pp
|
.Pp
|
||||||
If the write-back feature is disabled, the nextboot program is a convenient way
|
If the write-back feature is disabled, the nextboot program is a convenient way
|
||||||
to change the default boot string. Note, that should the file specified in
|
to change the default boot string. Note, that should the file specified in
|
||||||
the nameblock be non-existent, then the name compiled into the boot blocks
|
the nameblock be non-existent, then the name compiled into the boot blocks
|
||||||
will be used for the boot rather than the next name in the nameblock. The
|
will be used for the boot rather than the next name in the nameblock. The
|
||||||
nameblock is only consulted ONCE per boot.
|
nameblock is only consulted
|
||||||
|
.Em once
|
||||||
|
per boot.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr boot 8 ,
|
.Xr boot 8 ,
|
||||||
.Xr disklabel 8 ,
|
.Xr disklabel 8 ,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996 Whistle Communications
|
* Copyright (c) 1996 Whistle Communications
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
|
@ -14,22 +13,22 @@
|
||||||
* any damages whatsoever resulting from the use of this software.
|
* any damages whatsoever resulting from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/disklabel.h>
|
#include <sys/disklabel.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct mboot
|
struct mboot
|
||||||
{
|
{
|
||||||
unsigned char padding[2]; /* force the longs to be long alligned */
|
unsigned char padding[2]; /* force the longs to be long aligned */
|
||||||
unsigned char bootinst[DOSPARTOFF];
|
unsigned char bootinst[DOSPARTOFF];
|
||||||
struct dos_partition parts[4];
|
struct dos_partition parts[4];
|
||||||
unsigned short int signature;
|
unsigned short int signature;
|
||||||
|
@ -43,20 +42,18 @@ struct mboot mboot;
|
||||||
static int bflag;
|
static int bflag;
|
||||||
static int eflag;
|
static int eflag;
|
||||||
static int dflag;
|
static int dflag;
|
||||||
static int nameblock = NAMEBLOCK;
|
|
||||||
|
|
||||||
#define BOOT_MAGIC 0xAA55
|
#define BOOT_MAGIC 0xAA55
|
||||||
|
|
||||||
extern char *__progname;
|
static void
|
||||||
|
usage(void) {
|
||||||
static void usage(void) {
|
fprintf (stderr, "%s\n%s\n",
|
||||||
fprintf (stderr, " usage: %s [-b] device bootstring [bootstring] ...\n"
|
"usage: nextboot [-b] device bootstring [bootstring] ...",
|
||||||
, __progname);
|
" nextboot {-e,-d} device");
|
||||||
fprintf (stderr, " or: %s {-e,-d} device \n" , __progname);
|
|
||||||
fprintf (stderr, "The -e and -d flags are mutually exclusive\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
main (int argc, char** argv)
|
main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
@ -97,11 +94,8 @@ main (int argc, char** argv)
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((fd = open(argv[0], O_RDWR, 0)) < 0) {
|
if ((fd = open(argv[0], O_RDWR, 0)) < 0)
|
||||||
perror("open");
|
errx(1, "can't open %s", argv[0]);
|
||||||
printf ("file: %s\n",argv[0]);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
@ -109,18 +103,12 @@ main (int argc, char** argv)
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* Check that we have an MBR
|
* Check that we have an MBR
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,0,0) == -1) {
|
if (lseek(fd,0,0) == -1)
|
||||||
perror("lseek");
|
err(1, "lseek");
|
||||||
exit(1);
|
if (read (fd,&mboot.bootinst[0],BLOCKSIZE ) != BLOCKSIZE)
|
||||||
}
|
err(1, "read0");
|
||||||
if (read (fd,&mboot.bootinst[0],BLOCKSIZE ) != BLOCKSIZE) {
|
if (mboot.signature != (unsigned short)BOOT_MAGIC)
|
||||||
perror("read0");
|
errx(1, "no fdisk part.. not touching block 1");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if(mboot.signature != (unsigned short)BOOT_MAGIC) {
|
|
||||||
printf(" no fdisk part.. not touching block 1\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* And check that none of the partitions in it cover the name block;
|
* And check that none of the partitions in it cover the name block;
|
||||||
|
@ -129,28 +117,22 @@ main (int argc, char** argv)
|
||||||
if( mboot.parts[part].dp_size
|
if( mboot.parts[part].dp_size
|
||||||
&& (mboot.parts[part].dp_start <= NAMEBLOCK)
|
&& (mboot.parts[part].dp_start <= NAMEBLOCK)
|
||||||
&& (mboot.parts[part].dp_start
|
&& (mboot.parts[part].dp_start
|
||||||
+ mboot.parts[part].dp_size > NAMEBLOCK)) {
|
+ mboot.parts[part].dp_size > NAMEBLOCK))
|
||||||
printf(" Name sector lies within a Bios partition.\n");
|
errx(1,
|
||||||
printf(" Aborting write.\n");
|
"name sector lies within a Bios partition: aborting write");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* Now check the name sector itself to see if it's been initialised.
|
* Now check the name sector itself to see if it's been initialized.
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1) {
|
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
|
||||||
perror("lseek");
|
err(1, "lseek");
|
||||||
exit(1);
|
if (read(fd,namebuf,BLOCKSIZE) != BLOCKSIZE)
|
||||||
}
|
err(1, "read1");
|
||||||
if ( read (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE) {
|
|
||||||
perror("read1");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* check if we are just enabling or disabling
|
* check if we are just enabling or disabling
|
||||||
* Remember the flags are exlusive..
|
* Remember the flags are exclusive..
|
||||||
*/
|
*/
|
||||||
if(!bflag) { /* don't care what's there if bflag is set */
|
if(!bflag) { /* don't care what's there if bflag is set */
|
||||||
switch(*(unsigned long *)cp)
|
switch(*(unsigned long *)cp)
|
||||||
|
@ -159,10 +141,7 @@ main (int argc, char** argv)
|
||||||
case ENABLE_MAGIC:
|
case ENABLE_MAGIC:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,
|
errx(1, "namesector not initialized, use the -b flag");
|
||||||
"namesector not initialised.."
|
|
||||||
"use the -b flag..\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,24 +178,18 @@ main (int argc, char** argv)
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* write it to disk.
|
* write it to disk.
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1) {
|
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
|
||||||
perror("lseek");
|
err(1, "lseek");
|
||||||
exit(1);
|
if(write (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE)
|
||||||
}
|
err(1, "write");
|
||||||
if(write (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE) {
|
|
||||||
perror("write");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* just to be safe/paranoid.. read it back..
|
* just to be safe/paranoid.. read it back..
|
||||||
* and print it..
|
* and print it..
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1) {
|
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
|
||||||
perror("lseek (second) ");
|
err(1, "lseek (second)");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
read (fd,namebuf,512);
|
read (fd,namebuf,512);
|
||||||
for (i = 0;i< 16;i++) {
|
for (i = 0;i< 16;i++) {
|
||||||
for ( j = 0; j < 16; j++) {
|
for ( j = 0; j < 16; j++) {
|
||||||
|
@ -227,5 +200,3 @@ main (int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,40 +1,31 @@
|
||||||
.\" $Id: nextboot.8,v 1.6 1997/02/22 14:32:31 peter Exp $
|
.\" $Id: nextboot.8,v 1.7 1997/04/23 04:46:38 danny Exp $
|
||||||
.Dd July 9, 1996
|
.Dd July 9, 1996
|
||||||
.Dt NEXTBOOT 8
|
.Dt NEXTBOOT 8
|
||||||
.\".Os BSD 4
|
.\".Os BSD 4
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm nextboot
|
.Nm nextboot
|
||||||
.Nd Install a default bootstring block on the boot disk
|
.Nd install a default bootstring block on the boot disk
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm nextboot
|
||||||
.Op Fl b
|
.Op Fl b
|
||||||
.Ar filename bootstring ...
|
.Ar filename bootstring
|
||||||
.Pp
|
.Ar
|
||||||
.Nm
|
.Nm nextboot
|
||||||
.Op Fl ed
|
.Op Fl ed
|
||||||
.Ar filename
|
.Ar filename
|
||||||
.Bl -tag -width time
|
.Sh DESCRIPTION
|
||||||
.It Fl b
|
The
|
||||||
Is used for bootstrapping (initially configuring) the nameblock. Without
|
.Bx Free
|
||||||
this,
|
program
|
||||||
.Nm
|
|
||||||
will refuse to write to a block that does not already contain the magic
|
|
||||||
number.
|
|
||||||
.It Fl d
|
|
||||||
temporarily disables an existing name block by changing a bit
|
|
||||||
in the magic number.
|
|
||||||
.It Fl e
|
|
||||||
restores the good magic number on a block disabled by -d.
|
|
||||||
.El
|
|
||||||
.Sh PROLOGUE
|
|
||||||
The FreeBSD program
|
|
||||||
.Nm
|
.Nm
|
||||||
controls the actions of the boot blocks at the time of the next boot.
|
controls the actions of the boot blocks at the time of the next boot.
|
||||||
If compiled with the correct option,
|
If compiled with the correct option,
|
||||||
the boot blocks will check the nameblock for a magic number and a
|
the boot blocks will check the nameblock for a magic number and a
|
||||||
default name to use for booting. If compiled to do so they will also
|
default name to use for booting. If compiled to do so they will also
|
||||||
delete the name from the block, ensuring that if the boot should fail,
|
delete the name from the block, ensuring that if the boot should fail,
|
||||||
then it will not be tried again. It is the job of /etc/rc to use
|
then it will not be tried again. It is the job of
|
||||||
|
.Pa /etc/rc
|
||||||
|
to use
|
||||||
.Nm
|
.Nm
|
||||||
to re-install the string if that boot is found to have succeeded.
|
to re-install the string if that boot is found to have succeeded.
|
||||||
This allows a one-time only boot string to be used for such applications
|
This allows a one-time only boot string to be used for such applications
|
||||||
|
@ -42,8 +33,29 @@ as remote debugging, and installation of new, untrusted kernels.
|
||||||
The nameblock is defined at compile time to be the second physical block
|
The nameblock is defined at compile time to be the second physical block
|
||||||
on the disk.
|
on the disk.
|
||||||
.Pp
|
.Pp
|
||||||
.Sh DESCRIPTION
|
The following options are available:
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl b
|
||||||
|
Is used for bootstrapping (initially configuring) the nameblock. Without
|
||||||
|
this,
|
||||||
.Nm
|
.Nm
|
||||||
|
will refuse to write to a block that does not already contain the magic
|
||||||
|
number.
|
||||||
|
.It Fl d
|
||||||
|
Disable (temporarily) an existing name block by changing a bit
|
||||||
|
in the magic number.
|
||||||
|
.It Fl e
|
||||||
|
Restore the good magic number on a block disabled by
|
||||||
|
.Fl d .
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fl e
|
||||||
|
and
|
||||||
|
.Fl d
|
||||||
|
flags are mutually exclusive.
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm Nextboot
|
||||||
first checks that the disk has an fdisk table and checks that none of the
|
first checks that the disk has an fdisk table and checks that none of the
|
||||||
partitions defined in that table include the nameblock. If the name block is
|
partitions defined in that table include the nameblock. If the name block is
|
||||||
shown to be unused, it will install the bootstrings given as arguments,
|
shown to be unused, it will install the bootstrings given as arguments,
|
||||||
|
@ -61,18 +73,20 @@ An example of usage might be:
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Which would instruct the boot blocks at the next boot,
|
Which would instruct the boot blocks at the next boot,
|
||||||
to try boot the experimental kernel off the scsi disk.
|
to try boot the experimental kernel off the SCSI disk.
|
||||||
If for any reason this failed, the next boot attempt would
|
If for any reason this failed, the next boot attempt would
|
||||||
boot the kernel
|
boot the kernel
|
||||||
.Em /kernel.old
|
.Pa /kernel.old
|
||||||
off the IDE drive. (assuming the write-back option were enabled) If this
|
off the IDE drive. (Assuming the write-back option were enabled) If this
|
||||||
in turn failed. the compiled in default would be used.
|
in turn failed. The compiled in default would be used.
|
||||||
.Pp
|
.Pp
|
||||||
If the write-back feature is disabled, the nextboot program is a convenient way
|
If the write-back feature is disabled, the nextboot program is a convenient way
|
||||||
to change the default boot string. Note, that should the file specified in
|
to change the default boot string. Note, that should the file specified in
|
||||||
the nameblock be non-existent, then the name compiled into the boot blocks
|
the nameblock be non-existent, then the name compiled into the boot blocks
|
||||||
will be used for the boot rather than the next name in the nameblock. The
|
will be used for the boot rather than the next name in the nameblock. The
|
||||||
nameblock is only consulted ONCE per boot.
|
nameblock is only consulted
|
||||||
|
.Em once
|
||||||
|
per boot.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr boot 8 ,
|
.Xr boot 8 ,
|
||||||
.Xr disklabel 8 ,
|
.Xr disklabel 8 ,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996 Whistle Communications
|
* Copyright (c) 1996 Whistle Communications
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
|
@ -14,22 +13,22 @@
|
||||||
* any damages whatsoever resulting from the use of this software.
|
* any damages whatsoever resulting from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/disklabel.h>
|
#include <sys/disklabel.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct mboot
|
struct mboot
|
||||||
{
|
{
|
||||||
unsigned char padding[2]; /* force the longs to be long alligned */
|
unsigned char padding[2]; /* force the longs to be long aligned */
|
||||||
unsigned char bootinst[DOSPARTOFF];
|
unsigned char bootinst[DOSPARTOFF];
|
||||||
struct dos_partition parts[4];
|
struct dos_partition parts[4];
|
||||||
unsigned short int signature;
|
unsigned short int signature;
|
||||||
|
@ -43,20 +42,18 @@ struct mboot mboot;
|
||||||
static int bflag;
|
static int bflag;
|
||||||
static int eflag;
|
static int eflag;
|
||||||
static int dflag;
|
static int dflag;
|
||||||
static int nameblock = NAMEBLOCK;
|
|
||||||
|
|
||||||
#define BOOT_MAGIC 0xAA55
|
#define BOOT_MAGIC 0xAA55
|
||||||
|
|
||||||
extern char *__progname;
|
static void
|
||||||
|
usage(void) {
|
||||||
static void usage(void) {
|
fprintf (stderr, "%s\n%s\n",
|
||||||
fprintf (stderr, " usage: %s [-b] device bootstring [bootstring] ...\n"
|
"usage: nextboot [-b] device bootstring [bootstring] ...",
|
||||||
, __progname);
|
" nextboot {-e,-d} device");
|
||||||
fprintf (stderr, " or: %s {-e,-d} device \n" , __progname);
|
|
||||||
fprintf (stderr, "The -e and -d flags are mutually exclusive\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
main (int argc, char** argv)
|
main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
@ -97,11 +94,8 @@ main (int argc, char** argv)
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((fd = open(argv[0], O_RDWR, 0)) < 0) {
|
if ((fd = open(argv[0], O_RDWR, 0)) < 0)
|
||||||
perror("open");
|
errx(1, "can't open %s", argv[0]);
|
||||||
printf ("file: %s\n",argv[0]);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
@ -109,18 +103,12 @@ main (int argc, char** argv)
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* Check that we have an MBR
|
* Check that we have an MBR
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,0,0) == -1) {
|
if (lseek(fd,0,0) == -1)
|
||||||
perror("lseek");
|
err(1, "lseek");
|
||||||
exit(1);
|
if (read (fd,&mboot.bootinst[0],BLOCKSIZE ) != BLOCKSIZE)
|
||||||
}
|
err(1, "read0");
|
||||||
if (read (fd,&mboot.bootinst[0],BLOCKSIZE ) != BLOCKSIZE) {
|
if (mboot.signature != (unsigned short)BOOT_MAGIC)
|
||||||
perror("read0");
|
errx(1, "no fdisk part.. not touching block 1");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if(mboot.signature != (unsigned short)BOOT_MAGIC) {
|
|
||||||
printf(" no fdisk part.. not touching block 1\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* And check that none of the partitions in it cover the name block;
|
* And check that none of the partitions in it cover the name block;
|
||||||
|
@ -129,28 +117,22 @@ main (int argc, char** argv)
|
||||||
if( mboot.parts[part].dp_size
|
if( mboot.parts[part].dp_size
|
||||||
&& (mboot.parts[part].dp_start <= NAMEBLOCK)
|
&& (mboot.parts[part].dp_start <= NAMEBLOCK)
|
||||||
&& (mboot.parts[part].dp_start
|
&& (mboot.parts[part].dp_start
|
||||||
+ mboot.parts[part].dp_size > NAMEBLOCK)) {
|
+ mboot.parts[part].dp_size > NAMEBLOCK))
|
||||||
printf(" Name sector lies within a Bios partition.\n");
|
errx(1,
|
||||||
printf(" Aborting write.\n");
|
"name sector lies within a Bios partition: aborting write");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* Now check the name sector itself to see if it's been initialised.
|
* Now check the name sector itself to see if it's been initialized.
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1) {
|
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
|
||||||
perror("lseek");
|
err(1, "lseek");
|
||||||
exit(1);
|
if (read(fd,namebuf,BLOCKSIZE) != BLOCKSIZE)
|
||||||
}
|
err(1, "read1");
|
||||||
if ( read (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE) {
|
|
||||||
perror("read1");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* check if we are just enabling or disabling
|
* check if we are just enabling or disabling
|
||||||
* Remember the flags are exlusive..
|
* Remember the flags are exclusive..
|
||||||
*/
|
*/
|
||||||
if(!bflag) { /* don't care what's there if bflag is set */
|
if(!bflag) { /* don't care what's there if bflag is set */
|
||||||
switch(*(unsigned long *)cp)
|
switch(*(unsigned long *)cp)
|
||||||
|
@ -159,10 +141,7 @@ main (int argc, char** argv)
|
||||||
case ENABLE_MAGIC:
|
case ENABLE_MAGIC:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,
|
errx(1, "namesector not initialized, use the -b flag");
|
||||||
"namesector not initialised.."
|
|
||||||
"use the -b flag..\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,24 +178,18 @@ main (int argc, char** argv)
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* write it to disk.
|
* write it to disk.
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1) {
|
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
|
||||||
perror("lseek");
|
err(1, "lseek");
|
||||||
exit(1);
|
if(write (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE)
|
||||||
}
|
err(1, "write");
|
||||||
if(write (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE) {
|
|
||||||
perror("write");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* just to be safe/paranoid.. read it back..
|
* just to be safe/paranoid.. read it back..
|
||||||
* and print it..
|
* and print it..
|
||||||
*/
|
*/
|
||||||
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1) {
|
if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
|
||||||
perror("lseek (second) ");
|
err(1, "lseek (second)");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
read (fd,namebuf,512);
|
read (fd,namebuf,512);
|
||||||
for (i = 0;i< 16;i++) {
|
for (i = 0;i< 16;i++) {
|
||||||
for ( j = 0; j < 16; j++) {
|
for ( j = 0; j < 16; j++) {
|
||||||
|
@ -227,5 +200,3 @@ main (int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue