1994-10-20 02:51:55 +00:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
1995-02-13 06:52:16 +00:00
|
|
|
* $Id: utils.c,v 1.35 1995/01/14 10:31:29 jkh Exp $
|
1994-10-20 02:51:55 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
1994-10-20 02:51:55 +00:00
|
|
|
#include <dialog.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
1994-10-26 02:53:15 +00:00
|
|
|
#include <sys/file.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
1994-10-21 18:08:33 +00:00
|
|
|
#include <sys/reboot.h>
|
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
|
|
|
#include <sys/dkbad.h>
|
|
|
|
#include <sys/disklabel.h>
|
1994-10-20 02:51:55 +00:00
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
|
1994-11-02 07:34:01 +00:00
|
|
|
void
|
|
|
|
strip_trailing_newlines(char *p)
|
|
|
|
{
|
|
|
|
int len = strlen(p);
|
|
|
|
while (len > 0 && p[len-1] == '\n')
|
|
|
|
p[--len] = '\0';
|
|
|
|
}
|
|
|
|
|
1994-10-29 10:01:40 +00:00
|
|
|
void
|
|
|
|
Debug(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
write(debug_fd,"Debug <",7);
|
|
|
|
write(debug_fd,p,strlen(p));
|
|
|
|
write(debug_fd,">\n\r",3);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
1994-10-20 02:51:55 +00:00
|
|
|
void
|
|
|
|
TellEm(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
1994-11-02 07:34:01 +00:00
|
|
|
strip_trailing_newlines(p);
|
1994-10-29 10:01:40 +00:00
|
|
|
write(debug_fd,"Progress <",10);
|
|
|
|
write(debug_fd,p,strlen(p));
|
|
|
|
write(debug_fd,">\n\r",3);
|
1995-02-13 06:52:16 +00:00
|
|
|
if(!on_serial) {
|
|
|
|
dialog_clear_norefresh();
|
|
|
|
dialog_msgbox("Progress", p, -1, -1, 0);
|
|
|
|
}
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Fatal(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
1994-11-02 07:34:01 +00:00
|
|
|
strip_trailing_newlines(p);
|
1995-02-13 06:52:16 +00:00
|
|
|
if (dialog_active && !on_serial)
|
1994-11-17 14:12:38 +00:00
|
|
|
dialog_msgbox("Fatal", p, -1, -1, 1);
|
1994-10-22 02:37:24 +00:00
|
|
|
else
|
1994-11-02 07:34:01 +00:00
|
|
|
fprintf(stderr, "Fatal -- %s\n", p);
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
1994-10-21 18:08:33 +00:00
|
|
|
ExitSysinstall();
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
1994-10-21 18:08:33 +00:00
|
|
|
void
|
1994-10-20 05:00:00 +00:00
|
|
|
AskAbort(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
1994-12-27 23:26:59 +00:00
|
|
|
strcat(p, "\n\nDo you wish to abort the installation?");
|
1994-11-19 05:20:13 +00:00
|
|
|
if (!dialog_yesno("Abort", p, -1, -1)) {
|
|
|
|
dialog_clear_norefresh();
|
1994-10-21 18:08:33 +00:00
|
|
|
Abort();
|
1994-12-27 23:26:59 +00:00
|
|
|
}
|
|
|
|
dialog_clear();
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
1994-10-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Abort()
|
|
|
|
{
|
1994-12-27 23:26:59 +00:00
|
|
|
if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?",
|
1994-11-17 19:44:55 +00:00
|
|
|
-1, -1)) {
|
1994-10-21 18:08:33 +00:00
|
|
|
dialog_clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ExitSysinstall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ExitSysinstall()
|
|
|
|
{
|
1994-10-24 03:55:25 +00:00
|
|
|
if (dialog_active) {
|
|
|
|
clear();
|
|
|
|
dialog_update();
|
|
|
|
}
|
1994-10-21 18:08:33 +00:00
|
|
|
if (getpid() == 1) {
|
|
|
|
if (reboot(RB_AUTOBOOT) == -1)
|
|
|
|
if (dialog_active) {
|
1994-10-22 02:32:16 +00:00
|
|
|
clear();
|
1994-10-21 18:08:33 +00:00
|
|
|
dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button",
|
1994-11-17 19:44:55 +00:00
|
|
|
-1,-1,0);
|
1994-10-21 18:08:33 +00:00
|
|
|
} else
|
|
|
|
fprintf(stderr, "Can't reboot the machine -- hit the reset button");
|
|
|
|
while(1);
|
1994-10-22 02:32:16 +00:00
|
|
|
} else {
|
|
|
|
if (dialog_active) {
|
1994-10-22 02:35:09 +00:00
|
|
|
end_dialog();
|
1994-10-24 03:55:25 +00:00
|
|
|
dialog_active = 0;
|
1994-10-22 02:32:16 +00:00
|
|
|
}
|
1994-10-21 18:08:33 +00:00
|
|
|
exit(0);
|
1994-10-22 02:32:16 +00:00
|
|
|
}
|
1994-10-20 02:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
Malloc(size_t size)
|
|
|
|
{
|
|
|
|
void *p = malloc(size);
|
|
|
|
if (!p) {
|
|
|
|
exit(7); /* XXX longjmp bad */
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
1994-10-20 05:00:00 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
StrAlloc(char *str)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = (char *)Malloc(strlen(str) + 1);
|
|
|
|
strcpy(p,str);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-10-26 02:53:15 +00:00
|
|
|
MountUfs(char *device, char *mountpoint, int do_mkdir, int flags)
|
1994-10-20 05:00:00 +00:00
|
|
|
{
|
|
|
|
struct ufs_args ufsargs;
|
|
|
|
char dbuf[90];
|
|
|
|
|
1994-10-20 06:48:40 +00:00
|
|
|
memset(&ufsargs,0,sizeof ufsargs);
|
|
|
|
|
1994-10-26 02:53:15 +00:00
|
|
|
if(do_mkdir && access(mountpoint,R_OK)) {
|
1995-01-14 10:31:29 +00:00
|
|
|
Mkdir(mountpoint, TRUE);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(dbuf,"/dev/");
|
|
|
|
strcat(dbuf,device);
|
|
|
|
|
1994-10-26 02:53:15 +00:00
|
|
|
TellEm("mount %s %s",dbuf,mountpoint);
|
1994-10-20 05:00:00 +00:00
|
|
|
ufsargs.fspec = dbuf;
|
1994-10-26 02:53:15 +00:00
|
|
|
if (mount(MOUNT_UFS, mountpoint, flags, (caddr_t) &ufsargs) == -1) {
|
1994-10-21 18:08:33 +00:00
|
|
|
Fatal("Error mounting %s on %s : %s\n",
|
1994-10-26 02:53:15 +00:00
|
|
|
dbuf, mountpoint, strerror(errno));
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
1994-10-21 02:14:54 +00:00
|
|
|
|
|
|
|
void
|
1995-01-14 10:31:29 +00:00
|
|
|
Mkdir(char *ipath, int die)
|
1994-10-21 02:14:54 +00:00
|
|
|
{
|
1994-11-02 08:52:15 +00:00
|
|
|
struct stat sb;
|
|
|
|
int final=0;
|
1994-11-02 22:06:24 +00:00
|
|
|
char *p,*path=StrAlloc(ipath);
|
1994-11-02 08:52:15 +00:00
|
|
|
|
|
|
|
Debug("mkdir(%s)",path);
|
|
|
|
p = path;
|
|
|
|
if (p[0] == '/') /* Skip leading '/'. */
|
|
|
|
++p;
|
|
|
|
for (;!final; ++p) {
|
|
|
|
if (p[0] == '\0' || (p[0] == '/' && p[1] == '\0'))
|
|
|
|
final++;
|
|
|
|
else if (p[0] != '/')
|
|
|
|
continue;
|
|
|
|
*p = '\0';
|
|
|
|
if (stat(path, &sb)) {
|
1995-01-14 10:31:29 +00:00
|
|
|
if (errno != ENOENT && die)
|
1994-11-02 08:52:15 +00:00
|
|
|
Fatal("Couldn't stat directory %s: %s\n",
|
|
|
|
path,strerror(errno));
|
|
|
|
Debug("mkdir(%s..)",path);
|
1995-01-14 10:31:29 +00:00
|
|
|
if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0 &&
|
|
|
|
die)
|
1994-11-02 08:52:15 +00:00
|
|
|
Fatal("Couldn't create directory %s: %s\n",
|
|
|
|
path,strerror(errno));
|
|
|
|
}
|
|
|
|
*p = '/';
|
1994-10-21 02:14:54 +00:00
|
|
|
}
|
1994-11-02 08:52:15 +00:00
|
|
|
free(path);
|
|
|
|
return;
|
1994-10-21 02:14:54 +00:00
|
|
|
}
|
1994-10-26 02:53:15 +00:00
|
|
|
|
1994-11-02 06:19:53 +00:00
|
|
|
void
|
|
|
|
Link(char *from, char *to)
|
|
|
|
{
|
|
|
|
TellEm("ln %s %s", from, to);
|
1994-12-27 23:26:59 +00:00
|
|
|
if(fixit)
|
|
|
|
unlink(to);
|
1994-11-02 06:19:53 +00:00
|
|
|
if (link(from, to) == -1)
|
|
|
|
Fatal("Couldn't create link: %s -> %s\n", from, to);
|
|
|
|
}
|
|
|
|
|
1994-10-26 02:53:15 +00:00
|
|
|
void
|
|
|
|
CopyFile(char *p1, char *p2)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
int fd1,fd2;
|
|
|
|
int i;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
TellEm("Copy %s to %s",p1,p2);
|
|
|
|
fd1 = open(p1,O_RDONLY);
|
|
|
|
if (fd1 < 0) Fatal("Couldn't open %s: %s\n",p1,strerror(errno));
|
|
|
|
fd2 = open(p2,O_TRUNC|O_CREAT|O_WRONLY,0200);
|
|
|
|
if (fd2 < 0) Fatal("Couldn't open %s: %s\n",p2,strerror(errno));
|
|
|
|
for(;;) {
|
|
|
|
i = read(fd1,buf,sizeof buf);
|
|
|
|
if (i > 0)
|
|
|
|
if (i != write(fd2,buf,i)) {
|
|
|
|
Fatal("Write errror on %s: %s\n",
|
|
|
|
p2,strerror(errno));
|
|
|
|
}
|
|
|
|
if (i != sizeof buf)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fstat(fd1,&st);
|
|
|
|
fchmod(fd2,st.st_mode & 07777);
|
|
|
|
fchown(fd2,st.st_uid,st.st_gid);
|
|
|
|
close(fd1);
|
|
|
|
close(fd2);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
u_long
|
|
|
|
PartMb(struct disklabel *lbl,int part)
|
|
|
|
{
|
|
|
|
u_long l;
|
|
|
|
l = 1024*1024/lbl->d_secsize;
|
|
|
|
return (lbl->d_partitions[part].p_size + l/2)/l;
|
|
|
|
}
|
1994-12-27 23:26:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CleanMount(int disk, int part)
|
|
|
|
{
|
|
|
|
int i = MP[disk][part];
|
|
|
|
Faction[i] = 0;
|
|
|
|
if (Fmount[i]) {
|
|
|
|
free(Fmount[i]);
|
|
|
|
Fmount[i] = 0;
|
|
|
|
}
|
|
|
|
if (Fname[i]) {
|
|
|
|
free(Fname[i]);
|
|
|
|
Fname[i] = 0;
|
|
|
|
}
|
|
|
|
if (Ftype[i]) {
|
|
|
|
free(Ftype[i]);
|
|
|
|
Ftype[i] = 0;
|
|
|
|
}
|
|
|
|
MP[disk][part] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
SetMount(int disk, int part, char *path)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
CleanMount(disk,part);
|
|
|
|
for (k = 1; k < MAX_NO_FS; k++)
|
|
|
|
if (!Fmount[k])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (k >= MAX_NO_FS)
|
|
|
|
return "Maximum number of filesystems exceeded";
|
|
|
|
|
|
|
|
Fmount[k] = StrAlloc(path);
|
|
|
|
sprintf(buf, "%s%c", Dname[disk], part + 'a');
|
|
|
|
Fname[k] = StrAlloc(buf);
|
|
|
|
switch (Dlbl[disk]->d_partitions[part].p_fstype) {
|
|
|
|
case FS_BSDFFS:
|
|
|
|
Ftype[k] = StrAlloc("ufs");
|
|
|
|
if(!fixit)
|
|
|
|
Faction[k] = 1;
|
|
|
|
break;
|
|
|
|
case FS_MSDOS:
|
|
|
|
Ftype[k] = StrAlloc("msdos");
|
|
|
|
Faction[k] = 0;
|
|
|
|
break;
|
|
|
|
case FS_SWAP:
|
|
|
|
Ftype[k] = StrAlloc("swap");
|
|
|
|
Faction[k] = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CleanMount(disk,part);
|
|
|
|
return "Unknown filesystem-type";
|
|
|
|
}
|
|
|
|
Fsize[k] = (Dlbl[disk]->d_partitions[part].p_size+1024)/2048;
|
|
|
|
|
|
|
|
MP[disk][part] = k;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
enable_label(int fd)
|
|
|
|
{
|
|
|
|
int flag = 1;
|
|
|
|
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
|
|
|
Fatal("ioctl(DIOCWLABEL,1) failed: %s",strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
disable_label(int fd)
|
|
|
|
{
|
|
|
|
int flag = 0;
|
|
|
|
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
|
|
|
Fatal("ioctl(DIOCWLABEL,0) failed: %s",strerror(errno));
|
|
|
|
}
|
|
|
|
|