17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
237c478bd9Sstevel@tonic-gate /* All Rights Reserved */
247c478bd9Sstevel@tonic-gate
25*ace1a5f1Sdp /*
26*ace1a5f1Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27*ace1a5f1Sdp * Use is subject to license terms.
28*ace1a5f1Sdp */
297c478bd9Sstevel@tonic-gate
30*ace1a5f1Sdp #pragma ident "%Z%%M% %I% %E% SMI"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include "uucp.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #ifdef D_PROTOCOL
357c478bd9Sstevel@tonic-gate #include <dk.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #define XBUFSIZ 1024
387c478bd9Sstevel@tonic-gate time_t time();
397c478bd9Sstevel@tonic-gate static jmp_buf Dfailbuf;
407c478bd9Sstevel@tonic-gate extern int drdblk();
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * Datakit protocol
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate /* ARGSUSED */
467c478bd9Sstevel@tonic-gate static void
dalarm(sig)477c478bd9Sstevel@tonic-gate dalarm(sig)
487c478bd9Sstevel@tonic-gate int sig;
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate longjmp(Dfailbuf,1);
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate static void (*dsig)();
547c478bd9Sstevel@tonic-gate #ifndef V8
557c478bd9Sstevel@tonic-gate static short dkrmode[3] = { DKR_BLOCK, 0, 0 };
567c478bd9Sstevel@tonic-gate static short dkeof[3] = { 106, 0, 0 }; /* End of File signal */
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate * turn on protocol
617c478bd9Sstevel@tonic-gate */
627c478bd9Sstevel@tonic-gate int
dturnon()637c478bd9Sstevel@tonic-gate dturnon()
647c478bd9Sstevel@tonic-gate {
657c478bd9Sstevel@tonic-gate #ifdef V8
667c478bd9Sstevel@tonic-gate extern int dkp_ld;
677c478bd9Sstevel@tonic-gate #endif
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate dsig=signal(SIGALRM, dalarm);
707c478bd9Sstevel@tonic-gate #ifdef V8
717c478bd9Sstevel@tonic-gate if (dkproto(Ofn, dkp_ld) < 0)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate DEBUG(3, "%s\n", "No dkp_ld");
747c478bd9Sstevel@tonic-gate return(-1);
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate #else
777c478bd9Sstevel@tonic-gate if((*Ioctl)(Ofn, DIOCRMODE, dkrmode) < 0) {
787c478bd9Sstevel@tonic-gate int ret;
797c478bd9Sstevel@tonic-gate ret=(*Ioctl)(Ofn, DIOCRMODE, dkrmode);
807c478bd9Sstevel@tonic-gate DEBUG(4, "dturnon: ret=%d, ", ret);
817c478bd9Sstevel@tonic-gate DEBUG(4, "Ofn=%d, ", Ofn);
827c478bd9Sstevel@tonic-gate DEBUG(4, "errno=%d\n", errno);
837c478bd9Sstevel@tonic-gate return(-1);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate #endif /* V8 */
867c478bd9Sstevel@tonic-gate return(0);
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate int
dturnoff()907c478bd9Sstevel@tonic-gate dturnoff()
917c478bd9Sstevel@tonic-gate {
927c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, dsig);
937c478bd9Sstevel@tonic-gate return(0);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate * write message across Datakit link
987c478bd9Sstevel@tonic-gate * type -> message type
997c478bd9Sstevel@tonic-gate * str -> message body (ascii string)
1007c478bd9Sstevel@tonic-gate * fn -> Datakit file descriptor
1017c478bd9Sstevel@tonic-gate * return
1027c478bd9Sstevel@tonic-gate * SUCCESS -> message sent
1037c478bd9Sstevel@tonic-gate * FAIL -> write failed
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate int
dwrmsg(type,str,fn)1067c478bd9Sstevel@tonic-gate dwrmsg(type, str, fn)
1077c478bd9Sstevel@tonic-gate register char *str;
1087c478bd9Sstevel@tonic-gate int fn;
1097c478bd9Sstevel@tonic-gate char type;
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate register char *s;
1127c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ];
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate bufr[0] = type;
1157c478bd9Sstevel@tonic-gate s = &bufr[1];
1167c478bd9Sstevel@tonic-gate while (*str)
1177c478bd9Sstevel@tonic-gate *s++ = *str++;
1187c478bd9Sstevel@tonic-gate *s = '\0';
1197c478bd9Sstevel@tonic-gate if (*(--s) == '\n')
1207c478bd9Sstevel@tonic-gate *s = '\0';
1217c478bd9Sstevel@tonic-gate return((*Write)(fn, bufr, (unsigned) strlen(bufr) + 1) < 0 ? FAIL : SUCCESS);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate * read message from Datakit link
1267c478bd9Sstevel@tonic-gate * str -> message buffer
1277c478bd9Sstevel@tonic-gate * fn -> Datakit file descriptor
1287c478bd9Sstevel@tonic-gate * return
1297c478bd9Sstevel@tonic-gate * FAIL -> send timed out
1307c478bd9Sstevel@tonic-gate * SUCCESS -> ok message in str
1317c478bd9Sstevel@tonic-gate */
1327c478bd9Sstevel@tonic-gate int
drdmsg(str,fn)1337c478bd9Sstevel@tonic-gate drdmsg(str, fn)
1347c478bd9Sstevel@tonic-gate register char *str;
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate register int len;
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate if(setjmp(Dfailbuf))
1407c478bd9Sstevel@tonic-gate return(FAIL);
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate (void) alarm(60);
1437c478bd9Sstevel@tonic-gate for (;;) {
1447c478bd9Sstevel@tonic-gate if( (len = (*Read)(fn, str, XBUFSIZ)) <= 0) {
1457c478bd9Sstevel@tonic-gate (void) alarm(0);
1467c478bd9Sstevel@tonic-gate return(FAIL);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate str += len;
1497c478bd9Sstevel@tonic-gate if (*(str - 1) == '\0')
1507c478bd9Sstevel@tonic-gate break;
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate (void) alarm(0);
1537c478bd9Sstevel@tonic-gate return(SUCCESS);
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate * read data from file fp1 and write
1587c478bd9Sstevel@tonic-gate * on Datakit link
1597c478bd9Sstevel@tonic-gate * fp1 -> file descriptor
1607c478bd9Sstevel@tonic-gate * fn -> Datakit descriptor
1617c478bd9Sstevel@tonic-gate * returns:
1627c478bd9Sstevel@tonic-gate * FAIL ->failure in Datakit link
1637c478bd9Sstevel@tonic-gate * SUCCESS -> ok
1647c478bd9Sstevel@tonic-gate */
1657c478bd9Sstevel@tonic-gate int
dwrdata(fp1,fn)1667c478bd9Sstevel@tonic-gate dwrdata(fp1, fn)
1677c478bd9Sstevel@tonic-gate FILE *fp1;
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate register int fd1;
1707c478bd9Sstevel@tonic-gate register int len, ret;
1717c478bd9Sstevel@tonic-gate unsigned long bytes;
1727c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ];
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate bytes = 0L;
1757c478bd9Sstevel@tonic-gate fd1 = fileno( fp1 );
1767c478bd9Sstevel@tonic-gate while ((len = read( fd1, bufr, XBUFSIZ )) > 0) {
1777c478bd9Sstevel@tonic-gate bytes += len;
1787c478bd9Sstevel@tonic-gate putfilesize(bytes);
1797c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, (unsigned) len);
1807c478bd9Sstevel@tonic-gate if (ret != len) {
1817c478bd9Sstevel@tonic-gate return(FAIL);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate if (len != XBUFSIZ)
1847c478bd9Sstevel@tonic-gate break;
1857c478bd9Sstevel@tonic-gate }
186*ace1a5f1Sdp ASSERT(len >= 0, "DISK READ ERROR", strerror(errno), len);
1877c478bd9Sstevel@tonic-gate #ifndef V8
1887c478bd9Sstevel@tonic-gate (*Ioctl)(fn, DIOCXCTL, dkeof);
1897c478bd9Sstevel@tonic-gate #endif
1907c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, (unsigned) 0);
1917c478bd9Sstevel@tonic-gate return(SUCCESS);
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate * read data from Datakit link and
1967c478bd9Sstevel@tonic-gate * write into file
1977c478bd9Sstevel@tonic-gate * fp2 -> file descriptor
1987c478bd9Sstevel@tonic-gate * fn -> Datakit descriptor
1997c478bd9Sstevel@tonic-gate * returns:
2007c478bd9Sstevel@tonic-gate * SUCCESS -> ok
2017c478bd9Sstevel@tonic-gate * FAIL -> failure on Datakit link
2027c478bd9Sstevel@tonic-gate */
2037c478bd9Sstevel@tonic-gate int
drddata(fn,fp2)2047c478bd9Sstevel@tonic-gate drddata(fn, fp2)
2057c478bd9Sstevel@tonic-gate FILE *fp2;
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate register int fd2;
2087c478bd9Sstevel@tonic-gate register int len;
2097c478bd9Sstevel@tonic-gate register int ret = SUCCESS;
2107c478bd9Sstevel@tonic-gate unsigned long bytes;
2117c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ];
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate bytes = 0L;
2147c478bd9Sstevel@tonic-gate fd2 = fileno( fp2 );
2157c478bd9Sstevel@tonic-gate for (;;) {
2167c478bd9Sstevel@tonic-gate len = drdblk(bufr, XBUFSIZ, fn);
2177c478bd9Sstevel@tonic-gate if (len < 0) {
2187c478bd9Sstevel@tonic-gate return(FAIL);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate bytes += len;
2217c478bd9Sstevel@tonic-gate putfilesize(bytes);
2227c478bd9Sstevel@tonic-gate if( ret == SUCCESS && write( fd2, bufr, len ) != len )
2237c478bd9Sstevel@tonic-gate ret = errno;
2247c478bd9Sstevel@tonic-gate if (len < XBUFSIZ)
2257c478bd9Sstevel@tonic-gate break;
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate return(ret);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate /*
2317c478bd9Sstevel@tonic-gate * read block from Datakit link
2327c478bd9Sstevel@tonic-gate * reads are timed
2337c478bd9Sstevel@tonic-gate * blk -> address of buffer
2347c478bd9Sstevel@tonic-gate * len -> size to read
2357c478bd9Sstevel@tonic-gate * fn -> Datakit descriptor
2367c478bd9Sstevel@tonic-gate * returns:
2377c478bd9Sstevel@tonic-gate * FAIL -> link error timeout on link
2387c478bd9Sstevel@tonic-gate * i -> # of bytes read
2397c478bd9Sstevel@tonic-gate */
2407c478bd9Sstevel@tonic-gate int
drdblk(blk,len,fn)2417c478bd9Sstevel@tonic-gate drdblk(blk, len, fn)
2427c478bd9Sstevel@tonic-gate register char *blk;
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate register int i, ret;
2457c478bd9Sstevel@tonic-gate struct dkqqabo why;
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if(setjmp(Dfailbuf))
2487c478bd9Sstevel@tonic-gate return(FAIL);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate for (i = 0; i < len; i += ret) {
2517c478bd9Sstevel@tonic-gate (void) alarm(60);
2527c478bd9Sstevel@tonic-gate if ((ret = (*Read)(fn, blk, (unsigned) len - i)) < 0) {
2537c478bd9Sstevel@tonic-gate (void) alarm(0);
2547c478bd9Sstevel@tonic-gate return(FAIL);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate blk += ret;
2577c478bd9Sstevel@tonic-gate if (ret == 0) { /* zero length block contains only EOF signal */
2587c478bd9Sstevel@tonic-gate ioctl(fn, DIOCQQABO, &why);
2597c478bd9Sstevel@tonic-gate if (why.rcv_ctlchar != dkeof[0])
2607c478bd9Sstevel@tonic-gate i = FAIL;
2617c478bd9Sstevel@tonic-gate break;
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate (void) alarm(0);
2657c478bd9Sstevel@tonic-gate return(i);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate #endif /* D_PROTOCOL */
268