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
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
1994-10-21 04:43:07 +00:00
|
|
|
* $Id: utils.c,v 1.5 1994/10/21 02:14:54 phk 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>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
1994-10-20 02:51:55 +00:00
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
TellEm(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
dialog_msgbox("Progress", p, 3, 75, 0);
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Fatal(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
1994-10-21 02:14:54 +00:00
|
|
|
int i = errno;
|
1994-10-20 05:00:00 +00:00
|
|
|
va_list ap;
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
1994-10-21 02:14:54 +00:00
|
|
|
sprintf(p+strlen(p),"\nErrno= %d, %s.",i,strerror(i));
|
1994-10-21 04:43:07 +00:00
|
|
|
if (dialog_active) {
|
|
|
|
dialog_msgbox("Fatal", p, 12, 75, 1);
|
|
|
|
end_dialog();
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "Fatal -- %s", p);
|
1994-10-20 05:00:00 +00:00
|
|
|
free(p);
|
|
|
|
exit(7);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
AskAbort(char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
p = Malloc(2048);
|
|
|
|
va_start(ap,fmt);
|
|
|
|
vsnprintf(p, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
i = dialog_yesno("Abort", p, 12, 75);
|
|
|
|
free(p);
|
|
|
|
return i;
|
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
|
|
|
|
MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
|
|
|
|
{
|
|
|
|
struct ufs_args ufsargs;
|
|
|
|
char dbuf[90];
|
|
|
|
char pbuf[90];
|
|
|
|
|
1994-10-20 06:48:40 +00:00
|
|
|
memset(&ufsargs,0,sizeof ufsargs);
|
|
|
|
|
1994-10-20 05:00:00 +00:00
|
|
|
if (prefix)
|
|
|
|
strcpy(pbuf,prefix);
|
|
|
|
else
|
|
|
|
strcpy(pbuf,"");
|
|
|
|
|
|
|
|
strcat(pbuf,mountpoint);
|
|
|
|
|
|
|
|
if(do_mkdir && access(pbuf,R_OK)) {
|
1994-10-21 02:14:54 +00:00
|
|
|
Mkdir(pbuf);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(dbuf,"/dev/");
|
|
|
|
strcat(dbuf,device);
|
|
|
|
|
|
|
|
TellEm("mount /dev/%s /mnt%s",dbuf,pbuf);
|
|
|
|
ufsargs.fspec = dbuf;
|
|
|
|
if (mount(MOUNT_UFS,pbuf, 0, (caddr_t) &ufsargs) == -1) {
|
|
|
|
Fatal("Error mounting %s on : %s\n",
|
|
|
|
dbuf, pbuf, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
1994-10-21 02:14:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Mkdir(char *path)
|
|
|
|
{
|
|
|
|
TellEm("mkdir %s",path);
|
|
|
|
if (mkdir(path, S_IRWXU) == -1) {
|
|
|
|
Fatal("Couldn't create directory %s: %s\n",
|
|
|
|
path,strerror(errno));
|
|
|
|
}
|
|
|
|
}
|