]>
git.wh0rd.org - dump.git/blob - common/dumprmt.c
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994, 1995, 1996
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 static char sccsid
[] = "@(#)dumprmt.c 8.2 (Berkeley) 4/28/95";
45 #include <sys/param.h>
47 #include <sys/ioctl.h>
48 #include <sys/socket.h>
51 #include <linux/ext2_fs.h>
52 #include <bsdcompat.h>
55 #include <sys/vnode.h>
57 #include <ufs/inode.h>
59 #include <ufs/ufs/dinode.h>
63 #include <netinet/in.h>
64 #include <netinet/tcp.h>
66 #include <protocols/dumprestore.h>
81 #include <ext2fs/ext2fs.h>
84 #include "pathnames.h"
90 static int rmtstate
= TS_CLOSED
;
94 static int okname
__P((char *));
95 static int rmtcall
__P((char *, char *));
96 static void rmtconnaborted
__P((/* int, int */));
97 static int rmtgetb
__P((void));
98 static void rmtgetconn
__P((void));
99 static void rmtgets
__P((char *, int));
100 static int rmtreply
__P((char *));
102 extern int ntrec
; /* blocking factor on tape */
109 rmtpeer
= malloc(strlen(host
) + 1);
111 strcpy(rmtpeer
, host
);
114 signal(SIGPIPE
, rmtconnaborted
);
125 errx(1, "Lost connection to remote host.");
132 static struct servent
*sp
= NULL
;
133 static struct passwd
*pwd
= NULL
;
142 sp
= getservbyname("shell", "tcp");
144 errx(1, "shell/tcp: unknown service");
145 pwd
= getpwuid(getuid());
147 errx(1, "who are you?");
149 if ((cp
= strchr(rmtpeer
, '@')) != NULL
) {
156 tuser
= pwd
->pw_name
;
157 rmtape
= rcmd(&rmtpeer
, (u_short
)sp
->s_port
, pwd
->pw_name
, tuser
,
158 _PATH_RMT
, (int *)0);
159 size
= ntrec
* TP_BSIZE
;
160 if (size
> 60 * 1024) /* XXX */
162 /* Leave some space for rmt request/response protocol */
164 while (size
> TP_BSIZE
&&
165 setsockopt(rmtape
, SOL_SOCKET
, SO_SNDBUF
, &size
, sizeof (size
)) < 0)
167 (void)setsockopt(rmtape
, SOL_SOCKET
, SO_RCVBUF
, &size
, sizeof (size
));
169 if (setsockopt(rmtape
, IPPROTO_TCP
, TCP_MAXSEG
,
170 &maxseg
, sizeof (maxseg
)) < 0)
171 perror("TCP_MAXSEG setsockopt");
174 if (setsockopt(rmtape
, IPPROTO_TCP
, TCP_NODELAY
, &on
, sizeof (on
)) < 0)
175 perror("TCP_NODELAY setsockopt");
186 for (cp
= cp0
; *cp
; cp
++) {
188 if (!isascii(c
) || !(isalnum(c
) || c
== '_' || c
== '-')) {
189 warnx("invalid user name: %s", cp0
);
203 (void)sprintf(buf
, "O%s\n%d\n", tape
, mode
);
205 return (rmtcall(tape
, buf
));
212 if (rmtstate
!= TS_OPEN
)
214 rmtcall("close", "C\n");
215 rmtstate
= TS_CLOSED
;
227 (void)sprintf(line
, "R%d\n", count
);
228 n
= rmtcall("read", line
);
233 for (i
= 0; i
< n
; i
+= cc
) {
234 cc
= read(rmtape
, buf
+i
, n
- i
);
249 (void)sprintf(line
, "W%d\n", count
);
250 write(rmtape
, line
, strlen(line
));
251 write(rmtape
, buf
, count
);
252 return (rmtreply("write"));
261 (void)sprintf(line
, "W%d\n", count
);
262 write(rmtape
, line
, strlen(line
));
266 rmtwrite1(buf
, count
)
271 write(rmtape
, buf
, count
);
278 return (rmtreply("write"));
287 (void)sprintf(line
, "L%d\n%d\n", offset
, pos
);
288 return (rmtcall("seek", line
));
299 if (rmtstate
!= TS_OPEN
)
301 rmtcall("status", "S\n");
302 for (i
= 0, cp
= (char *)&mts
; i
< sizeof(mts
); i
++)
315 (void)sprintf(buf
, "I%d\n%d\n", cmd
, count
);
316 return (rmtcall("ioctl", buf
));
324 if (write(rmtape
, buf
, strlen(buf
)) != strlen(buf
))
326 return (rmtreply(cmd
));
334 char code
[30], emsg
[BUFSIZ
];
336 rmtgets(code
, sizeof (code
));
337 if (*code
== 'E' || *code
== 'F') {
338 rmtgets(emsg
, sizeof (emsg
));
339 msg("%s: %s", cmd
, emsg
);
341 rmtstate
= TS_CLOSED
;
347 /* Kill trailing newline */
348 cp
= code
+ strlen(code
);
349 if (cp
> code
&& *--cp
== '\n')
352 msg("Protocol to remote tape server botched (code \"%s\").\n",
356 return (atoi(code
+ 1));
364 if (read(rmtape
, &c
, 1) != 1)
369 /* Get a line (guaranteed to have a trailing newline). */
375 register char *cp
= line
;
387 msg("Protocol to remote tape server botched.\n");
388 msg("(rmtgets got \"%s\").\n", line
);