1994-10-18 07:56:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, Paul Richards.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software may be used, modified, copied, distributed, and
|
|
|
|
* sold, in both source and binary form provided that the above
|
|
|
|
* copyright and these terms are retained, verbatim, as the first
|
|
|
|
* lines of this file. Under no circumstances is the author
|
|
|
|
* responsible for the proper functioning of this software, nor does
|
|
|
|
* the author assume any responsibility for damages incurred with
|
|
|
|
* its use.
|
|
|
|
*/
|
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
#include <fstab.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dialog.h>
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-10-18 07:56:34 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/uio.h>
|
1994-11-18 18:13:13 +00:00
|
|
|
#include <ufs/ffs/fs.h>
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
#include "disk.h"
|
1994-10-18 07:56:34 +00:00
|
|
|
#include "sysinstall.h"
|
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
char boot1[] = BOOT1;
|
|
|
|
char boot2[] = BOOT2;
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
int
|
1994-10-18 07:56:34 +00:00
|
|
|
enable_label(int fd)
|
1994-10-19 23:58:03 +00:00
|
|
|
{
|
1994-10-18 07:56:34 +00:00
|
|
|
int flag = 1;
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
1994-11-18 18:13:13 +00:00
|
|
|
return (-1);
|
|
|
|
return (0);
|
1994-10-18 07:56:34 +00:00
|
|
|
}
|
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
int
|
1994-10-18 07:56:34 +00:00
|
|
|
disable_label(int fd)
|
1994-10-19 23:58:03 +00:00
|
|
|
{
|
1994-10-18 07:56:34 +00:00
|
|
|
int flag = 0;
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
1994-11-18 18:13:13 +00:00
|
|
|
return (-1);
|
|
|
|
return (0);
|
1994-10-18 07:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-11-18 18:13:13 +00:00
|
|
|
write_bootblocks(int disk)
|
1994-10-18 07:56:34 +00:00
|
|
|
{
|
1994-11-18 18:13:13 +00:00
|
|
|
int fd;
|
|
|
|
off_t offset;
|
|
|
|
int part = disk_list[disk].inst_part;
|
|
|
|
struct disklabel *lbl = &disk_list[disk].lbl;
|
|
|
|
unsigned char bootblocks[BBSIZE];
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Load MBR boot code */
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if ((fd = open(boot1, O_RDONLY)) == -1) {
|
|
|
|
sprintf(errmsg, "Couldn't open boot file %s for bootblocks\n%s\n",
|
|
|
|
boot1, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (read(fd, bootblocks, MBRSIZE) < 0) {
|
|
|
|
sprintf(errmsg, "Couldn't load boot file %s into bootblocks\n%s\n",
|
|
|
|
boot1, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (close(fd) == -1) {
|
|
|
|
sprintf(errmsg, "Couldn't close boot file %s\n%s\n", boot1,
|
|
|
|
strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Load second level boot code */
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if ((fd = open(boot2, O_RDONLY)) == -1) {
|
|
|
|
sprintf(errmsg, "Couldn't open boot file %s for bootblocks\n%s\n",
|
|
|
|
boot2, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(fd, &bootblocks[MBRSIZE], (int)(lbl->d_bbsize - MBRSIZE)) < 0) {
|
|
|
|
sprintf(errmsg, "Couldn't load boot file %s into bootblocks\n%s\n",
|
|
|
|
boot2, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (close(fd) == -1) {
|
|
|
|
sprintf(errmsg, "Couldn't close boot file %s\n%s\n", boot2,
|
|
|
|
strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Copy the current MBR table into the boot blocks */
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
bcopy(&disk_list[disk].mbr.dospart, &bootblocks[DOSPARTOFF],
|
|
|
|
sizeof(struct dos_partition) * NDOSPART);
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Set checksum */
|
|
|
|
lbl->d_checksum = 0;
|
|
|
|
lbl->d_checksum = dkcksum(lbl);
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Copy disklabel into bootblocks */
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
bcopy(lbl, &bootblocks[(LABELSECTOR * lbl->d_secsize) + LABELOFFSET],
|
|
|
|
sizeof *lbl);
|
1994-10-21 18:08:33 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Calculate offset to start of MBR partition we're installing to */
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
offset = disk_list[disk].mbr.dospart[part].dp_start;
|
|
|
|
offset *= lbl->d_secsize;
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
/* Write the boot blocks out to the raw disk */
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if ((fd = open(diskname(disk), O_RDWR)) == -1) {
|
|
|
|
sprintf(errmsg, "Couldn't open %s to write bootblocks\n%s\n",
|
|
|
|
scratch,strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
1994-10-21 18:26:25 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (lseek(fd, offset, SEEK_SET) < 0) {
|
|
|
|
sprintf(errmsg, "Couldn't seek to bootblocks area %s\n%s\n",
|
|
|
|
scratch, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
1994-10-19 23:58:03 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (enable_label(fd) == -1)
|
|
|
|
return (-1);
|
1994-10-19 23:58:03 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (write(fd, bootblocks, lbl->d_bbsize) != lbl->d_bbsize) {
|
|
|
|
sprintf(errmsg, "Failed to write out bootblocks to %s\n%s\n",
|
|
|
|
scratch, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
if (disable_label(fd) == -1)
|
|
|
|
return (-1);
|
1994-10-18 07:56:34 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
return(0);
|
1994-10-18 07:56:34 +00:00
|
|
|
}
|