devices.c (8636) | devices.c (8641) |
---|---|
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: devices.c,v 1.19 1995/05/19 02:31:13 jkh Exp $ | 7 * $Id: devices.c,v 1.20 1995/05/20 00:13:06 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 --- 48 unchanged lines hidden (view full) --- 64#include <netiso/iso_var.h> 65#include <sys/protosw.h> 66 67#include <ctype.h> 68 69static Device *Devices[DEV_MAX]; 70static int numDevs; 71 | 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 --- 48 unchanged lines hidden (view full) --- 64#include <netiso/iso_var.h> 65#include <sys/protosw.h> 66 67#include <ctype.h> 68 69static Device *Devices[DEV_MAX]; 70static int numDevs; 71 |
72#define CHECK_DEVS \ 73 if (numDevs == DEV_MAX) msgFatal("Too many devices found!") 74 | |
75static struct { 76 DeviceType type; 77 char *name; 78 char *description; 79} device_names[] = { 80 { DEVICE_TYPE_CDROM, "cd0a", "SCSI CDROM drive" }, 81 { DEVICE_TYPE_CDROM, "cd1a", "SCSI CDROM drive (2nd unit)" }, 82 { DEVICE_TYPE_CDROM, "mcd0a", "Mitsumi (old model) CDROM drive" }, --- 22 unchanged lines hidden (view full) --- 105 { DEVICE_TYPE_NETWORK, "ie", "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" }, 106 { DEVICE_TYPE_NETWORK, "le", "DEC EtherWorks 2 and 3" }, 107 { DEVICE_TYPE_NETWORK, "lnc", "Lance/PCnet cards (Isolan/Novell NE2100/NE32-VL)" }, 108 { DEVICE_TYPE_NETWORK, "ze", "IBM/National Semiconductor PCMCIA ethernet" }, 109 { DEVICE_TYPE_NETWORK, "zp", "3Com PCMCIA Etherlink III" }, 110 { NULL }, 111}; 112 | 72static struct { 73 DeviceType type; 74 char *name; 75 char *description; 76} device_names[] = { 77 { DEVICE_TYPE_CDROM, "cd0a", "SCSI CDROM drive" }, 78 { DEVICE_TYPE_CDROM, "cd1a", "SCSI CDROM drive (2nd unit)" }, 79 { DEVICE_TYPE_CDROM, "mcd0a", "Mitsumi (old model) CDROM drive" }, --- 22 unchanged lines hidden (view full) --- 102 { DEVICE_TYPE_NETWORK, "ie", "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" }, 103 { DEVICE_TYPE_NETWORK, "le", "DEC EtherWorks 2 and 3" }, 104 { DEVICE_TYPE_NETWORK, "lnc", "Lance/PCnet cards (Isolan/Novell NE2100/NE32-VL)" }, 105 { DEVICE_TYPE_NETWORK, "ze", "IBM/National Semiconductor PCMCIA ethernet" }, 106 { DEVICE_TYPE_NETWORK, "zp", "3Com PCMCIA Etherlink III" }, 107 { NULL }, 108}; 109 |
113static Device * | 110Device * |
114new_device(char *name) 115{ 116 Device *dev; 117 118 dev = safe_malloc(sizeof(Device)); 119 if (name) 120 strcpy(dev->name, name); 121 else --- 16 unchanged lines hidden (view full) --- 138} 139 140static void 141deviceDiskFree(Device *dev) 142{ 143 Free_Disk(dev->private); 144} 145 | 111new_device(char *name) 112{ 113 Device *dev; 114 115 dev = safe_malloc(sizeof(Device)); 116 if (name) 117 strcpy(dev->name, name); 118 else --- 16 unchanged lines hidden (view full) --- 135} 136 137static void 138deviceDiskFree(Device *dev) 139{ 140 Free_Disk(dev->private); 141} 142 |
143/* Register a new device in the devices array */ 144Device * 145deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled, 146 Boolean (*init)(Device *), Boolean (*get)(char *), void (*close)(Device *), void *private) 147{ 148 Device *newdev; 149 150 if (numDevs == DEV_MAX) 151 msgFatal("Too many devices found!"); 152 newdev = new_device(name); 153 newdev->description = desc; 154 newdev->devname = devname; 155 newdev->type = type; 156 newdev->enabled = enabled; 157 newdev->init = init; 158 newdev->get = get; 159 newdev->close = close; 160 newdev->private = private; 161 Devices[numDevs] = newdev; 162 Devices[++numDevs] = NULL; 163 return newdev; 164} 165 |
|
146/* Get all device information for devices we have attached */ 147void 148deviceGetAll(void) 149{ 150 int i, fd, s; 151 struct ifconf ifc; 152 struct ifreq *ifptr, *end; 153 int ifflags; 154 char buffer[INTERFACE_MAX * sizeof(struct ifreq)]; 155 char **names; 156 157 /* Try and get the disks first */ 158 if ((names = Disk_Names()) != NULL) { 159 int i; 160 161 for (i = 0; names[i]; i++) { | 166/* Get all device information for devices we have attached */ 167void 168deviceGetAll(void) 169{ 170 int i, fd, s; 171 struct ifconf ifc; 172 struct ifreq *ifptr, *end; 173 int ifflags; 174 char buffer[INTERFACE_MAX * sizeof(struct ifreq)]; 175 char **names; 176 177 /* Try and get the disks first */ 178 if ((names = Disk_Names()) != NULL) { 179 int i; 180 181 for (i = 0; names[i]; i++) { |
162 CHECK_DEVS; 163 Devices[numDevs] = new_device(names[i]); 164 Devices[numDevs]->type = DEVICE_TYPE_DISK; 165 Devices[numDevs]->enabled = FALSE; 166 Devices[numDevs]->init = mediaInitUFS; 167 Devices[numDevs]->get = mediaGetUFS; 168 Devices[numDevs]->close = deviceDiskFree; 169 Devices[numDevs]->private = Open_Disk(names[i]); 170 if (!Devices[numDevs]->private) 171 msgFatal("Unable to open device for %s!", names[i]); | 182 Disk *d; 183 184 d = Open_Disk(names[i]); 185 if (!d) 186 msgFatal("Unable to open disk %s", names[i]); 187 188 (void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, 189 mediaInitUFS, mediaGetUFS, deviceDiskFree, d); |
172 msgDebug("Found a device of type disk named: %s\n", names[i]); | 190 msgDebug("Found a device of type disk named: %s\n", names[i]); |
173 ++numDevs; | |
174 } 175 free(names); 176 } 177 178 /* 179 * Try to get all the types of devices it makes sense to get at the 180 * second stage of the installation. 181 */ 182 for (i = 0; device_names[i].name; i++) { 183 char try[FILENAME_MAX]; 184 185 switch(device_names[i].type) { 186 case DEVICE_TYPE_CDROM: 187 fd = deviceTry(device_names[i].name, try); 188 if (fd >= 0) { 189 close(fd); | 191 } 192 free(names); 193 } 194 195 /* 196 * Try to get all the types of devices it makes sense to get at the 197 * second stage of the installation. 198 */ 199 for (i = 0; device_names[i].name; i++) { 200 char try[FILENAME_MAX]; 201 202 switch(device_names[i].type) { 203 case DEVICE_TYPE_CDROM: 204 fd = deviceTry(device_names[i].name, try); 205 if (fd >= 0) { 206 close(fd); |
190 CHECK_DEVS; 191 Devices[numDevs] = new_device(device_names[i].name); 192 Devices[numDevs]->type = DEVICE_TYPE_CDROM; 193 Devices[numDevs]->description = device_names[i].description; 194 Devices[numDevs]->devname = strdup(try); 195 Devices[numDevs]->enabled = TRUE; /* XXX check for FreeBSD disk later XXX */ 196 Devices[numDevs]->init = mediaInitCDROM; 197 Devices[numDevs]->get = mediaGetCDROM; 198 Devices[numDevs]->close = NULL; 199 Devices[numDevs]->private = NULL; 200 msgDebug("Found a device of type CDROM named: %s\n", 201 device_names[i].name); 202 ++numDevs; | 207 (void)deviceRegister(device_names[i].name, device_names[i].description, strdup(try), 208 DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, mediaCloseCDROM, NULL); 209 msgDebug("Found a device of type CDROM named: %s\n", device_names[i].name); |
203 } 204 break; 205 206 case DEVICE_TYPE_TAPE: 207 fd = deviceTry(device_names[i].name, try); 208 if (fd >= 0) { 209 close(fd); | 210 } 211 break; 212 213 case DEVICE_TYPE_TAPE: 214 fd = deviceTry(device_names[i].name, try); 215 if (fd >= 0) { 216 close(fd); |
210 CHECK_DEVS; 211 Devices[numDevs] = new_device(device_names[i].name); 212 Devices[numDevs]->type = DEVICE_TYPE_TAPE; 213 Devices[numDevs]->devname = strdup(try); 214 Devices[numDevs]->enabled = TRUE; 215 Devices[numDevs]->init = mediaInitTape; 216 Devices[numDevs]->get = mediaGetTape; 217 Devices[numDevs]->close = mediaCloseTape; 218 Devices[numDevs]->private = NULL; | 217 deviceRegister(device_names[i].name, device_names[i].description, strdup(try), 218 DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaCloseTape, NULL); |
219 msgDebug("Found a device of type TAPE named: %s\n", device_names[i].name); | 219 msgDebug("Found a device of type TAPE named: %s\n", device_names[i].name); |
220 ++numDevs; | |
221 } 222 break; 223 224 case DEVICE_TYPE_FLOPPY: 225 fd = deviceTry(device_names[i].name, try); 226 if (fd >= 0) { 227 close(fd); | 220 } 221 break; 222 223 case DEVICE_TYPE_FLOPPY: 224 fd = deviceTry(device_names[i].name, try); 225 if (fd >= 0) { 226 close(fd); |
228 CHECK_DEVS; 229 Devices[numDevs] = new_device(device_names[i].name); 230 Devices[numDevs]->type = DEVICE_TYPE_FLOPPY; 231 Devices[numDevs]->devname = strdup(try); 232 Devices[numDevs]->enabled = TRUE; 233 Devices[numDevs]->init = mediaInitFloppy; 234 Devices[numDevs]->get = mediaGetFloppy; 235 Devices[numDevs]->close = mediaCloseFloppy; 236 Devices[numDevs]->private = NULL; | 227 deviceRegister(device_names[i].name, device_names[i].description, strdup(try), 228 DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, mediaCloseFloppy, NULL); |
237 msgDebug("Found a device of type TAPE named: %s\n", device_names[i].name); | 229 msgDebug("Found a device of type TAPE named: %s\n", device_names[i].name); |
238 ++numDevs; | |
239 } 240 break; 241 242 case DEVICE_TYPE_NETWORK: 243 fd = deviceTry(device_names[i].name, try); 244 if (fd >= 0) { 245 close(fd); | 230 } 231 break; 232 233 case DEVICE_TYPE_NETWORK: 234 fd = deviceTry(device_names[i].name, try); 235 if (fd >= 0) { 236 close(fd); |
246 CHECK_DEVS; 247 Devices[numDevs] = new_device(device_names[i].name); 248 Devices[numDevs]->type = DEVICE_TYPE_NETWORK; 249 Devices[numDevs]->devname = strdup(try); 250 Devices[numDevs]->enabled = FALSE; 251 Devices[numDevs]->init = mediaInitNetwork; 252 Devices[numDevs]->get = mediaGetNetwork; 253 Devices[numDevs]->close = mediaCloseNetwork; 254 Devices[numDevs]->private = NULL; | 237 deviceRegister(device_names[i].name, device_names[i].description, strdup(try), 238 DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork, mediaGetNetwork, mediaCloseNetwork, NULL); |
255 msgDebug("Found a device of type network named: %s\n", device_names[i].name); | 239 msgDebug("Found a device of type network named: %s\n", device_names[i].name); |
256 ++numDevs; | |
257 } 258 break; 259 260 default: 261 break; 262 } 263 } 264 --- 15 unchanged lines hidden (view full) --- 280 for (ifptr = ifc.ifc_req; ifptr < end; ifptr++) { 281 /* If it's not a link entry, forget it */ 282 if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK) 283 continue; 284 /* Eliminate network devices that don't make sense */ 285 if (!strncmp(ifptr->ifr_name, "tun", 3) 286 || !strncmp(ifptr->ifr_name, "lo0", 3)) 287 continue; | 240 } 241 break; 242 243 default: 244 break; 245 } 246 } 247 --- 15 unchanged lines hidden (view full) --- 263 for (ifptr = ifc.ifc_req; ifptr < end; ifptr++) { 264 /* If it's not a link entry, forget it */ 265 if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK) 266 continue; 267 /* Eliminate network devices that don't make sense */ 268 if (!strncmp(ifptr->ifr_name, "tun", 3) 269 || !strncmp(ifptr->ifr_name, "lo0", 3)) 270 continue; |
288 CHECK_DEVS; 289 Devices[numDevs] = new_device(ifptr->ifr_name); 290 Devices[numDevs]->type = DEVICE_TYPE_NETWORK; 291 Devices[numDevs]->devname = NULL; 292 Devices[numDevs]->enabled = FALSE; 293 Devices[numDevs]->init = mediaInitNetwork; 294 Devices[numDevs]->get = mediaGetNetwork; 295 Devices[numDevs]->close = mediaCloseNetwork; 296 Devices[numDevs]->private = NULL; | 271 deviceRegister(ifptr->ifr_name, ifptr->ifr_name, ifptr->ifr_name, 272 DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork, mediaGetNetwork, mediaCloseNetwork, NULL); |
297 msgDebug("Found a device of type network named: %s\n", ifptr->ifr_name); | 273 msgDebug("Found a device of type network named: %s\n", ifptr->ifr_name); |
298 ++numDevs; | |
299 close(s); 300 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 301 msgConfirm("ifconfig: socket"); 302 continue; 303 } | 274 close(s); 275 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 276 msgConfirm("ifconfig: socket"); 277 continue; 278 } |
304 if (ifptr->ifr_addr.sa_len) /* Dohw! */ 305 ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len 306 - sizeof(struct sockaddr)); | 279 if (ifptr->ifr_addr.sa_len) /* I'm not sure why this is here - it's inherited */ 280 ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len - sizeof(struct sockaddr)); |
307 } | 281 } |
308 /* Terminate the devices array */ 309 Devices[numDevs] = NULL; | |
310} 311 312/* 313 * Find all devices that match the criteria, allowing "wildcarding" as well | 282} 283 284/* 285 * Find all devices that match the criteria, allowing "wildcarding" as well |
314 * by allowing NULL or ANY values to match all. | 286 * by allowing NULL or ANY values to match all. The array returned is static 287 * and may be used until the next invocation of deviceFind(). |
315 */ 316Device ** 317deviceFind(char *name, DeviceType class) 318{ 319 static Device *found[DEV_MAX]; 320 int i, j; 321 322 for (i = 0, j = 0; i < numDevs; i++) { --- 58 unchanged lines hidden --- | 288 */ 289Device ** 290deviceFind(char *name, DeviceType class) 291{ 292 static Device *found[DEV_MAX]; 293 int i, j; 294 295 for (i = 0, j = 0; i < numDevs; i++) { --- 58 unchanged lines hidden --- |