aboutsummaryrefslogtreecommitdiffstats
path: root/add_supplemental_media.html
blob: ed4aa8e806f9447f248e9e0dce9845c109cde602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   
      <title>Supplemental Installation Media</title>
      <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
      <link rel="home" href="index.html" title="Installation with DrakX">
      <link rel="up" href="index.html" title="Installation with DrakX">
      <link rel="prev" href="formatPartitions.html" title="Formatting">
      <link rel="next" href="media_selection.html" title="Available Media"><style xmlns="http://www.w3.org/TR/xhtml1/transitional" type="text/css">
         <!--
      body { font-family: sans-serif; font-size: 13px }
      table { font-family: sans-serif; font-size: 13px }
    --></style></head>
   <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
      <div class="section" title="Supplemental Installation Media">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title"><a name="add_supplemental_media"></a>Supplemental Installation
                         Media
                  </h2>
               </div>
            </div>
         </div>
           
         
           
         
           
         
           
         
           
         
           
         
           
         
           
         <p>This screen shows you the list of already recognised repositories. You
            can add other sources for packages, like an optical-disc or a remote source.
              The source selection determines which packages will be available during the
              subsequent steps.
         </p>
         
           
         <p>For a network source, there are two steps to follow:</p>
         
           
         <div class="orderedlist">
            <ol class="orderedlist" type="1">
               <li class="listitem">
                        
                  <p>Choosing and activating the network, if not already up.</p>
                      
               </li>
               <li class="listitem">
                        
                  <p>Selecting a mirror or specifying a URL (very first entry). By
                           selecting a mirror, you have access to the selection of all repositories
                           managed by Mageia, like the <span class="emphasis"><em>Nonfree</em></span>, the
                           <span class="emphasis"><em>Tainted</em></span> repositories and the
                           <span class="emphasis"><em>Updates</em></span>. With the URL, you can designate a specific
                           repository or your own NFS installation.
                  </p>
                      
               </li>
            </ol>
         </div>
         
           
         <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
            <table border="0" summary="Note">
               <tr>
                  <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="note.png"></td>
                  <th align="left"></th>
               </tr>
               <tr>
                  <td align="left" valign="top">
                         
                     <p>If you are updating a 64-bit installation which may contain some
                            32-bit packages, it is advised to use this screen to add an online mirror
                            by selecting one of the Network protocols here. The 64-bit DVD ISO only
                            contains 64-bit and <span class="emphasis"><em>noarch</em></span> packages, it will not be
                            able to update the 32-bit packages. However, after adding an online
                            mirror, the installer will find the needed 32-bit packages there.
                     </p>
                       
                  </td>
               </tr>
            </table>
         </div>
         
      </div>
   </body>
</html>
25'>325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652
/*
 * Guillaume Cottenceau (gc@mandrakesoft.com)
 *
 * Copyright 2000 MandrakeSoft
 *
 * This software may be freely redistributed under the terms of the GNU
 * public license.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * Code comes from /anonymous@projects.sourceforge.net:/pub/pcmcia-cs/pcmcia-cs-3.1.29.tar.bz2
 *
 *   Licence of this code follows:
 *
 */
/*======================================================================

    PCMCIA Card Manager daemon

    cardmgr.c 1.161 2001/08/24 12:19:19

    The contents of this file are subject to the Mozilla Public
    License Version 1.1 (the "License"); you may not use this file
    except in compliance with the License. You may obtain a copy of
    the License at http://www.mozilla.org/MPL/

    Software distributed under the License is distributed on an "AS
    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
    implied. See the License for the specific language governing
    rights and limitations under the License.

    The initial developer of the original code is David A. Hinds
    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.

    Alternatively, the contents of this file may be used under the
    terms of the GNU General Public License version 2 (the "GPL"), in
    which case the provisions of the GPL are applicable instead of the
    above.  If you wish to allow the use of your version of this file
    only under the terms of the GPL and not to allow others to use
    your version of this file under the MPL, indicate your decision
    by deleting the provisions above and replace them with the notice
    and other provisions required by the GPL.  If you do not delete
    the provisions above, a recipient may use your version of this
    file under either the MPL or the GPL.
    
======================================================================*/

#ifndef __linux__
#include <pcmcia/u_compat.h>
#endif

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
//mdk-stage1// #include <syslog.h>
//mdk-stage1// #include <getopt.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/file.h>

#include <pcmcia_/version.h>
//mdk-stage1// #include <pcmcia/config.h>
#include <pcmcia_/cs_types.h>
#include <pcmcia_/cs.h>
#include <pcmcia_/cistpl.h>
#include <pcmcia_/ds.h>

#include "cardmgr.h"

#include "../log.h"
#include "modules.h"
#include "pcmcia.h"

/*====================================================================*/

typedef struct socket_info_t {
    int			fd;
    int			state;
    card_info_t		*card;
    bind_info_t		*bind[MAX_BINDINGS];
    mtd_ident_t		*mtd[2*CISTPL_MAX_DEVICES];
} socket_info_t;

#define SOCKET_PRESENT	0x01
#define SOCKET_READY	0x02
#define SOCKET_HOTPLUG	0x04

/* Linked list of resource adjustments */
struct adjust_list_t *root_adjust = NULL;

/* Linked list of device definitions */
struct device_info_t *root_device = NULL;

/* Special pointer to "anonymous" card definition */
struct card_info_t *blank_card = NULL;

/* Linked list of card definitions */
struct card_info_t *root_card = NULL;

/* Linked list of function definitions */
struct card_info_t *root_func = NULL;

/* Linked list of MTD definitions */
struct mtd_ident_t *root_mtd = NULL;

/* Default MTD */
struct mtd_ident_t *default_mtd = NULL;

static int sockets;
static struct socket_info_t socket[MAX_SOCKS];

/* Default path for config file, device scripts */
#ifdef ETC
static char *configpath = ETC;
#else
static char *configpath = "/etc/pcmcia";
#endif

