wizard.c revision 50479
1/* 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 * 9 * $FreeBSD: head/usr.sbin/sade/wizard.c 50479 1999-08-28 01:35:59Z peter $ 10 * 11 */ 12 13#include "sysinstall.h" 14#include <fcntl.h> 15#include <err.h> 16 17int 18scan_block(int fd, daddr_t block) 19{ 20 u_char foo[512]; 21 22 if (-1 == lseek(fd,block * 512,SEEK_SET)) 23 err(1,"lseek"); 24 if (512 != read(fd,foo, 512)) 25 return 1; 26 return 0; 27} 28 29void 30Scan_Disk(Disk *d) 31{ 32 char device[64]; 33 u_long l; 34 int i,j,fd; 35 36 strcpy(device,"/dev/r"); 37 strcat(device,d->name); 38 39 fd = open(device,O_RDWR); 40 if (fd < 0) { 41 msgWarn("open(%s) failed", device); 42 return; 43 } 44 for(i=-1,l=0;;l++) { 45 j = scan_block(fd,l); 46 if (j != i) { 47 if (i == -1) { 48 printf("%c: %lu.",j ? 'B' : 'G', l); 49 fflush(stdout); 50 } else if (i == 0) { 51 printf(".%lu\nB: %lu.",l-1,l); 52 fflush(stdout); 53 } else { 54 printf(".%lu\nG: %lu.",l-1,l); 55 fflush(stdout); 56 } 57 i = j; 58 } 59 } 60 close(fd); 61} 62 63void 64slice_wizard(Disk *d) 65{ 66 Disk *db; 67 char myprompt[BUFSIZ]; 68 char input[BUFSIZ]; 69 char *p,*q=0; 70 char **cp,*cmds[200]; 71 int ncmd,i; 72 73 sprintf(myprompt,"%s> ", d->name); 74 while(1) { 75 printf("--==##==--\n"); 76 Debug_Disk(d); 77 p = CheckRules(d); 78 if (p) { 79 printf("%s",p); 80 free(p); 81 } 82 printf(myprompt); 83 fflush(stdout); 84 q = p = fgets(input,sizeof(input),stdin); 85 if(!p) 86 break; 87 for(cp = cmds; (*cp = strsep(&p, " \t\n")) != NULL;) 88 if (**cp != '\0') 89 cp++; 90 ncmd = cp - cmds; 91 if(!ncmd) 92 continue; 93 if (!strcasecmp(*cmds,"quit")) { break; } 94 if (!strcasecmp(*cmds,"exit")) { break; } 95 if (!strcasecmp(*cmds,"q")) { break; } 96 if (!strcasecmp(*cmds,"x")) { break; } 97 if (!strcasecmp(*cmds,"delete") && ncmd == 2) { 98 printf("delete = %d\n", 99 Delete_Chunk(d, 100 (struct chunk *)strtol(cmds[1],0,0))); 101 continue; 102 } 103 if (!strcasecmp(*cmds,"allfreebsd")) { 104 All_FreeBSD(d, 0); 105 continue; 106 } 107 if (!strcasecmp(*cmds,"dedicate")) { 108 All_FreeBSD(d, 1); 109 continue; 110 } 111 if (!strcasecmp(*cmds,"bios") && ncmd == 4) { 112 Set_Bios_Geom(d, 113 strtol(cmds[1],0,0), 114 strtol(cmds[2],0,0), 115 strtol(cmds[3],0,0)); 116 continue; 117 } 118 if (!strcasecmp(*cmds,"list")) { 119 cp = Disk_Names(); 120 printf("Disks:"); 121 for(i=0;cp[i];i++) { 122 printf(" %s",cp[i]); 123 free(cp[i]); 124 } 125 free(cp); 126 continue; 127 } 128 if (!strcasecmp(*cmds,"create") && ncmd == 6) { 129 130 printf("Create=%d\n", 131 Create_Chunk(d, 132 strtol(cmds[1],0,0), 133 strtol(cmds[2],0,0), 134 strtol(cmds[3],0,0), 135 strtol(cmds[4],0,0), 136 strtol(cmds[5],0,0))); 137 continue; 138 } 139 if (!strcasecmp(*cmds,"read")) { 140 db = d; 141 if (ncmd > 1) 142 d = Open_Disk(cmds[1]); 143 else 144 d = Open_Disk(d->name); 145 if (d) 146 Free_Disk(db); 147 else 148 d = db; 149 continue; 150 } 151 if (!strcasecmp(*cmds,"scan")) { 152 Scan_Disk(d); 153 continue; 154 } 155 if (!strcasecmp(*cmds,"write")) { 156 printf("Write=%d\n", 157 Fake ? 0 : Write_Disk(d)); 158 Free_Disk(d); 159 d = Open_Disk(d->name); 160 continue; 161 } 162 if (strcasecmp(*cmds,"help")) 163 printf("\007ERROR\n"); 164 printf("CMDS:\n"); 165 printf("allfreebsd\t\t"); 166 printf("dedicate\t\t"); 167 printf("bios cyl hd sect\n"); 168 printf("collapse [pointer]\t\t"); 169 printf("create offset size enum subtype flags\n"); 170 printf("subtype(part): swap=1, ffs=7\t\t"); 171 printf("delete pointer\n"); 172 printf("list\t\t"); 173 printf("quit\n"); 174 printf("read [disk]\t\t"); 175 printf("scan\n"); 176 printf("write\t\t"); 177 printf("ENUM:\n\t"); 178 for(i=0;chunk_n[i];i++) 179 printf("%d = %s%s",i,chunk_n[i],i == 4 ? "\n\t" : " "); 180 printf("\n"); 181 182 } 183} 184