Lines Matching +full:read +full:- +full:out
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 #define MAXFLT 10 /* default media read error limit */
60 static char *bufpt; /* read/write point in i/o buffer */
64 int rdblksz; /* first read blksize (tapes only) */
67 off_t rdcnt; /* # of bytes read on current vol */
73 * 0 if ok, -1 if the user specified write block size violates pax spec
84 * archive that might be hard to read elsewhere. If all ok, we then in wr_start()
88 wrblksz = frmt->bsz; in wr_start()
92 return(-1); in wr_start()
97 return(-1); in wr_start()
102 return(-1); in wr_start()
110 return(-1); in wr_start()
119 * set up buffering system to read an archive
121 * 0 if ok, -1 otherwise
137 return(-1); in rd_start()
142 return(-1); in rd_start()
150 return(-1); in rd_start()
172 * was just read. The last block(s) of an archive may contain a format
176 * format specific end read function tells us how many bytes to move
180 * stored in the read (soon to become write) buffer. We may have to move
182 * record and the size of the format trailer) to read up the record where
186 * move the OS file offset back to the start of this record and read it
198 * 0 for success, -1 for failure
209 return(-1); in appnd_start()
213 * in the last archive volume read. (If a is set we still use rdblksz in appnd_start()
225 return(-1); in appnd_start()
233 skcnt += bufend - bufpt; in appnd_start()
237 goto out; in appnd_start()
241 * now in front of, read up the block and position the pointer after in appnd_start()
244 if ((cnt -= skcnt) > 0) { in appnd_start()
246 * watch out for stupid tape drives. ar_rev() will set rdblksz in appnd_start()
255 goto out; in appnd_start()
258 if (ar_rev((off_t)(bufpt - buf)) < 0) in appnd_start()
259 goto out; in appnd_start()
270 rdcnt -= skcnt; in appnd_start()
280 return(-1); in appnd_start()
284 out: in appnd_start()
286 return(-1); in appnd_start()
291 * A read error occurred on this archive volume. Resync the buffer and
292 * try to reset the device (if possible) so we can continue to read. Keep
293 * trying to do this until we get a valid read, or we reach the limit on
294 * consecutive read faults (at which point we give up). The user can
295 * adjust the read error limit through a command line option.
297 * 0 on success, and -1 on failure
307 * if the user says bail out on first fault, we are out of here... in rd_sync()
310 return(-1); in rd_sync()
312 paxwarn(1, "Unable to append when there are archive read errors."); in rd_sync()
313 return(-1); in rd_sync()
321 return(-1); in rd_sync()
338 * Oh well, yet another failed read... in rd_sync()
343 * can extract out of the archive. in rd_sync()
346 paxwarn(0,"Archive read error limit (%d) reached",maxflt); in rd_sync()
354 return(-1); in rd_sync()
371 bufpt -= cnt; in pback()
378 * skip forward in the archive during an archive read. Used to get quickly
381 * 0 if ok, -1 failure, and 1 when EOF on the archive volume was detected.
399 res = MIN((bufend - bufpt), skcnt); in rd_skip()
401 skcnt -= res; in rd_skip()
410 * We have to read more, calculate complete and partial record reads in rd_skip()
418 * how much it can skip over. We will have to read the rest. in rd_skip()
421 return(-1); in rd_skip()
422 res += cnt - skipped; in rd_skip()
426 * what is left we have to read (which may be the whole thing if in rd_skip()
427 * ar_fow() told us the device can only read to skip records); in rd_skip()
430 cnt = bufend - bufpt; in rd_skip()
432 * if the read fails, we will have to resync in rd_skip()
435 return(-1); in rd_skip()
440 res -= cnt; in rd_skip()
447 * flush out any data (and pad if required) the last block. We always pad
457 memset(bufpt, 0, bufend - bufpt); in wr_fin()
471 * 0 if buffer was filled ok, -1 o.w. (buffer flush failure)
475 wr_rdbuf(char *out, int outcnt) in wr_rdbuf() argument
484 cnt = bufend - bufpt; in wr_rdbuf()
486 return(-1); in wr_rdbuf()
491 memcpy(bufpt, out, cnt); in wr_rdbuf()
493 out += cnt; in wr_rdbuf()
494 outcnt -= cnt; in wr_rdbuf()
501 * copy from the read buffer into a supplied buffer a specified number of
502 * bytes. If the read buffer is empty fill it and continue to copy.
504 * specific read routine.
507 * -1 is a read error
521 cnt = bufend - bufpt; in rd_wrbuf()
524 * read error, return what we got (or the error if in rd_wrbuf()
529 if ((res = cpcnt - incnt) > 0) in rd_wrbuf()
541 incnt -= cnt; in rd_wrbuf()
555 * 0 if ok, -1 if there was a buf_flush failure
567 cnt = bufend - bufpt; in wr_skip()
569 return(-1); in wr_skip()
573 skcnt -= cnt; in wr_skip()
592 * 0 ok, -1 if archive write failure. a short read of the file returns a
601 off_t size = arcn->sb.st_size; in wr_rdfile()
608 cnt = bufend - bufpt; in wr_rdfile()
611 return(-1); in wr_rdfile()
614 if ((res = read(ifd, bufpt, cnt)) <= 0) in wr_rdfile()
616 size -= res; in wr_rdfile()
622 * or the file read failed. in wr_rdfile()
625 syswarn(1, errno, "Read fault on %s", arcn->org_name); in wr_rdfile()
627 paxwarn(1, "File changed size during read %s", arcn->org_name); in wr_rdfile()
629 syswarn(1, errno, "Failed stat on %s", arcn->org_name); in wr_rdfile()
630 else if (arcn->sb.st_mtime != sb.st_mtime) in wr_rdfile()
632 arcn->org_name); in wr_rdfile()
643 * was due to an archive read, we will catch that when we try to skip. If
653 * 0 ok, -1 if archive read failure. if we cannot write the entire file,
661 off_t size = arcn->sb.st_size; in rd_wrfile()
663 char *fnm = arcn->name; in rd_wrfile()
688 cnt = bufend - bufpt; in rd_wrfile()
690 * if we get a read error, we do not want to skip, as we may in rd_wrfile()
707 while (--cnt >= 0) in rd_wrfile()
711 size -= res; in rd_wrfile()
720 if (isem && (arcn->sb.st_size > 0L)) in rd_wrfile()
724 * if we failed from archive read, we do not want to skip in rd_wrfile()
727 return(-1); in rd_wrfile()
733 if (docrc && (size == 0L) && (arcn->crc != crc)) in rd_wrfile()
734 paxwarn(1,"Actual crc does not match expected crc %s",arcn->name); in rd_wrfile()
740 * copy the contents of one file to another. used during -rw phase of pax
751 char *fnm = arcn->name; in cp_file()
762 if (((off_t)(arcn->sb.st_blocks * BLKMULT)) >= arcn->sb.st_size) in cp_file()
777 * read the source file and copy to destination file until EOF in cp_file()
780 if ((cnt = read(fd1, buf, blksz)) <= 0) in cp_file()
796 arcn->org_name, arcn->name); in cp_file()
797 else if (cpcnt != arcn->sb.st_size) in cp_file()
799 arcn->org_name, arcn->name); in cp_file()
801 syswarn(1, errno, "Failed stat of %s", arcn->org_name); in cp_file()
802 else if (arcn->sb.st_mtime != sb.st_mtime) in cp_file()
804 arcn->org_name, arcn->name); in cp_file()
812 if (!no_hole && isem && (arcn->sb.st_size > 0L)) in cp_file()
819 * fill the read buffer with the next record (or what we can get) from
822 * Number of bytes of data in the read buffer, -1 for read error, and
862 return(-1); in buf_fill()
871 * 0 if all is ok, -1 when a write error occurs.
883 * volume, prompt for the next volume. (The non-standard -R flag). in buf_flush()
892 return(-1); in buf_flush()
898 * write blocksize. if so we figure out if we need to write in buf_flush()
909 push = bufcnt - blksz; in buf_flush()
917 * write a block and check if it all went out ok in buf_flush()
934 push -= blksz; in buf_flush()
950 cnt = bufcnt - cnt; in buf_flush()
953 if (!frmt->blkalgn || ((cnt % frmt->blkalgn) == 0)) in buf_flush()
967 * size. if so, figure out if we have too much or too little in buf_flush()
974 push = bufcnt - blksz; in buf_flush()
981 return(-1); in buf_flush()