/* Default path for pid file */
//mdk-stage1// static char *pidfile = "/var/run/cardmgr.pid";

#ifdef __linux__
/* Default path for finding modules */
//mdk-stage1// static char *modpath = NULL;
#endif

/* Default path for socket info table */
static char *stabfile;

/* If set, don't generate beeps when cards are inserted */
//mdk-stage1// static int be_quiet = 0;

/* If set, use modprobe instead of insmod */
//mdk-stage1// static int do_modprobe = 0;

/* If set, configure already inserted cards, then exit */
//mdk-stage1// static int one_pass = 0;

/* Extra message logging? */
//mdk-stage1// static int verbose = 0;

/*====================================================================*/

#ifdef __linux__

static int major = 0;

static int lookup_dev(char *name)
{
    FILE *f;
    int n;
    char s[32], t[32];
    
    f = fopen("/proc/devices", "r");
    if (f == NULL)
	return -errno;
    while (fgets(s, 32, f) != NULL) {
	if (sscanf(s, "%d %s", &n, t) == 2)
	    if (strcmp(name, t) == 0)
		break;
    }
    fclose(f);
    if (strcmp(name, t) == 0)
	return n;
    else
	return -ENODEV;
}

int open_dev(dev_t dev, int mode)
{
    char * fn = "/tmp/cardmgr_tmp";
    int fd;

    unlink(fn);
	if (mknod(fn, mode, dev) != 0)
		return -1;
    fd = open(fn, (mode&S_IWRITE)?O_RDWR:O_RDONLY);
    if (fd < 0)
	fd = open(fn, O_NONBLOCK|((mode&S_IWRITE)?O_RDWR:O_RDONLY));
    unlink(fn);
    return fd;
}

#endif /* __linux__ */

int open_sock(int sock, int mode)
{
#ifdef __linux__
    dev_t dev = (major<<8)+sock;
    return open_dev(dev, mode);
#endif
#ifdef __BEOS__
    int fd;
    char fn[B_OS_NAME_LENGTH];
    sprintf(fn, "/dev/pcmcia/sock%d", sock);
    return open(fn, (mode & S_IWRITE) ? O_RDWR: O_RDONLY);
#endif
}

/*======================================================================

    xlate_scsi_name() is a sort-of-hack used to deduce the minor
    device numbers of SCSI devices, from the information available to
    the low-level driver.
    
======================================================================*/

#ifdef __linux__

#include <linux/major.h>
#include <scsi/scsi.h>
//mdk-stage1// #define VERSION(v,p,s) (((v)<<16)+(p<<8)+s)
//mdk-stage1// #if (LINUX_VERSION_CODE < VERSION(2,1,126))
//mdk-stage1// #define SCSI_DISK0_MAJOR SCSI_DISK_MAJOR
//mdk-stage1// #endif

static int xlate_scsi_name(bind_info_t *bind)
{
    int i, fd, mode, minor;
    u_long arg[2], id1, id2;

    id1 = strtol(bind->name+3, NULL, 16);
    if ((bind->major == SCSI_DISK0_MAJOR) ||
	(bind->major == SCSI_CDROM_MAJOR))
	mode = S_IREAD|S_IFBLK;
    else
	mode = S_IREAD|S_IFCHR;
    
    for (i = 0; i < 16; i++) {
	minor = (bind->major == SCSI_DISK0_MAJOR) ? (i<<4) : i;
	fd = open_dev((bind->major<<8)+minor, mode);
	if (fd < 0)
	    continue;
	if (ioctl(fd, SCSI_IOCTL_GET_IDLUN, arg) == 0) {
	    id2 = (arg[0]&0x0f) + ((arg[0]>>4)&0xf0) +
		((arg[0]>>8)&0xf00) + ((arg[0]>>12)&0xf000);
	    if (id1 == id2) {
		close(fd);
		switch (bind->major) {
		case SCSI_DISK0_MAJOR:
		case SCSI_GENERIC_MAJOR:
		    sprintf(bind->name+2, "%c", 'a'+i); break;
		case SCSI_CDROM_MAJOR:
		    sprintf(bind->name, "scd%d", i); break;
		case SCSI_TAPE_MAJOR:
		    sprintf(bind->name+2, "%d", i); break;
		}
		bind->minor = minor;
		return 0;
	    }
	}
	close(fd);
    }
    return -1;
}
#endif

/*====================================================================*/

#define BEEP_TIME 150
#define BEEP_OK   1000
#define BEEP_WARN 2000
#define BEEP_ERR  4000

#ifdef __linux__

//mdk-stage1// #include <sys/kd.h>
//mdk-stage1// 
static void beep(unsigned int ms, unsigned int freq)
{
//mdk-stage1//     int fd, arg;
//mdk-stage1// 
//mdk-stage1//     if (be_quiet)
//mdk-stage1// 	return;
//mdk-stage1//     fd = open("/dev/console", O_RDWR);
//mdk-stage1//     if (fd < 0)
//mdk-stage1// 	return;
//mdk-stage1//     arg = (ms << 16) | freq;
//mdk-stage1//     ioctl(fd, KDMKTONE, arg);
//mdk-stage1//     close(fd);
//mdk-stage1//     usleep(ms*1000);
}

#endif /* __linux__ */

#ifdef __BEOS__
static void beep(unsigned int ms, unsigned int freq)
{
    if (!be_quiet) system("/bin/beep");
}
#endif

/*====================================================================*/

//mdk-stage1// static void write_pid(void)
//mdk-stage1// {
//mdk-stage1//     FILE *f;
//mdk-stage1//     f = fopen(pidfile, "w");
//mdk-stage1//     if (f == NULL)
//mdk-stage1// 	syslog(LOG_WARNING, "could not open %s: %m", pidfile);
//mdk-stage1//     else {
//mdk-stage1// 	fprintf(f, "%d\n", getpid());
//mdk-stage1// 	fclose(f);
//mdk-stage1//     }
//mdk-stage1// }

