mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
Fix more mongoloid coding style.
Make a stab at getting free space display to work. Forward decls to shut compiler warnings up. Increase some fields to width 2 in order to get edit_line to let you actually edit them. Sanity check values and yell at bonehead users.
This commit is contained in:
parent
9e92d9eb90
commit
207d0a541b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=4084
@ -16,6 +16,9 @@
|
||||
#include <dialog.h>
|
||||
#include "sysinstall.h"
|
||||
|
||||
/* Forward decls */
|
||||
int disk_size(struct disklabel *);
|
||||
int getfstype(char *);
|
||||
int sectstoMb(int, int);
|
||||
|
||||
char *partname[MAXPARTITIONS] = {"a", "b", "c", "d", "e", "f", "g", "h"};
|
||||
@ -33,6 +36,12 @@ struct field {
|
||||
|
||||
struct field label_fields[MAXPARTITIONS][EDITABLES];
|
||||
|
||||
void
|
||||
yelp(char *str)
|
||||
{
|
||||
dialog_msgbox("Validation Error", str, 6, 75, 1);
|
||||
}
|
||||
|
||||
void
|
||||
setup_label_fields(struct disklabel *lbl)
|
||||
{
|
||||
@ -83,7 +92,7 @@ update_label_form(WINDOW *window, struct disklabel *lbl)
|
||||
mvwprintw(window, label_fields[i][2].y, label_fields[i][2].x, "%s",
|
||||
&label_fields[i][2].field);
|
||||
}
|
||||
mvwprintw(window, 20, 10, "Allocated %5luMb, Unalloacted %5lu Mb",
|
||||
mvwprintw(window, 20, 10, "Allocated %5luMb, Unallocated %5lu Mb",
|
||||
used, disk_size(lbl) - used);
|
||||
|
||||
wrefresh(window);
|
||||
@ -385,7 +394,7 @@ AskWhichPartition(char *prompt)
|
||||
char buf[10];
|
||||
int i;
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr,prompt,buf,1);
|
||||
i = AskEm(stdscr, prompt, buf, 2);
|
||||
if (i != '\n' && i != '\r') return -1;
|
||||
if (!strchr("abefghABEFGH",*buf)) return -1;
|
||||
return tolower(*buf) - 'a';
|
||||
@ -410,6 +419,8 @@ CleanMount(int disk, int part)
|
||||
MP[disk][part] = 0;
|
||||
}
|
||||
|
||||
int free_space;
|
||||
|
||||
void
|
||||
DiskLabel()
|
||||
{
|
||||
@ -420,17 +431,19 @@ DiskLabel()
|
||||
u_long l1, l2, l3, l4;
|
||||
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr,"Enter number of disk to Disklabel ",buf,1);
|
||||
i = AskEm(stdscr, "Enter number of disk to Disklabel ", buf, 2);
|
||||
printf("%d", i);
|
||||
if (i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
if(!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) return;
|
||||
if (!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno]))
|
||||
return;
|
||||
olbl = *Dlbl[diskno];
|
||||
lbl = &olbl;
|
||||
cyl = lbl->d_ncylinders;
|
||||
hd = lbl->d_ntracks;
|
||||
sec = lbl->d_nsectors;
|
||||
tsec = lbl->d_secperunit;
|
||||
free_space = lbl->d_partitions[OURPART].p_size;
|
||||
while(!done) {
|
||||
clear(); standend();
|
||||
j = 0;
|
||||
@ -439,7 +452,8 @@ DiskLabel()
|
||||
mvprintw(j++, 0, "Part Start End Blocks MB Type Mountpoint");
|
||||
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||
mvprintw(j++, 0, "%c ", 'a'+i);
|
||||
if(i>=lbl->d_npartitions) continue;
|
||||
if (i >= lbl->d_npartitions)
|
||||
continue;
|
||||
printw(" %8u %8u %8u %5u ",
|
||||
lbl->d_partitions[i].p_offset,
|
||||
lbl->d_partitions[i].p_offset+
|
||||
@ -457,9 +471,13 @@ DiskLabel()
|
||||
printw("<Entire FreeBSD slice>");
|
||||
else if (i == RAWPART)
|
||||
printw("<Entire Disk>");
|
||||
else if(Fmount[MP[diskno][i]])
|
||||
else {
|
||||
if (Fmount[MP[diskno][i]])
|
||||
printw(Fmount[MP[diskno][i]]);
|
||||
free_space -= lbl->d_partitions[i].p_size;
|
||||
}
|
||||
}
|
||||
mvprintw(19, 0, "Free space: %d blocks.", free_space);
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(S)ize (M)ountpoint (D)elete (R)eread (W)rite (Q)uit");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
@ -467,19 +485,32 @@ DiskLabel()
|
||||
switch(i) {
|
||||
case 'd': case 'D':
|
||||
j = AskWhichPartition("Delete which partition? ");
|
||||
if(j < 0) break;
|
||||
if (j < 0) {
|
||||
yelp("Invalid partition");
|
||||
break;
|
||||
}
|
||||
CleanMount(diskno, j);
|
||||
lbl->d_partitions[j].p_fstype = FS_UNUSED;
|
||||
lbl->d_partitions[j].p_size = 0;
|
||||
lbl->d_partitions[j].p_offset = 0;
|
||||
break;
|
||||
|
||||
case 's': case 'S':
|
||||
j = AskWhichPartition("Change size of which partition? ");
|
||||
if(j < 0) break;
|
||||
if (j < 0) {
|
||||
yelp("Invalid partition");
|
||||
break;
|
||||
}
|
||||
if (lbl->d_partitions[j].p_fstype != FS_BSDFFS &&
|
||||
lbl->d_partitions[j].p_fstype != FS_UNUSED &&
|
||||
lbl->d_partitions[j].p_fstype != FS_SWAP) break;
|
||||
if(lbl->d_partitions[OURPART].p_size == 0) break;
|
||||
lbl->d_partitions[j].p_fstype != FS_SWAP) {
|
||||
yelp("Invalid partition type");
|
||||
break;
|
||||
}
|
||||
if (lbl->d_partitions[OURPART].p_size == 0) {
|
||||
yelp("No FreeBSD partition defined?");
|
||||
break;
|
||||
}
|
||||
l1=lbl->d_partitions[OURPART].p_offset;
|
||||
l2=lbl->d_partitions[OURPART].p_offset +
|
||||
lbl->d_partitions[OURPART].p_size;
|
||||
@ -501,11 +532,17 @@ DiskLabel()
|
||||
else
|
||||
l2 = l1;
|
||||
}
|
||||
if(!(l2-l1)) break;
|
||||
if (!(l2 - l1)) {
|
||||
yelp("Oh god, I'm so confused!");
|
||||
break;
|
||||
}
|
||||
sprintf(buf, "%lu", (l2-l1+1024L)/2048L);
|
||||
i = AskEm(stdscr, "Size of slice in MB ", buf, 10);
|
||||
l3= strtol(buf, 0, 0) * 2048L;
|
||||
if(!l3) break;
|
||||
if (!l3) {
|
||||
yelp("Invalid size given");
|
||||
break;
|
||||
}
|
||||
if (l3 > l2 - l1)
|
||||
l3 = l2 - l1;
|
||||
lbl->d_partitions[j].p_size = l3;
|
||||
@ -514,20 +551,30 @@ DiskLabel()
|
||||
lbl->d_partitions[j].p_fstype = FS_SWAP;
|
||||
else
|
||||
lbl->d_partitions[j].p_fstype = FS_BSDFFS;
|
||||
|
||||
break;
|
||||
|
||||
case 'r': case 'R':
|
||||
olbl = *Dlbl[diskno];
|
||||
/* XXX be more selective here */
|
||||
for (i = 0; i < MAXPARTITIONS; i++)
|
||||
CleanMount(diskno, i);
|
||||
break;
|
||||
|
||||
case 'm': case 'M':
|
||||
j = AskWhichPartition("Mountpoint of which partition ? ");
|
||||
if(j < 0) break;
|
||||
if (j < 0) {
|
||||
yelp("Invalid partition");
|
||||
break;
|
||||
}
|
||||
k = lbl->d_partitions[j].p_fstype;
|
||||
if(k != FS_BSDFFS && k != FS_MSDOS && k != FS_SWAP) break;
|
||||
if(!lbl->d_partitions[j].p_size) break;
|
||||
if (k != FS_BSDFFS && k != FS_MSDOS && k != FS_SWAP) {
|
||||
yelp("Invalid partition type");
|
||||
break;
|
||||
}
|
||||
if (!lbl->d_partitions[j].p_size) {
|
||||
yelp("Zero partition size");
|
||||
break;
|
||||
}
|
||||
if (k == FS_SWAP)
|
||||
strcpy(buf, "swap");
|
||||
else if (Fmount[MP[diskno][j]])
|
||||
@ -536,13 +583,19 @@ DiskLabel()
|
||||
*buf = 0;
|
||||
if (k != FS_SWAP) {
|
||||
i = AskEm(stdscr, "Mount on directory ", buf, 28);
|
||||
if(i != '\n' && i != '\r') break;
|
||||
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) 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');
|
||||
@ -555,6 +608,7 @@ DiskLabel()
|
||||
Ftype[MP[diskno][j]] = StrAlloc("swap");
|
||||
Fsize[MP[diskno][j]] = (lbl->d_partitions[j].p_size+1024)/2048;
|
||||
break;
|
||||
|
||||
case 'w': case 'W':
|
||||
*Dlbl[diskno] = *lbl;
|
||||
Dlbl[diskno]->d_magic = DISKMAGIC;
|
||||
@ -572,7 +626,11 @@ DiskLabel()
|
||||
flag=0;
|
||||
if (ioctl(Dfd[diskno], DIOCWLABEL, &flag) < 0)
|
||||
Fatal("Couldn't disable writing of labels");
|
||||
|
||||
mvprintw(24, 0, "Label written successfully.");
|
||||
beep();
|
||||
break;
|
||||
|
||||
case 'q': case 'Q':
|
||||
if (!memcmp(lbl, Dlbl[diskno], sizeof *lbl))
|
||||
return;
|
||||
|
@ -235,8 +235,8 @@ build_mbr(struct mbr *mbr, char *bootcode, struct disklabel *lb)
|
||||
dp->dp_start = (dp->dp_scyl * lb->d_ntracks * lb->d_nsectors) +
|
||||
(dp->dp_shd * lb->d_nsectors) +
|
||||
dp->dp_ssect - 1;
|
||||
dp->dp_size = (lb->d_nsectors * lb->d_ntracks * lb->d_ncylinders) -
|
||||
dp->dp_start;
|
||||
dp->dp_size =
|
||||
(lb->d_nsectors * lb->d_ntracks * lb->d_ncylinders) - dp->dp_start;
|
||||
}
|
||||
|
||||
/* Validate partition - XXX need to spend some time making this robust */
|
||||
@ -275,7 +275,7 @@ Fdisk()
|
||||
u_long l, l1, l2, l3, l4;
|
||||
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr,"Enter number of disk to Fdisk ",buf,1);
|
||||
i = AskEm(stdscr, "Enter number of disk to Fdisk ", buf, 2);
|
||||
printf("%d", i);
|
||||
if(i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
@ -334,12 +334,14 @@ Fdisk()
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
|
||||
case 'r': case 'R':
|
||||
read_dospart(Dfd[diskno], dp);
|
||||
break;
|
||||
|
||||
case 'e': case 'E':
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr,"Edit which Slice ? ",buf,1);
|
||||
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;
|
||||
@ -415,17 +417,19 @@ Fdisk()
|
||||
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,1);
|
||||
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;
|
||||
memset(&dp[l-1], 0, sizeof dp[l-1]);
|
||||
break;
|
||||
|
||||
case 'w': case 'W':
|
||||
strcpy(buf, "N");
|
||||
i = AskEm(stdscr,"Confirm write ",buf,1);
|
||||
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;
|
||||
@ -454,6 +458,7 @@ Fdisk()
|
||||
if (Dlbl[diskno]->d_partitions[OURPART].p_size)
|
||||
build_bootblocks(Dfd[diskno], lbl, dp);
|
||||
break;
|
||||
|
||||
case 'q': case 'Q':
|
||||
return;
|
||||
break;
|
||||
|
@ -50,9 +50,12 @@ int whole_disk = 0;
|
||||
int custom_install = 0;
|
||||
int dialog_active = 0;
|
||||
|
||||
void exit_sysinstall();
|
||||
void exit_prompt();
|
||||
/* Forward decls */
|
||||
void exit_sysinstall(void);
|
||||
void exit_prompt(void);
|
||||
extern char *part_type(int);
|
||||
void Fdisk(void);
|
||||
void DiskLabel(void);
|
||||
|
||||
char selection[30];
|
||||
char boot1[] = BOOT1;
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
#define SCRATCHSIZE 1024
|
||||
#define ERRMSGSIZE 256
|
||||
#define DEFROOTSIZE 16
|
||||
#define DEFROOTSIZE 18
|
||||
#define DEFSWAPSIZE 16
|
||||
#define DEFUSRSIZE 80
|
||||
#define DEFFSIZE 1024
|
||||
|
Loading…
Reference in New Issue
Block a user