summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-05-30 03:38:50 +0000
committermidipix <writeonce@midipix.org>2024-05-30 03:38:50 +0000
commitfa0b0349b3987f37885cccbe8cefb80d404db90a (patch)
tree189e975764ef30469956350606c9ae5dbe70ebf7
parent333924297a38d0d8e0b94bd64a6bbcfd845f4ca7 (diff)
downloadtpax-fa0b0349b3987f37885cccbe8cefb80d404db90a.tar.bz2
tpax-fa0b0349b3987f37885cccbe8cefb80d404db90a.tar.xz
tpax_archive_seal(): reimplemented with correct format-specific semantics.
-rw-r--r--src/logic/tpax_archive_write.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/src/logic/tpax_archive_write.c b/src/logic/tpax_archive_write.c
index b0dad94..2555d26 100644
--- a/src/logic/tpax_archive_write.c
+++ b/src/logic/tpax_archive_write.c
@@ -242,6 +242,12 @@ int tpax_archive_write(const struct tpax_driver_ctx * dctx)
return 0;
}
+static int tpax_archive_seal_cpio(const struct tpax_driver_ctx * dctx)
+{
+ (void)dctx;
+ return -1;
+}
+
int tpax_archive_seal(const struct tpax_driver_ctx * dctx)
{
int fdout;
@@ -249,37 +255,52 @@ int tpax_archive_seal(const struct tpax_driver_ctx * dctx)
ssize_t nbytes;
ssize_t nwritten;
ssize_t blksize;
- char buf[512];
+ char buf[1024];
+ /* archive block size, current position */
blksize = dctx->cctx->blksize;
cpos = tpax_get_driver_cpos(dctx);
+ /* internal error? */
if (cpos % 512)
return TPAX_CUSTOM_ERROR(dctx,TPAX_ERR_FLOW_ERROR);
+ /* cpio trailer? */
+ if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_CPIO)
+ return tpax_archive_seal_cpio(dctx);
+
+ /* ustar, pax */
fdout = tpax_driver_fdout(dctx);
memset(buf,0,sizeof(buf));
- switch (cpos % blksize) {
- case 0:
- nbytes = cpos + blksize;
- break;
+ if (tpax_archive_append_memory_data(fdout,buf,2*512) < 0)
+ return TPAX_SYSTEM_ERROR(dctx);
- default:
- nbytes = cpos / blksize;
- nbytes *= blksize;
- nbytes += blksize;
+ cpos += 2*512;
- if (nbytes-cpos == 512)
- nbytes += blksize;
+ /* pax? */
+ if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_PAX) {
+ tpax_set_driver_cpos(dctx,cpos);
+ return 0;
}
- for (nwritten=cpos; nwritten<nbytes; nwritten+=512) {
+ /* already at block boundary? */
+ if ((cpos % blksize) == 0) {
+ tpax_set_driver_cpos(dctx,cpos);
+ return 0;
+ }
+
+ /* zero-fill the remainder of the block */
+ nbytes = cpos / blksize;
+ nbytes *= blksize;
+ nbytes += blksize;
+
+ for (nwritten=cpos; nwritten<nbytes; nwritten+=512)
if (tpax_archive_append_memory_data(fdout,buf,512) < 0)
return TPAX_SYSTEM_ERROR(dctx);
- tpax_set_driver_cpos(dctx,nwritten);
- }
+ /* all done */
+ tpax_set_driver_cpos(dctx,nwritten);
return 0;
}