static void write_stab(void)
{
    int i, j, k;
    FILE *f;
    socket_info_t *s;
    bind_info_t *bind;

    f = fopen(stabfile, "w");
    if (f == NULL) {
	log_message("CM: fopen(stabfile) failed: %m");
	return;
    }
#ifndef __BEOS__
    if (flock(fileno(f), LOCK_EX) != 0) {
	log_message("CM: flock(stabfile) failed: %m");
	return;
    }
#endif
    for (i = 0; i < sockets; i++) {
	s = &socket[i];
	fprintf(f, "Socket %d: ", i);
	if (!(s->state & SOCKET_PRESENT)) {
	    fprintf(f, "empty\n");
//mdk-stage1// 	} else if (s->state & SOCKET_HOTPLUG) {
//mdk-stage1// 	    fprintf(f, "CardBus hotplug device\n");
	} else if (!s->card) {
	    fprintf(f, "unsupported card\n");
	} else {
	    fprintf(f, "%s\n", s->card->name);
	    for (j = 0; j < s->card->bindings; j++)
		for (k = 0, bind = s->bind[j];
		     bind != NULL;
		     k++, bind = bind->next) {
		    char *class = s->card->device[j]->class;
		    fprintf(f, "%d\t%s\t%s\t%d\t%s",
			    i, (class ? class : "none"),
			    bind->dev_info, k, bind->name);
		    if (bind->major)
			fprintf(f, "\t%d\t%d\n",
				bind->major, bind->minor);
		    else
			fputc('\n', f);
		}
	}
    }
    fflush(f);
#ifndef __BEOS__
    flock(fileno(f), LOCK_UN);
#endif
    fclose(f);
}

/*====================================================================*/

static int get_tuple(int ns, cisdata_t code, ds_ioctl_arg_t *arg)
{
    socket_info_t *s = &socket[ns];
    
    arg->tuple.DesiredTuple = code;
    arg->tuple.Attributes = 0;
    if (ioctl(s->fd, DS_GET_FIRST_TUPLE, arg) != 0)
	return -1;
    arg->tuple.TupleOffset = 0;
    if (ioctl(s->fd, DS_GET_TUPLE_DATA, arg) != 0) {
	log_message("CM: error reading CIS data on socket %d: %m", ns);
	return -1;
    }
    if (ioctl(s->fd, DS_PARSE_TUPLE, arg) != 0) {
	log_message("CM: error parsing CIS on socket %d: %m", ns);
	return -1;
    }
    return 0;
}

/*======================================================================

    Code to fetch a 2.4 kernel's hot plug PCI driver list

    This is distasteful but is the best I could come up with.

======================================================================*/

#ifdef __linux__

typedef struct pci_id {
    u_short vendor, device;
    struct pci_id *next;
} pci_id_t;

static int get_pci_id(int ns, pci_id_t *id)
{
    socket_info_t *s = &socket[ns];
    config_info_t config;

    config.Function = config.ConfigBase = 0;
    if ((ioctl(s->fd, DS_GET_CONFIGURATION_INFO, &config) != 0) ||
	(config.IntType != INT_CARDBUS) || !config.ConfigBase)
	return 0;
    id->vendor = config.ConfigBase & 0xffff;
    id->device = config.ConfigBase >> 16;
    return 1;
}

#endif /* __linux__ */

/*====================================================================*/

//mdk-stage1// static void log_card_info(cistpl_vers_1_t *vers,
//mdk-stage1// 			  cistpl_manfid_t *manfid,
//mdk-stage1// 			  cistpl_funcid_t *funcid,
//mdk-stage1// 			  pci_id_t *pci_id)
//mdk-stage1// {
//mdk-stage1//     char v[256] = "";
//mdk-stage1//     int i;
//mdk-stage1//     static char *fn[] = {
//mdk-stage1// 	"multi", "memory", "serial", "parallel", "fixed disk",
//mdk-stage1// 	"video", "network", "AIMS", "SCSI"
//mdk-stage1//     };
//mdk-stage1//     
//mdk-stage1//     if (vers) {
//mdk-stage1// 	for (i = 0; i < vers->ns; i++)
//mdk-stage1// 	    sprintf(v+strlen(v), "%s\"%s\"",
//mdk-stage1// 		    (i>0) ? ", " : "", vers->str+vers->ofs[i]);
//mdk-stage1// 	syslog(LOG_INFO, "  product info: %s", v);
//mdk-stage1//     } else {
//mdk-stage1// 	syslog(LOG_INFO, "  no product info available");
//mdk-stage1//     }
//mdk-stage1//     *v = '\0';
//mdk-stage1//     if (manfid->manf != 0)
//mdk-stage1// 	sprintf(v, "  manfid: 0x%04x, 0x%04x",
//mdk-stage1// 		manfid->manf, manfid->card);
//mdk-stage1//     if (funcid->func != 0xff)
//mdk-stage1// 	sprintf(v+strlen(v), "  function: %d (%s)", funcid->func,
//mdk-stage1// 		fn[funcid->func]);
//mdk-stage1//     if (strlen(v) > 0) syslog(LOG_INFO, "%s", v);
//mdk-stage1//     if (pci_id->vendor != 0)
//mdk-stage1// 	syslog(LOG_INFO, "  PCI id: 0x%04x, 0x%04x",
//mdk-stage1// 	       pci_id->vendor, pci_id->device);
//mdk-stage1// }

