]>
git.wh0rd.org - dump.git/blob - dump/tape.c
b0d7fd4b01a74f9011eaacbe6dd46909667c13ce
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 <pop@cybercable.fr>, 1999
9 * Copyright (c) 1980, 1991, 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 const char rcsid
[] =
43 "$Id: tape.c,v 1.6 1999/10/13 09:57:20 stelian Exp $";
47 #include <sys/types.h>
48 #include <linux/types.h>
50 #include <sys/param.h>
51 #include <sys/socket.h>
55 #include <linux/ext2_fs.h>
56 #include <bsdcompat.h>
59 #include <sys/vnode.h>
62 #include <ufs/inode.h>
64 #include <ufs/ufs/dinode.h>
65 #include <ufs/ffs/fs.h>
67 #endif /* __linux__ */
69 #include <protocols/dumprestore.h>
85 #include <ext2fs/ext2fs.h>
89 int writesize
; /* size of malloc()ed buffer for tape */
90 long lastspclrec
= -1; /* tape block number of last written header */
91 int trecno
= 0; /* next record to write in current block */
92 extern long blocksperfile
; /* number of blocks per output file */
93 long blocksthisvol
; /* number of blocks on current output file */
94 extern int ntrec
; /* blocking factor on tape */
99 static ssize_t atomic_read
__P((int, void *, size_t));
100 static ssize_t atomic_write
__P((int, const void *, size_t));
101 static void doslave
__P((int, int));
102 static void enslave
__P((void));
103 static void flushtape
__P((void));
104 static void killall
__P((void));
105 static void rollforward
__P((void));
108 * Concurrent dump mods (Caltech) - disk block reading and tape writing
109 * are exported to several slave processes. While one slave writes the
110 * tape, the others read disk blocks; they pass control of the tape in
111 * a ring via signals. The parent process traverses the filesystem and
112 * sends writeheader()'s and lists of daddr's to the slaves via pipes.
113 * The following structure defines the instruction packets sent to slaves.
121 #define SLAVES 3 /* 1 slave writing, 1 reading, 1 for slack */
123 int tapea
; /* header number at start of this chunk */
124 int count
; /* count to next header (used for TS_TAPE */
126 int inode
; /* inode that we are currently dealing with */
127 int fd
; /* FD for this slave */
128 int pid
; /* PID for this slave */
129 int sent
; /* 1 == we've sent this slave requests */
130 int firstrec
; /* record number of this block */
131 char (*tblock
)[TP_BSIZE
]; /* buffer for data blocks */
132 struct req
*req
; /* buffer for requests */
136 char (*nextblock
)[TP_BSIZE
];
138 static time_t tstart_volume
; /* time of volume start */
139 static int tapea_volume
; /* value of spcl.c_tapea at volume start */
141 int master
; /* pid of master, for sending error signals */
142 int tenths
; /* length of tape used per block written */
143 static int caught
; /* have we caught the signal to proceed? */
144 static int ready
; /* have we reached the lock point without having */
145 /* received the SIGUSR2 signal from the prev slave? */
146 static sigjmp_buf jmpbuf
; /* where to jump to if we are ready when the */
147 /* SIGUSR2 arrives from the previous slave */
152 int pgoff
= getpagesize() - 1;
156 writesize
= ntrec
* TP_BSIZE
;
157 reqsiz
= (ntrec
+ 1) * sizeof(struct req
);
159 * CDC 92181's and 92185's make 0.8" gaps in 1600-bpi start/stop mode
160 * (see DEC TU80 User's Guide). The shorter gaps of 6250-bpi require
161 * repositioning after stopping, i.e, streaming mode, where the gap is
162 * variable, 0.30" to 0.45". The gap is maximal when the tape stops.
164 if (blocksperfile
== 0 && !unlimited
)
165 tenths
= writesize
/ density
+
166 (cartridge
? 16 : density
== 625 ? 5 : 8);
168 * Allocate tape buffer contiguous with the array of instruction
169 * packets, so flushtape() can write them together with one write().
170 * Align tape buffer on page boundary to speed up tape write().
172 for (i
= 0; i
<= SLAVES
; i
++) {
174 malloc((unsigned)(reqsiz
+ writesize
+ pgoff
+ TP_BSIZE
));
177 slaves
[i
].tblock
= (char (*)[TP_BSIZE
])
179 (((long)&buf
[reqsiz
] + pgoff
) &~ pgoff
);
181 (((long)&buf
[ntrec
+ 1] + pgoff
) &~ pgoff
);
183 slaves
[i
].req
= (struct req
*)slaves
[i
].tblock
- ntrec
- 1;
189 nextblock
= slp
->tblock
;
194 writerec(const void *dp
, int isspcl
)
197 slp
->req
[trecno
].dblk
= (daddr_t
)0;
198 slp
->req
[trecno
].count
= 1;
199 /* XXX post increment triggers an egcs-1.1.2-12 bug on alpha/sparc */
200 *(union u_spcl
*)(*(nextblock
)) = *(union u_spcl
*)dp
;
203 lastspclrec
= spcl
.c_tapea
;
211 dumpblock(daddr_t blkno
, int size
)
213 int avail
, tpblks
, dblkno
;
215 dblkno
= fsbtodb(sblock
, blkno
);
216 tpblks
= size
>> tp_bshift
;
217 while ((avail
= MIN(tpblks
, ntrec
- trecno
)) > 0) {
218 slp
->req
[trecno
].dblk
= dblkno
;
219 slp
->req
[trecno
].count
= avail
;
221 spcl
.c_tapea
+= avail
;
224 dblkno
+= avail
<< (tp_bshift
- dev_bshift
);
236 msg("write error on %s\n", tape
);
237 quit("Cannot recover\n");
240 msg("write error %d blocks into volume %d\n", blocksthisvol
, tapeno
);
241 broadcast("DUMP WRITE ERROR!\n");
242 if (!query("Do you want to restart?"))
244 msg("Closing this volume. Prepare to restart with new media;\n");
245 msg("this dump volume will be rewritten.\n");
256 quit("Broken pipe\n");
261 * Update xferrate stats
274 ttaken
= tnow
- tstart_volume
;
275 blocks
= spcl
.c_tapea
- tapea_volume
;
276 msg("Volume %d completed at: %s", tapeno
,
283 msg("Volume %d took %d:%02d:%02d\n", tapeno
,
284 ttaken
/ 3600, (ttaken
% 3600) / 60, ttaken
% 60);
285 msg("Volume %d transfer rate: %ld KB/s\n", tapeno
,
287 xferrate
+= blocks
/ ttaken
;
295 * information message upon receipt of SIGINFO
296 * (derived from optr.c::timeest())
299 statussig(int notused
)
303 int save_errno
= errno
;
305 if (blockswritten
< 500)
310 (void) time((time_t *) &tnow
);
312 deltat
= tstart_writing
- tnow
+ (1.0 * (tnow
- tstart_writing
))
313 / blockswritten
* tapesize
;
314 (void)snprintf(msgbuf
, sizeof(msgbuf
),
315 "%3.2f%% done at %ld KB/s, finished in %d:%02d\n",
316 (blockswritten
* 100.0) / tapesize
,
317 (spcl
.c_tapea
- tapea_volume
) / (tnow
- tstart_volume
),
318 (int)(deltat
/ 3600), (int)((deltat
% 3600) / 60));
319 write(STDERR_FILENO
, msgbuf
, strlen(msgbuf
));
330 int siz
= (char *)nextblock
- (char *)slp
->req
;
332 slp
->req
[trecno
].count
= 0; /* Sentinel */
334 if (atomic_write( slp
->fd
, (char *)slp
->req
, siz
) != siz
)
335 quit("error writing command pipe: %s\n", strerror(errno
));
336 slp
->sent
= 1; /* we sent a request, read the response later */
338 lastfirstrec
= slp
->firstrec
;
340 if (++slp
>= &slaves
[SLAVES
])
343 /* Read results back from next slave */
345 if (atomic_read( slp
->fd
, (char *)&got
, sizeof got
)
347 perror(" DUMP: error reading command pipe in master");
352 /* Check for end of tape */
353 if (got
< writesize
) {
354 msg("End of tape detected\n");
357 * Drain the results, don't care what the values were.
358 * If we read them here then trewind won't...
360 for (i
= 0; i
< SLAVES
; i
++) {
361 if (slaves
[i
].sent
) {
362 if (atomic_read( slaves
[i
].fd
,
363 (char *)&got
, sizeof got
)
365 perror(" DUMP: error reading command pipe in master");
379 if (spcl
.c_type
!= TS_END
) {
380 for (i
= 0; i
< spcl
.c_count
; i
++)
381 if (spcl
.c_addr
[i
] != 0)
384 slp
->count
= lastspclrec
+ blks
+ 1 - spcl
.c_tapea
;
385 slp
->tapea
= spcl
.c_tapea
;
386 slp
->firstrec
= lastfirstrec
+ ntrec
;
388 nextblock
= slp
->tblock
;
391 blockswritten
+= ntrec
;
392 blocksthisvol
+= ntrec
;
393 if (!pipeout
&& !unlimited
&& (blocksperfile
?
394 (blocksthisvol
>= blocksperfile
) : (asize
> tsize
))) {
407 for (f
= 0; f
< SLAVES
; f
++) {
409 * Drain the results, but unlike EOT we DO (or should) care
410 * what the return values were, since if we detect EOT after
411 * we think we've written the last blocks to the tape anyway,
412 * we have to replay those blocks with rollforward.
414 * fixme: punt for now.
416 if (slaves
[f
].sent
) {
417 if (atomic_read( slaves
[f
].fd
, (char *)&got
, sizeof got
)
419 perror(" DUMP: error reading command pipe in master");
423 if (got
!= writesize
) {
424 msg("EOT detected in last 2 tape records!\n");
425 msg("Use a longer tape, decrease the size estimate\n");
426 quit("or use no size estimate at all.\n");
429 (void) close(slaves
[f
].fd
);
431 while (wait((int *)NULL
) >= 0) /* wait for any signals from slaves */
437 msg("Closing %s\n", tape
);
442 while (rmtopen(tape
, 0) < 0)
448 (void) close(tapefd
);
449 while ((f
= open(tape
, 0)) < 0)
462 msg("Change Volumes: Mount volume #%d\n", tapeno
+1);
463 broadcast("CHANGE DUMP VOLUMES!\7\7\n");
465 while (!query("Is the new volume mounted and ready to go?"))
466 if (query("Do you want to abort?")) {
475 register struct req
*p
, *q
, *prev
;
476 register struct slave
*tslp
;
477 int i
, size
, savedtapea
, got
;
478 union u_spcl
*ntb
, *otb
;
483 tslp
= &slaves
[SLAVES
];
484 ntb
= (union u_spcl
*)tslp
->tblock
[1];
487 * Each of the N slaves should have requests that need to
488 * be replayed on the next tape. Use the extra slave buffers
489 * (slaves[SLAVES]) to construct request lists to be sent to
490 * each slave in turn.
492 for (i
= 0; i
< SLAVES
; i
++) {
494 otb
= (union u_spcl
*)slp
->tblock
;
497 * For each request in the current slave, copy it to tslp.
501 for (p
= slp
->req
; p
->count
> 0; p
+= p
->count
) {
504 *ntb
++ = *otb
++; /* copy the datablock also */
509 quit("rollforward: protocol botch");
521 nextblock
= tslp
->tblock
;
522 savedtapea
= spcl
.c_tapea
;
523 spcl
.c_tapea
= slp
->tapea
;
525 spcl
.c_tapea
= savedtapea
;
526 lastspclrec
= savedtapea
- 1;
528 size
= (char *)ntb
- (char *)q
;
529 if (atomic_write( slp
->fd
, (char *)q
, size
) != size
) {
530 perror(" DUMP: error writing command pipe");
535 lastfirstrec
= slp
->firstrec
;
537 if (++slp
>= &slaves
[SLAVES
])
542 if (prev
->dblk
!= 0) {
544 * If the last one was a disk block, make the
545 * first of this one be the last bit of that disk
548 q
->dblk
= prev
->dblk
+
549 prev
->count
* (TP_BSIZE
/ DEV_BSIZE
);
550 ntb
= (union u_spcl
*)tslp
->tblock
;
553 * It wasn't a disk block. Copy the data to its
554 * new location in the buffer.
557 *((union u_spcl
*)tslp
->tblock
) = *ntb
;
558 ntb
= (union u_spcl
*)tslp
->tblock
[1];
562 nextblock
= slp
->tblock
;
565 *(union u_spcl
*)(*(nextblock
)++) = *(union u_spcl
*)tslp
->tblock
;
572 * Clear the first slaves' response. One hopes that it
573 * worked ok, otherwise the tape is much too short!
576 if (atomic_read( slp
->fd
, (char *)&got
, sizeof got
)
578 perror(" DUMP: error reading command pipe in master");
583 if (got
!= writesize
) {
584 quit("EOT detected at start of the tape!\n");
590 if (spcl
.c_type
!= TS_END
) {
591 for (i
= 0; i
< spcl
.c_count
; i
++)
592 if (spcl
.c_addr
[i
] != 0)
596 slp
->firstrec
= lastfirstrec
+ ntrec
;
597 slp
->count
= lastspclrec
+ blks
+ 1 - spcl
.c_tapea
;
600 blockswritten
+= ntrec
;
601 blocksthisvol
+= ntrec
;
606 * We implement taking and restoring checkpoints on the tape level.
607 * When each tape is opened, a new process is created by forking; this
608 * saves all of the necessary context in the parent. The child
609 * continues the dump; the parent waits around, saving the context.
610 * If the child returns X_REWRITE, then it had problems writing that tape;
611 * this causes the parent to fork again, duplicating the context, and
612 * everything continues as if nothing had happened.
615 startnewtape(int top
)
623 void (*interrupt_save
) __P((int signo
));
624 #else /* __linux__ */
626 void (*interrupt_save
)();
628 sig_t interrupt_save
;
630 #endif /* __linux__ */
632 interrupt_save
= signal(SIGINT
, SIG_IGN
);
633 parentpid
= getpid();
634 tapea_volume
= spcl
.c_tapea
;
636 (void)time4(&tstart_volume
);
638 (void)time((&tstart_volume
);
642 (void)signal(SIGINT
, interrupt_save
);
644 * All signals are inherited...
648 msg("Context save fork fails in parent %d\n", parentpid
);
654 * save the context by waiting
655 * until the child doing all of the work returns.
656 * don't catch the interrupt
658 signal(SIGINT
, SIG_IGN
);
660 msg("Tape: %d; parent process: %d child process %d\n",
661 tapeno
+1, parentpid
, childpid
);
663 while ((waitpid
= wait(&status
)) != childpid
)
664 msg("Parent %d waiting for child %d has another child %d return\n",
665 parentpid
, childpid
, waitpid
);
667 msg("Child %d returns LOB status %o\n",
668 childpid
, status
&0xFF);
670 status
= (status
>> 8) & 0xFF;
674 msg("Child %d finishes X_FINOK\n", childpid
);
677 msg("Child %d finishes X_ABORT\n", childpid
);
680 msg("Child %d finishes X_REWRITE\n", childpid
);
683 msg("Child %d finishes unknown %d\n",
694 goto restore_check_point
;
696 msg("Bad return code from dump: %d\n", status
);
700 } else { /* we are the child; just continue */
702 sleep(4); /* allow time for parent's message to get out */
703 msg("Child on Tape %d has parent %d, my pid = %d\n",
704 tapeno
+1, parentpid
, getpid());
707 * If we have a name like "/dev/rmt0,/dev/rmt1",
708 * use the name before the comma first, and save
709 * the remaining names for subsequent volumes.
711 tapeno
++; /* current tape sequence */
712 if (nexttape
|| strchr(tape
, ',')) {
713 if (nexttape
&& *nexttape
)
715 if ((p
= strchr(tape
, ',')) != NULL
) {
720 msg("Dumping volume %d on %s\n", tapeno
, tape
);
723 while ((tapefd
= (host
? rmtopen(tape
, 2) :
724 pipeout
? 1 : open(tape
, O_WRONLY
|O_CREAT
, 0666))) < 0)
726 while ((tapefd
= (pipeout
? 1 :
727 open(tape
, O_WRONLY
|O_CREAT
, 0666))) < 0)
730 msg("Cannot open output \"%s\".\n", tape
);
731 if (!query("Do you want to retry the open?"))
735 enslave(); /* Share open tape file descriptor with slaves */
740 newtape
++; /* new tape signal */
741 spcl
.c_count
= slp
->count
;
743 * measure firstrec in TP_BSIZE units since restore doesn't
744 * know the correct ntrec value...
746 spcl
.c_firstrec
= slp
->firstrec
;
748 spcl
.c_type
= TS_TAPE
;
749 spcl
.c_flags
|= DR_NEWHEADER
;
750 writeheader((ino_t
)slp
->inode
);
751 spcl
.c_flags
&=~ DR_NEWHEADER
;
752 msg("Volume %d started at: %s", tapeno
,
754 ctime4(&tstart_volume
));
756 ctime(&tstart_volume
));
759 msg("Volume %d begins with blocks from inode %d\n",
768 if (master
!= 0 && master
!= getpid())
769 /* Signals master to call dumpabort */
770 (void) kill(master
, SIGTERM
);
773 msg("The ENTIRE dump is aborted.\n");
786 msg("pid = %d exits with status %d\n", getpid(), status
);
792 * proceed - handler for SIGUSR2, used to synchronize IO between the slaves.
799 siglongjmp(jmpbuf
, 1);
807 #ifdef LINUX_FORK_BUG
815 signal(SIGTERM
, dumpabort
); /* Slave sends SIGTERM on dumpabort() */
816 signal(SIGPIPE
, sigpipe
);
817 signal(SIGUSR1
, tperror
); /* Slave sends SIGUSR1 on tape errors */
818 signal(SIGUSR2
, proceed
); /* Slave sends SIGUSR2 to next slave */
820 for (i
= 0; i
< SLAVES
; i
++) {
821 if (i
== slp
- &slaves
[0]) {
827 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, cmd
) < 0 ||
828 (slaves
[i
].pid
= fork()) < 0)
829 quit("too many slaves, %d (recompile smaller): %s\n",
832 slaves
[i
].fd
= cmd
[1];
834 if (slaves
[i
].pid
== 0) { /* Slave starts up here */
835 for (j
= 0; j
<= i
; j
++)
836 (void) close(slaves
[j
].fd
);
837 signal(SIGINT
, SIG_IGN
); /* Master handles this */
839 signal(SIGINFO
, SIG_IGN
);
842 #ifdef LINUX_FORK_BUG
843 if (atomic_write( cmd
[0], (char *) &i
, sizeof i
)
845 quit("master/slave protocol botched 3\n");
852 #ifdef LINUX_FORK_BUG
854 * Wait for all slaves to _actually_ start to circumvent a bug in
855 * Linux kernels >= 2.1.3 where a signal sent to a child that hasn't
856 * returned from fork() causes a SEGV in the child process
858 for (i
= 0; i
< SLAVES
; i
++)
859 if (atomic_read( slaves
[i
].fd
, (char *) &j
, sizeof j
) != sizeof j
)
860 quit("master/slave protocol botched 4\n");
863 for (i
= 0; i
< SLAVES
; i
++)
864 (void) atomic_write( slaves
[i
].fd
,
865 (char *) &slaves
[(i
+ 1) % SLAVES
].pid
,
866 sizeof slaves
[0].pid
);
876 for (i
= 0; i
< SLAVES
; i
++)
877 if (slaves
[i
].pid
> 0) {
878 (void) kill(slaves
[i
].pid
, SIGKILL
);
884 * Synchronization - each process has a lockfile, and shares file
885 * descriptors to the following process's lockfile. When our write
886 * completes, we release our lock on the following process's lock-
887 * file, allowing the following process to lock it and proceed. We
888 * get the lock back for the next cycle by swapping descriptors.
891 doslave(int cmd
, int slave_number
)
894 int nextslave
, size
, eot_count
;
895 volatile int wrote
= 0;
902 * Need our own seek pointer.
904 (void) close(diskfd
);
905 if ((diskfd
= open(disk
, O_RDONLY
)) < 0)
906 quit("slave couldn't reopen disk: %s\n", strerror(errno
));
909 retval
= ext2fs_open(disk
, 0, 0, 0, unix_io_manager
, &fs
);
911 quit("slave couldn't reopen disk: %s\n", strerror(errno
));
912 #endif /* __linux__ */
915 * Need the pid of the next slave in the loop...
917 if ((nread
= atomic_read( cmd
, (char *)&nextslave
, sizeof nextslave
))
918 != sizeof nextslave
) {
919 quit("master/slave protocol botched - didn't get pid of next slave.\n");
923 * Get list of blocks to dump, read the blocks into tape buffer
925 while ((nread
= atomic_read( cmd
, (char *)slp
->req
, reqsiz
)) == reqsiz
) {
926 register struct req
*p
= slp
->req
;
928 for (trecno
= 0; trecno
< ntrec
;
929 trecno
+= p
->count
, p
+= p
->count
) {
931 bread(p
->dblk
, slp
->tblock
[trecno
],
932 p
->count
* TP_BSIZE
);
934 if (p
->count
!= 1 || atomic_read( cmd
,
935 (char *)slp
->tblock
[trecno
],
936 TP_BSIZE
) != TP_BSIZE
)
937 quit("master/slave protocol botched.\n");
940 if (setjmp(jmpbuf
) == 0) {
948 /* Try to write the data... */
953 while (eot_count
< 10 && size
< writesize
) {
956 wrote
= rmtwrite(slp
->tblock
[0]+size
,
960 wrote
= write(tapefd
, slp
->tblock
[0]+size
,
963 printf("slave %d wrote %d\n", slave_number
, wrote
);
973 if (size
!= writesize
)
974 printf("slave %d only wrote %d out of %d bytes and gave up.\n",
975 slave_number
, size
, writesize
);
979 * Handle ENOSPC as an EOT condition.
981 if (wrote
< 0 && errno
== ENOSPC
) {
990 (void) kill(master
, SIGUSR1
);
991 sigemptyset(&sigset
);
996 * pass size of write back to master
999 (void) atomic_write( cmd
, (char *)&size
, sizeof size
);
1003 * If partial write, don't want next slave to go.
1004 * Also jolts him awake.
1006 (void) kill(nextslave
, SIGUSR2
);
1009 quit("error reading command pipe: %s\n", strerror(errno
));
1013 * Since a read from a pipe may not return all we asked for,
1014 * or a write may not write all we ask if we get a signal,
1015 * loop until the count is satisfied (or error).
1018 atomic_read(int fd
, void *buf
, size_t count
)
1020 int got
, need
= count
;
1022 while ((got
= read(fd
, buf
, need
)) > 0 && (need
-= got
) > 0)
1024 return (got
< 0 ? got
: count
- need
);
1028 * Since a read from a pipe may not return all we asked for,
1029 * or a write may not write all we ask if we get a signal,
1030 * loop until the count is satisfied (or error).
1033 atomic_write(int fd
, const void *buf
, size_t count
)
1035 int got
, need
= count
;
1037 while ((got
= write(fd
, buf
, need
)) > 0 && (need
-= got
) > 0)
1039 return (got
< 0 ? got
: count
- need
);