Annotation of driverkit/tests/testdriver.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*
        !            25:  * sample driver. Exec'd by Config as devr_0999_0000.
        !            26:  */
        !            27:  
        !            28: #import <bsd/sys/types.h>
        !            29: #import <mach/mach.h>
        !            30: #import <servers/bootstrap.h>
        !            31: #import <servers/netname.h>
        !            32: #import <bsd/libc.h>
        !            33: #import <mach/mach_error.h>
        !            34: #import <bsd/syslog.h>
        !            35: #import <driverkit/driverServer.h>
        !            36: #import <driverkit/userConfigServer.h>
        !            37: #import <bsd/sys/signal.h>
        !            38: 
        !            39: int get_devr_port(port_t *port_array, int max_devices);
        !            40: #ifdef notdef
        !            41: void sigint(int foo);
        !            42: #endif notdef
        !            43: void sighup(int foo);
        !            44: 
        !            45: #define NUM_DEVICES    10
        !            46: #define DEV_TYPE       0x0999
        !            47: 
        !            48: port_t config_port;
        !            49: port_t driver_sig_port;
        !            50: port_t dev_ports[NUM_DEVICES];
        !            51: port_t driver_port;
        !            52: char *driver_name;
        !            53: 
        !            54: #define print(x,a,b,c,d,e)     syslog(LOG_ERR, x,a,b,c,d,e)
        !            55: 
        !            56: int main(int argc, char **argv)
        !            57: {
        !            58:        IOConfigReturn crtn;
        !            59:        kern_return_t krtn;
        !            60:        
        !            61:        print("driver %s: starting\n", argv[0], 2,3,4,5);
        !            62:        driver_name = argv[0];
        !            63:        
        !            64:        /*
        !            65:         * sigint (signal 2) causes a device_destroy().
        !            66:         * sighup (1) causes a driver_destroy() and clean exit.
        !            67:         */
        !            68: #ifdef notdef
        !            69:        signal(SIGINT, sigint);
        !            70: #endif notdef
        !            71:        signal(SIGHUP, sighup);
        !            72:        
        !            73:        /*
        !            74:         * Get some ports.
        !            75:         */
        !            76:        krtn = netname_look_up(name_server_port,
        !            77:                "",                                     // hostname
        !            78:                CONFIG_SERVER_NAME,
        !            79:                &config_port);
        !            80:        if(krtn) {
        !            81:                print("%s: can't find %s: %s\n",
        !            82:                        argv[0], CONFIG_SERVER_NAME, mach_error_string(krtn),
        !            83:                        4,5);
        !            84:                exit(1);
        !            85:        }
        !            86:        krtn = bootstrap_look_up(bootstrap_port, 
        !            87:                SIG_PORT_NAME,
        !            88:                &driver_sig_port);
        !            89:        if(krtn) {
        !            90:                print("%s: can't find %s: %s\n",
        !            91:                        argv[0], SIG_PORT_NAME, mach_error_string(krtn), 4,5);
        !            92:                exit(1);
        !            93:        }
        !            94:        port_allocate(task_self(), &driver_port);
        !            95:        if(get_devr_port(dev_ports, NUM_DEVICES)) {
        !            96:                /*
        !            97:                 * Register with Config.
        !            98:                 */
        !            99:                crtn = IORegisterDriver(config_port,
        !           100:                        driver_sig_port,
        !           101:                        driver_port);   
        !           102:                if(crtn) {
        !           103:                        print("%s: IORegisterDriver: crtn = %d\n",
        !           104:                                argv[0], crtn, 3,4,5);
        !           105:                        exit(1);
        !           106:                }
        !           107:        }
        !           108:        
        !           109:        /*
        !           110:         * Sleep until killed.
        !           111:         */
        !           112:        while(1)
        !           113:                sleep(1);
        !           114:        exit(0);
        !           115: }
        !           116: 
        !           117: /*
        !           118:  * look up all of our dev_ports. returns # of ports found.
        !           119:  */
        !           120: int get_devr_port(port_t *dev_ports, int max_devices)
        !           121: {
        !           122:        int i;
        !           123:        name_array_t service_names;
        !           124:        unsigned int service_cnt;
        !           125:        name_array_t server_names;
        !           126:        unsigned int server_cnt;
        !           127:        bool_array_t service_active;
        !           128:        unsigned int service_active_cnt;
        !           129:        kern_return_t krtn;
        !           130:        int port_index = 0;
        !           131:        
        !           132:        krtn = bootstrap_info(bootstrap_port, 
        !           133:                &service_names, 
        !           134:                &service_cnt,
        !           135:                &server_names, 
        !           136:                &server_cnt, 
        !           137:                &service_active, 
        !           138:                &service_active_cnt);
        !           139:        if (krtn != BOOTSTRAP_SUCCESS) {
        !           140:                print("%s: bootstrap_info: %s", 
        !           141:                        driver_name, mach_error_string(krtn), 3,4,5);
        !           142:                return(PORT_NULL);
        !           143:        }
        !           144: 
        !           145:        /*
        !           146:         * Search for devr_XXXX_XXXX. Later - versions and dev_index via
        !           147:         * dev_port_to_type().
        !           148:         */
        !           149:        print("%s: service_cnt %d\n", driver_name, service_cnt, 3,4,5);
        !           150:        for (i = 0; i < service_cnt; i++) {
        !           151: #ifdef notdef
        !           152:                print("%s: service_name %s\n", driver_name, service_names[i],
        !           153:                        4,5);
        !           154: #endif notdef
        !           155:                if(strncmp(service_names[i], 
        !           156:                    "dev_port_", strlen("dev_port_")) == 0) {
        !           157:                        print("%s: port %s found\n", 
        !           158:                                driver_name, service_names[i], 3,4,5);
        !           159:                        
        !           160:                        /*
        !           161:                         * Get the dev_port. 
        !           162:                         */
        !           163:                        krtn = bootstrap_look_up(bootstrap_port,
        !           164:                                service_names[i],
        !           165:                                &dev_ports[port_index]);
        !           166:                        if(krtn) {
        !           167:                                print("%s: bootstrap_look_up: %s",
        !           168:                                        driver_name, mach_error_string(krtn),
        !           169:                                        3,4,5);
        !           170:                                return(0);
        !           171:                        }
        !           172:                        else {
        !           173:                                if(++port_index >= max_devices) {
        !           174:                                        print("%s: num_devices exceeded\n",
        !           175:                                                driver_name, 2,3,4,5);
        !           176:                                        return(port_index);
        !           177:                                }
        !           178:                        }
        !           179:                }
        !           180:        }
        !           181:        print("%s: %d dev_ports found\n", driver_name, port_index, 3,4,5);
        !           182:        return(port_index);
        !           183: }
        !           184: 
        !           185: #ifdef notdef
        !           186: /*
        !           187:  * Destroy a dev_port.
        !           188:  *
        !           189:  * NOT SUPPORTED....
        !           190:  */
        !           191: static int delete_dev = 0; 
        !           192: 
        !           193: void sigint(int foo)
        !           194: {
        !           195:        config_return_t crtn;
        !           196:        
        !           197:        crtn = IODeleteDevice(config_port,
        !           198:                driver_sig_port,
        !           199:                dev_ports[delete_dev],
        !           200:                &crtn);
        !           201:        if(crtn) {
        !           202:                print("%s: crtn %d", driver_name, crtn, 3,4,5);
        !           203:                return;
        !           204:        }
        !           205:        dev_ports[delete_dev++] = PORT_NULL;
        !           206: }
        !           207: #endif notdef
        !           208: 
        !           209: /*
        !           210:  * Destroy driver (without re-exec).
        !           211:  */
        !           212: void sighup(int foo)
        !           213: {
        !           214:        IOConfigReturn crtn;
        !           215:        
        !           216:        crtn = IODeleteDriver(config_port, driver_sig_port);
        !           217:        if(crtn) {
        !           218:                print("%s IODeleteDriver: crtn %d", driver_name, crtn, 3,4,5);
        !           219:                return;
        !           220:        }
        !           221:        exit(0);
        !           222: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.