static card_info_t *lookup_card(int ns)
{
    socket_info_t *s = &socket[ns];
    card_info_t *card = NULL;
    ds_ioctl_arg_t arg;
    cistpl_vers_1_t *vers = NULL;
    cistpl_manfid_t manfid = { 0, 0 };
    pci_id_t pci_id = { 0, 0 };
    cistpl_funcid_t funcid = { 0xff, 0xff };
    cs_status_t status;
    int i, ret, has_cis = 0;

    /* Do we have a CIS structure? */
    ret = ioctl(s->fd, DS_VALIDATE_CIS, &arg);
    has_cis = ((ret == 0) && (arg.cisinfo.Chains > 0));
    
    /* Try to read VERS_1, MANFID tuples */
    if (has_cis) {
	/* rule of thumb: cards with no FUNCID, but with common memory
	   device geometry information, are probably memory cards */
	if (get_tuple(ns, CISTPL_FUNCID, &arg) == 0)
	    memcpy(&funcid, &arg.tuple_parse.parse.funcid,
		   sizeof(funcid));
	else if (get_tuple(ns, CISTPL_DEVICE_GEO, &arg) == 0)
	    funcid.func = CISTPL_FUNCID_MEMORY;
	if (get_tuple(ns, CISTPL_MANFID, &arg) == 0)
	    memcpy(&manfid, &arg.tuple_parse.parse.manfid,
		   sizeof(manfid));
	if (get_tuple(ns, CISTPL_VERS_1, &arg) == 0)
	    vers = &arg.tuple_parse.parse.version_1;

	for (card = root_card; card; card = card->next) {

	    if (card->ident_type &
		~(VERS_1_IDENT|MANFID_IDENT|TUPLE_IDENT))
		continue;

	    if (card->ident_type & VERS_1_IDENT) {
		if (vers == NULL)
		    continue;
		for (i = 0; i < card->id.vers.ns; i++) {
		    if (strcmp(card->id.vers.pi[i], "*") == 0)
			continue;
		    if (i >= vers->ns)
			break;
		    if (strcmp(card->id.vers.pi[i],
			       vers->str+vers->ofs[i]) != 0)
			break;
		}
		if (i < card->id.vers.ns)
		    continue;
	    }
	    
	    if (card->ident_type & MANFID_IDENT) {
		if ((manfid.manf != card->manfid.manf) ||
		    (manfid.card != card->manfid.card))
		    continue;
	    }
		
	    if (card->ident_type & TUPLE_IDENT) {
		arg.tuple.DesiredTuple = card->id.tuple.code;
		arg.tuple.Attributes = 0;
		ret = ioctl(s->fd, DS_GET_FIRST_TUPLE, &arg);
		if (ret != 0) continue;
		arg.tuple.TupleOffset = card->id.tuple.ofs;
		ret = ioctl(s->fd, DS_GET_TUPLE_DATA, &arg);
		if (ret != 0) continue;
		if (strncmp((char *)arg.tuple_parse.data,
			    card->id.tuple.info,
			    strlen(card->id.tuple.info)) != 0)
		    continue;
	    }

	    break; /* we have a match */
	}
    }

    /* Check PCI vendor/device info */
    status.Function = 0;
    ioctl(s->fd, DS_GET_STATUS, &status);
    if (status.CardState & CS_EVENT_CB_DETECT) {
	if (get_pci_id(ns, &pci_id)) {
	    if (!card) {
		for (card = root_card; card; card = card->next)
		    if ((card->ident_type == PCI_IDENT) &&
			(pci_id.vendor == card->manfid.manf) &&
			(pci_id.device == card->manfid.card))
			break;
	    }
	} else {
	    /* this is a 2.4 kernel; hotplug handles these cards */
//mdk-stage1//	    s->state |= SOCKET_HOTPLUG;
	    log_message("CM: socket %d: CardBus hotplug device", ns);
	    //beep(BEEP_TIME, BEEP_OK);
//mdk-stage1//	    return NULL;
	}
    }

    /* Try for a FUNCID match */
    if (!card && (funcid.func != 0xff)) {
	for (card = root_func; card; card = card->next)
	    if (card->id.func.funcid == funcid.func)
		break;
    }

    if (card) {
	log_message("CM: socket %d: %s", ns, card->name);
 	beep(BEEP_TIME, BEEP_OK);
//mdk-stage1// 	if (verbose) log_card_info(vers, &manfid, &funcid, &pci_id);
	return card;
    }

    if (!blank_card || (status.CardState & CS_EVENT_CB_DETECT) ||
	manfid.manf || manfid.card || pci_id.vendor || vers) {
	log_message("CM: unsupported card in socket %d", ns);
//mdk-stage1// 	if (one_pass) return NULL;
	beep(BEEP_TIME, BEEP_ERR);
//mdk-stage1// 	log_card_info(vers, &manfid, &funcid, &pci_id);
	return NULL;
    } else {
	card = blank_card;
	log_message("CM: socket %d: %s", ns, card->name);
 	beep(BEEP_TIME, BEEP_WARN);
	return card;
    }
}

/*====================================================================*/

static int load_config(void)
{
    if (chdir(configpath) != 0) {
	    log_message("CM: chdir to %s failed: %m", configpath);
	    return -1;
    }
    if (parse_configfile("config") != 0) {
	    log_message("CM: parsing of config file failed: %m");
	    return -1;
    }
    if (root_device == NULL)
		log_message("CM: no device drivers defined");
    if ((root_card == NULL) && (root_func == NULL))
		log_message("CM: no cards defined");
    return 0;
}

