1995-05-01 21:56:32 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1998-10-19 14:58:38 +00:00
|
|
|
* $Id: devices.c,v 1.85 1998/10/18 16:24:20 wpaul Exp $
|
1995-05-01 21:56:32 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Jordan Hubbard. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1995-05-30 08:29:07 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
1995-05-01 21:56:32 +00:00
|
|
|
* point in the file.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
1995-05-11 06:47:46 +00:00
|
|
|
#include <sys/fcntl.h>
|
1995-05-16 02:53:31 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-12-11 16:32:33 +00:00
|
|
|
#include <sys/errno.h>
|
1996-12-14 23:09:10 +00:00
|
|
|
#include <sys/time.h>
|
1995-05-16 02:53:31 +00:00
|
|
|
#include <net/if.h>
|
1997-01-06 11:32:44 +00:00
|
|
|
#include <net/if_var.h>
|
1995-05-16 02:53:31 +00:00
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ctype.h>
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1998-03-15 16:15:47 +00:00
|
|
|
/* how much to bias minor number for a given /dev/<ct#><un#>s<s#> slice */
|
|
|
|
#define SLICE_DELTA (0x10000)
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
static Device *Devices[DEV_MAX];
|
|
|
|
static int numDevs;
|
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
static struct _devname {
|
1995-05-16 02:53:31 +00:00
|
|
|
DeviceType type;
|
|
|
|
char *name;
|
|
|
|
char *description;
|
1998-02-10 18:31:27 +00:00
|
|
|
int major, minor, delta, max;
|
|
|
|
char dev_type;
|
1995-05-16 02:53:31 +00:00
|
|
|
} device_names[] = {
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_CDROM, "cd%dc", "SCSI CDROM drive", 6, 2, 8, 4, 'b' },
|
1998-05-11 00:47:27 +00:00
|
|
|
{ DEVICE_TYPE_CDROM, "mcd%da", "Mitsumi (old model) CDROM drive", 7, 0, 8, 4, 'b' },
|
|
|
|
{ DEVICE_TYPE_CDROM, "scd%da", "Sony CDROM drive - CDU31/33A type", 16, 0, 8, 4, 'b' },
|
1998-05-11 00:45:06 +00:00
|
|
|
{ DEVICE_TYPE_CDROM, "matcd%da", "Matsushita CDROM ('sound blaster' type)", 17, 0, 8, 4, 'b' },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_CDROM, "wcd%dc", "ATAPI IDE CDROM", 19, 2, 8, 4, 'b' },
|
1998-09-15 10:24:46 +00:00
|
|
|
{ DEVICE_TYPE_TAPE, "rsa%d", "SCSI tape drive", 14, 0, 16, 4, 'c' },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_TAPE, "rwt%d", "Wangtek tape drive", 10, 0, 1, 4, 'c' },
|
1998-09-15 10:24:46 +00:00
|
|
|
{ DEVICE_TYPE_DISK, "da%d", "SCSI disk device", 4, 65538, 8, 16, 'b' },
|
|
|
|
{ DEVICE_TYPE_DISK, "rda%d", "SCSI disk device", 13, 65538, 8, 16, 'c' },
|
1998-06-29 09:28:01 +00:00
|
|
|
{ DEVICE_TYPE_DISK, "wd%d", "IDE/ESDI/MFM/ST506 disk device", 0, 65538, 8, 16, 'b' },
|
|
|
|
{ DEVICE_TYPE_DISK, "rwd%d", "IDE/ESDI/MFM/ST506 disk device", 3, 65538, 8, 16, 'c' },
|
1998-10-19 14:58:38 +00:00
|
|
|
{ DEVICE_TYPE_DISK, "fla%d", "DiskOnChip2000 Flash device", 28, 65538, 8, 16, 'b' },
|
|
|
|
{ DEVICE_TYPE_DISK, "rfla%d", "DiskOnChip2000 Flash devicee", 101, 65538, 8, 16, 'c' },
|
1998-07-18 09:42:02 +00:00
|
|
|
{ DEVICE_TYPE_DISK, "wfd%d", "ATAPI floppy device", 1, 65538, 8, 4, 'b' },
|
|
|
|
{ DEVICE_TYPE_DISK, "rwfd%d", "ATAPI floppy device", 87, 65538, 8, 4, 'c' },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_FLOPPY, "fd%d", "floppy drive unit A", 2, 0, 64, 4, 'b' },
|
1998-07-18 09:42:02 +00:00
|
|
|
{ DEVICE_TYPE_FLOPPY, "wfd%d", "ATAPI floppy drive unit A", 1, 0, 8, 4, 'b' },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_FLOPPY, "worm%d", "SCSI optical disk / CDR", 23, 0, 1, 4, 'b' },
|
1998-07-18 09:42:02 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "fpa", "DEC DEFPA PCI FDDI card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "sr", "SDL T1/E1 sync serial PCI card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "cc3i", "SDL HSSI sync serial PCI card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "en", "Efficient Networks ATM PCI card" },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "de", "DEC DE435 PCI NIC or other DC21040-AA based card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "fxp", "Intel EtherExpress Pro/100B PCI Fast Ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ed", "WD/SMC 80xx; Novell NE1000/2000; 3Com 3C503 card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ep", "3Com 3C509 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "el", "3Com 3C501 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ex", "Intel EtherExpress Pro/10 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "fe", "Fujitsu MB86960A/MB86965A ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ie", "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ix", "Intel Etherexpress ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "le", "DEC EtherWorks 2 or 3 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "lnc", "Lance/PCnet (Isolan/Novell NE2100/NE32-VL) ethernet" },
|
1998-10-18 16:24:34 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "rl", "RealTek 8129/8139 PCI ethernet card" },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "tx", "SMC 9432TX ethernet card" },
|
1998-09-13 16:45:10 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "tl", "Texas Instruments ThunderLAN PCI ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "vx", "3COM 3c590 / 3c595 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "xl", "3COM 3c90x / 3c90xB PCI ethernet card" },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "ze", "IBM/National Semiconductor PCMCIA ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "zp", "3Com Etherlink III PCMCIA ethernet card" },
|
1998-03-15 16:15:47 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "cuaa%d", "%s on device %s (COM%d)", 28, 128, 1, 16, 'c' },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "lp", "Parallel Port IP (PLIP) peer connection" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "lo", "Loop-back (local) network interface" },
|
1998-02-10 18:31:27 +00:00
|
|
|
{ 0 },
|
1995-05-08 21:39:40 +00:00
|
|
|
};
|
|
|
|
|
1995-05-20 10:33:14 +00:00
|
|
|
Device *
|
1995-05-16 02:53:31 +00:00
|
|
|
new_device(char *name)
|
1995-05-01 21:56:32 +00:00
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
Device *dev;
|
|
|
|
|
|
|
|
dev = safe_malloc(sizeof(Device));
|
1995-06-11 19:33:05 +00:00
|
|
|
bzero(dev, sizeof(Device));
|
1995-05-16 02:53:31 +00:00
|
|
|
if (name)
|
1996-12-09 08:22:19 +00:00
|
|
|
SAFE_STRCPY(dev->name, name);
|
1995-05-16 02:53:31 +00:00
|
|
|
return dev;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|
|
|
|
|
1995-06-11 19:33:05 +00:00
|
|
|
/* Stubs for unimplemented strategy routines */
|
|
|
|
Boolean
|
|
|
|
dummyInit(Device *dev)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1996-12-11 09:35:06 +00:00
|
|
|
FILE *
|
1996-03-02 07:31:58 +00:00
|
|
|
dummyGet(Device *dev, char *dist, Boolean probe)
|
1995-06-11 19:33:05 +00:00
|
|
|
{
|
1996-12-11 09:35:06 +00:00
|
|
|
return NULL;
|
1995-06-11 19:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dummyShutdown(Device *dev)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
static int
|
1998-02-10 18:31:27 +00:00
|
|
|
deviceTry(struct _devname dev, char *try, int i)
|
1995-05-01 21:56:32 +00:00
|
|
|
{
|
1995-05-16 11:37:27 +00:00
|
|
|
int fd;
|
1998-02-10 18:31:27 +00:00
|
|
|
char unit[80];
|
|
|
|
mode_t m;
|
|
|
|
dev_t d;
|
|
|
|
int fail;
|
|
|
|
|
|
|
|
snprintf(unit, sizeof unit, dev.name, i);
|
|
|
|
snprintf(try, FILENAME_MAX, "/dev/%s", unit);
|
1998-03-16 14:33:18 +00:00
|
|
|
fd = open(try, O_RDONLY);
|
|
|
|
if (fd >= 0)
|
|
|
|
return fd;
|
1998-03-15 16:15:47 +00:00
|
|
|
m = 0640;
|
1998-02-10 18:31:27 +00:00
|
|
|
if (dev.dev_type == 'c')
|
|
|
|
m |= S_IFCHR;
|
|
|
|
else
|
|
|
|
m |= S_IFBLK;
|
|
|
|
d = makedev(dev.major, dev.minor + (i * dev.delta));
|
|
|
|
fail = mknod(try, m, d);
|
1996-11-27 01:01:52 +00:00
|
|
|
fd = open(try, O_RDONLY);
|
1998-03-15 16:15:47 +00:00
|
|
|
if (fd >= 0)
|
1995-05-16 02:53:31 +00:00
|
|
|
return fd;
|
1998-02-10 18:31:27 +00:00
|
|
|
else if (!fail)
|
|
|
|
(void)unlink(try);
|
|
|
|
/* Don't try a "make-under" here since we're using a fixit floppy in this case */
|
|
|
|
snprintf(try, FILENAME_MAX, "/mnt/dev/%s", unit);
|
1996-11-27 01:01:52 +00:00
|
|
|
fd = open(try, O_RDONLY);
|
1995-05-16 02:53:31 +00:00
|
|
|
return fd;
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
|
|
|
|
1995-05-20 10:33:14 +00:00
|
|
|
/* Register a new device in the devices array */
|
|
|
|
Device *
|
|
|
|
deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled,
|
1996-12-11 09:35:06 +00:00
|
|
|
Boolean (*init)(Device *), FILE * (*get)(Device *, char *, Boolean),
|
|
|
|
void (*shutdown)(Device *), void *private)
|
1995-05-20 10:33:14 +00:00
|
|
|
{
|
1996-06-13 17:07:41 +00:00
|
|
|
Device *newdev = NULL;
|
1995-05-20 10:33:14 +00:00
|
|
|
|
|
|
|
if (numDevs == DEV_MAX)
|
|
|
|
msgFatal("Too many devices found!");
|
1996-06-12 17:09:34 +00:00
|
|
|
else {
|
|
|
|
newdev = new_device(name);
|
|
|
|
newdev->description = desc;
|
|
|
|
newdev->devname = devname;
|
|
|
|
newdev->type = type;
|
|
|
|
newdev->enabled = enabled;
|
|
|
|
newdev->init = init ? init : dummyInit;
|
|
|
|
newdev->get = get ? get : dummyGet;
|
|
|
|
newdev->shutdown = shutdown ? shutdown : dummyShutdown;
|
|
|
|
newdev->private = private;
|
|
|
|
Devices[numDevs] = newdev;
|
|
|
|
Devices[++numDevs] = NULL;
|
|
|
|
}
|
1995-05-20 10:33:14 +00:00
|
|
|
return newdev;
|
|
|
|
}
|
1995-05-24 09:00:58 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
/* Get all device information for devices we have attached */
|
|
|
|
void
|
1995-05-16 11:37:27 +00:00
|
|
|
deviceGetAll(void)
|
1995-05-01 21:56:32 +00:00
|
|
|
{
|
1998-02-10 18:31:27 +00:00
|
|
|
int i, j, fd, s;
|
1995-05-16 02:53:31 +00:00
|
|
|
struct ifconf ifc;
|
|
|
|
struct ifreq *ifptr, *end;
|
1995-05-16 11:37:27 +00:00
|
|
|
int ifflags;
|
|
|
|
char buffer[INTERFACE_MAX * sizeof(struct ifreq)];
|
|
|
|
char **names;
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1998-09-30 01:46:27 +00:00
|
|
|
msgNotify("Probing devices, please wait (this can take a while)...");
|
1998-02-10 18:31:27 +00:00
|
|
|
/* First go for the network interfaces. Stolen shamelessly from ifconfig! */
|
1996-10-05 11:56:50 +00:00
|
|
|
ifc.ifc_len = sizeof(buffer);
|
|
|
|
ifc.ifc_buf = buffer;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
msgConfirm("ifconfig: socket");
|
1996-12-08 12:27:58 +00:00
|
|
|
goto skipif; /* Jump over network iface probing */
|
1996-10-05 11:56:50 +00:00
|
|
|
}
|
|
|
|
if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
|
|
|
|
msgConfirm("ifconfig (SIOCGIFCONF)");
|
1996-12-08 12:27:58 +00:00
|
|
|
goto skipif; /* Jump over network iface probing */
|
1996-10-05 11:56:50 +00:00
|
|
|
}
|
|
|
|
ifflags = ifc.ifc_req->ifr_flags;
|
|
|
|
end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
|
|
|
|
for (ifptr = ifc.ifc_req; ifptr < end; ifptr++) {
|
|
|
|
char *descr;
|
|
|
|
|
|
|
|
/* If it's not a link entry, forget it */
|
|
|
|
if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK)
|
|
|
|
continue;
|
1996-12-08 12:27:58 +00:00
|
|
|
|
1996-10-05 11:56:50 +00:00
|
|
|
/* Eliminate network devices that don't make sense */
|
1998-02-10 18:31:27 +00:00
|
|
|
if (!strncmp(ifptr->ifr_name, "lo", 2))
|
1996-10-05 11:56:50 +00:00
|
|
|
continue;
|
1996-12-08 12:27:58 +00:00
|
|
|
|
1997-01-15 13:39:50 +00:00
|
|
|
/* If we have a slip device, don't register it */
|
1997-01-04 13:29:10 +00:00
|
|
|
if (!strncmp(ifptr->ifr_name, "sl", 2)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* And the same for ppp */
|
|
|
|
if (!strncmp(ifptr->ifr_name, "tun", 3) || !strncmp(ifptr->ifr_name, "ppp", 3)) {
|
|
|
|
continue;
|
|
|
|
}
|
1996-12-08 12:27:58 +00:00
|
|
|
/* Try and find its description */
|
|
|
|
for (i = 0, descr = NULL; device_names[i].name; i++) {
|
1996-10-05 11:56:50 +00:00
|
|
|
int len = strlen(device_names[i].name);
|
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
if (!ifptr->ifr_name || !ifptr->ifr_name[0])
|
|
|
|
continue;
|
|
|
|
else if (!strncmp(ifptr->ifr_name, device_names[i].name, len)) {
|
1996-10-05 11:56:50 +00:00
|
|
|
descr = device_names[i].description;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!descr)
|
|
|
|
descr = "<unknown network interface type>";
|
1996-12-08 12:27:58 +00:00
|
|
|
|
1996-10-05 11:56:50 +00:00
|
|
|
deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE,
|
1996-12-11 09:35:06 +00:00
|
|
|
mediaInitNetwork, NULL, mediaShutdownNetwork, NULL);
|
1996-12-08 12:27:58 +00:00
|
|
|
msgDebug("Found a network device named %s\n", ifptr->ifr_name);
|
1996-10-05 11:56:50 +00:00
|
|
|
close(s);
|
|
|
|
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
|
|
|
msgConfirm("ifconfig: socket");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ifptr->ifr_addr.sa_len) /* I'm not sure why this is here - it's inherited */
|
|
|
|
ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len - sizeof(struct sockaddr));
|
|
|
|
}
|
|
|
|
|
1996-12-08 12:27:58 +00:00
|
|
|
skipif:
|
1998-02-10 18:31:27 +00:00
|
|
|
/* Next, try to find all the types of devices one might need
|
1996-10-05 11:56:50 +00:00
|
|
|
* during the second stage of the installation.
|
1995-05-16 02:53:31 +00:00
|
|
|
*/
|
|
|
|
for (i = 0; device_names[i].name; i++) {
|
1998-02-10 18:31:27 +00:00
|
|
|
for (j = 0; j < device_names[i].max; j++) {
|
|
|
|
char try[FILENAME_MAX];
|
|
|
|
|
|
|
|
switch(device_names[i].type) {
|
|
|
|
case DEVICE_TYPE_CDROM:
|
|
|
|
fd = deviceTry(device_names[i], try, j);
|
|
|
|
if (fd >= 0 || errno == EBUSY) { /* EBUSY if already mounted */
|
1998-02-10 18:43:11 +00:00
|
|
|
char n[BUFSIZ];
|
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
if (fd >= 0) close(fd);
|
1998-02-10 18:43:11 +00:00
|
|
|
snprintf(n, sizeof n, device_names[i].name, j);
|
|
|
|
deviceRegister(strdup(n), device_names[i].description, strdup(try),
|
1998-02-10 18:31:27 +00:00
|
|
|
DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM,
|
|
|
|
mediaShutdownCDROM, NULL);
|
|
|
|
msgDebug("Found a CDROM device for %s\n", try);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_TAPE:
|
|
|
|
fd = deviceTry(device_names[i], try, j);
|
|
|
|
if (fd >= 0) {
|
1998-02-10 18:43:11 +00:00
|
|
|
char n[BUFSIZ];
|
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
close(fd);
|
1998-02-10 18:43:11 +00:00
|
|
|
snprintf(n, sizeof n, device_names[i].name, j);
|
|
|
|
deviceRegister(strdup(n), device_names[i].description, strdup(try),
|
1998-02-10 18:31:27 +00:00
|
|
|
DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaShutdownTape, NULL);
|
|
|
|
msgDebug("Found a TAPE device for %s\n", try);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_DISK:
|
|
|
|
fd = deviceTry(device_names[i], try, j);
|
1998-03-16 14:33:18 +00:00
|
|
|
if (fd >= 0 && RunningAsInit) {
|
1998-03-15 16:15:47 +00:00
|
|
|
dev_t d;
|
1998-03-20 23:39:57 +00:00
|
|
|
mode_t m;
|
1998-03-15 16:15:47 +00:00
|
|
|
int s, fail;
|
1998-03-20 18:07:02 +00:00
|
|
|
char unit[80], slice[80];
|
1998-03-15 16:15:47 +00:00
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
close(fd);
|
1998-03-15 16:15:47 +00:00
|
|
|
/* Make associated slice entries */
|
1998-06-29 09:28:01 +00:00
|
|
|
for (s = 1; s < 8; s++) {
|
1998-03-20 18:26:04 +00:00
|
|
|
snprintf(unit, sizeof unit, device_names[i].name, j);
|
1998-03-20 18:07:02 +00:00
|
|
|
snprintf(slice, sizeof slice, "/dev/%ss%d", unit, s);
|
1998-03-15 16:15:47 +00:00
|
|
|
d = makedev(device_names[i].major, device_names[i].minor +
|
|
|
|
(j * device_names[i].delta) + (s * SLICE_DELTA));
|
1998-03-20 23:39:57 +00:00
|
|
|
m = 0640;
|
|
|
|
if (device_names[i].dev_type == 'c')
|
|
|
|
m |= S_IFCHR;
|
|
|
|
else
|
|
|
|
m |= S_IFBLK;
|
|
|
|
fail = mknod(slice, m, d);
|
1998-03-15 16:15:47 +00:00
|
|
|
fd = open(slice, O_RDONLY);
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
else if (!fail)
|
|
|
|
(void)unlink(slice);
|
|
|
|
}
|
|
|
|
}
|
1998-02-10 18:31:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_FLOPPY:
|
|
|
|
fd = deviceTry(device_names[i], try, j);
|
|
|
|
if (fd >= 0) {
|
1998-02-10 18:43:11 +00:00
|
|
|
char n[BUFSIZ];
|
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
close(fd);
|
1998-02-10 18:43:11 +00:00
|
|
|
snprintf(n, sizeof n, device_names[i].name, j);
|
|
|
|
deviceRegister(strdup(n), device_names[i].description, strdup(try),
|
1998-02-10 18:31:27 +00:00
|
|
|
DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy,
|
|
|
|
mediaShutdownFloppy, NULL);
|
|
|
|
msgDebug("Found a floppy device for %s\n", try);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_NETWORK:
|
|
|
|
fd = deviceTry(device_names[i], try, j);
|
|
|
|
/* The only network devices that you can open this way are serial ones */
|
|
|
|
if (fd >= 0) {
|
|
|
|
char *newdesc, *cp;
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
cp = device_names[i].description;
|
|
|
|
/* Serial devices get a slip and ppp device each, if supported */
|
|
|
|
newdesc = safe_malloc(strlen(cp) + 40);
|
|
|
|
sprintf(newdesc, cp, "SLIP interface", try, j + 1);
|
|
|
|
deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
|
|
|
|
NULL, mediaShutdownNetwork, NULL);
|
|
|
|
msgDebug("Add mapping for %s to sl0\n", try);
|
|
|
|
newdesc = safe_malloc(strlen(cp) + 50);
|
|
|
|
sprintf(newdesc, cp, "PPP interface", try, j + 1);
|
|
|
|
deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
|
|
|
|
NULL, mediaShutdownNetwork, NULL);
|
|
|
|
msgDebug("Add mapping for %s to ppp0\n", try);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1995-05-19 02:31:13 +00:00
|
|
|
}
|
1998-02-10 18:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, go get the disks and look for DOS partitions to register */
|
|
|
|
if ((names = Disk_Names()) != NULL) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; names[i]; i++) {
|
|
|
|
Chunk *c1;
|
|
|
|
Disk *d;
|
1995-05-19 02:31:13 +00:00
|
|
|
|
1998-02-10 18:31:27 +00:00
|
|
|
d = Open_Disk(names[i]);
|
|
|
|
if (!d)
|
|
|
|
msgFatal("Unable to open disk %s", names[i]);
|
|
|
|
|
|
|
|
deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE,
|
|
|
|
dummyInit, dummyGet, dummyShutdown, d);
|
|
|
|
msgDebug("Found a disk device named %s\n", names[i]);
|
|
|
|
|
|
|
|
/* Look for existing DOS partitions to register as "DOS media devices" */
|
|
|
|
for (c1 = d->chunks->part; c1; c1 = c1->next) {
|
|
|
|
if (c1->type == fat || c1->type == extended) {
|
|
|
|
Device *dev;
|
|
|
|
char devname[80];
|
|
|
|
|
|
|
|
/* Got one! */
|
|
|
|
snprintf(devname, sizeof devname, "/dev/%s", c1->name);
|
|
|
|
dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE,
|
|
|
|
mediaInitDOS, mediaGetDOS, mediaShutdownDOS, NULL);
|
|
|
|
dev->private = c1;
|
|
|
|
msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name);
|
|
|
|
}
|
|
|
|
}
|
1995-05-08 01:27:07 +00:00
|
|
|
}
|
1998-02-10 18:31:27 +00:00
|
|
|
free(names);
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find all devices that match the criteria, allowing "wildcarding" as well
|
1995-05-20 10:33:14 +00:00
|
|
|
* by allowing NULL or ANY values to match all. The array returned is static
|
|
|
|
* and may be used until the next invocation of deviceFind().
|
1995-05-16 02:53:31 +00:00
|
|
|
*/
|
|
|
|
Device **
|
|
|
|
deviceFind(char *name, DeviceType class)
|
|
|
|
{
|
|
|
|
static Device *found[DEV_MAX];
|
|
|
|
int i, j;
|
|
|
|
|
1997-01-04 13:29:10 +00:00
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < numDevs; i++) {
|
1995-05-17 14:40:00 +00:00
|
|
|
if ((!name || !strcmp(Devices[i]->name, name))
|
|
|
|
&& (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
|
1995-05-16 02:53:31 +00:00
|
|
|
found[j++] = Devices[i];
|
1995-05-04 23:36:23 +00:00
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
found[j] = NULL;
|
|
|
|
return j ? found : NULL;
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
|
|
|
|
1997-01-15 16:21:10 +00:00
|
|
|
Device **
|
|
|
|
deviceFindDescr(char *name, char *desc, DeviceType class)
|
|
|
|
{
|
|
|
|
static Device *found[DEV_MAX];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < numDevs; i++) {
|
|
|
|
if ((!name || !strcmp(Devices[i]->name, name)) &&
|
|
|
|
(!desc || !strcmp(Devices[i]->description, desc)) &&
|
|
|
|
(class == DEVICE_TYPE_ANY || class == Devices[i]->type))
|
|
|
|
found[j++] = Devices[i];
|
|
|
|
}
|
|
|
|
found[j] = NULL;
|
|
|
|
return j ? found : NULL;
|
|
|
|
}
|
|
|
|
|
1995-05-20 00:13:14 +00:00
|
|
|
int
|
|
|
|
deviceCount(Device **devs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!devs)
|
|
|
|
return 0;
|
|
|
|
for (i = 0; devs[i]; i++);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
1995-05-04 03:51:22 +00:00
|
|
|
/*
|
1995-05-16 02:53:31 +00:00
|
|
|
* Create a menu listing all the devices of a certain type in the system.
|
|
|
|
* The passed-in menu is expected to be a "prototype" from which the new
|
|
|
|
* menu is cloned.
|
1995-05-04 03:51:22 +00:00
|
|
|
*/
|
|
|
|
DMenu *
|
1996-04-13 13:32:15 +00:00
|
|
|
deviceCreateMenu(DMenu *menu, DeviceType type, int (*hook)(dialogMenuItem *d), int (*check)(dialogMenuItem *d))
|
1995-05-04 03:51:22 +00:00
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
Device **devs;
|
1995-05-16 11:37:27 +00:00
|
|
|
int numdevs;
|
|
|
|
DMenu *tmp = NULL;
|
|
|
|
int i, j;
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
devs = deviceFind(NULL, type);
|
1996-06-13 17:07:41 +00:00
|
|
|
numdevs = deviceCount(devs);
|
|
|
|
if (!numdevs)
|
1995-05-16 11:37:27 +00:00
|
|
|
return NULL;
|
1996-04-07 03:52:36 +00:00
|
|
|
tmp = (DMenu *)safe_malloc(sizeof(DMenu) + (sizeof(dialogMenuItem) * (numdevs + 1)));
|
1995-05-16 11:37:27 +00:00
|
|
|
bcopy(menu, tmp, sizeof(DMenu));
|
|
|
|
for (i = 0; devs[i]; i++) {
|
1996-04-07 03:52:36 +00:00
|
|
|
tmp->items[i].prompt = devs[i]->name;
|
1996-06-13 17:07:41 +00:00
|
|
|
for (j = 0; j < numDevs; j++) {
|
|
|
|
if (devs[i] == Devices[j]) {
|
|
|
|
tmp->items[i].title = Devices[j]->description;
|
1995-05-16 11:37:27 +00:00
|
|
|
break;
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
1996-06-13 17:07:41 +00:00
|
|
|
if (j == numDevs)
|
1996-04-07 03:52:36 +00:00
|
|
|
tmp->items[i].title = "<unknown device type>";
|
|
|
|
tmp->items[i].fire = hook;
|
1996-04-13 13:32:15 +00:00
|
|
|
tmp->items[i].checked = check;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|
1995-05-16 11:37:27 +00:00
|
|
|
tmp->items[i].title = NULL;
|
|
|
|
return tmp;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|