diff --git a/sbin/sysinstall/sysinstall.h b/sbin/sysinstall/sysinstall.h index cd199a40549a..1c769c8b9f22 100644 --- a/sbin/sysinstall/sysinstall.h +++ b/sbin/sysinstall/sysinstall.h @@ -1,138 +1,140 @@ /* * 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. */ #define TITLE "FreeBSD 2.0.1-Development Installation" #define BOOT1 "/stand/sdboot" #define BOOT2 "/stand/bootsd" #define MAX_NO_DISKS 10 #define MAX_NO_FS 30 #define MAXFS MAX_NO_FS #include #include #include #include #include #include #include #include #include #include #include #include #define SCRATCHSIZE 1024 #define ERRMSGSIZE 256 #define DEFROOTSIZE 18 #define DEFSWAPSIZE 16 #define DEFUSRSIZE 80 #define DEFFSIZE 1024 #define DEFFRAG 8 #define BOOT_MAGIC 0xAA55 #define ACTIVE 0x80 #define COPYRIGHT_FILE "/COPYRIGHT" #define README_FILE "/README" #ifndef EXTERN # define EXTERN extern #endif /* All this "disk" stuff */ EXTERN int Ndisk; EXTERN struct disklabel *Dlbl[MAX_NO_DISKS]; EXTERN char *Dname[MAX_NO_DISKS]; EXTERN int Dfd[MAX_NO_DISKS]; EXTERN int MP[MAX_NO_DISKS][MAXPARTITIONS]; /* All this "filesystem" stuff */ EXTERN int Nfs; EXTERN char *Fname[MAX_NO_FS+1]; EXTERN char *Fmount[MAX_NO_FS+1]; EXTERN char *Ftype[MAX_NO_FS+1]; EXTERN u_long Fsize[MAX_NO_FS+1]; EXTERN int dialog_active; EXTERN char selection[]; EXTERN int debug_fd; extern unsigned char **avail_disknames; extern int no_disks; extern int inst_disk; extern unsigned char *scratch; extern unsigned char *errmsg; extern int *avail_fds; extern unsigned char **avail_disknames; extern struct disklabel *avail_disklabels; extern u_short dkcksum(struct disklabel *); /* utils.c */ +int strheight __P((const char *p)); +int strwidth __P((const char *p)); void Abort __P((void)); void ExitSysinstall __P((void)); void TellEm __P((char *fmt, ...)); void Debug __P((char *fmt, ...)); void stage0 __P((void)); void *Malloc __P((size_t size)); char *StrAlloc __P((char *str)); void Fatal __P((char *fmt, ...)); void AskAbort __P((char *fmt, ...)); void MountUfs __P((char *device, char *mountpoint, int do_mkdir,int flags)); void Mkdir __P((char *path)); void Link __P((char *from, char *to)); void CopyFile __P((char *p1, char *p2)); u_long PartMb(struct disklabel *lbl,int part); /* exec.c */ int exec __P((int magic, char *cmd, char *args, ...)); #define EXEC_MAXARG 100 /* stage0.c */ void stage0 __P((void)); /* stage1.c */ void stage1 __P((void)); /* stage2.c */ void stage2 __P((void)); /* stage3.c */ void stage3 __P((void)); /* stage4.c */ void stage4 __P((void)); /* stage5.c */ void stage5 __P((void)); /* termcap.c */ int set_termcap __P((void)); /* makedevs.c */ int makedevs __P((void)); /* outcurses.c */ int edit_line __P((WINDOW *window, int y, int x, char *field, int width, int maxlen)); int AskEm __P((WINDOW *w,char *prompt, char *answer, int len)); /* bootarea.c */ void enable_label __P((int fd)); void disable_label __P((int fd)); int write_bootblocks __P((int fd, struct disklabel *lbl)); int build_bootblocks __P((int dfd,struct disklabel *label,struct dos_partition *dospart)); diff --git a/sbin/sysinstall/utils.c b/sbin/sysinstall/utils.c index fcaa871af2c2..b3a09e94519a 100644 --- a/sbin/sysinstall/utils.c +++ b/sbin/sysinstall/utils.c @@ -1,293 +1,291 @@ /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * 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 * ---------------------------------------------------------------------------- * - * $Id: utils.c,v 1.18 1994/11/02 08:52:15 phk Exp $ + * $Id: utils.c,v 1.19 1994/11/02 22:06:24 phk Exp $ * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "sysinstall.h" void strip_trailing_newlines(char *p) { int len = strlen(p); while (len > 0 && p[len-1] == '\n') p[--len] = '\0'; } -int strwidth(char *p) +int strwidth(const char *p) { int i = 0, len; - char *start, *s; + const char *start, *s; for (start = s = p; (s = strchr(s, '\n')) != NULL; start = ++s) { - *s = '\0'; - len = strlen(start); - *s = '\n'; + len = s - start; if (len > i) i = len; } len = strlen(start); if (len > i) i = len; return i; } -int strheight(char *p) +int strheight(const char *p) { int i = 1; - char *s; + const char *s; for (s = p; (s = strchr(s, '\n')) != NULL; s++) i++; return i; } 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); } void TellEm(char *fmt, ...) { char *p; va_list ap; p = Malloc(2048); va_start(ap,fmt); vsnprintf(p, 2048, fmt, ap); va_end(ap); strip_trailing_newlines(p); write(debug_fd,"Progress <",10); write(debug_fd,p,strlen(p)); write(debug_fd,">\n\r",3); dialog_msgbox("Progress", p, strheight(p)+2, strwidth(p)+4, 0); 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); strip_trailing_newlines(p); if (dialog_active) dialog_msgbox("Fatal", p, strheight(p)+4, strwidth(p)+4, 1); else fprintf(stderr, "Fatal -- %s\n", p); free(p); ExitSysinstall(); } void AskAbort(char *fmt, ...) { char *p; va_list ap; p = Malloc(2048); va_start(ap,fmt); vsnprintf(p, 2048, fmt, ap); va_end(ap); strcat(p, "\n\nDo you wish to abort the installation?"); if (!dialog_yesno("Abort", p, 15, 60)) { dialog_clear(); Abort(); } dialog_clear(); free(p); } void Abort() { if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?", 10, 40)) { dialog_clear(); return; } ExitSysinstall(); } void ExitSysinstall() { if (dialog_active) { clear(); dialog_update(); } if (getpid() == 1) { if (reboot(RB_AUTOBOOT) == -1) if (dialog_active) { clear(); dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button", 5,30,0); } else fprintf(stderr, "Can't reboot the machine -- hit the reset button"); while(1); } else { if (dialog_active) { end_dialog(); dialog_active = 0; } exit(0); } } void * Malloc(size_t size) { void *p = malloc(size); if (!p) { exit(7); /* XXX longjmp bad */ } return p; } char * StrAlloc(char *str) { char *p; p = (char *)Malloc(strlen(str) + 1); strcpy(p,str); return p; } void MountUfs(char *device, char *mountpoint, int do_mkdir, int flags) { struct ufs_args ufsargs; char dbuf[90]; memset(&ufsargs,0,sizeof ufsargs); if(do_mkdir && access(mountpoint,R_OK)) { Mkdir(mountpoint); } strcpy(dbuf,"/dev/"); strcat(dbuf,device); TellEm("mount %s %s",dbuf,mountpoint); ufsargs.fspec = dbuf; if (mount(MOUNT_UFS, mountpoint, flags, (caddr_t) &ufsargs) == -1) { Fatal("Error mounting %s on %s : %s\n", dbuf, mountpoint, strerror(errno)); } } void Mkdir(char *ipath) { struct stat sb; int final=0; char *p,*path=StrAlloc(ipath); 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)) { if (errno != ENOENT) Fatal("Couldn't stat directory %s: %s\n", path,strerror(errno)); Debug("mkdir(%s..)",path); if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) Fatal("Couldn't create directory %s: %s\n", path,strerror(errno)); } *p = '/'; } free(path); return; } void Link(char *from, char *to) { TellEm("ln %s %s", from, to); if (link(from, to) == -1) Fatal("Couldn't create link: %s -> %s\n", from, to); } 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); } 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; }