//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// static void free_card(card_info_t *card)
//mdk-stage1// {
//mdk-stage1//     if (card && (--card->refs == 0)) {
//mdk-stage1// 	int i;
//mdk-stage1// 	free(card->name);
//mdk-stage1// 	switch(card->ident_type) {
//mdk-stage1// 	case VERS_1_IDENT:
//mdk-stage1// 	    for (i = 0; i < card->id.vers.ns; i++)
//mdk-stage1// 		free(card->id.vers.pi[i]);
//mdk-stage1// 	break;
//mdk-stage1// 	case TUPLE_IDENT:
//mdk-stage1// 	    free(card->id.tuple.info);
//mdk-stage1// 	    break;
//mdk-stage1// 	default:
//mdk-stage1// 	    break;
//mdk-stage1// 	}
//mdk-stage1// 	free(card);
//mdk-stage1//     }
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// static void free_device(device_info_t *dev)
//mdk-stage1// {
//mdk-stage1//     if (dev && (--dev->refs == 0)) {
//mdk-stage1// 	int i;
//mdk-stage1// 	for (i = 0; i < dev->modules; i++) {
//mdk-stage1// 	    free(dev->module[i]);
//mdk-stage1// 	    if (dev->opts[i]) free(dev->opts[i]);
//mdk-stage1// 	}
//mdk-stage1// 	if (dev->class) free(dev->class);
//mdk-stage1// 	free(dev);
//mdk-stage1//     }
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// static void free_mtd(mtd_ident_t *mtd)
//mdk-stage1// {
//mdk-stage1//     if (mtd && (--mtd->refs == 0)) {
//mdk-stage1// 	free(mtd->name);
//mdk-stage1// 	free(mtd->module);
//mdk-stage1// 	free(mtd);
//mdk-stage1//     }
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// static void free_config(void)
//mdk-stage1// {
//mdk-stage1//     while (root_adjust != NULL) {
//mdk-stage1// 	adjust_list_t *adj = root_adjust;
//mdk-stage1// 	root_adjust = root_adjust->next;
//mdk-stage1// 	free(adj);
//mdk-stage1//     }
//mdk-stage1//     
//mdk-stage1//     while (root_device != NULL) {
//mdk-stage1// 	device_info_t *dev = root_device;
//mdk-stage1// 	root_device = root_device->next;
//mdk-stage1// 	free_device(dev);
//mdk-stage1//     }
//mdk-stage1// 
//mdk-stage1//     while (root_card != NULL) {
//mdk-stage1// 	card_info_t *card = root_card;
//mdk-stage1// 	root_card = root_card->next;
//mdk-stage1// 	free_card(card);
//mdk-stage1//     }
//mdk-stage1//     
//mdk-stage1//     while (root_func != NULL) {
//mdk-stage1// 	card_info_t *card = root_func;
//mdk-stage1// 	root_func = root_func->next;
//mdk-stage1// 	free_card(card);
//mdk-stage1//     }
//mdk-stage1//     blank_card = NULL;
//mdk-stage1//     
//mdk-stage1//     while (root_mtd != NULL) {
//mdk-stage1// 	mtd_ident_t *mtd = root_mtd;
//mdk-stage1// 	root_mtd = root_mtd->next;
//mdk-stage1// 	free_mtd(mtd);
//mdk-stage1//     }
//mdk-stage1//     default_mtd = NULL;
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// static int execute(char *msg, char *cmd)
//mdk-stage1// {
//mdk-stage1//     int ret;
//mdk-stage1//     FILE *f;
//mdk-stage1//     char line[256];
//mdk-stage1// 
//mdk-stage1//     syslog(LOG_INFO, "executing: '%s'", cmd);
//mdk-stage1//     strcat(cmd, " 2>&1");
//mdk-stage1//     f = popen(cmd, "r");
//mdk-stage1//     while (fgets(line, 255, f)) {
//mdk-stage1// 	line[strlen(line)-1] = '\0';
//mdk-stage1// 	syslog(LOG_INFO, "+ %s", line);
//mdk-stage1//     }
//mdk-stage1//     ret = pclose(f);
//mdk-stage1//     if (WIFEXITED(ret)) {
//mdk-stage1// 	if (WEXITSTATUS(ret))
//mdk-stage1// 	    syslog(LOG_INFO, "%s exited with status %d",
//mdk-stage1// 		   msg, WEXITSTATUS(ret));
//mdk-stage1// 	return WEXITSTATUS(ret);
//mdk-stage1//     } else
//mdk-stage1// 	syslog(LOG_INFO, "%s exited on signal %d",
//mdk-stage1// 	       msg, WTERMSIG(ret));
//mdk-stage1//     return -1;
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// static int execute_on_dev(char *action, char *class, char *dev)
//mdk-stage1// {
//mdk-stage1//     /* Fixed length strings are ok here */
//mdk-stage1//     char msg[128], cmd[128];
//mdk-stage1// 
//mdk-stage1//     sprintf(msg, "%s cmd", action);
//mdk-stage1//     sprintf(cmd, "./%s %s %s", class, action, dev);
//mdk-stage1//     return execute(msg, cmd);
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// static int execute_on_all(char *cmd, char *class, int sn, int fn)
//mdk-stage1// {
//mdk-stage1//     socket_info_t *s = &socket[sn];
//mdk-stage1//     bind_info_t *bind;
//mdk-stage1//     int ret = 0;
//mdk-stage1//     for (bind = s->bind[fn]; bind != NULL; bind = bind->next)
//mdk-stage1// 	if (bind->name[0] && (bind->name[2] != '#'))
//mdk-stage1// 	    ret |= execute_on_dev(cmd, class, bind->name);
//mdk-stage1//     return ret;
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// #ifdef __linux__
//mdk-stage1// 
//mdk-stage1// typedef struct module_list_t {
//mdk-stage1//     char *mod;
//mdk-stage1//     int usage;
//mdk-stage1//     struct module_list_t *next;
//mdk-stage1// } module_list_t;
//mdk-stage1// 
//mdk-stage1// static module_list_t *module_list = NULL;
//mdk-stage1// 
//mdk-stage1// static int try_insmod(char *mod, char *opts)
//mdk-stage1// {
//mdk-stage1//     char *cmd = malloc(strlen(mod) + strlen(modpath) +
//mdk-stage1// 		       (opts ? strlen(opts) : 0) + 30);
//mdk-stage1//     int ret;
//mdk-stage1// 
//mdk-stage1//     strcpy(cmd, "insmod ");
//mdk-stage1//     if (strchr(mod, '/') != NULL)
//mdk-stage1// 	sprintf(cmd+7, "%s/%s.o", modpath, mod);
//mdk-stage1//     else
//mdk-stage1// 	sprintf(cmd+7, "%s/pcmcia/%s.o", modpath, mod);
//mdk-stage1//     if (access(cmd+7, R_OK) != 0) {
//mdk-stage1// 	syslog(LOG_INFO, "module %s not available", cmd+7);
//mdk-stage1// 	free(cmd);
//mdk-stage1// 	return -1;
//mdk-stage1//     }
//mdk-stage1//     if (opts) {
//mdk-stage1// 	strcat(cmd, " ");
//mdk-stage1// 	strcat(cmd, opts);
//mdk-stage1//     }
//mdk-stage1//     ret = execute("insmod", cmd);
//mdk-stage1//     free(cmd);
//mdk-stage1//     return ret;
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// static int try_modprobe(char *mod, char *opts)
//mdk-stage1// {
//mdk-stage1//     char *cmd = malloc(strlen(mod) + (opts ? strlen(opts) : 0) + 20);
//mdk-stage1//     char *s = strrchr(mod, '/');
//mdk-stage1//     int ret;
//mdk-stage1// 
//mdk-stage1//     sprintf(cmd, "modprobe %s", (s) ? s+1 : mod);
//mdk-stage1//     if (opts) {
//mdk-stage1// 	strcat(cmd, " ");
//mdk-stage1// 	strcat(cmd, opts);
//mdk-stage1//     }
//mdk-stage1//     ret = execute("modprobe", cmd);
//mdk-stage1//     free(cmd);
//mdk-stage1//     return ret;
//mdk-stage1// }

