devices.c revision 8208
18208Sjkh/* 28208Sjkh * The new sysinstall program. 38208Sjkh * 48208Sjkh * This is probably the last program in the `sysinstall' line - the next 58208Sjkh * generation being essentially a complete rewrite. 68208Sjkh * 78208Sjkh * $Id: install.c,v 1.2 1995/04/27 18:03:53 jkh Exp $ 88208Sjkh * 98208Sjkh * Copyright (c) 1995 108208Sjkh * Jordan Hubbard. All rights reserved. 118208Sjkh * 128208Sjkh * Redistribution and use in source and binary forms, with or without 138208Sjkh * modification, are permitted provided that the following conditions 148208Sjkh * are met: 158208Sjkh * 1. Redistributions of source code must retain the above copyright 168208Sjkh * notice, this list of conditions and the following disclaimer, 178208Sjkh * verbatim and that no modifications are made prior to this 188208Sjkh * point in the file. 198208Sjkh * 2. Redistributions in binary form must reproduce the above copyright 208208Sjkh * notice, this list of conditions and the following disclaimer in the 218208Sjkh * documentation and/or other materials provided with the distribution. 228208Sjkh * 3. All advertising materials mentioning features or use of this software 238208Sjkh * must display the following acknowledgement: 248208Sjkh * This product includes software developed by Jordan Hubbard 258208Sjkh * for the FreeBSD Project. 268208Sjkh * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to 278208Sjkh * endorse or promote products derived from this software without specific 288208Sjkh * prior written permission. 298208Sjkh * 308208Sjkh * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 318208Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 328208Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 338208Sjkh * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 348208Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 358208Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 368208Sjkh * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 378208Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 388208Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 398208Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 408208Sjkh * SUCH DAMAGE. 418208Sjkh * 428208Sjkh */ 438208Sjkh 448208Sjkh#include "sysinstall.h" 458208Sjkh#include "libdisk.h" 468208Sjkh 478208Sjkh/* Get all device information for a given device class */ 488208SjkhDevice * 498208Sjkhdevice_get_all(DeviceType which, int *ndevs) 508208Sjkh{ 518208Sjkh char **names; 528208Sjkh Device *devs = NULL; 538208Sjkh 548208Sjkh *ndevs = 0; 558208Sjkh if (which == DEVICE_TYPE_DISK || which == DEVICE_TYPE_ANY) { 568208Sjkh if ((names = Disk_Names()) != NULL) { 578208Sjkh int i; 588208Sjkh 598208Sjkh for (i = 0; names[i]; i++) 608208Sjkh ++*ndevs; 618208Sjkh devs = safe_malloc(sizeof(Device) * (*ndevs + 1)); 628208Sjkh for (i = 0; names[i]; i++) { 638208Sjkh strcpy(devs[i].name, names[i]); 648208Sjkh devs[i].type = DEVICE_TYPE_DISK; 658208Sjkh } 668208Sjkh devs[i].name[0] = '\0'; 678208Sjkh free(names); 688208Sjkh } 698208Sjkh } 708208Sjkh /* put detection for other classes here just as soon as I figure out how */ 718208Sjkh return devs; 728208Sjkh} 738208Sjkh 748208Sjkhvoid 758208Sjkhdevice_print_chunk(struct chunk *c1, int offset, int *row) 768208Sjkh{ 778208Sjkh CHAR_N 788208Sjkh 798208Sjkh if (!c1) 808208Sjkh return; 818208Sjkh mvprintw(*row++, offset, "%10lu %10lu %10lu %-8s %d %-8s %4d %lx", 828208Sjkh c1->offset, c1->size, c1->end, c1->name, c1->type, 838208Sjkh chunk_n[c1->type], c1->subtype, c1->flags); 848208Sjkh device_print_chunk(c1->part, offset + 2, row); 858208Sjkh device_print_chunk(c1->next, offset, row); 868208Sjkh} 878208Sjkh 888208Sjkhint 898208Sjkhdevice_slice_disk(char *disk) 908208Sjkh{ 918208Sjkh struct disk *d; 928208Sjkh char *p; 938208Sjkh int row; 948208Sjkh 958208Sjkh d = Open_Disk(disk); 968208Sjkh if (!d) 978208Sjkh msgFatal("Couldn't open disk `%s'!", disk); 988208Sjkh p = CheckRules(d); 998208Sjkh if (p) { 1008208Sjkh msgConfirm(p); 1018208Sjkh free(p); 1028208Sjkh } 1038208Sjkh dialog_clear(); 1048208Sjkh while (1) { 1058208Sjkh clear(); 1068208Sjkh mvprintw(0, 0, "Disk name: %s, Flags: %lx", disk, d->flags); 1078208Sjkh mvprintw(1, 0, 1088208Sjkh "Real Geometry: %lu/%lu/%lu, BIOS Geometry: %lu/%lu/%lu [cyls/heads/sectors]", 1098208Sjkh d->real_cyl, d->real_hd, d->real_sect, 1108208Sjkh d->bios_cyl, d->bios_hd, d->bios_sect); 1118208Sjkh mvprintw(4, 0, "%10s %10s %10s %-8s %4s %-8s %4s %4s", 1128208Sjkh "Offset", "Size", "End", "Name", "PType", "Desc", 1138208Sjkh "Subtype", "Flags"); 1148208Sjkh row = 5; 1158208Sjkh device_print_chunk(d->chunks, 0, &row); 1168208Sjkh move(23, 0); 1178208Sjkh addstr("Done!"); 1188208Sjkh if (getch() == 'q') 1198208Sjkh return 0; 1208208Sjkh } 1218208Sjkh return 0; 1228208Sjkh} 123