]> git.wh0rd.org - dump.git/blob - dump/tape.c
Made dump work with new Linux 2.5 EOT early warning semantics.
[dump.git] / dump / tape.c
1 /*
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-1997
5 * Stelian Pop <stelian@popies.net>, 1999-2000
6 * Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 2000-2002
7 */
8
9 /*-
10 * Copyright (c) 1980, 1991, 1993
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 #ifndef lint
39 static const char rcsid[] =
40 "$Id: tape.c,v 1.76 2003/04/09 10:42:57 stelian Exp $";
41 #endif /* not lint */
42
43 #include <config.h>
44 #include <compatlfs.h>
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <setjmp.h>
48 #include <signal.h>
49 #include <stdio.h>
50 #include <compaterr.h>
51 #include <system.h>
52 #ifdef __STDC__
53 #include <stdlib.h>
54 #include <string.h>
55 #include <unistd.h>
56 #else
57 int write(), read();
58 #endif
59
60 #ifdef __linux__
61 #include <sys/types.h>
62 #include <sys/time.h>
63 #include <time.h>
64 #endif
65 #include <sys/param.h>
66 #include <sys/socket.h>
67 #include <sys/wait.h>
68 #include <sys/mtio.h>
69 #ifdef __linux__
70 #ifdef HAVE_EXT2FS_EXT2_FS_H
71 #include <ext2fs/ext2_fs.h>
72 #else
73 #include <linux/ext2_fs.h>
74 #endif
75 #include <ext2fs/ext2fs.h>
76 #include <sys/stat.h>
77 #include <bsdcompat.h>
78 #elif defined sunos
79 #include <sys/vnode.h>
80
81 #include <ufs/fs.h>
82 #include <ufs/inode.h>
83 #else
84 #include <ufs/ufs/dinode.h>
85 #include <ufs/ffs/fs.h>
86 #endif /* __linux__ */
87
88 #include <protocols/dumprestore.h>
89
90 #ifdef HAVE_ZLIB
91 #include <zlib.h>
92 #endif /* HAVE_ZLIB */
93
94 #ifdef HAVE_BZLIB
95 #include <bzlib.h>
96 #endif /* HAVE_BZLIB */
97
98 #ifdef HAVE_LZO
99 #include <minilzo.h>
100 #endif /* HAVE_LZO */
101
102 #include "dump.h"
103
104 int writesize; /* size of malloc()ed buffer for tape */
105 long lastspclrec = -1; /* tape block number of last written header */
106 int trecno = 0; /* next record to write in current block */
107 extern long blocksperfile; /* number of blocks per output file */
108 long blocksthisvol; /* number of blocks on current output file */
109 extern int ntrec; /* blocking factor on tape */
110 extern int cartridge;
111 char *nexttape;
112 extern pid_t rshpid;
113 long long tapea_bytes = 0; /* bytes_written at start of current volume */
114 static int magtapeout; /* output is really a tape */
115
116 static ssize_t dump_atomic_read __P((int, void *, size_t));
117 static ssize_t dump_atomic_write __P((int, const void *, size_t));
118 #ifdef WRITEDEBUG
119 static void doslave __P((int, int, int));
120 #else
121 static void doslave __P((int, int));
122 #endif
123 static void enslave __P((void));
124 static void flushtape __P((void));
125 static void killall __P((void));
126 static void rollforward __P((void));
127 #ifdef USE_QFA
128 static int GetTapePos __P((long long *));
129 static void MkTapeString __P((struct s_spcl *, long long));
130 #endif
131
132 /*
133 * Concurrent dump mods (Caltech) - disk block reading and tape writing
134 * are exported to several slave processes. While one slave writes the
135 * tape, the others read disk blocks; they pass control of the tape in
136 * a ring via signals. The parent process traverses the filesystem and
137 * sends writeheader()'s and lists of daddr's to the slaves via pipes.
138 * The following structure defines the instruction packets sent to slaves.
139 */
140 struct req {
141 daddr_t dblk;
142 int count;
143 };
144 int reqsiz;
145
146 struct slave_results {
147 ssize_t unclen; /* uncompressed length */
148 ssize_t clen; /* compressed length */
149 };
150
151 #define SLAVES 3 /* 1 slave writing, 1 reading, 1 for slack */
152 struct slave {
153 int tapea; /* header number at start of this chunk */
154 int count; /* count to next header (used for TS_TAPE */
155 /* after EOT) */
156 int inode; /* inode that we are currently dealing with */
157 int fd; /* FD for this slave */
158 int pid; /* PID for this slave */
159 int sent; /* 1 == we've sent this slave requests */
160 int firstrec; /* record number of this block */
161 char (*tblock)[TP_BSIZE]; /* buffer for data blocks */
162 struct req *req; /* buffer for requests */
163 } slaves[SLAVES+1];
164 struct slave *slp;
165
166 char (*nextblock)[TP_BSIZE];
167
168 static time_t tstart_volume; /* time of volume start */
169 static int tapea_volume; /* value of spcl.c_tapea at volume start */
170
171 int master; /* pid of master, for sending error signals */
172 int tenths; /* length of tape overhead per block written */
173 static int caught; /* have we caught the signal to proceed? */
174 static int ready; /* have we reached the lock point without having */
175 /* received the SIGUSR2 signal from the prev slave? */
176 static sigjmp_buf jmpbuf; /* where to jump to if we are ready when the */
177 /* SIGUSR2 arrives from the previous slave */
178 #ifdef USE_QFA
179 static int gtperr = 0;
180 #endif
181
182 int
183 alloctape(void)
184 {
185 int pgoff = getpagesize() - 1;
186 char *buf;
187 int i;
188
189 writesize = ntrec * TP_BSIZE;
190 reqsiz = (ntrec + 1) * sizeof(struct req);
191 /*
192 * CDC 92181's and 92185's make 0.8" gaps in 1600-bpi start/stop mode
193 * (see DEC TU80 User's Guide). The shorter gaps of 6250-bpi require
194 * repositioning after stopping, i.e, streaming mode, where the gap is
195 * variable, 0.30" to 0.45". The gap is maximal when the tape stops.
196 */
197 if (blocksperfile == 0 && !unlimited)
198 tenths = (cartridge ? 16 : density == 625 ? 5 : 8);
199 else {
200 tenths = 0;
201 density = 1;
202 }
203 /*
204 * Allocate tape buffer contiguous with the array of instruction
205 * packets, so flushtape() can write them together with one write().
206 * Align tape buffer on page boundary to speed up tape write().
207 */
208 for (i = 0; i <= SLAVES; i++) {
209 buf = (char *)
210 malloc((unsigned)(reqsiz + writesize + pgoff + TP_BSIZE));
211 if (buf == NULL)
212 return(0);
213 slaves[i].tblock = (char (*)[TP_BSIZE])
214 #ifdef __linux__
215 (((long)&buf[reqsiz] + pgoff) &~ pgoff);
216 #else
217 (((long)&buf[ntrec + 1] + pgoff) &~ pgoff);
218 #endif
219 slaves[i].req = (struct req *)slaves[i].tblock - ntrec - 1;
220 }
221 slp = &slaves[0];
222 slp->count = 1;
223 slp->tapea = 0;
224 slp->firstrec = 0;
225 nextblock = slp->tblock;
226 return(1);
227 }
228
229 void
230 writerec(const void *dp, int isspcl)
231 {
232
233 slp->req[trecno].dblk = (daddr_t)0;
234 slp->req[trecno].count = 1;
235 /* XXX post increment triggers an egcs-1.1.2-12 bug on alpha/sparc */
236 *(union u_spcl *)(*(nextblock)) = *(union u_spcl *)dp;
237
238 /* Need to write it to the archive file */
239 if (! AfileActive && isspcl && (spcl.c_type == TS_END))
240 AfileActive = 1;
241 if (AfileActive && Afile >= 0) {
242 /* When we dump an inode which is not a directory,
243 * it means we ended the archive contents */
244 if (isspcl && (spcl.c_type == TS_INODE) &&
245 ((spcl.c_dinode.di_mode & S_IFMT) != IFDIR))
246 AfileActive = 0;
247 else {
248 union u_spcl tmp;
249 tmp = *(union u_spcl *)dp;
250 /* Write the record, _uncompressed_ */
251 if (isspcl) {
252 tmp.s_spcl.c_flags &= ~DR_COMPRESSED;
253 mkchecksum(&tmp);
254 }
255 if (write(Afile, &tmp, TP_BSIZE) != TP_BSIZE)
256 msg("error writing archive file: %s\n",
257 strerror(errno));
258 }
259 }
260
261 nextblock++;
262 if (isspcl)
263 lastspclrec = spcl.c_tapea;
264 trecno++;
265 spcl.c_tapea++;
266 if (trecno >= ntrec)
267 flushtape();
268 }
269
270 void
271 dumpblock(daddr_t blkno, int size)
272 {
273 int avail, tpblks, dblkno;
274
275 dblkno = fsbtodb(sblock, blkno);
276 tpblks = size >> tp_bshift;
277 while ((avail = MIN(tpblks, ntrec - trecno)) > 0) {
278 slp->req[trecno].dblk = dblkno;
279 slp->req[trecno].count = avail;
280 trecno += avail;
281 spcl.c_tapea += avail;
282 if (trecno >= ntrec)
283 flushtape();
284 dblkno += avail << (tp_bshift - dev_bshift);
285 tpblks -= avail;
286 }
287 }
288
289 int nogripe = 0;
290
291 static void
292 tperror(int errnum)
293 {
294
295 if (pipeout) {
296 msg("write error on %s: %s\n", tape, strerror(errnum));
297 quit("Cannot recover\n");
298 /* NOTREACHED */
299 }
300 msg("write error %d blocks into volume %d: %s\n",
301 blocksthisvol, tapeno, strerror(errnum));
302 broadcast("DUMP WRITE ERROR!\n");
303 if (query("Do you want to rewrite this volume?")) {
304 msg("Closing this volume. Prepare to restart with new media;\n");
305 msg("this dump volume will be rewritten.\n");
306 killall();
307 nogripe = 1;
308 close_rewind();
309 Exit(X_REWRITE);
310 }
311 if (query("Do you want to start the next tape?"))
312 return;
313 dumpabort(0);
314 }
315
316 static void
317 sigpipe(UNUSED(int signo))
318 {
319
320 quit("Broken pipe\n");
321 }
322
323 /*
324 * do_stats --
325 * Update xferrate stats
326 */
327 time_t
328 do_stats(void)
329 {
330 time_t tnow, ttaken;
331 int blocks;
332
333 tnow = time(NULL);
334 ttaken = tnow - tstart_volume;
335 blocks = spcl.c_tapea - tapea_volume;
336 msg("Volume %d completed at: %s", tapeno, ctime(&tnow));
337 if (! compressed)
338 msg("Volume %d %ld blocks (%.2fMB)\n", tapeno,
339 blocks, ((double)blocks * TP_BSIZE / 1048576));
340 if (ttaken > 0) {
341 long volkb = (bytes_written - tapea_bytes) / 1024;
342 long txfrate = volkb / ttaken;
343 msg("Volume %d took %d:%02d:%02d\n", tapeno,
344 ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60);
345 msg("Volume %d transfer rate: %ld kB/s\n", tapeno,
346 txfrate);
347 xferrate += txfrate;
348 if (compressed) {
349 double rate = .0005 + (double) blocks / (double) volkb;
350 msg("Volume %d %ldkB uncompressed, %ldkB compressed,"
351 " %1.3f:1\n",
352 tapeno, blocks, volkb, rate);
353 }
354 }
355 return(tnow);
356 }
357
358 char *
359 mktimeest(time_t tnow)
360 {
361 static char msgbuf[128];
362 time_t deltat;
363
364 msgbuf[0] = '\0';
365
366 if (blockswritten < 500)
367 return NULL;
368 if (blockswritten > tapesize)
369 tapesize = blockswritten;
370 deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing))
371 / blockswritten * tapesize;
372 if (tnow > tstart_volume)
373 (void)snprintf(msgbuf, sizeof(msgbuf),
374 "%3.2f%% done at %ld kB/s, finished in %d:%02d\n",
375 (blockswritten * 100.0) / tapesize,
376 (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume),
377 (int)(deltat / 3600), (int)((deltat % 3600) / 60));
378 else
379 (void)snprintf(msgbuf, sizeof(msgbuf),
380 "%3.2f%% done, finished in %d:%02d\n",
381 (blockswritten * 100.0) / tapesize,
382 (int)(deltat / 3600), (int)((deltat % 3600) / 60));
383
384 return msgbuf;
385 }
386
387 #if defined(SIGINFO)
388 /*
389 * statussig --
390 * information message upon receipt of SIGINFO
391 */
392 void
393 statussig(int notused)
394 {
395 int save_errno = errno;
396 char *buf;
397
398 buf = mktimeest(time(NULL));
399 if (buf)
400 write(STDERR_FILENO, buf, strlen(buf));
401 errno = save_errno;
402 }
403 #endif
404
405 static void
406 flushtape(void)
407 {
408 int i, blks, got;
409 long lastfirstrec;
410 struct slave_results returned;
411
412 int siz = (char *)nextblock - (char *)slp->req;
413
414 slp->req[trecno].count = 0; /* Sentinel */
415
416 if (dump_atomic_write( slp->fd, (char *)slp->req, siz) != siz)
417 quit("error writing command pipe: %s\n", strerror(errno));
418 slp->sent = 1; /* we sent a request, read the response later */
419
420 lastfirstrec = slp->firstrec;
421
422 if (++slp >= &slaves[SLAVES])
423 slp = &slaves[0];
424
425 /* Read results back from next slave */
426 if (slp->sent) {
427 if (dump_atomic_read( slp->fd, (char *)&returned, sizeof returned)
428 != sizeof returned) {
429 perror(" DUMP: error reading command pipe in master");
430 dumpabort(0);
431 }
432 got = returned.unclen;
433 bytes_written += returned.clen;
434 if (returned.unclen == returned.clen)
435 uncomprblks++;
436 slp->sent = 0;
437
438 /* Check for errors or end of tape */
439 if (got <= 0) {
440 /* Check for errors */
441 if (got < 0)
442 tperror(-got);
443 else
444 msg("End of tape detected\n");
445
446 /*
447 * Drain the results, don't care what the values were.
448 * If we read them here then trewind won't...
449 */
450 for (i = 0; i < SLAVES; i++) {
451 if (slaves[i].sent) {
452 if (dump_atomic_read( slaves[i].fd,
453 (char *)&returned, sizeof returned)
454 != sizeof returned) {
455 perror(" DUMP: error reading command pipe in master");
456 dumpabort(0);
457 }
458 slaves[i].sent = 0;
459 }
460 }
461
462 close_rewind();
463 rollforward();
464 return;
465 }
466 }
467
468 blks = 0;
469 if (spcl.c_type != TS_END) {
470 for (i = 0; i < spcl.c_count; i++)
471 if (spcl.c_addr[i] != 0)
472 blks++;
473 }
474 slp->count = lastspclrec + blks + 1 - spcl.c_tapea;
475 slp->tapea = spcl.c_tapea;
476 slp->firstrec = lastfirstrec + ntrec;
477 slp->inode = curino;
478 nextblock = slp->tblock;
479 trecno = 0;
480 asize += tenths + returned.clen / density;
481 blockswritten += ntrec;
482 blocksthisvol += ntrec;
483 if (!pipeout && !unlimited) {
484 if (blocksperfile) {
485 if ( compressed ? (bytes_written - tapea_bytes + SLAVES * (writesize + sizeof(struct tapebuf))) >= (((long long)blocksperfile) * 1024)
486 : blocksthisvol >= blocksperfile ) {
487 close_rewind();
488 startnewtape(0);
489 }
490 }
491 else if (asize > tsize) {
492 close_rewind();
493 startnewtape(0);
494 }
495 }
496 timeest();
497 }
498
499 time_t
500 trewind(void)
501 {
502 int f;
503 int got;
504 struct slave_results returned;
505
506 for (f = 0; f < SLAVES; f++) {
507 /*
508 * Drain the results, but unlike EOT we DO (or should) care
509 * what the return values were, since if we detect EOT after
510 * we think we've written the last blocks to the tape anyway,
511 * we have to replay those blocks with rollforward.
512 *
513 * fixme: punt for now.
514 */
515 if (slaves[f].sent) {
516 if (dump_atomic_read( slaves[f].fd, (char *)&returned, sizeof returned)
517 != sizeof returned) {
518 perror(" DUMP: error reading command pipe in master");
519 dumpabort(0);
520 }
521 got = returned.unclen;
522 bytes_written += returned.clen;
523 if (returned.unclen == returned.clen)
524 uncomprblks++;
525 slaves[f].sent = 0;
526
527 if (got < 0)
528 tperror(-got);
529
530 if (got == 0) {
531 msg("EOT detected in last 2 tape records!\n");
532 msg("Use a longer tape, decrease the size estimate\n");
533 quit("or use no size estimate at all.\n");
534 }
535 }
536 (void) close(slaves[f].fd);
537 }
538 while (wait((int *)NULL) >= 0) /* wait for any signals from slaves */
539 /* void */;
540
541 if (!pipeout) {
542
543 msg("Closing %s\n", tape);
544
545 #ifdef RDUMP
546 if (host) {
547 rmtclose();
548 while (rmtopen(tape, O_RDONLY) < 0)
549 sleep(10);
550 rmtclose();
551 }
552 else
553 #endif
554 {
555 (void) close(tapefd);
556 if (!fifoout) {
557 while ((f = OPEN(tape, O_RDONLY)) < 0)
558 sleep (10);
559 (void) close(f);
560 }
561 }
562 }
563 return do_stats();
564 }
565
566
567 void
568 close_rewind(void)
569 {
570 int eot_code = 1;
571 (void)trewind();
572 if (nexttape || Mflag)
573 return;
574 if (eot_script) {
575 msg("Launching %s\n", eot_script);
576 eot_code = system_command(eot_script, tape, tapeno);
577 }
578 if (eot_code != 0 && eot_code != 1) {
579 msg("Dump aborted by the end of tape script\n");
580 dumpabort(0);
581 }
582 if (eot_code == 0)
583 return;
584 if (!nogripe) {
585 msg("Change Volumes: Mount volume #%d\n", tapeno+1);
586 broadcast("CHANGE DUMP VOLUMES!\7\7\n");
587 }
588 while (!query("Is the new volume mounted and ready to go?"))
589 if (query("Do you want to abort?")) {
590 dumpabort(0);
591 /*NOTREACHED*/
592 }
593 }
594
595 void
596 rollforward(void)
597 {
598 struct req *p, *q = NULL, *prev;
599 struct slave *tslp;
600 int i, size, savedtapea, got;
601 union u_spcl *ntb, *otb;
602 struct slave_results returned;
603 #ifdef __linux__
604 int blks;
605 long lastfirstrec;
606 #endif
607 tslp = &slaves[SLAVES];
608 ntb = (union u_spcl *)tslp->tblock[1];
609
610 /*
611 * Each of the N slaves should have requests that need to
612 * be replayed on the next tape. Use the extra slave buffers
613 * (slaves[SLAVES]) to construct request lists to be sent to
614 * each slave in turn.
615 */
616 for (i = 0; i < SLAVES; i++) {
617 q = &tslp->req[1];
618 otb = (union u_spcl *)slp->tblock;
619
620 /*
621 * For each request in the current slave, copy it to tslp.
622 */
623
624 prev = NULL;
625 for (p = slp->req; p->count > 0; p += p->count) {
626 *q = *p;
627 if (p->dblk == 0)
628 *ntb++ = *otb++; /* copy the datablock also */
629 prev = q;
630 q += q->count;
631 }
632 if (prev == NULL)
633 quit("rollforward: protocol botch");
634 if (prev->dblk != 0)
635 prev->count -= 1;
636 else
637 ntb--;
638 q -= 1;
639 q->count = 0;
640 q = &tslp->req[0];
641 if (i == 0) {
642 q->dblk = 0;
643 q->count = 1;
644 trecno = 0;
645 nextblock = tslp->tblock;
646 savedtapea = spcl.c_tapea;
647 spcl.c_tapea = slp->tapea;
648 startnewtape(0);
649 spcl.c_tapea = savedtapea;
650 lastspclrec = savedtapea - 1;
651 }
652 size = (char *)ntb - (char *)q;
653 if (dump_atomic_write( slp->fd, (char *)q, size) != size) {
654 perror(" DUMP: error writing command pipe");
655 dumpabort(0);
656 }
657 slp->sent = 1;
658 #ifdef __linux__
659 lastfirstrec = slp->firstrec;
660 #endif
661 if (++slp >= &slaves[SLAVES])
662 slp = &slaves[0];
663
664 q->count = 1;
665
666 if (prev->dblk != 0) {
667 /*
668 * If the last one was a disk block, make the
669 * first of this one be the last bit of that disk
670 * block...
671 */
672 q->dblk = prev->dblk +
673 prev->count * (TP_BSIZE / DEV_BSIZE);
674 ntb = (union u_spcl *)tslp->tblock;
675 } else {
676 /*
677 * It wasn't a disk block. Copy the data to its
678 * new location in the buffer.
679 */
680 q->dblk = 0;
681 *((union u_spcl *)tslp->tblock) = *ntb;
682 ntb = (union u_spcl *)tslp->tblock[1];
683 }
684 }
685 slp->req[0] = *q;
686 nextblock = slp->tblock;
687 if (q->dblk == 0) {
688 #ifdef __linux__
689 /* XXX post increment triggers an egcs-1.1.2-12 bug on alpha/sparc */
690 *(union u_spcl *)(*nextblock) = *(union u_spcl *)tslp->tblock;
691 #endif
692 nextblock++;
693 }
694 trecno = 1;
695
696 /*
697 * Clear the first slaves' response. One hopes that it
698 * worked ok, otherwise the tape is much too short!
699 */
700 if (slp->sent) {
701 if (dump_atomic_read( slp->fd, (char *)&returned, sizeof returned)
702 != sizeof returned) {
703 perror(" DUMP: error reading command pipe in master");
704 dumpabort(0);
705 }
706 got = returned.unclen;
707 bytes_written += returned.clen;
708 if (returned.clen == returned.unclen)
709 uncomprblks++;
710 slp->sent = 0;
711
712 if (got < 0)
713 tperror(-got);
714
715 if (got == 0) {
716 quit("EOT detected at start of the tape!\n");
717 }
718 }
719
720 #ifdef __linux__
721 blks = 0;
722 if (spcl.c_type != TS_END) {
723 for (i = 0; i < spcl.c_count; i++)
724 if (spcl.c_addr[i] != 0)
725 blks++;
726 }
727
728 slp->firstrec = lastfirstrec + ntrec;
729 slp->count = lastspclrec + blks + 1 - spcl.c_tapea;
730 slp->inode = curino;
731 asize += tenths + returned.clen / density;
732 blockswritten += ntrec;
733 blocksthisvol += ntrec;
734 #endif
735 }
736
737 /*
738 * We implement taking and restoring checkpoints on the tape level.
739 * When each tape is opened, a new process is created by forking; this
740 * saves all of the necessary context in the parent. The child
741 * continues the dump; the parent waits around, saving the context.
742 * If the child returns X_REWRITE, then it had problems writing that tape;
743 * this causes the parent to fork again, duplicating the context, and
744 * everything continues as if nothing had happened.
745 */
746 void
747 startnewtape(int top)
748 {
749 int parentpid;
750 int childpid;
751 int status;
752 int waitpid;
753 char *p;
754
755 #ifdef __linux__
756 sigset_t sigs;
757 sigemptyset(&sigs);
758 sigaddset(&sigs, SIGINT);
759 sigprocmask(SIG_BLOCK, &sigs, NULL);
760 #else /* __linux__ */
761 #ifdef sunos
762 void (*interrupt_save)();
763 #else
764 sig_t interrupt_save;
765 #endif
766 interrupt_save = signal(SIGINT, SIG_IGN);
767 #endif /* __linux__ */
768
769 parentpid = getpid();
770 tapea_volume = spcl.c_tapea;
771 tapea_bytes = bytes_written;
772 tstart_volume = time(NULL);
773
774 restore_check_point:
775 #ifdef __linux__
776 sigprocmask(SIG_UNBLOCK, &sigs, NULL);
777 #else
778 (void)signal(SIGINT, interrupt_save);
779 #endif
780 /*
781 * All signals are inherited...
782 */
783 childpid = fork();
784 if (childpid < 0) {
785 msg("Context save fork fails in parent %d\n", parentpid);
786 Exit(X_ABORT);
787 }
788 if (childpid != 0) {
789 /*
790 * PARENT:
791 * save the context by waiting
792 * until the child doing all of the work returns.
793 * don't catch the interrupt
794 */
795 #ifdef __linux__
796 sigprocmask(SIG_BLOCK, &sigs, NULL);
797 #else
798 signal(SIGINT, SIG_IGN);
799 #endif
800 #ifdef TDEBUG
801 msg("Tape: %d; parent process: %d child process %d\n",
802 tapeno+1, parentpid, childpid);
803 #endif /* TDEBUG */
804 while ((waitpid = wait(&status)) != childpid)
805 if (waitpid != rshpid)
806 msg("Parent %d waiting for child %d has another child %d return\n",
807 parentpid, childpid, waitpid);
808 if (status & 0xFF) {
809 msg("Child %d returns LOB status %o\n",
810 childpid, status&0xFF);
811 }
812 status = (status >> 8) & 0xFF;
813 #ifdef TDEBUG
814 switch(status) {
815 case X_FINOK:
816 msg("Child %d finishes X_FINOK\n", childpid);
817 break;
818 case X_ABORT:
819 msg("Child %d finishes X_ABORT\n", childpid);
820 break;
821 case X_REWRITE:
822 msg("Child %d finishes X_REWRITE\n", childpid);
823 break;
824 default:
825 msg("Child %d finishes unknown %d\n",
826 childpid, status);
827 break;
828 }
829 #endif /* TDEBUG */
830 switch(status) {
831 case X_FINOK:
832 Exit(X_FINOK);
833 case X_ABORT:
834 Exit(X_ABORT);
835 case X_REWRITE:
836 goto restore_check_point;
837 default:
838 msg("Bad return code from dump: %d\n", status);
839 Exit(X_ABORT);
840 }
841 /*NOTREACHED*/
842 } else { /* we are the child; just continue */
843 #ifdef TDEBUG
844 sleep(4); /* allow time for parent's message to get out */
845 msg("Child on Tape %d has parent %d, my pid = %d\n",
846 tapeno+1, parentpid, getpid());
847 #endif /* TDEBUG */
848 /*
849 * If we have a name like "/dev/rmt0,/dev/rmt1",
850 * use the name before the comma first, and save
851 * the remaining names for subsequent volumes.
852 */
853 tapeno++; /* current tape sequence */
854 if (Mflag) {
855 snprintf(tape, MAXPATHLEN, "%s%03d", tapeprefix, tapeno);
856 tape[MAXPATHLEN - 1] = '\0';
857 msg("Dumping volume %d on %s\n", tapeno, tape);
858 }
859 else if (nexttape || strchr(tapeprefix, ',')) {
860 if (nexttape && *nexttape)
861 tapeprefix = nexttape;
862 if ((p = strchr(tapeprefix, ',')) != NULL) {
863 *p = '\0';
864 nexttape = p + 1;
865 } else
866 nexttape = NULL;
867 strncpy(tape, tapeprefix, MAXPATHLEN);
868 tape[MAXPATHLEN - 1] = '\0';
869 msg("Dumping volume %d on %s\n", tapeno, tape);
870 }
871 #ifdef RDUMP
872 while ((tapefd = (host ? rmtopen(tape, O_WRONLY|O_CREAT|O_TRUNC) : pipeout ?
873 fileno(stdout) :
874 OPEN(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0)
875 #else
876 while ((tapefd = (pipeout ? fileno(stdout) :
877 OPEN(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0)
878 #endif
879 {
880 msg("Cannot open output \"%s\": %s\n", tape,
881 strerror(errno));
882 if (!query("Do you want to retry the open?"))
883 dumpabort(0);
884 }
885 #ifdef RDUMP
886 if (!host)
887 #endif
888 {
889 struct mtget mt_stat;
890 magtapeout = ioctl(tapefd, MTIOCGET, (char *)&mt_stat) == 0;
891 /*
892 msg("Output is to %s\n",
893 magtapeout ? "tape" : "file/pipe");
894 */
895 }
896
897 enslave(); /* Share open tape file descriptor with slaves */
898
899 asize = 0;
900 blocksthisvol = 0;
901 if (top)
902 newtape++; /* new tape signal */
903 spcl.c_count = slp->count;
904 /*
905 * measure firstrec in TP_BSIZE units since restore doesn't
906 * know the correct ntrec value...
907 */
908 spcl.c_firstrec = slp->firstrec;
909 spcl.c_volume++;
910 spcl.c_type = TS_TAPE;
911 spcl.c_flags |= DR_NEWHEADER;
912 spcl.c_ntrec = ntrec;
913 if (compressed)
914 spcl.c_flags |= DR_COMPRESSED;
915 writeheader((dump_ino_t)slp->inode);
916 spcl.c_flags &=~ DR_NEWHEADER;
917 msg("Volume %d started with block %ld at: %s", tapeno,
918 spcl.c_tapea, ctime(&tstart_volume));
919 if (tapeno > 1)
920 msg("Volume %d begins with blocks from inode %d\n",
921 tapeno, slp->inode);
922 if (tapeno < (int)TP_NINOS)
923 volinfo[tapeno] = slp->inode;
924 }
925 }
926
927 void
928 dumpabort(UNUSED(int signo))
929 {
930
931 if (master != 0 && master != getpid())
932 /* Signals master to call dumpabort */
933 (void) kill(master, SIGTERM);
934 else {
935 killall();
936 msg("The ENTIRE dump is aborted.\n");
937 }
938 #ifdef RDUMP
939 rmtclose();
940 #endif
941 Exit(X_ABORT);
942 }
943
944 void
945 Exit(int status)
946 {
947
948 #ifdef TDEBUG
949 msg("pid = %d exits with status %d\n", getpid(), status);
950 #endif /* TDEBUG */
951 exit(status);
952 }
953
954 /*
955 * proceed - handler for SIGUSR2, used to synchronize IO between the slaves.
956 */
957 static void
958 proceed(UNUSED(int signo))
959 {
960 if (ready)
961 siglongjmp(jmpbuf, 1);
962 caught++;
963 }
964
965 void
966 enslave(void)
967 {
968 int cmd[2];
969 #ifdef LINUX_FORK_BUG
970 int i, j;
971 #else
972 int i, j;
973 #endif
974
975 master = getpid();
976
977 { struct sigaction sa;
978 memset(&sa, 0, sizeof sa);
979 sigemptyset(&sa.sa_mask);
980 sa.sa_handler = dumpabort;
981 sigaction(SIGTERM, &sa, NULL); /* Slave sends SIGTERM on dumpabort() */
982 sa.sa_handler = sigpipe;
983 sigaction(SIGPIPE, &sa, NULL);
984 sa.sa_handler = proceed;
985 sa.sa_flags = SA_RESTART;
986 sigaction(SIGUSR2, &sa, NULL); /* Slave sends SIGUSR2 to next slave */
987 }
988
989 for (i = 0; i < SLAVES; i++) {
990 if (i == slp - &slaves[0]) {
991 caught = 1;
992 } else {
993 caught = 0;
994 }
995
996 if (socketpair(AF_UNIX, SOCK_STREAM, 0, cmd) < 0 ||
997 (slaves[i].pid = fork()) < 0)
998 quit("too many slaves, %d (recompile smaller): %s\n",
999 i, strerror(errno));
1000
1001 slaves[i].fd = cmd[1];
1002 slaves[i].sent = 0;
1003 if (slaves[i].pid == 0) { /* Slave starts up here */
1004 sigset_t sigs;
1005 for (j = 0; j <= i; j++)
1006 (void) close(slaves[j].fd);
1007 sigemptyset(&sigs);
1008 sigaddset(&sigs, SIGINT); /* Master handles this */
1009 #if defined(SIGINFO)
1010 sigaddset(&sigs, SIGINFO);
1011 #endif
1012 sigprocmask(SIG_BLOCK, &sigs, NULL);
1013
1014 #ifdef LINUX_FORK_BUG
1015 if (dump_atomic_write( cmd[0], (char *) &i, sizeof i)
1016 != sizeof i)
1017 quit("master/slave protocol botched 3\n");
1018 #endif
1019 doslave(cmd[0],
1020 #ifdef WRITEDEBUG
1021 i,
1022 #endif
1023 (slaves[i].pid == slp->pid));
1024 Exit(X_FINOK);
1025 }
1026 else
1027 close(cmd[0]);
1028 }
1029
1030 #ifdef LINUX_FORK_BUG
1031 /*
1032 * Wait for all slaves to _actually_ start to circumvent a bug in
1033 * Linux kernels >= 2.1.3 where a signal sent to a child that hasn't
1034 * returned from fork() causes a SEGV in the child process
1035 */
1036 for (i = 0; i < SLAVES; i++)
1037 if (dump_atomic_read( slaves[i].fd, (char *) &j, sizeof j) != sizeof j)
1038 quit("master/slave protocol botched 4\n");
1039 #endif
1040
1041 for (i = 0; i < SLAVES; i++)
1042 (void) dump_atomic_write( slaves[i].fd,
1043 (char *) &slaves[(i + 1) % SLAVES].pid,
1044 sizeof slaves[0].pid);
1045
1046 master = 0;
1047 }
1048
1049 void
1050 killall(void)
1051 {
1052 int i;
1053
1054 for (i = 0; i < SLAVES; i++)
1055 if (slaves[i].pid > 0) {
1056 (void) kill(slaves[i].pid, SIGKILL);
1057 slaves[i].sent = 0;
1058 }
1059 }
1060
1061 /*
1062 * Synchronization - each process waits for a SIGUSR2 from the
1063 * previous process before writing to the tape, and sends SIGUSR2
1064 * to the next process when the tape write completes. On tape errors
1065 * a SIGUSR1 is sent to the master which then terminates all of the
1066 * slaves.
1067 */
1068 static void
1069 doslave(int cmd,
1070 #ifdef WRITEDEBUG
1071 int slave_number,
1072 #endif
1073 int first)
1074 {
1075 int nread;
1076 int nextslave;
1077 volatile int wrote = 0, size, eot_count, bufsize;
1078 char * volatile buffer;
1079 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
1080 struct tapebuf * volatile comp_buf = NULL;
1081 int compresult;
1082 volatile int do_compress = !first;
1083 unsigned long worklen;
1084 #ifdef HAVE_BZLIB
1085 unsigned int worklen2;
1086 #endif
1087 #ifdef HAVE_LZO
1088 lzo_align_t __LZO_MMODEL *LZO_WorkMem;
1089 #endif
1090 #endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
1091 struct slave_results returns;
1092 #ifdef __linux__
1093 errcode_t retval;
1094 #endif
1095 #ifdef USE_QFA
1096 long long curtapepos;
1097 union u_spcl *uspclptr;
1098 struct s_spcl *spclptr;
1099 #endif /* USE_QFA */
1100 sigset_t set;
1101
1102 sigemptyset(&set);
1103 sigaddset(&set, SIGUSR2);
1104 sigprocmask(SIG_BLOCK, &set, NULL);
1105 sigemptyset(&set);
1106
1107 /*
1108 * Need our own seek pointer.
1109 */
1110 (void) close(diskfd);
1111 if ((diskfd = OPEN(disk, O_RDONLY)) < 0)
1112 quit("slave couldn't reopen disk: %s\n", strerror(errno));
1113 #ifdef __linux__
1114 #ifdef BLKFLSBUF
1115 (void)ioctl(diskfd, BLKFLSBUF);
1116 #endif
1117 ext2fs_close(fs);
1118 retval = dump_fs_open(disk, &fs);
1119 if (retval)
1120 quit("slave couldn't reopen disk: %s\n", error_message(retval));
1121 #endif /* __linux__ */
1122
1123 /*
1124 * Need the pid of the next slave in the loop...
1125 */
1126 if ((nread = dump_atomic_read( cmd, (char *)&nextslave, sizeof nextslave))
1127 != sizeof nextslave) {
1128 quit("master/slave protocol botched - didn't get pid of next slave.\n");
1129 }
1130
1131 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
1132 /* if we're doing a compressed dump, allocate the compress buffer */
1133 if (compressed) {
1134 int bsiz = sizeof(struct tapebuf) + writesize;
1135 /* Add extra space to deal with compression enlarging the buffer */
1136 if (TP_BSIZE > writesize/64 + 19)
1137 bsiz += TP_BSIZE;
1138 else
1139 bsiz += writesize/64 + 19;
1140 comp_buf = malloc(bsiz);
1141 if (comp_buf == NULL)
1142 quit("couldn't allocate a compress buffer.\n");
1143 if (zipflag == COMPRESS_ZLIB)
1144 comp_buf->flags = COMPRESS_ZLIB;
1145 else if (zipflag == COMPRESS_BZLIB)
1146 comp_buf->flags = COMPRESS_BZLIB;
1147 else if (zipflag == COMPRESS_LZO) {
1148 comp_buf->flags = COMPRESS_LZO;
1149 if (lzo_init() != LZO_E_OK) quit("lzo_init failed\n");
1150 } else
1151 quit("internal error - unknown compression method: %d\n", zipflag);
1152 }
1153 #ifdef HAVE_LZO
1154 LZO_WorkMem = malloc(LZO1X_1_MEM_COMPRESS);
1155 if (!LZO_WorkMem)
1156 quit("couldn't allocate a compress buffer.\n");
1157 #endif
1158 #endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
1159
1160 /*
1161 * Get list of blocks to dump, read the blocks into tape buffer
1162 */
1163 while ((nread = dump_atomic_read( cmd, (char *)slp->req, reqsiz)) == reqsiz) {
1164 struct req *p = slp->req;
1165
1166 for (trecno = 0; trecno < ntrec;
1167 trecno += p->count, p += p->count) {
1168 if (p->dblk) { /* read a disk block */
1169 bread(p->dblk, slp->tblock[trecno],
1170 p->count * TP_BSIZE);
1171 } else { /* read record from pipe */
1172 if (p->count != 1 || dump_atomic_read( cmd,
1173 (char *)slp->tblock[trecno],
1174 TP_BSIZE) != TP_BSIZE)
1175 quit("master/slave protocol botched.\n");
1176 }
1177 }
1178
1179 /* Try to write the data... */
1180 wrote = 0;
1181 eot_count = 0;
1182 size = 0;
1183 buffer = (char *) slp->tblock[0]; /* set write pointer */
1184 bufsize = writesize; /* length to write */
1185 returns.clen = returns.unclen = bufsize;
1186
1187 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
1188 /*
1189 * When writing a compressed dump, each block except
1190 * the first one on each tape is written
1191 * from struct tapebuf with an 4 byte prefix
1192 * followed by the data. This can be less than
1193 * writesize. Restore, on a short read, can compare the
1194 * length read to the compressed length in the header
1195 * to verify that the read was good. Blocks which don't
1196 * compress well are written uncompressed.
1197 * The first block written by each slave is not compressed
1198 * and does not have a prefix.
1199 */
1200
1201 if (compressed && do_compress) {
1202 comp_buf->length = bufsize;
1203 worklen = TP_BSIZE + writesize;
1204 compresult = 1;
1205 #ifdef HAVE_ZLIB
1206 if (zipflag == COMPRESS_ZLIB) {
1207 compresult = compress2(comp_buf->buf,
1208 &worklen,
1209 (char *)slp->tblock[0],
1210 writesize,
1211 compressed);
1212 if (compresult == Z_OK)
1213 compresult = 1;
1214 else
1215 compresult = 0;
1216 }
1217 #endif /* HAVE_ZLIB */
1218 #ifdef HAVE_BZLIB
1219 if (zipflag == COMPRESS_BZLIB) {
1220 worklen2 = worklen;
1221 compresult = BZ2_bzBuffToBuffCompress(
1222 comp_buf->buf,
1223 &worklen2,
1224 (char *)slp->tblock[0],
1225 writesize,
1226 compressed,
1227 0, 30);
1228 worklen = worklen2;
1229 if (compresult == BZ_OK)
1230 compresult = 1;
1231 else
1232 compresult = 0;
1233 }
1234
1235 #endif /* HAVE_BZLIB */
1236 #ifdef HAVE_LZO
1237 if (zipflag == COMPRESS_LZO) {
1238 compresult = lzo1x_1_compress((char *)slp->tblock[0],writesize,
1239 comp_buf->buf,
1240 (lzo_uintp)&worklen,
1241 LZO_WorkMem);
1242 if (compresult == LZO_E_OK)
1243 compresult = 1;
1244 else
1245 compresult = 0;
1246 }
1247 #endif /* HAVE_LZO */
1248 if (compresult && worklen <= ((unsigned long)writesize - 16)) {
1249 /* write the compressed buffer */
1250 comp_buf->length = worklen;
1251 comp_buf->compressed = 1;
1252 buffer = (char *) comp_buf;
1253 returns.clen = bufsize = worklen + sizeof(struct tapebuf);
1254 }
1255 else {
1256 /* write the data uncompressed */
1257 comp_buf->length = writesize;
1258 comp_buf->compressed = 0;
1259 buffer = (char *) comp_buf;
1260 returns.clen = bufsize = writesize + sizeof(struct tapebuf);
1261 returns.unclen = returns.clen;
1262 memcpy(comp_buf->buf, (char *)slp->tblock[0], writesize);
1263 }
1264 }
1265 /* compress the remaining blocks if we're compressing */
1266 do_compress = compressed;
1267 #endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
1268
1269 if (sigsetjmp(jmpbuf, 1) == 0) {
1270 ready = 1;
1271 if (!caught)
1272 sigsuspend(&set);
1273 }
1274 ready = 0;
1275 caught = 0;
1276
1277 #ifdef USE_QFA
1278 if (gTapeposfd >= 0) {
1279 int i;
1280 int firstpass = 1;
1281 for (i = 0; i < ntrec; ++i) {
1282 uspclptr = (union u_spcl *)&slp->tblock[i];
1283 spclptr = &uspclptr->s_spcl;
1284 if ((spclptr->c_magic == NFS_MAGIC) &&
1285 (spclptr->c_type == TS_INODE) &&
1286 ((spclptr->c_dinode.di_mode & S_IFMT) != IFDIR) &&
1287 (spclptr->c_date == gThisDumpDate)) {
1288 /* if an error occured previously don't
1289 * try again */
1290 if (firstpass) {
1291 firstpass = 0;
1292 if (gtperr == 0)
1293 gtperr = GetTapePos(&curtapepos);
1294 }
1295 if (gtperr == 0)
1296 MkTapeString(spclptr, curtapepos);
1297 }
1298 }
1299 }
1300 #endif /* USE_QFA */
1301
1302 while (eot_count < 10 && size < bufsize) {
1303 #ifdef RDUMP
1304 if (host)
1305 wrote = rmtwrite(buffer + size, bufsize - size);
1306 else
1307 #endif
1308 wrote = write(tapefd, buffer + size, bufsize - size);
1309 #ifdef WRITEDEBUG
1310 printf("slave %d wrote %d\n", slave_number, wrote);
1311 #endif
1312 if (wrote < 0 && errno != ENOSPC)
1313 break;
1314 if (wrote == 0 || (wrote < 0 && errno == ENOSPC))
1315 eot_count++;
1316 else
1317 size += wrote;
1318 }
1319
1320 #ifdef WRITEDEBUG
1321 if (size != bufsize)
1322 printf("slave %d only wrote %d out of %d bytes and gave up.\n",
1323 slave_number, size, bufsize);
1324 #endif
1325
1326 /*
1327 * Handle ENOSPC as an EOT condition.
1328 */
1329 if (wrote < 0 && errno == ENOSPC) {
1330 wrote = 0;
1331 eot_count++;
1332 }
1333
1334 if (eot_count > 0)
1335 returns.clen = returns.unclen = 0;
1336
1337 /*
1338 * pass errno back to master for special handling
1339 */
1340 if (wrote < 0)
1341 returns.unclen = -errno;
1342
1343 /*
1344 * pass size of data and size of write back to master
1345 * (for EOT handling)
1346 */
1347 (void) dump_atomic_write( cmd, (char *)&returns, sizeof returns);
1348
1349 /*
1350 * Signal the next slave to go.
1351 */
1352 (void) kill(nextslave, SIGUSR2);
1353 }
1354 if (nread != 0)
1355 quit("error reading command pipe: %s\n", strerror(errno));
1356 }
1357
1358 /*
1359 * Since a read from a pipe may not return all we asked for,
1360 * or a write may not write all we ask if we get a signal,
1361 * loop until the count is satisfied (or error).
1362 */
1363 static ssize_t
1364 dump_atomic_read(int fd, void *buf, size_t count)
1365 {
1366 int got, need = count;
1367
1368 do {
1369 while ((got = read(fd, buf, need)) > 0 && (need -= got) > 0)
1370 (char *)buf += got;
1371 } while (got == -1 && errno == EINTR);
1372 return (got < 0 ? got : (ssize_t)count - need);
1373 }
1374
1375 /*
1376 * Since a read from a pipe may not return all we asked for,
1377 * or a write may not write all we ask if we get a signal,
1378 * loop until the count is satisfied (or error).
1379 */
1380 static ssize_t
1381 dump_atomic_write(int fd, const void *buf, size_t count)
1382 {
1383 int got, need = count;
1384
1385 do {
1386 while ((got = write(fd, buf, need)) > 0 && (need -= got) > 0)
1387 (char *)buf += got;
1388 } while (got == -1 && errno == EINTR);
1389 return (got < 0 ? got : (ssize_t)count - need);
1390 }
1391
1392
1393 #ifdef USE_QFA
1394 /*
1395 * read the current tape position
1396 */
1397 static int
1398 GetTapePos(long long *pos)
1399 {
1400 int err = 0;
1401
1402 #ifdef RDUMP
1403 if (host) {
1404 *pos = (long long) rmtseek(0, SEEK_CUR);
1405 err = *pos < 0;
1406 }
1407 else
1408 #endif
1409 {
1410 if (magtapeout) {
1411 long mtpos;
1412 *pos = 0;
1413 err = (ioctl(tapefd, MTIOCPOS, &mtpos) < 0);
1414 *pos = (long long)mtpos;
1415 }
1416 else {
1417 *pos = LSEEK(tapefd, 0, SEEK_CUR);
1418 err = (*pos < 0);
1419 }
1420 }
1421 if (err) {
1422 err = errno;
1423 msg("[%ld] error: %d (getting tapepos: %lld)\n", getpid(),
1424 err, *pos);
1425 return err;
1426 }
1427 return err;
1428 }
1429
1430 static void
1431 MkTapeString(struct s_spcl *spclptr, long long curtapepos) {
1432
1433 #ifdef DEBUG_QFA
1434 msg("inode %ld at tapepos %lld\n", spclptr->c_inumber, curtapepos);
1435 #endif
1436
1437 snprintf(gTps, sizeof(gTps), "%ld\t%d\t%lld\n",
1438 (unsigned long)spclptr->c_inumber,
1439 tapeno,
1440 curtapepos);
1441 gTps[sizeof(gTps) - 1] = '\0';
1442 if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps)) {
1443 warn("error writing tapepos file.\n");
1444 }
1445 }
1446 #endif /* USE_QFA */