static void install_module(char *mod, char *opts)
{
	my_insmod(mod, ANY_DRIVER_TYPE, opts);
//mdk-stage1//     module_list_t *ml;
//mdk-stage1// 
//mdk-stage1//     for (ml = module_list; ml != NULL; ml = ml->next)
//mdk-stage1// 	if (strcmp(mod, ml->mod) == 0) break;
//mdk-stage1//     if (ml == NULL) {
//mdk-stage1// 	ml = (module_list_t *)malloc(sizeof(struct module_list_t));
//mdk-stage1// 	ml->mod = mod;
//mdk-stage1// 	ml->usage = 0;
//mdk-stage1// 	ml->next = module_list;
//mdk-stage1// 	module_list = ml;
//mdk-stage1//     }
//mdk-stage1//     ml->usage++;
//mdk-stage1//     if (ml->usage != 1)
//mdk-stage1// 	return;
//mdk-stage1// 
//mdk-stage1// #ifdef __linux__
//mdk-stage1//     if (access("/proc/bus/pccard/drivers", R_OK) == 0) {
//mdk-stage1// 	FILE *f = fopen("/proc/bus/pccard/drivers", "r");
//mdk-stage1// 	if (f) {
//mdk-stage1// 	    char a[61], s[33];
//mdk-stage1// 	    while (fgets(a, 60, f)) {
//mdk-stage1// 		int is_kernel;
//mdk-stage1// 		sscanf(a, "%s %d", s, &is_kernel);
//mdk-stage1// 		if (strcmp(s, mod) != 0) continue;
//mdk-stage1// 		/* If it isn't a module, we won't try to rmmod */
//mdk-stage1// 		ml->usage += is_kernel;
//mdk-stage1// 		fclose(f);
//mdk-stage1// 		return;
//mdk-stage1// 	    }
//mdk-stage1// 	    fclose(f);
//mdk-stage1// 	}
//mdk-stage1//     }
//mdk-stage1// #endif
//mdk-stage1// 
//mdk-stage1//     if (do_modprobe) {
//mdk-stage1// 	if (try_modprobe(mod, opts) != 0)
//mdk-stage1// 	    try_insmod(mod, opts);
//mdk-stage1//     } else {
//mdk-stage1// 	if (try_insmod(mod, opts) != 0)
//mdk-stage1// 	    try_modprobe(mod, opts);
//mdk-stage1//     }
}

//mdk-stage1// static void remove_module(char *mod)
//mdk-stage1// {
//mdk-stage1//     char *s, cmd[128];
//mdk-stage1//     module_list_t *ml;
//mdk-stage1// 
//mdk-stage1//     for (ml = module_list; ml != NULL; ml = ml->next)
//mdk-stage1// 	if (strcmp(mod, ml->mod) == 0) break;
//mdk-stage1//     if (ml != NULL) {
//mdk-stage1// 	ml->usage--;
//mdk-stage1// 	if (ml->usage == 0) {
//mdk-stage1// 	    /* Strip off leading path names */
//mdk-stage1// 	    s = strrchr(mod, '/');
//mdk-stage1// 	    s = (s) ? s+1 : mod;
//mdk-stage1// 	    sprintf(cmd, do_modprobe ? "modprobe -r %s" : "rmmod %s", s);
//mdk-stage1// 	    execute(do_modprobe ? "modprobe" : "rmmod", cmd);
//mdk-stage1// 	}
//mdk-stage1//     }
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// #endif /* __linux__ */
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// #ifdef __BEOS__
//mdk-stage1// 
//mdk-stage1// #define install_module(a,b)
//mdk-stage1// #define remove_module(a)
//mdk-stage1// 
//mdk-stage1// static void republish_driver(char *mod)
//mdk-stage1// {
//mdk-stage1//     int fd = open("/dev", O_RDWR);
//mdk-stage1//     write(fd, mod, strlen(mod));
//mdk-stage1//     close(fd);
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// #endif /* __BEOS__ */
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/

static mtd_ident_t *lookup_mtd(region_info_t *region)
{
    mtd_ident_t *mtd;
    int match = 0;
    
    for (mtd = root_mtd; mtd; mtd = mtd->next) {
	switch (mtd->mtd_type) {
	case JEDEC_MTD:
	    if ((mtd->jedec_mfr == region->JedecMfr) &&
		(mtd->jedec_info == region->JedecInfo)) {
		match = 1;
		break;
	    }
	case DTYPE_MTD:
	    break;
	default:
	    break;
	}
	if (match) break;
    }
    if (mtd)
	return mtd;
    else
	return default_mtd;
}

