]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/sysinstall/devices.c
This commit was generated by cvs2svn to compensate for changes in r47133,
[FreeBSD/FreeBSD.git] / release / sysinstall / devices.c
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.89 1999/04/06 08:25:52 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
16  *    notice, this list of conditions and the following disclaimer,
17  *    verbatim and that no modifications are made prior to this
18  *    point in the file.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36
37 #include "sysinstall.h"
38 #include <sys/fcntl.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <sys/ioctl.h>
42 #include <sys/errno.h>
43 #include <sys/time.h>
44 #include <net/if.h>
45 #include <net/if_var.h>
46 #include <net/if_dl.h>
47 #include <netinet/in.h>
48 #include <netinet/in_var.h>
49 #include <arpa/inet.h>
50 #include <ctype.h>
51
52 /* how much to bias minor number for a given /dev/<ct#><un#>s<s#> slice */
53 #define SLICE_DELTA     (0x10000)
54
55 static Device *Devices[DEV_MAX];
56 static int numDevs;
57
58 static struct _devname {
59     DeviceType type;
60     char *name;
61     char *description;
62     int major, minor, delta, max;
63     char dev_type;
64 } device_names[] = {
65     { DEVICE_TYPE_CDROM,        "cd%dc",        "SCSI CDROM drive",     6, 2, 8, 4, 'b'                         },
66     { DEVICE_TYPE_CDROM,        "mcd%da",       "Mitsumi (old model) CDROM drive",      7, 0, 8, 4, 'b'         },
67     { DEVICE_TYPE_CDROM,        "scd%da",       "Sony CDROM drive - CDU31/33A type",    16, 0, 8, 4, 'b'        },
68     { DEVICE_TYPE_CDROM,        "matcd%da",     "Matsushita CDROM ('sound blaster' type)", 17, 0, 8, 4, 'b'     },
69     { DEVICE_TYPE_CDROM,        "wcd%dc",       "ATAPI IDE CDROM",      19, 2, 8, 4, 'b'                        },
70     { DEVICE_TYPE_TAPE,         "rsa%d",        "SCSI tape drive",      14, 0, 16, 4, 'c'                       },
71     { DEVICE_TYPE_TAPE,         "rwt%d",        "Wangtek tape drive",   10, 0, 1, 4, 'c'                        },
72     { DEVICE_TYPE_DISK,         "da%d",         "SCSI disk device",     4, 65538, 8, 16, 'b'                    },
73     { DEVICE_TYPE_DISK,         "rda%d",        "SCSI disk device",     13, 65538, 8, 16, 'c'                   },
74     { DEVICE_TYPE_DISK,         "wd%d",         "IDE/ESDI/MFM/ST506 disk device",       0, 65538, 8, 16, 'b'    },
75     { DEVICE_TYPE_DISK,         "rwd%d",        "IDE/ESDI/MFM/ST506 disk device",       3, 65538, 8, 16, 'c'    },
76     { DEVICE_TYPE_DISK,         "fla%d",        "DiskOnChip2000 Flash device", 28, 65538, 8, 16, 'b'    },
77     { DEVICE_TYPE_DISK,         "rfla%d",       "DiskOnChip2000 Flash devicee", 101, 65538, 8, 16, 'c'  },
78     { DEVICE_TYPE_DISK,         "wfd%d",        "ATAPI floppy device",  1, 65538, 8, 4, 'b'             },
79     { DEVICE_TYPE_DISK,         "rwfd%d",       "ATAPI floppy device",  87, 65538, 8, 4, 'c'            },
80     { DEVICE_TYPE_FLOPPY,       "fd%d",         "floppy drive unit A",  2, 0, 64, 4, 'b'                        },
81     { DEVICE_TYPE_FLOPPY,       "wfd%d",        "ATAPI floppy drive unit A",    1, 0, 8, 4, 'b'                 },
82     { DEVICE_TYPE_FLOPPY,       "worm%d",       "SCSI optical disk / CDR",      23, 0, 1, 4, 'b'                },
83     { DEVICE_TYPE_NETWORK,      "ax",           "ASIX AX88140A PCI ethernet card"                               },
84     { DEVICE_TYPE_NETWORK,      "fpa",          "DEC DEFPA PCI FDDI card"                                       },
85     { DEVICE_TYPE_NETWORK,      "sr",           "SDL T1/E1 sync serial PCI card"                                },
86     { DEVICE_TYPE_NETWORK,      "cc3i",         "SDL HSSI sync serial PCI card"                                 },
87     { DEVICE_TYPE_NETWORK,      "en",           "Efficient Networks ATM PCI card"                               },
88     { DEVICE_TYPE_NETWORK,      "de",           "DEC DE435 PCI NIC or other DC21040-AA based card"              },
89     { DEVICE_TYPE_NETWORK,      "fxp",          "Intel EtherExpress Pro/100B PCI Fast Ethernet card"            },
90     { DEVICE_TYPE_NETWORK,      "ed",           "WD/SMC 80xx; Novell NE1000/2000; 3Com 3C503 card"              },
91     { DEVICE_TYPE_NETWORK,      "ep",           "3Com 3C509 ethernet card"                                      },
92     { DEVICE_TYPE_NETWORK,      "el",           "3Com 3C501 ethernet card"                                      },
93     { DEVICE_TYPE_NETWORK,      "ex",           "Intel EtherExpress Pro/10 ethernet card"                       },
94     { DEVICE_TYPE_NETWORK,      "fe",           "Fujitsu MB86960A/MB86965A ethernet card"                       },
95     { DEVICE_TYPE_NETWORK,      "ie",           "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210"                 },
96     { DEVICE_TYPE_NETWORK,      "ix",           "Intel Etherexpress ethernet card"                              },
97     { DEVICE_TYPE_NETWORK,      "le",           "DEC EtherWorks 2 or 3 ethernet card"                           },
98     { DEVICE_TYPE_NETWORK,      "lnc",          "Lance/PCnet (Isolan/Novell NE2100/NE32-VL) ethernet"           },
99     { DEVICE_TYPE_NETWORK,      "mx",           "Macronix 98713/98715/98725 PCI ethernet card"          },
100     { DEVICE_TYPE_NETWORK,      "pn",           "Lite-On 82168/82169 PNIC PCI ethernet card"            },
101     { DEVICE_TYPE_NETWORK,      "rl",           "RealTek 8129/8139 PCI ethernet card"           },
102     { DEVICE_TYPE_NETWORK,      "tx",           "SMC 9432TX ethernet card"                                      },
103     { DEVICE_TYPE_NETWORK,      "ti",           "Alteon Networks PCI gigabit ethernet card"             },
104     { DEVICE_TYPE_NETWORK,      "tl",           "Texas Instruments ThunderLAN PCI ethernet card"                },
105     { DEVICE_TYPE_NETWORK,      "vr",           "VIA VT3043/VT86C100A Rhine PCI ethernet card"                          },
106     { DEVICE_TYPE_NETWORK,      "vx",           "3COM 3c590 / 3c595 ethernet card"                              },
107     { DEVICE_TYPE_NETWORK,      "wb",           "Winbond W89C840F PCI ethernet card"                            },
108     { DEVICE_TYPE_NETWORK,      "xl",           "3COM 3c90x / 3c90xB PCI ethernet card"                         },
109     { DEVICE_TYPE_NETWORK,      "ze",           "IBM/National Semiconductor PCMCIA ethernet card"               },
110     { DEVICE_TYPE_NETWORK,      "zp",           "3Com Etherlink III PCMCIA ethernet card"                       },
111     { DEVICE_TYPE_NETWORK,      "cuaa%d",       "%s on device %s (COM%d)",      28, 128, 1, 16, 'c'             },
112     { DEVICE_TYPE_NETWORK,      "lp",           "Parallel Port IP (PLIP) peer connection"                       },
113     { DEVICE_TYPE_NETWORK,      "lo",           "Loop-back (local) network interface"                           },
114     { 0 },
115 };
116
117 Device *
118 new_device(char *name)
119 {
120     Device *dev;
121
122     dev = safe_malloc(sizeof(Device));
123     bzero(dev, sizeof(Device));
124     if (name)
125         SAFE_STRCPY(dev->name, name);
126     return dev;
127 }
128
129 /* Stubs for unimplemented strategy routines */
130 Boolean
131 dummyInit(Device *dev)
132 {
133     return TRUE;
134 }
135
136 FILE *
137 dummyGet(Device *dev, char *dist, Boolean probe)
138 {
139     return NULL;
140 }
141
142 void
143 dummyShutdown(Device *dev)
144 {
145     return;
146 }
147
148 static int
149 deviceTry(struct _devname dev, char *try, int i)
150 {
151     int fd;
152     char unit[80];
153     mode_t m;
154     dev_t d;
155     int fail;
156
157     snprintf(unit, sizeof unit, dev.name, i);
158     snprintf(try, FILENAME_MAX, "/dev/%s", unit);
159     fd = open(try, O_RDONLY);
160     if (fd >= 0)
161         return fd;
162     m = 0640;
163     if (dev.dev_type == 'c')
164         m |= S_IFCHR;
165     else
166         m |= S_IFBLK;
167     d = makedev(dev.major, dev.minor + (i * dev.delta));
168     fail = mknod(try, m, d);
169     fd = open(try, O_RDONLY);
170     if (fd >= 0)
171         return fd;
172     else if (!fail)
173         (void)unlink(try);
174     /* Don't try a "make-under" here since we're using a fixit floppy in this case */
175     snprintf(try, FILENAME_MAX, "/mnt/dev/%s", unit);
176     fd = open(try, O_RDONLY);
177     return fd;
178 }
179
180 /* Register a new device in the devices array */
181 Device *
182 deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled,
183                Boolean (*init)(Device *), FILE * (*get)(Device *, char *, Boolean),
184                void (*shutdown)(Device *), void *private)
185 {
186     Device *newdev = NULL;
187
188     if (numDevs == DEV_MAX)
189         msgFatal("Too many devices found!");
190     else {
191         newdev = new_device(name);
192         newdev->description = desc;
193         newdev->devname = devname;
194         newdev->type = type;
195         newdev->enabled = enabled;
196         newdev->init = init ? init : dummyInit;
197         newdev->get = get ? get : dummyGet;
198         newdev->shutdown = shutdown ? shutdown : dummyShutdown;
199         newdev->private = private;
200         Devices[numDevs] = newdev;
201         Devices[++numDevs] = NULL;
202     }
203     return newdev;
204 }
205
206 /* Reset the registered device chain */
207 void
208 deviceReset(void)
209 {
210     int i;
211
212     for (i = 0; i < numDevs; i++) {
213         Devices[i]->shutdown(Devices[i]);
214
215         /* XXX this potentially leaks Devices[i]->private if it's being
216          * used to point to something dynamic, but you're not supposed
217          * to call this routine at such times that some open instance
218          * has its private ptr pointing somewhere anyway. XXX
219          */
220         free(Devices[i]);
221     }
222     Devices[numDevs = 0] = NULL;
223 }
224
225 /* Get all device information for devices we have attached */
226 void
227 deviceGetAll(void)
228 {
229     int i, j, fd, s;
230     struct ifconf ifc;
231     struct ifreq *ifptr, *end;
232     int ifflags;
233     char buffer[INTERFACE_MAX * sizeof(struct ifreq)];
234     char **names;
235
236     msgNotify("Probing devices, please wait (this can take a while)...");
237     /* First go for the network interfaces.  Stolen shamelessly from ifconfig! */
238     ifc.ifc_len = sizeof(buffer);
239     ifc.ifc_buf = buffer;
240
241     s = socket(AF_INET, SOCK_DGRAM, 0);
242     if (s < 0) {
243         msgConfirm("ifconfig: socket");
244         goto skipif;    /* Jump over network iface probing */
245     }
246     if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
247         msgConfirm("ifconfig (SIOCGIFCONF)");
248         goto skipif;    /* Jump over network iface probing */
249     }
250     ifflags = ifc.ifc_req->ifr_flags;
251     end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
252     for (ifptr = ifc.ifc_req; ifptr < end; ifptr++) {
253         char *descr;
254
255         /* If it's not a link entry, forget it */
256         if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK)
257             continue;
258
259         /* Eliminate network devices that don't make sense */
260         if (!strncmp(ifptr->ifr_name, "lo", 2))
261             continue;
262
263         /* If we have a slip device, don't register it */
264         if (!strncmp(ifptr->ifr_name, "sl", 2)) {
265             continue;
266         }
267         /* And the same for ppp */
268         if (!strncmp(ifptr->ifr_name, "tun", 3) || !strncmp(ifptr->ifr_name, "ppp", 3)) {
269             continue;
270         }
271         /* Try and find its description */
272         for (i = 0, descr = NULL; device_names[i].name; i++) {
273             int len = strlen(device_names[i].name);
274
275             if (!ifptr->ifr_name || !ifptr->ifr_name[0])
276                 continue;
277             else if (!strncmp(ifptr->ifr_name, device_names[i].name, len)) {
278                 descr = device_names[i].description;
279                 break;
280             }
281         }
282         if (!descr)
283             descr = "<unknown network interface type>";
284
285         deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE,
286                        mediaInitNetwork, NULL, mediaShutdownNetwork, NULL);
287         msgDebug("Found a network device named %s\n", ifptr->ifr_name);
288         close(s);
289         if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
290             msgConfirm("ifconfig: socket");
291             continue;
292         }
293         if (ifptr->ifr_addr.sa_len)     /* I'm not sure why this is here - it's inherited */
294             ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len - sizeof(struct sockaddr));
295     }
296
297 skipif:
298     /* Next, try to find all the types of devices one might need
299      * during the second stage of the installation.
300      */
301     for (i = 0; device_names[i].name; i++) {
302         for (j = 0; j < device_names[i].max; j++) {
303             char try[FILENAME_MAX];
304
305             switch(device_names[i].type) {
306             case DEVICE_TYPE_CDROM:
307                 fd = deviceTry(device_names[i], try, j);
308                 if (fd >= 0 || errno == EBUSY) {        /* EBUSY if already mounted */
309                     char n[BUFSIZ];
310
311                     if (fd >= 0) close(fd);
312                     snprintf(n, sizeof n, device_names[i].name, j);
313                     deviceRegister(strdup(n), device_names[i].description, strdup(try),
314                                          DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM,
315                                          mediaShutdownCDROM, NULL);
316                     msgDebug("Found a CDROM device for %s\n", try);
317                 }
318                 break;
319
320             case DEVICE_TYPE_TAPE:
321                 fd = deviceTry(device_names[i], try, j);
322                 if (fd >= 0) {
323                     char n[BUFSIZ];
324
325                     close(fd);
326                     snprintf(n, sizeof n, device_names[i].name, j);
327                     deviceRegister(strdup(n), device_names[i].description, strdup(try),
328                                    DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaShutdownTape, NULL);
329                     msgDebug("Found a TAPE device for %s\n", try);
330                 }
331                 break;
332
333             case DEVICE_TYPE_DISK:
334                 fd = deviceTry(device_names[i], try, j);
335                 if (fd >= 0 && RunningAsInit) {
336                     dev_t d;
337                     mode_t m;
338                     int s, fail;
339                     char unit[80], slice[80];
340
341                     close(fd);
342                     /* Make associated slice entries */
343                     for (s = 1; s < 8; s++) {
344                         snprintf(unit, sizeof unit, device_names[i].name, j);
345                         snprintf(slice, sizeof slice, "/dev/%ss%d", unit, s);
346                         d = makedev(device_names[i].major, device_names[i].minor +
347                                     (j * device_names[i].delta) + (s * SLICE_DELTA));
348                         m = 0640;
349                         if (device_names[i].dev_type == 'c')
350                             m |= S_IFCHR;
351                         else
352                             m |= S_IFBLK;
353                         fail = mknod(slice, m, d);
354                         fd = open(slice, O_RDONLY);
355                         if (fd >= 0)
356                             close(fd);
357                         else if (!fail)
358                             (void)unlink(slice);
359                     }
360                 }
361                 break;
362
363             case DEVICE_TYPE_FLOPPY:
364                 fd = deviceTry(device_names[i], try, j);
365                 if (fd >= 0) {
366                     char n[BUFSIZ];
367
368                     close(fd);
369                     snprintf(n, sizeof n, device_names[i].name, j);
370                     deviceRegister(strdup(n), device_names[i].description, strdup(try),
371                                    DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy,
372                                    mediaShutdownFloppy, NULL);
373                     msgDebug("Found a floppy device for %s\n", try);
374                 }
375                 break;
376
377             case DEVICE_TYPE_NETWORK:
378                 fd = deviceTry(device_names[i], try, j);
379                 /* The only network devices that you can open this way are serial ones */
380                 if (fd >= 0) {
381                     char *newdesc, *cp;
382
383                     close(fd);
384                     cp = device_names[i].description;
385                     /* Serial devices get a slip and ppp device each, if supported */
386                     newdesc = safe_malloc(strlen(cp) + 40);
387                     sprintf(newdesc, cp, "SLIP interface", try, j + 1);
388                     deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
389                                    NULL, mediaShutdownNetwork, NULL);
390                     msgDebug("Add mapping for %s to sl0\n", try);
391                     newdesc = safe_malloc(strlen(cp) + 50);
392                     sprintf(newdesc, cp, "PPP interface", try, j + 1);
393                     deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
394                                    NULL, mediaShutdownNetwork, NULL);
395                     msgDebug("Add mapping for %s to ppp0\n", try);
396                 }
397                 break;
398
399             default:
400                 break;
401             }
402         }
403     }
404
405     /* Finally, go get the disks and look for DOS partitions to register */
406     if ((names = Disk_Names()) != NULL) {
407         int i;
408
409         for (i = 0; names[i]; i++) {
410             Chunk *c1;
411             Disk *d;
412
413             d = Open_Disk(names[i]);
414             if (!d)
415                 msgFatal("Unable to open disk %s", names[i]);
416
417             deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE,
418                            dummyInit, dummyGet, dummyShutdown, d);
419             msgDebug("Found a disk device named %s\n", names[i]);
420
421             /* Look for existing DOS partitions to register as "DOS media devices" */
422             for (c1 = d->chunks->part; c1; c1 = c1->next) {
423                 if (c1->type == fat || c1->type == extended) {
424                     Device *dev;
425                     char devname[80];
426
427                     /* Got one! */
428                     snprintf(devname, sizeof devname, "/dev/%s", c1->name);
429                     dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE,
430                                          mediaInitDOS, mediaGetDOS, mediaShutdownDOS, NULL);
431                     dev->private = c1;
432                     msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name);
433                 }
434             }
435         }
436         free(names);
437     }
438 }
439
440 /* Rescan all devices, after closing previous set - convenience function */
441 void
442 deviceRescan(void)
443 {
444     deviceReset();
445     deviceGetAll();
446 }
447
448 /*
449  * Find all devices that match the criteria, allowing "wildcarding" as well
450  * by allowing NULL or ANY values to match all.  The array returned is static
451  * and may be used until the next invocation of deviceFind().
452  */
453 Device **
454 deviceFind(char *name, DeviceType class)
455 {
456     static Device *found[DEV_MAX];
457     int i, j;
458
459     j = 0;
460     for (i = 0; i < numDevs; i++) {
461         if ((!name || !strcmp(Devices[i]->name, name))
462             && (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
463             found[j++] = Devices[i];
464     }
465     found[j] = NULL;
466     return j ? found : NULL;
467 }
468
469 Device **
470 deviceFindDescr(char *name, char *desc, DeviceType class)
471 {
472     static Device *found[DEV_MAX];
473     int i, j;
474
475     j = 0;
476     for (i = 0; i < numDevs; i++) {
477         if ((!name || !strcmp(Devices[i]->name, name)) &&
478             (!desc || !strcmp(Devices[i]->description, desc)) &&
479             (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
480             found[j++] = Devices[i];
481     }
482     found[j] = NULL;
483     return j ? found : NULL;
484 }
485
486 int
487 deviceCount(Device **devs)
488 {
489     int i;
490
491     if (!devs)
492         return 0;
493     for (i = 0; devs[i]; i++);
494     return i;
495 }
496
497 /*
498  * Create a menu listing all the devices of a certain type in the system.
499  * The passed-in menu is expected to be a "prototype" from which the new
500  * menu is cloned.
501  */
502 DMenu *
503 deviceCreateMenu(DMenu *menu, DeviceType type, int (*hook)(dialogMenuItem *d), int (*check)(dialogMenuItem *d))
504 {
505     Device **devs;
506     int numdevs;
507     DMenu *tmp = NULL;
508     int i, j;
509
510     devs = deviceFind(NULL, type);
511     numdevs = deviceCount(devs);
512     if (!numdevs)
513         return NULL;
514     tmp = (DMenu *)safe_malloc(sizeof(DMenu) + (sizeof(dialogMenuItem) * (numdevs + 1)));
515     bcopy(menu, tmp, sizeof(DMenu));
516     for (i = 0; devs[i]; i++) {
517         tmp->items[i].prompt = devs[i]->name;
518         for (j = 0; j < numDevs; j++) {
519             if (devs[i] == Devices[j]) {
520                 tmp->items[i].title = Devices[j]->description;
521                 break;
522             }
523         }
524         if (j == numDevs)
525             tmp->items[i].title = "<unknown device type>";
526         tmp->items[i].fire = hook;
527         tmp->items[i].checked = check;
528     }
529     tmp->items[i].title = NULL;
530     return tmp;
531 }