Annotation of researchv10no/dk/libc/dkctlchan.c, revision 1.1.1.1

1.1       root        1: #include <sys/ioctl.h>
                      2: #include <stdio.h>
                      3: 
                      4: static char *names[] = {
                      5:        "/dev/dk/dk0%c%d",
                      6:        "/dev/dk/dk2%c%d",
                      7:        "/dev/dk/dkctl0",
                      8:        "/dev/dk/dkctl2",
                      9:        "/dev/dk/dk%c%d",
                     10:        "/dev/dk/dkctl",
                     11:        0
                     12: };
                     13: 
                     14: static char *namefmt;
                     15: static char alph[] = "0123456789abcdefghijklmnopqrstuvwxyz";
                     16: 
                     17: /*
                     18:  * open channel 1 to controller
                     19:  *   leave record of file name
                     20:  */
                     21: dkctlchan(traffic)
                     22: register traffic;
                     23: {
                     24:        register i ;
                     25:        extern int rdk_ld, dkp_ld ;
                     26:        char dk01file[32];
                     27: 
                     28:        namefmt = traffic? names[1]:names[0];
                     29:        sprintf(dk01file, namefmt, alph[0], 1);
                     30:        i = open(dk01file, 2) ;
                     31:        if (i < 0) {
                     32:                sprintf(dk01file, traffic?names[3]:names[2]) ;
                     33:                i = open(dk01file, 2) ;
                     34:                if (i < 0) {
                     35:                        namefmt = names[4];
                     36:                        sprintf(dk01file, namefmt, alph[0], 1);
                     37:                        i = open(dk01file, 2);
                     38:                        if (i < 0) {
                     39:                                sprintf(dk01file, names[5]) ;
                     40:                                i = open(dk01file, 2);
                     41:                                if (i < 0)
                     42:                                        return (i) ;
                     43:                        }
                     44:                }
                     45:        }
                     46:        ioctl(i, DIOCNXCL, 0);
                     47:        if (ioctl(i, FIOLOOKLD, 0) != rdk_ld) {
                     48:                if (dkproto(i, dkp_ld) < 0) {
                     49:                        fprintf(stderr, "can't start dkp on %s\n", dk01file) ;
                     50:                        close(i) ;
                     51:                        return (-1) ;
                     52:                }
                     53:                if (ioctl(i, FIOPUSHLD, &rdk_ld) < 0) {
                     54:                        fprintf(stderr, "can't push rdk_ld on %s\n", dk01file) ;
                     55:                        close(i) ;
                     56:                        return (-1) ;
                     57:                }
                     58:                if (ioctl(i, DIOCLHN, (char *)0) < 0) {
                     59:                        fprintf(stderr, "can't be manager on %s\n", dk01file) ;
                     60:                        close(i);
                     61:                        return(-1);
                     62:                }
                     63:        }
                     64:        return (i) ;
                     65: }
                     66: 
                     67: /*
                     68:  * find the file name corresponding to a given channel.
                     69:  * assumes dkctlchan has been called.
                     70:  * Used for incoming calls.
                     71:  */
                     72: 
                     73: char *
                     74: dkfilename(chan)
                     75: {
                     76:        static char name[64];
                     77: 
                     78:        if (namefmt==NULL)
                     79:                return(NULL);
                     80:        sprintf(name, namefmt, alph[chan/10], chan%10);
                     81:        return(name);
                     82: }

unix.superglobalmegacorp.com

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