/*====================================================================*/

static void bind_mtd(int sn)
{
    socket_info_t *s = &socket[sn];
    region_info_t region;
    bind_info_t bind;
    mtd_info_t mtd_info;
    mtd_ident_t *mtd;
    int i, attr, ret, nr;

    nr = 0;
    for (attr = 0; attr < 2; attr++) {
	region.Attributes = attr;
	ret = ioctl(s->fd, DS_GET_FIRST_REGION, &region);
	while (ret == 0) {
	    mtd = lookup_mtd(&region);
	    if (mtd) {
		/* Have we seen this MTD before? */
		for (i = 0; i < nr; i++)
		    if (s->mtd[i] == mtd) break;
		if (i == nr) {
		    install_module(mtd->module, mtd->opts);
		    s->mtd[nr] = mtd;
		    mtd->refs++;
		    nr++;
		}
		log_message("CM: %s memory region at 0x%x: %s",
		       attr ? "Attribute" : "Common", region.CardOffset,
		       mtd->name);
		/* Bind MTD to this region */
		strcpy(mtd_info.dev_info, s->mtd[i]->module);
		mtd_info.Attributes = region.Attributes;
		mtd_info.CardOffset = region.CardOffset;
		if (ioctl(s->fd, DS_BIND_MTD, &mtd_info) != 0) {
		    log_message("CM: bind MTD '%s' to region at 0x%x failed: %m",
			   (char *)mtd_info.dev_info, region.CardOffset);
		}
	    }
	    ret = ioctl(s->fd, DS_GET_NEXT_REGION, &region);
	}
    }
    s->mtd[nr] = NULL;
    
    /* Now bind each unique MTD as a normal client of this socket */
    for (i = 0; i < nr; i++) {
	strcpy(bind.dev_info, s->mtd[i]->module);
	bind.function = 0;
	if (ioctl(s->fd, DS_BIND_REQUEST, &bind) != 0)
	    log_message("CM: bind MTD '%s' to socket %d failed: %m",
		   (char *)bind.dev_info, sn);
    }
}

/*====================================================================*/

static void update_cis(socket_info_t *s)
{
    cisdump_t cis;
    FILE *f = fopen(s->card->cis_file, "r");
    if (f == NULL)
	log_message("CM: could not open '%s': %m", s->card->cis_file);
    else {
	cis.Length = fread(cis.Data, 1, CISTPL_MAX_CIS_SIZE, f);
	fclose(f);
	if (ioctl(s->fd, DS_REPLACE_CIS, &cis) != 0)
	    log_message("CM: could not replace CIS: %m");
    }
}

/*====================================================================*/

static void do_insert(int sn)
{
    socket_info_t *s = &socket[sn];
    card_info_t *card;
    device_info_t **dev;
    bind_info_t *bind, **tail;
    int i, j, ret;

    /* Already identified? */
    if ((s->card != NULL) && (s->card != blank_card))
	return;

    log_message("CM: initializing socket %d", sn);
    card = lookup_card(sn);
    if (s->state & SOCKET_HOTPLUG) {
	write_stab();
	return;
    }
    /* Make sure we've learned something new before continuing */
    if (card == s->card)
	return;
    s->card = card;
    card->refs++;
    if (card->cis_file) update_cis(s);

    dev = card->device;

    /* Set up MTD's */
    for (i = 0; i < card->bindings; i++)
	if (dev[i]->needs_mtd)
	    break;
    if (i < card->bindings)
	bind_mtd(sn);

#ifdef __linux__
    /* Install kernel modules */
    for (i = 0; i < card->bindings; i++) {
	dev[i]->refs++;
	for (j = 0; j < dev[i]->modules; j++)
	    install_module(dev[i]->module[j], dev[i]->opts[j]);
    }
#endif
    
    /* Bind drivers by their dev_info identifiers */
    for (i = 0; i < card->bindings; i++) {
	bind = calloc(1, sizeof(bind_info_t));
	strcpy((char *)bind->dev_info, (char *)dev[i]->dev_info);
	if (strcmp(bind->dev_info, "cb_enabler") == 0)
	    bind->function = BIND_FN_ALL;
	else
	    bind->function = card->dev_fn[i];
	if (ioctl(s->fd, DS_BIND_REQUEST, bind) != 0) {
	    if (errno == EBUSY) {
		log_message("CM: '%s' already bound to socket %d",
		       (char *)bind->dev_info, sn);
	    } else {
		log_message("CM: bind '%s' to socket %d failed: %m",
		       (char *)bind->dev_info, sn);
		beep(BEEP_TIME, BEEP_ERR);
		write_stab();
		return;
	    }
	}

#ifdef __BEOS__
	republish_driver(dev[i]->module[0]);
#endif

	for (ret = j = 0; j < 10; j++) {
	    ret = ioctl(s->fd, DS_GET_DEVICE_INFO, bind);
	    if ((ret == 0) || (errno != EAGAIN))
		break;
	    usleep(100000);
	}
	if (ret != 0) {
	    log_message("CM: get dev info on socket %d failed: %m",
		   sn);
	    ioctl(s->fd, DS_UNBIND_REQUEST, bind);
	    beep(BEEP_TIME, BEEP_ERR);
	    write_stab();
	    return;
	}
	tail = &s->bind[i];
	while (ret == 0) {
	    bind_info_t *old;
#ifdef __linux__
	    if ((strlen(bind->name) > 3) && (bind->name[2] == '#'))
		xlate_scsi_name(bind);
#endif
	    old = *tail = bind; tail = (bind_info_t **)&bind->next;
	    bind = (bind_info_t *)malloc(sizeof(bind_info_t));
	    memcpy(bind, old, sizeof(bind_info_t));
	    ret = ioctl(s->fd, DS_GET_NEXT_DEVICE, bind);
	}
	*tail = NULL; free(bind);
	write_stab();
    }

//mdk-stage1//     /* Run "start" commands */
//mdk-stage1//     for (i = ret = 0; i < card->bindings; i++)
//mdk-stage1// 	if (dev[i]->class)
//mdk-stage1// 	    ret |= execute_on_all("start", dev[i]->class, sn, i);
//mdk-stage1//     beep(BEEP_TIME, (ret) ? BEEP_ERR : BEEP_OK);
    
}

