Deleted Added
full compact
devices.c (8208) devices.c (8262)
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: install.c,v 1.2 1995/04/27 18:03:53 jkh Exp $
7 * $Id: devices.c,v 1.1 1995/05/01 21:56:19 jkh Exp $
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright

--- 23 unchanged lines hidden (view full) ---

39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 */
43
44#include "sysinstall.h"
45#include "libdisk.h"
46
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright

--- 23 unchanged lines hidden (view full) ---

39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 */
43
44#include "sysinstall.h"
45#include "libdisk.h"
46
47/* Where we start displaying chunk information on the screen */
48#define CHUNK_START_ROW 5
49
47/* Get all device information for a given device class */
48Device *
49device_get_all(DeviceType which, int *ndevs)
50{
51 char **names;
52 Device *devs = NULL;
53
54 *ndevs = 0;

--- 11 unchanged lines hidden (view full) ---

66 devs[i].name[0] = '\0';
67 free(names);
68 }
69 }
70 /* put detection for other classes here just as soon as I figure out how */
71 return devs;
72}
73
50/* Get all device information for a given device class */
51Device *
52device_get_all(DeviceType which, int *ndevs)
53{
54 char **names;
55 Device *devs = NULL;
56
57 *ndevs = 0;

--- 11 unchanged lines hidden (view full) ---

69 devs[i].name[0] = '\0';
70 free(names);
71 }
72 }
73 /* put detection for other classes here just as soon as I figure out how */
74 return devs;
75}
76
74void
75device_print_chunk(struct chunk *c1, int offset, int *row)
77static struct chunk *chunk_info[10];
78static int current_chunk;
79
80static void
81record_chunks(char *disk, struct disk *d)
76{
82{
77 CHAR_N
83 struct chunk *c1;
84 int i = 0;
85 int last_free = 0;
86 if (!d->chunks)
87 msgFatal("No chunk list found for %s!", disk);
88 c1 = d->chunks->part;
89 while (c1) {
90 if (c1->type == unused && c1->size > last_free) {
91 last_free = c1->size;
92 current_chunk = i;
93 }
94 chunk_info[i++] = c1;
95 c1 = c1->next;
96 }
97 chunk_info[i] = NULL;
98}
78
99
79 if (!c1)
80 return;
81 mvprintw(*row++, offset, "%10lu %10lu %10lu %-8s %d %-8s %4d %lx",
82 c1->offset, c1->size, c1->end, c1->name, c1->type,
83 chunk_n[c1->type], c1->subtype, c1->flags);
84 device_print_chunk(c1->part, offset + 2, row);
85 device_print_chunk(c1->next, offset, row);
100static void
101print_chunks(char *disk, struct disk *d)
102{
103 int row;
104 int i;
105
106 attrset(A_NORMAL);
107 mvaddstr(0, 0, "Disk name:\t");
108 attrset(A_BOLD); addstr(disk); attrset(A_NORMAL);
109 mvprintw(1, 0,
110 "BIOS Geometry:\t%lu cyls/%lu heads/%lu sectors",
111 d->bios_cyl, d->bios_hd, d->bios_sect);
112 mvprintw(3, 1, "%10s %10s %10s %8s %8s %8s %8s %8s",
113 "Offset", "Size", "End", "Name", "PType", "Desc",
114 "Subtype", "Flags");
115 attrset(A_NORMAL);
116 for (i = 0, row = CHUNK_START_ROW; chunk_info[i]; i++, row++) {
117 if (i == current_chunk)
118 attrset(A_BOLD);
119 mvprintw(row, 2, "%10lu %10lu %10lu %8s %8d %8s %8d %6lx",
120 chunk_info[i]->offset, chunk_info[i]->size,
121 chunk_info[i]->end, chunk_info[i]->name,
122 chunk_info[i]->type, chunk_n[chunk_info[i]->type],
123 chunk_info[i]->subtype, chunk_info[i]->flags);
124 if (i == current_chunk)
125 attrset(A_NORMAL);
126 }
86}
87
127}
128
88int
129static void
130print_command_summary()
131{
132 mvprintw(15, 0, "The following commands are supported (in upper or lower case):");
133 mvprintw(17, 0, "C = Create New Partition D = Delete Partition");
134 mvprintw(18, 0, "B = Scan For Bad Blocks U = Undo All Changes");
135 mvprintw(19, 0, "ESC = Proceed to next screen");
136 mvprintw(21, 0, "The currently selected partition is displayed in ");
137 attrset(A_BOLD); addstr("bold"); attrset(A_NORMAL);
138 move(0, 0);
139}
140
141struct disk *
89device_slice_disk(char *disk)
90{
91 struct disk *d;
92 char *p;
142device_slice_disk(char *disk)
143{
144 struct disk *d;
145 char *p;
93 int row;
146 int key = 0;
147 Boolean chunking;
148 char *msg = NULL;
94
95 d = Open_Disk(disk);
96 if (!d)
97 msgFatal("Couldn't open disk `%s'!", disk);
98 p = CheckRules(d);
99 if (p) {
100 msgConfirm(p);
101 free(p);
102 }
149
150 d = Open_Disk(disk);
151 if (!d)
152 msgFatal("Couldn't open disk `%s'!", disk);
153 p = CheckRules(d);
154 if (p) {
155 msgConfirm(p);
156 free(p);
157 }
158
103 dialog_clear();
159 dialog_clear();
104 while (1) {
160 chunking = TRUE;
161 keypad(stdscr, TRUE);
162
163 record_chunks(disk, d);
164 while (chunking) {
105 clear();
165 clear();
106 mvprintw(0, 0, "Disk name: %s, Flags: %lx", disk, d->flags);
107 mvprintw(1, 0,
108 "Real Geometry: %lu/%lu/%lu, BIOS Geometry: %lu/%lu/%lu [cyls/heads/sectors]",
109 d->real_cyl, d->real_hd, d->real_sect,
110 d->bios_cyl, d->bios_hd, d->bios_sect);
111 mvprintw(4, 0, "%10s %10s %10s %-8s %4s %-8s %4s %4s",
112 "Offset", "Size", "End", "Name", "PType", "Desc",
113 "Subtype", "Flags");
114 row = 5;
115 device_print_chunk(d->chunks, 0, &row);
116 move(23, 0);
117 addstr("Done!");
118 if (getch() == 'q')
119 return 0;
166 print_chunks(disk, d);
167 print_command_summary();
168 if (msg) {
169 standout(); mvprintw(23, 0, msg); standend();
170 beep();
171 msg = NULL;
172 }
173 refresh();
174
175 key = getch();
176 switch (key) {
177 case KEY_UP:
178 case '-':
179 if (current_chunk != 0)
180 --current_chunk;
181 break;
182
183 case KEY_DOWN:
184 case '+':
185 case '\r':
186 case '\n':
187 if (chunk_info[current_chunk + 1])
188 ++current_chunk;
189 break;
190
191 case KEY_HOME:
192 current_chunk = 0;
193 break;
194
195 case KEY_END:
196 while (chunk_info[current_chunk + 1])
197 ++current_chunk;
198 break;
199
200 case KEY_F(1):
201 case '?':
202 systemDisplayFile("slice.hlp");
203 break;
204
205 case 'B':
206 case 'b':
207 if (chunk_info[current_chunk]->type != freebsd)
208 msg = "Can only scan for bad blocks in FreeBSD partition.";
209 else
210 chunk_info[current_chunk]->flags |= CHUNK_BAD144;
211 break;
212
213 case 'C':
214 case 'c':
215 if (chunk_info[current_chunk]->type != unused)
216 msg = "Partition in use, delete it first or move to an unused one.";
217 else {
218 char *val;
219 char tmp[20];
220 int size;
221
222 snprintf(tmp, 20, "%d", chunk_info[current_chunk]->size);
223 val = msgGetInput(tmp, "Please specify size for new FreeBSD partition");
224 if (val && (size = atoi(val)) > 0) {
225 Create_Chunk(d, chunk_info[current_chunk]->offset,
226 size,
227 freebsd,
228 3,
229 chunk_info[current_chunk]->flags);
230 record_chunks(disk, d);
231 }
232 }
233 break;
234
235 case 'D':
236 case 'd':
237 if (chunk_info[current_chunk]->type == unused)
238 msg = "Partition is already unused!";
239 else {
240 Delete_Chunk(d, chunk_info[current_chunk]);
241 record_chunks(disk, d);
242 }
243 break;
244
245 case 'U':
246 case 'u':
247 Free_Disk(d);
248 d = Open_Disk(disk);
249 record_chunks(disk, d);
250 break;
251
252 case 27: /* ESC */
253 chunking = FALSE;
254 break;
255
256 default:
257 msg = "Invalid character typed.";
258 break;
259 }
120 }
260 }
121 return 0;
261 clear();
262 refresh();
263 return d;
122}
264}
265
266/*
267 * Create a menu listing all the devices in the system. The pass-in menu
268 * is expected to be a "prototype" from which the new menu is cloned.
269 */
270DMenu *
271device_create_disk_menu(DMenu *menu, Device **rdevs, int (*hook)())
272{
273 Device *devices;
274 int numdevs;
275
276 devices = device_get_all(DEVICE_TYPE_DISK, &numdevs);
277 *rdevs = devices;
278 if (!devices) {
279 msgConfirm("No devices suitable for installation found!\n\nPlease verify that your disk controller (and attached drives) were detected properly. This can be done by selecting the ``Bootmsg'' option on the main menu and reviewing the boot messages carefully.");
280 return NULL;
281 }
282 else {
283 Device *start;
284 DMenu *tmp;
285 int i;
286
287 tmp = (DMenu *)safe_malloc(sizeof(DMenu) +
288 (sizeof(DMenuItem) * (numdevs + 1)));
289 bcopy(menu, tmp, sizeof(DMenu));
290 for (start = devices, i = 0; start->name[0]; start++, i++) {
291 tmp->items[i].title = start->name;
292 if (!strncmp(start->name, "sd", 2))
293 tmp->items[i].prompt = "SCSI disk";
294 else if (!strncmp(start->name, "wd", 2))
295 tmp->items[i].prompt = "IDE/ESDI/MFM/ST506 disk";
296 else
297 msgFatal("Unknown disk type: %s!", start->name);
298 tmp->items[i].type = DMENU_CALL;
299 tmp->items[i].ptr = hook;
300 tmp->items[i].disabled = FALSE;
301 }
302 tmp->items[i].type = DMENU_NOP;
303 tmp->items[i].title = NULL;
304 return tmp;
305 }
306}