7600 zfs rollback should pass target snapshot to kernel
[unleashed.git] / usr / src / cmd / bnu / gio.c
blobc09bfdca36c25c2c71b9429aaa26f559762886ca
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
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include "uucp.h"
35 #include "pk.h"
37 struct pack *Pk;
38 extern int pkread(), pkwrite();
39 extern void pkclose();
41 static int grdblk(char *, int);
42 static int gwrblk(char *, int);
44 extern int packsize, xpacksize;
46 jmp_buf Getjbuf, Gfailbuf;
48 static void (*gsig)();
50 /* ARGSUSED */
51 static void
52 galarm(sig)
53 int sig;
55 signal(SIGALRM, galarm);
56 longjmp(Getjbuf, 1);
59 void
60 pkfail()
62 longjmp(Gfailbuf, 1);
65 int
66 gturnon()
68 struct pack *pkopen();
69 if (setjmp(Gfailbuf))
70 return(FAIL);
71 gsig=signal(SIGALRM, galarm);
72 if (Debug > 4)
73 pkdebug = 1;
74 Pk = pkopen(Ifn, Ofn);
75 if ((int) Pk == NULL)
76 return(FAIL);
77 return(0);
80 int
81 gturnoff()
83 if(setjmp(Gfailbuf))
84 return(FAIL);
85 pkclose();
86 (void) signal(SIGALRM, gsig);
87 return(0);
90 /*ARGSUSED*/
91 int
92 gwrmsg(type, str, fn)
93 char type, *str;
95 char bufr[BUFSIZ], *s;
96 int len, i;
98 if(setjmp(Gfailbuf))
99 return(FAIL);
100 bufr[0] = type;
101 s = &bufr[1];
102 while (*str)
103 *s++ = *str++;
104 *s = '\0';
105 if (*(--s) == '\n')
106 *s = '\0';
107 len = strlen(bufr) + 1;
108 if ((i = len % xpacksize) != 0) {
109 len = len + xpacksize - i;
110 bufr[len - 1] = '\0';
112 gwrblk(bufr, len);
113 return(0);
117 /*ARGSUSED*/
119 grdmsg(str, fn)
120 char *str;
122 unsigned len;
124 if(setjmp(Gfailbuf))
125 return(FAIL);
126 for (;;) {
127 len = pkread(str, packsize);
128 if (len == 0)
129 continue;
130 str += len;
131 if (*(str - 1) == '\0')
132 break;
134 return(0);
138 /*ARGSUSED*/
140 gwrdata(fp1, fn)
141 FILE *fp1;
143 char bufr[BUFSIZ];
144 int fd1;
145 int len;
146 int ret;
147 unsigned long bytes;
149 if(setjmp(Gfailbuf))
150 return(FAIL);
151 bytes = 0L;
152 fd1 = fileno( fp1 );
153 while ((len = read( fd1, bufr, BUFSIZ )) > 0) {
154 bytes += len;
155 putfilesize(bytes);
156 ret = gwrblk(bufr, len);
157 if (ret != len) {
158 return(FAIL);
160 if (len != BUFSIZ)
161 break;
163 ret = gwrblk(bufr, 0);
164 return(0);
167 /*ARGSUSED*/
169 grddata(fn, fp2)
170 FILE *fp2;
172 int ret = SUCCESS;
173 int fd2;
174 int len;
175 char bufr[BUFSIZ];
176 unsigned long bytes;
178 if(setjmp(Gfailbuf))
179 return(FAIL);
180 bytes = 0L;
181 fd2 = fileno( fp2 );
182 for (;;) {
183 len = grdblk(bufr, BUFSIZ);
184 if (len < 0) {
185 return(FAIL);
187 bytes += len;
188 putfilesize(bytes);
189 if ( ret == SUCCESS && write( fd2, bufr, len ) != len) {
190 ret = errno;
191 DEBUG(7, "grddata: write to file failed, errno %d\n", errno);
193 if (len < BUFSIZ)
194 break;
196 return(ret);
200 static
202 grdblk(blk, len)
203 char *blk;
205 int i, ret;
207 for (i = 0; i < len; i += ret) {
208 ret = pkread(blk, len - i);
209 if (ret < 0)
210 return(FAIL);
211 blk += ret;
212 if (ret == 0)
213 return(i);
215 return(i);
219 static int
220 gwrblk(blk, len)
221 char *blk;
223 return(pkwrite(blk, len));