//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// static int do_check(int sn)
//mdk-stage1// {
//mdk-stage1//     socket_info_t *s = &socket[sn];
//mdk-stage1//     card_info_t *card;
//mdk-stage1//     device_info_t **dev;
//mdk-stage1//     int i, ret;
//mdk-stage1// 
//mdk-stage1//     card = s->card;
//mdk-stage1//     if (card == NULL)
//mdk-stage1// 	return 0;
//mdk-stage1//     
//mdk-stage1//     /* Run "check" commands */
//mdk-stage1//     dev = card->device;
//mdk-stage1//     for (i = 0; i < card->bindings; i++) {
//mdk-stage1// 	if (dev[i]->class) {
//mdk-stage1// 	    ret = execute_on_all("check", dev[i]->class, sn, i);
//mdk-stage1// 	    if (ret != 0)
//mdk-stage1// 		return CS_IN_USE;
//mdk-stage1// 	}
//mdk-stage1//     }
//mdk-stage1//     return 0;
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// static void do_remove(int sn)
//mdk-stage1// {
//mdk-stage1//     socket_info_t *s = &socket[sn];
//mdk-stage1//     card_info_t *card;
//mdk-stage1//     device_info_t **dev;
//mdk-stage1//     bind_info_t *bind;
//mdk-stage1//     int i, j;
//mdk-stage1// 
//mdk-stage1//     if (verbose) syslog(LOG_INFO, "shutting down socket %d", sn);
//mdk-stage1// 
//mdk-stage1//     card = s->card;
//mdk-stage1//     if (card == NULL)
//mdk-stage1// 	goto done;
//mdk-stage1// 
//mdk-stage1//     /* Run "stop" commands */
//mdk-stage1//     dev = card->device;
//mdk-stage1//     for (i = 0; i < card->bindings; i++) {
//mdk-stage1// 	if (dev[i]->class) {
//mdk-stage1// 	    execute_on_all("stop", dev[i]->class, sn, i);
//mdk-stage1// 	}
//mdk-stage1//     }
//mdk-stage1// 
//mdk-stage1//     /* unbind driver instances */
//mdk-stage1//     for (i = 0; i < card->bindings; i++) {
//mdk-stage1// 	if (s->bind[i]) {
//mdk-stage1// 	    if (ioctl(s->fd, DS_UNBIND_REQUEST, s->bind[i]) != 0)
//mdk-stage1// 		syslog(LOG_INFO, "unbind '%s' from socket %d failed: %m",
//mdk-stage1// 		       (char *)s->bind[i]->dev_info, sn);
//mdk-stage1// 	    while (s->bind[i]) {
//mdk-stage1// 		bind = s->bind[i];
//mdk-stage1// 		s->bind[i] = bind->next;
//mdk-stage1// 		free(bind);
//mdk-stage1// 	    }
//mdk-stage1// 	}
//mdk-stage1//     }
//mdk-stage1//     for (i = 0; (s->mtd[i] != NULL); i++) {
//mdk-stage1// 	bind_info_t b;
//mdk-stage1// 	strcpy(b.dev_info, s->mtd[i]->module);
//mdk-stage1// 	b.function = 0;
//mdk-stage1// 	if (ioctl(s->fd, DS_UNBIND_REQUEST, &b) != 0)
//mdk-stage1// 	    syslog(LOG_INFO, "unbind MTD '%s' from socket %d failed: %m",
//mdk-stage1// 		   s->mtd[i]->module, sn);
//mdk-stage1//     }
//mdk-stage1// 
//mdk-stage1//     /* remove kernel modules in inverse order */
//mdk-stage1//     for (i = 0; i < card->bindings; i++) {
//mdk-stage1// 	for (j = dev[i]->modules-1; j >= 0; j--)
//mdk-stage1// 	    remove_module(dev[i]->module[j]);
//mdk-stage1// 	free_device(dev[i]);
//mdk-stage1//     }
//mdk-stage1//     /* Remove any MTD's bound to this socket */
//mdk-stage1//     for (i = 0; (s->mtd[i] != NULL); i++) {
//mdk-stage1// 	remove_module(s->mtd[i]->module);
//mdk-stage1// 	free_mtd(s->mtd[i]);
//mdk-stage1// 	s->mtd[i] = NULL;
//mdk-stage1//     }
//mdk-stage1// 
//mdk-stage1// done:
//mdk-stage1//     beep(BEEP_TIME, BEEP_OK);
//mdk-stage1//     free_card(card);
//mdk-stage1//     s->card = NULL;
//mdk-stage1//     write_stab();
//mdk-stage1// }
//mdk-stage1// 
//mdk-stage1// /*====================================================================*/
//mdk-stage1// 
//mdk-stage1// static void do_suspend(int sn)
//mdk-stage1// {
//mdk-stage1//     socket_info_t *s = &socket[sn];
//mdk-stage1//     card_info_t *card;
//mdk-stage1//     device_info_t **dev;
//mdk-stage1//     int i, ret;
//mdk-stage1//     
//mdk-stage1//     card = s->card;
//mdk-stage1//     if (card == NULL)
//mdk-stage1// 	return;
//mdk-stage1//     dev = card->device;
//mdk-stage1//     for (i = 0; i < card->bindings; i++) {
//mdk-stage1// 	if (dev[i]->class) {
//mdk-stage1// 	    ret = execute_on_all("suspend", dev[i]->class, sn, i);