Lines Matching +full:write +full:- +full:1

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
14 * 1. Redistributions of source code must retain the above copyright
60 static char *bufpt; /* read/write point in i/o buffer */
71 * set up the buffering system to operate in a write mode
73 * 0 if ok, -1 if the user specified write block size violates pax spec
81 * Check to make sure the write block size meets pax specs. If the user in wr_start()
88 wrblksz = frmt->bsz; in wr_start()
90 paxwarn(1, "Write block size of %d too large, maximum is: %d", in wr_start()
92 return(-1); in wr_start()
95 paxwarn(1, "Write block size of %d is not a %d byte multiple", in wr_start()
97 return(-1); in wr_start()
100 paxwarn(0, "Write block size of %d larger than POSIX max %d, archive may not be portable", in wr_start()
102 return(-1); in wr_start()
110 return(-1); in wr_start()
121 * 0 if ok, -1 otherwise
129 * going to append and user specified a write block size, check it in rd_start()
135 paxwarn(1,"Write block size %d too large, maximum is: %d", in rd_start()
137 return(-1); in rd_start()
140 paxwarn(1, "Write block size %d is not a %d byte multiple", in rd_start()
142 return(-1); in rd_start()
150 return(-1); in rd_start()
179 * position of the tape head) and the write point within the data we have
180 * stored in the read (soon to become write) buffer. We may have to move
187 * up. We set the buffer write pointer to be at this byte (the byte where
193 * about the conditions under which they will allow a write to occur.
198 * 0 for success, -1 for failure
209 return(-1); in appnd_start()
212 * if the user did not specify a write blocksize, inherit the size used in appnd_start()
225 return(-1); in appnd_start()
233 skcnt += bufend - bufpt; in appnd_start()
244 if ((cnt -= skcnt) > 0) { in appnd_start()
258 if (ar_rev((off_t)(bufpt - buf)) < 0) in appnd_start()
270 rdcnt -= skcnt; in appnd_start()
274 * At this point we are ready to write. If the device requires special in appnd_start()
275 * handling to write at a point were previously recorded data resides, in appnd_start()
277 * ARCHIVE mode (write) conditions in appnd_start()
280 return(-1); in appnd_start()
285 paxwarn(1, "Unable to rewrite archive trailer, cannot append."); in appnd_start()
286 return(-1); in appnd_start()
297 * 0 on success, and -1 on failure
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()
354 return(-1); in rd_sync()
371 bufpt -= cnt; in pback()
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()
421 return(-1); in rd_skip()
422 res += cnt - skipped; in rd_skip()
430 cnt = bufend - bufpt; in rd_skip()
435 return(-1); in rd_skip()
437 return(1); in rd_skip()
440 res -= cnt; in rd_skip()
457 memset(bufpt, 0, bufend - bufpt); in wr_fin()
465 * fill the write buffer from data passed to it in a buffer (usually used
466 * by format specific write routines to pass a file header). On failure we
467 * punt. We do not allow the user to continue to write flawed archives.
471 * 0 if buffer was filled ok, -1 o.w. (buffer flush failure)
480 * while there is data to copy into the write buffer. when the in wr_rdbuf()
481 * write buffer fills, flush it to the archive and continue in wr_rdbuf()
484 cnt = bufend - bufpt; in wr_rdbuf()
486 return(-1); in wr_rdbuf()
494 outcnt -= cnt; in wr_rdbuf()
507 * -1 is a read error
521 cnt = bufend - bufpt; in rd_wrbuf()
529 if ((res = cpcnt - incnt) > 0) in rd_wrbuf()
541 incnt -= cnt; in rd_wrbuf()
549 * skip forward during a write. In other words add padding to the file.
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()
580 * fill write buffer with the contents of a file. We are passed an open
583 * number of bytes of the file we were NOT able to write to the archive.
584 * it is important that we always write EXACTLY the number of bytes that
585 * the format specific write routine told us to. The file can also get
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()
605 * while there are more bytes to write in wr_rdfile()
608 cnt = bufend - bufpt; in wr_rdfile()
611 return(-1); in wr_rdfile()
616 size -= res; 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()
631 paxwarn(1, "File %s was modified during copy to archive", in wr_rdfile()
632 arcn->org_name); in wr_rdfile()
640 * extract the entire file (due to failure to write the file) we return
647 * We call a special function to write the file. This function attempts to
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()
664 int isem = 1; in rd_wrfile()
671 * pass the blocksize of the file being written to the write routine, in rd_wrfile()
688 cnt = bufend - bufpt; in rd_wrfile()
691 * miss a header, so we do not set left, but if we get a write 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()
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
741 * just as in rd_wrfile() we use a special write function to write the
751 char *fnm = arcn->name; in cp_file()
753 int isem = 1; in cp_file()
760 * write instead of file write. in cp_file()
762 if (((off_t)(arcn->sb.st_blocks * BLKMULT)) >= arcn->sb.st_size) in cp_file()
766 * pass the blocksize of the file being written to the write routine, in cp_file()
783 res = write(fd2, buf, cnt); in cp_file()
795 syswarn(1, errno, "Failed write during copy of %s to %s", in cp_file()
796 arcn->org_name, arcn->name); in cp_file()
797 else if (cpcnt != arcn->sb.st_size) in cp_file()
798 paxwarn(1, "File %s changed size during copy to %s", 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()
803 paxwarn(1, "File %s was modified during copy to %s", 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()
822 * Number of bytes of data in the read buffer, -1 for read error, and
856 fini = 1; in buf_fill()
861 exit_val = 1; in buf_fill()
862 return(-1); in buf_fill()
867 * force the write buffer to the archive. We are passed the number of
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()
884 * NOTE: If the wrlimit is smaller than wrcnt, we will always write in buf_flush()
891 exit_val = 1; 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()
913 * We have enough data to write at least one archive block in buf_flush()
917 * write a block and check if it all went out ok in buf_flush()
922 * the write went ok in buf_flush()
928 * check for more than 1 block of push, and if in buf_flush()
929 * so we loop back to write again in buf_flush()
934 push -= blksz; in buf_flush()
942 * Oh drat we got a partial write! in buf_flush()
950 cnt = bufcnt - cnt; in buf_flush()
953 if (!frmt->blkalgn || ((cnt % frmt->blkalgn) == 0)) in buf_flush()
974 push = bufcnt - blksz; in buf_flush()
978 * write failed, stop pax. we must not create a bad archive! in buf_flush()
980 exit_val = 1; in buf_flush()
981 return(-1); in buf_flush()