mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
Added a (H)elp function to the fdisk/disklabel code, much needed, now I only
have to write the text-file it will dump on you. Stopped using cleartoeol in AskEm(), just as a test to see if the screen looks more sane. Added a attempted auto-recognition of /, swap and /usr for the first disk where it looks sensible. Logic of this might need to be improved. Made a "ShowFile()" which will not bomb/ignore you if the file isn't there.
This commit is contained in:
parent
7da9aa9e49
commit
4c78915acc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=4146
@ -408,36 +408,17 @@ AskWhichPartition(char *prompt)
|
||||
return tolower(*buf) - 'a';
|
||||
}
|
||||
|
||||
static void
|
||||
CleanMount(int disk, int part)
|
||||
{
|
||||
int i = MP[disk][part];
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
DiskLabel()
|
||||
{
|
||||
int i, j, done = 0, diskno, flag, k;
|
||||
char buf[128];
|
||||
char buf[128],*p;
|
||||
struct disklabel *lbl, olbl;
|
||||
u_long cyl, hd, sec, tsec;
|
||||
u_long l1, l2, l3, l4;
|
||||
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Enter number of disk to Disklabel ", buf, 2);
|
||||
i = AskEm(stdscr, "Enter number of disk to Disklabel> ", buf, 2);
|
||||
printf("%d", i);
|
||||
if (i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
@ -494,10 +475,13 @@ DiskLabel()
|
||||
mvprintw(18, 0, "Total size: %d blocks", ourpart_size);
|
||||
mvprintw(19, 0, "Space allocated: %d blocks", allocated_space);
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(S)ize (M)ountpoint (D)elete (R)eread (W)rite (Q)uit");
|
||||
mvprintw(22, 0, "(H)elp (S)ize (M)ountpoint (D)elete (R)eread (W)rite (Q)uit");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
case 'h': case 'H':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
case 'd': case 'D':
|
||||
j = AskWhichPartition("Delete which partition? ");
|
||||
if (j < 0) {
|
||||
@ -552,7 +536,7 @@ DiskLabel()
|
||||
break;
|
||||
}
|
||||
sprintf(buf, "%lu", (l2-l1+1024L)/2048L);
|
||||
i = AskEm(stdscr, "Size of slice in MB ", buf, 10);
|
||||
i = AskEm(stdscr, "Size of partition in MB> ", buf, 10);
|
||||
l3= strtol(buf, 0, 0) * 2048L;
|
||||
if (!l3) {
|
||||
yelp("Invalid size given");
|
||||
@ -597,31 +581,16 @@ DiskLabel()
|
||||
else
|
||||
*buf = 0;
|
||||
if (k != FS_SWAP) {
|
||||
i = AskEm(stdscr, "Mount on directory ", buf, 28);
|
||||
i = AskEm(stdscr, "Mount on directory> ", buf, 28);
|
||||
if (i != '\n' && i != '\r') {
|
||||
yelp("Invalid directory name");
|
||||
break;
|
||||
}
|
||||
}
|
||||
CleanMount(diskno, j);
|
||||
for (k = 1; k < MAX_NO_FS; k++)
|
||||
if (!Fmount[k])
|
||||
break;
|
||||
if (k >= MAX_NO_FS) {
|
||||
yelp("Maximum number of filesystems exceeded");
|
||||
break;
|
||||
}
|
||||
Fmount[k] = StrAlloc(buf);
|
||||
MP[diskno][j] = k;
|
||||
sprintf(buf, "%s%c", Dname[diskno], j+'a');
|
||||
Fname[MP[diskno][j]] = StrAlloc(buf);
|
||||
if (lbl->d_partitions[j].p_fstype == FS_BSDFFS)
|
||||
Ftype[MP[diskno][j]] = StrAlloc("ufs");
|
||||
else if (lbl->d_partitions[j].p_fstype == FS_MSDOS)
|
||||
Ftype[MP[diskno][j]] = StrAlloc("msdos");
|
||||
else if (lbl->d_partitions[j].p_fstype == FS_SWAP)
|
||||
Ftype[MP[diskno][j]] = StrAlloc("swap");
|
||||
Fsize[MP[diskno][j]] = (lbl->d_partitions[j].p_size+1024)/2048;
|
||||
p = SetMount(diskno,j,buf);
|
||||
if(p)
|
||||
yelp(p);
|
||||
break;
|
||||
|
||||
case 'w': case 'W':
|
||||
|
@ -275,7 +275,7 @@ Fdisk()
|
||||
u_long l, l1, l2, l3, l4;
|
||||
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Enter number of disk to Fdisk ", buf, 2);
|
||||
i = AskEm(stdscr, "Enter number of disk to Fdisk> ", buf, 2);
|
||||
printf("%d", i);
|
||||
if(i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
@ -330,18 +330,22 @@ Fdisk()
|
||||
}
|
||||
}
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(D)elete (E)dit (R)eread (W)rite (Q)uit");
|
||||
mvprintw(22, 0, "(H)elp (D)elete (E)dit (R)eread (W)rite (Q)uit");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
|
||||
case 'h': case 'H':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
|
||||
case 'r': case 'R':
|
||||
read_dospart(Dfd[diskno], dp);
|
||||
break;
|
||||
|
||||
case 'e': case 'E':
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Edit which Slice ? ", buf, 2);
|
||||
i = AskEm(stdscr, "Edit which Slice> ", buf, 2);
|
||||
if(i != '\n' && i != '\r') break;
|
||||
l = strtol(buf, 0, 0);
|
||||
if(l < 1 || l > NDOSPART) break;
|
||||
@ -365,7 +369,7 @@ Fdisk()
|
||||
l1 = dp[i].dp_start + dp[i].dp_size;
|
||||
}
|
||||
sprintf(buf, "%lu", (l2-l1+1024L)/2048L);
|
||||
i = AskEm(stdscr, "Size of slice in MB ", buf, 10);
|
||||
i = AskEm(stdscr, "Size of slice in MB> ", buf, 10);
|
||||
l3=strtol(buf, 0, 0) * 2048L;
|
||||
if(!l3) break;
|
||||
if(l3 > l2-l1)
|
||||
@ -403,7 +407,7 @@ Fdisk()
|
||||
l4 = dp[l-1].dp_typ;
|
||||
if(!l4) l4 = MBR_PTYPE_FreeBSD;
|
||||
sprintf(buf, "0x%lx", l4);
|
||||
i = AskEm(stdscr, "Type of slice (0xa5=FreeBSD) ", buf, 5);
|
||||
i = AskEm(stdscr, "Type of slice (0xa5=FreeBSD)> ", buf, 5);
|
||||
l3 = strtol(buf, 0, 0);
|
||||
if(l3 == MBR_PTYPE_FreeBSD) {
|
||||
for(i=0;i<NDOSPART;i++)
|
||||
@ -414,13 +418,13 @@ Fdisk()
|
||||
sprintf(buf, "0");
|
||||
}
|
||||
dp[l-1].dp_typ=l3;
|
||||
i = AskEm(stdscr, "Bootflag (0x80 for YES) ", buf, 5);
|
||||
i = AskEm(stdscr, "Bootflag (0x80 for YES)> ", buf, 5);
|
||||
dp[l-1].dp_flag=strtol(buf, 0, 0);
|
||||
break;
|
||||
|
||||
case 'd': case 'D':
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Delete which Slice ? ", buf, 2);
|
||||
i = AskEm(stdscr, "Delete which Slice> ", buf, 2);
|
||||
if(i != '\n' && i != '\r') break;
|
||||
l = strtol(buf, 0, 0);
|
||||
if(l < 1 || l > NDOSPART) break;
|
||||
@ -429,7 +433,7 @@ Fdisk()
|
||||
|
||||
case 'w': case 'W':
|
||||
strcpy(buf, "N");
|
||||
i = AskEm(stdscr, "Confirm write ", buf, 2);
|
||||
i = AskEm(stdscr, "Confirm write> ", buf, 2);
|
||||
if(*buf != 'y' && *buf != 'Y') break;
|
||||
write_dospart(Dfd[diskno], dp);
|
||||
Dlbl[diskno]->d_partitions[OURPART].p_offset = 0;
|
||||
|
@ -162,7 +162,22 @@ AskEm(WINDOW *w,char *prompt, char *answer, int len)
|
||||
{
|
||||
int x,y;
|
||||
mvwprintw(w,23,0,prompt);
|
||||
wclrtoeol(w);
|
||||
getyx(w,y,x);
|
||||
addstr(" ");
|
||||
return edit_line(w,y,x,answer,len,len+1);
|
||||
}
|
||||
|
||||
void
|
||||
ShowFile(char *filename, char *header)
|
||||
{
|
||||
char buf[800];
|
||||
if (access(filename, R_OK)) {
|
||||
sprintf(buf,"Odd, I thought I had a file called %s around here somewhere,\nbut I can't seem to find it now that I need it. Sorry about that",filename);
|
||||
dialog_msgbox("Sorry!", buf,
|
||||
6, 75, 1);
|
||||
return;
|
||||
}
|
||||
dialog_clear();
|
||||
dialog_textbox(header, filename, LINES-1, COLS);
|
||||
dialog_clear();
|
||||
}
|
||||
|
@ -50,20 +50,12 @@ stage0()
|
||||
}
|
||||
switch (atoi(selection)) {
|
||||
case 1: /* View readme */
|
||||
if (!access(README_FILE, R_OK)) {
|
||||
dialog_clear();
|
||||
dialog_textbox("READ ME FIRST", README_FILE, LINES-1, COLS);
|
||||
dialog_clear();
|
||||
}
|
||||
ShowFile(README_FILE, "Read Me First");
|
||||
goto evil_goto;
|
||||
break;
|
||||
|
||||
case 2: /* View copyrights */
|
||||
if (!access(COPYRIGHT_FILE, R_OK)) {
|
||||
dialog_clear();
|
||||
dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, LINES-1, COLS);
|
||||
dialog_clear();
|
||||
}
|
||||
ShowFile(COPYRIGHT_FILE, "COPYRIGHT");
|
||||
goto evil_goto;
|
||||
break;
|
||||
|
||||
|
@ -259,8 +259,40 @@ stage1()
|
||||
int i,j;
|
||||
int ok = 0;
|
||||
int ready = 0;
|
||||
int foundroot=0,foundusr=0,foundswap=0;
|
||||
|
||||
query_disks();
|
||||
/*
|
||||
* Try to be intelligent about this and assign some mountpoints
|
||||
*/
|
||||
#define LEGAL(disk,part) ( \
|
||||
Dlbl[disk]->d_partitions[part].p_size && \
|
||||
(Dlbl[disk]->d_partitions[part].p_offset >= \
|
||||
Dlbl[disk]->d_partitions[OURPART].p_offset) && \
|
||||
((Dlbl[disk]->d_partitions[part].p_size + \
|
||||
Dlbl[disk]->d_partitions[part].p_offset) <= \
|
||||
(Dlbl[disk]->d_partitions[OURPART].p_offset + \
|
||||
Dlbl[disk]->d_partitions[OURPART].p_size)))
|
||||
|
||||
for(i = 0; i < MAX_NO_DISKS && Dname[i]; i++) {
|
||||
if (Dlbl[i]->d_partitions[OURPART].p_size == 0)
|
||||
break;
|
||||
if (!foundroot && LEGAL(i,0) &&
|
||||
Dlbl[i]->d_partitions[0].p_fstype == FS_BSDFFS) {
|
||||
SetMount(i,0,"/");
|
||||
foundroot++;
|
||||
}
|
||||
if (!foundswap && LEGAL(i,1) &&
|
||||
Dlbl[i]->d_partitions[1].p_fstype == FS_SWAP) {
|
||||
SetMount(i,1,"swap");
|
||||
foundswap++;
|
||||
}
|
||||
if (!foundusr && LEGAL(i,4) &&
|
||||
Dlbl[i]->d_partitions[4].p_fstype == FS_BSDFFS) {
|
||||
SetMount(i,4,"/usr");
|
||||
foundusr++;
|
||||
}
|
||||
}
|
||||
while (!ready) {
|
||||
clear(); standend();
|
||||
j = 0;
|
||||
@ -268,9 +300,7 @@ stage1()
|
||||
j++;
|
||||
mvprintw(j++, 0, "Disks Total FreeBSD ");
|
||||
j++;
|
||||
for(i = 0; i < MAX_NO_DISKS; i++) {
|
||||
if(!Dname[i])
|
||||
continue;
|
||||
for(i = 0; i < MAX_NO_DISKS && Dname[i]; i++) {
|
||||
mvprintw(j++, 0, "%2d: %-6s %5lu MB %5lu MB",
|
||||
i,
|
||||
Dname[i],
|
||||
@ -288,10 +318,13 @@ stage1()
|
||||
}
|
||||
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(F)disk (D)isklabel (Q)uit");
|
||||
mvprintw(22, 0, "(H)elp (F)disk (D)isklabel (Q)uit");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i = getch();
|
||||
switch(i) {
|
||||
case 'h': case 'H':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
case 'q': case 'Q':
|
||||
return;
|
||||
case 'f': case 'F':
|
||||
|
@ -48,6 +48,7 @@
|
||||
|
||||
#define COPYRIGHT_FILE "/COPYRIGHT"
|
||||
#define README_FILE "/README"
|
||||
#define HELPME_FILE "/HELPME"
|
||||
|
||||
#ifndef EXTERN
|
||||
# define EXTERN extern
|
||||
@ -100,6 +101,8 @@ 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);
|
||||
char * SetMount __P((int disk, int part, char *path));
|
||||
void CleanMount __P((int disk, int part));
|
||||
|
||||
/* exec.c */
|
||||
int exec __P((int magic, char *cmd, char *args, ...));
|
||||
@ -129,9 +132,10 @@ int set_termcap __P((void));
|
||||
/* makedevs.c */
|
||||
int makedevs __P((void));
|
||||
|
||||
/* outcurses.c */
|
||||
/* ourcurses.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));
|
||||
void ShowFile __P((char *filename, char *header));
|
||||
|
||||
/* bootarea.c */
|
||||
void enable_label __P((int fd));
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: utils.c,v 1.20 1994/11/03 00:28:05 ache Exp $
|
||||
* $Id: utils.c,v 1.21 1994/11/04 21:38:37 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -291,3 +291,58 @@ PartMb(struct disklabel *lbl,int part)
|
||||
l = 1024*1024/lbl->d_secsize;
|
||||
return (lbl->d_partitions[part].p_size + l/2)/l;
|
||||
}
|
||||
|
||||
void
|
||||
CleanMount(int disk, int part)
|
||||
{
|
||||
int i = MP[disk][part];
|
||||
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");
|
||||
break;
|
||||
case FS_MSDOS:
|
||||
Ftype[k] = StrAlloc("msdos");
|
||||
break;
|
||||
case FS_SWAP:
|
||||
Ftype[k] = StrAlloc("swap");
|
||||
break;
|
||||
default:
|
||||
CleanMount(disk,part);
|
||||
return "Unknown filesystem-type";
|
||||
}
|
||||
Fsize[k] = (Dlbl[disk]->d_partitions[part].p_size+1024)/2048;
|
||||
|
||||
MP[disk][part] = k;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user