8349 thrd_equal implements the wrong specification
[unleashed.git] / usr / src / cmd / bnu / dio.c
blob5ff4a34b6f916b8ff38a0986a7765f95c02ea947
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include "uucp.h"
34 #ifdef D_PROTOCOL
35 #include <dk.h>
37 #define XBUFSIZ 1024
38 time_t time();
39 static jmp_buf Dfailbuf;
40 extern int drdblk();
43 * Datakit protocol
45 /* ARGSUSED */
46 static void
47 dalarm(sig)
48 int sig;
50 longjmp(Dfailbuf,1);
53 static void (*dsig)();
54 #ifndef V8
55 static short dkrmode[3] = { DKR_BLOCK, 0, 0 };
56 static short dkeof[3] = { 106, 0, 0 }; /* End of File signal */
57 #endif
60 * turn on protocol
62 int
63 dturnon()
65 #ifdef V8
66 extern int dkp_ld;
67 #endif
69 dsig=signal(SIGALRM, dalarm);
70 #ifdef V8
71 if (dkproto(Ofn, dkp_ld) < 0)
73 DEBUG(3, "%s\n", "No dkp_ld");
74 return(-1);
76 #else
77 if((*Ioctl)(Ofn, DIOCRMODE, dkrmode) < 0) {
78 int ret;
79 ret=(*Ioctl)(Ofn, DIOCRMODE, dkrmode);
80 DEBUG(4, "dturnon: ret=%d, ", ret);
81 DEBUG(4, "Ofn=%d, ", Ofn);
82 DEBUG(4, "errno=%d\n", errno);
83 return(-1);
85 #endif /* V8 */
86 return(0);
89 int
90 dturnoff()
92 (void) signal(SIGALRM, dsig);
93 return(0);
97 * write message across Datakit link
98 * type -> message type
99 * str -> message body (ascii string)
100 * fn -> Datakit file descriptor
101 * return
102 * SUCCESS -> message sent
103 * FAIL -> write failed
106 dwrmsg(type, str, fn)
107 register char *str;
108 int fn;
109 char type;
111 register char *s;
112 char bufr[XBUFSIZ];
114 bufr[0] = type;
115 s = &bufr[1];
116 while (*str)
117 *s++ = *str++;
118 *s = '\0';
119 if (*(--s) == '\n')
120 *s = '\0';
121 return((*Write)(fn, bufr, (unsigned) strlen(bufr) + 1) < 0 ? FAIL : SUCCESS);
125 * read message from Datakit link
126 * str -> message buffer
127 * fn -> Datakit file descriptor
128 * return
129 * FAIL -> send timed out
130 * SUCCESS -> ok message in str
133 drdmsg(str, fn)
134 register char *str;
137 register int len;
139 if(setjmp(Dfailbuf))
140 return(FAIL);
142 (void) alarm(60);
143 for (;;) {
144 if( (len = (*Read)(fn, str, XBUFSIZ)) <= 0) {
145 (void) alarm(0);
146 return(FAIL);
148 str += len;
149 if (*(str - 1) == '\0')
150 break;
152 (void) alarm(0);
153 return(SUCCESS);
157 * read data from file fp1 and write
158 * on Datakit link
159 * fp1 -> file descriptor
160 * fn -> Datakit descriptor
161 * returns:
162 * FAIL ->failure in Datakit link
163 * SUCCESS -> ok
166 dwrdata(fp1, fn)
167 FILE *fp1;
169 register int fd1;
170 register int len, ret;
171 unsigned long bytes;
172 char bufr[XBUFSIZ];
174 bytes = 0L;
175 fd1 = fileno( fp1 );
176 while ((len = read( fd1, bufr, XBUFSIZ )) > 0) {
177 bytes += len;
178 putfilesize(bytes);
179 ret = (*Write)(fn, bufr, (unsigned) len);
180 if (ret != len) {
181 return(FAIL);
183 if (len != XBUFSIZ)
184 break;
186 ASSERT(len >= 0, "DISK READ ERROR", strerror(errno), len);
187 #ifndef V8
188 (*Ioctl)(fn, DIOCXCTL, dkeof);
189 #endif
190 ret = (*Write)(fn, bufr, (unsigned) 0);
191 return(SUCCESS);
195 * read data from Datakit link and
196 * write into file
197 * fp2 -> file descriptor
198 * fn -> Datakit descriptor
199 * returns:
200 * SUCCESS -> ok
201 * FAIL -> failure on Datakit link
204 drddata(fn, fp2)
205 FILE *fp2;
207 register int fd2;
208 register int len;
209 register int ret = SUCCESS;
210 unsigned long bytes;
211 char bufr[XBUFSIZ];
213 bytes = 0L;
214 fd2 = fileno( fp2 );
215 for (;;) {
216 len = drdblk(bufr, XBUFSIZ, fn);
217 if (len < 0) {
218 return(FAIL);
220 bytes += len;
221 putfilesize(bytes);
222 if( ret == SUCCESS && write( fd2, bufr, len ) != len )
223 ret = errno;
224 if (len < XBUFSIZ)
225 break;
227 return(ret);
231 * read block from Datakit link
232 * reads are timed
233 * blk -> address of buffer
234 * len -> size to read
235 * fn -> Datakit descriptor
236 * returns:
237 * FAIL -> link error timeout on link
238 * i -> # of bytes read
241 drdblk(blk, len, fn)
242 register char *blk;
244 register int i, ret;
245 struct dkqqabo why;
247 if(setjmp(Dfailbuf))
248 return(FAIL);
250 for (i = 0; i < len; i += ret) {
251 (void) alarm(60);
252 if ((ret = (*Read)(fn, blk, (unsigned) len - i)) < 0) {
253 (void) alarm(0);
254 return(FAIL);
256 blk += ret;
257 if (ret == 0) { /* zero length block contains only EOF signal */
258 ioctl(fn, DIOCQQABO, &why);
259 if (why.rcv_ctlchar != dkeof[0])
260 i = FAIL;
261 break;
264 (void) alarm(0);
265 return(i);
267 #endif /* D_PROTOCOL */