Lines Matching refs:ap

38 getprologue(register Archive_t* ap)
41 register File_t* f = &ap->file;
47 message((-6, "getprologue() volume=%d eof=%d", ap->volume, ap->io->eof));
48 if (ap->io->eof || state.volume && (ap->io->mode & O_ACCMODE) == O_WRONLY)
51 ap->entry = 0;
52 ap->format = 0;
53 ap->swapio = 0;
54 ap->io->offset += ap->io->count;
55 ap->io->count = 0;
56 ap->section = SECTION_CONTROL;
57 convert(ap, SECTION_CONTROL, CC_NATIVE, CC_NATIVE);
58 ap->sum++;
62 ap->checkdelta = !ap->delta || ap->delta->format && !(ap->delta->format->flags & PSEUDO);
68 bsave(ap);
74 if ((n = bread(ap, (char*)buf, (off_t)0, (off_t)sizeof(buf), 0)) <= MINID && !bcount(ap))
76 if (n && ap->volume <= 0)
80 bunread(ap, buf, n);
84 if (ap->volume <= 0 && !ap->compress)
88 if ((fp->flags & COMPRESS) && (*fp->getprologue)(&state, fp, ap, f, buf, sizeof(buf)) > 0)
96 ap->compress = fp;
98 if (bseek(ap, (off_t)0, SEEK_SET, 1))
99 error(3, "%s: %s input must be seekable", ap->name, ap->compress->name);
100 undoable(ap, ap->compress);
101 if (state.meter.on && ap == state.in && ap->uncompressed)
102 state.meter.size = ap->uncompressed;
106 ops[0] = PROC_FD_DUP(ap->io->fd, 0, PROC_FD_PARENT|PROC_FD_CHILD);
107 if (ap->parent && !state.ordered)
110 error(ERROR_SYSTEM|3, "%s: cannot create %s base temporary file %s", ap->name, cp->undo[0], state.tmp.file);
121 error(3, "%s: cannot execute %s filter", ap->name, cp->undo[0]);
122 if (ap->parent && !state.ordered)
125 error(3, "%s: %s filter exit code %d", ap->name, cp->undo[0], n);
126 if ((ap->io->fd = open(state.tmp.file, O_RDONLY|O_BINARY)) < 0)
127 error(ERROR_SYSTEM|3, "%s: cannot read %s base temporary file %s", ap->name, cp->undo[0], state.tmp.file);
129 error(ERROR_SYSTEM|1, "%s: cannot remove %s base temporary file %s", ap->name, cp->undo[0], state.tmp.file);
135 ap->io->fd = proc->rfd;
142 if ((n = bread(ap, (char*)buf, (off_t)0, (off_t)sizeof(buf), 0)) <= MINID && !bcount(ap))
144 bunread(ap, buf, n);
153 if (!(fp = ap->expected))
156 ap->entry = 1;
164 convert(ap, SECTION_CONTROL, (fp->flags & CONV) ? CC_NATIVE : CC_ASCII, CC_NATIVE);
165 if ((n = (*fp->getprologue)(&state, fp, ap, f, ((fp->flags & CONV) || CC_NATIVE == CC_ASCII) ? buf : cvt, sizeof(buf))) < 0)
169 if (ap->data)
172 ap->data = 0;
174 ap->checksum = ap->old.checksum = ap->memsum = ap->old.memsum = 0;
178 convert(ap, SECTION_CONTROL, CC_NATIVE, CC_NATIVE);
179 if (!state.keepgoing || ap->io->eof || bread(ap, buf, (off_t)0, (off_t)1, 0) < 1)
182 if (ap->expected)
183 error(3, "%s: unknown input format -- %s expected", ap->name, ap->expected->name);
184 if (ap->volume)
186 error(1, "%s: junk data after volume %d", ap->name, ap->volume);
189 error(3, "%s: unknown input format", ap->name);
193 ap->entry = 0;
195 error(1, "%s: %I*d byte%s skipped before identifying %s format archive", ap->name, sizeof(skipped), skipped, skipped == 1 ? "" : "s", fp->name);
197 else if (!(fp->flags & ARCHIVE) || !fp->getprologue || (*fp->getprologue)(&state, fp, ap, f, buf, sizeof(buf)) <= 0)
198 error(3, "%s: %s: archive format mismatch", ap->name, fp->name);
199 if (!ap->format)
200 ap->format = fp;
201 if (!ap->type)
202 ap->type = ap->format->name;
203 message((-1, "%s format", ap->type));
204 if ((state.operation & IN) && !state.list && !(ap->format->flags & IN))
205 error(3, "%s: %s read not implemented", ap->name, ap->type);
206 if ((state.operation & OUT) && !(ap->format->flags & OUT))
207 error(3, "%s: %s write not implemented", ap->name, ap->type);
208 ap->flags = state.operation | (ap->format->flags & ~(IN|OUT));
209 ap->sum--;
210 ap->volume++;
211 if (ap->peek && (ap->checkdelta || ap->delta) && deltacheck(ap, f))
212 ap->peek = 0;
213 if (state.summary && state.verbose && ap->volume > 0)
215 if (ap->io->blok)
217 if (ap->parent)
218 sfprintf(sfstderr, "%s base %s", ap->parent->name, ap->name);
221 sfprintf(sfstderr, "%s", ap->name);
222 if (ap->volume > 1)
223 sfprintf(sfstderr, " volume %d", ap->volume);
228 if (ap->package)
229 sfprintf(sfstderr, " %s", ap->package);
230 if (ap->compress)
231 sfprintf(sfstderr, " %s", ap->compress->name);
232 if (ap->delta && ap->delta->format)
233 sfprintf(sfstderr, " %s", ap->delta->format->name);
234 sfprintf(sfstderr, " %s format", ap->type);
235 if (ap->swapio)
236 sfprintf(sfstderr, " %s swapped", "unix\0nuxi\0ixun\0xinu" + 5 * ap->swapio);
239 if (ap->volume > 1)
241 if (ap->delta)
243 if (state.operation == (IN|OUT) || !(ap->delta->format->flags & DELTA))
244 error(3, "%s: %s archive cannot be multi-volume", ap->name, ap->parent ? "base" : "delta");
245 ap->delta = 0;
264 setinfo(register Archive_t* ap, register File_t* f)
268 if (ap->delta && ap->delta->format)
270 if (ap->delta->format->variant != DELTA_IGNORE && ap->entry > 1 && f->st->st_mtime)
272 if ((n = f->st->st_mtime - ap->delta->index) < 0)
273 error(3, "%s: corrupt archive: %d extra file%s", ap->name, -n, n == -1 ? "" : "s");
275 error(3, "%s: corrupt archive: %d missing file%s", ap->name, n, n == 1 ? "" : "s");
277 ap->delta->epilogue = 1;
286 putinfo(register Archive_t* ap, char* file, unsigned long mtime, unsigned long checksum)
288 register File_t* f = &ap->file;
296 if (!ap->delta || ap->delta->format->variant == DELTA_88)
300 sfprintf(np, "%c%s%c%c%c%s", INFO_SEP, ID, INFO_SEP, ap->delta->compress ? TYPE_COMPRESS : TYPE_DELTA, INFO_SEP, (dp = (Delta_format_t*)ap->delta->format->data) ? dp->variant : "");
308 initfile(ap, f, f->st, file, X_IFREG);
313 if (putheader(ap, f))
314 puttrailer(ap, f);
324 putprologue(register Archive_t* ap, int append)
327 ap->section = SECTION_CONTROL;
328 if (ap->delta && ap->delta->format->variant == DELTA_88)
329 ap->checksum = ap->old.checksum;
330 if (!(ap->format->flags & CONV))
332 convert(ap, SECTION_CONTROL, CC_NATIVE, CC_ASCII);
333 if (!ap->convert[0].on)
334 convert(ap, SECTION_DATA, CC_NATIVE, CC_NATIVE);
336 if ((!ap->format->putprologue || (*ap->format->putprologue)(&state, ap, append) >= 0) && !(ap->format->flags & DELTAINFO) && ap->delta && !(ap->delta->format->flags & PSEUDO))
338 if (ap->delta->base)
339 putinfo(ap, NiL, ap->delta->base->size, ap->delta->base->checksum);
341 putinfo(ap, NiL, 0, 0);
350 getepilogue(register Archive_t* ap)
360 ap->section = SECTION_CONTROL;
361 state.updated = ap->updated;
362 if (ap->delta && ap->delta->epilogue < 0)
363 error(3, "%s: corrupt archive: missing epilogue", ap->name);
364 if (state.append || state.update && (ap->io->mode & O_RDWR))
366 backup(ap);
369 if (!ap->format->getepilogue || !(*ap->format->getepilogue)(&state, ap))
377 if (ap->io->keep)
379 bskip(ap);
380 if (ap->io->eof)
381 ap->io->keep = 0;
382 else if (ap->io->keep > 0)
383 ap->io->keep--;
389 if (!(n = roundof(ap->io->count, BLOCKSIZE) - ap->io->count) || bread(ap, buf, (off_t)0, (off_t)n, 0) > 0)
400 if (!x && ap->format->event && (ap->format->events & PAX_EVENT_SKIP_JUNK))
402 if ((*ap->format->event)(&state, ap, NiL, buf, PAX_EVENT_SKIP_JUNK) > 0)
405 error(1, "%s: %d junk block%s after volume %d", ap->name, i, i == 1 ? "" : "s", ap->volume);
407 bunread(ap, buf, BLOCKSIZE);
410 if (ap->volume > 1)
411 error(1, "junk data after volume %d", ap->volume);
416 } while (bread(ap, buf, (off_t)0, n, 0) > 0);
417 bflushin(ap, 0);
420 if (ap->format->done)
421 (*ap->format->done)(&state, ap);
422 ap->swapio = 0;
431 putepilogue(register Archive_t* ap)
459 ap->section = SECTION_CONTROL;
460 if (ap->selected > state.selected)
462 state.selected = ap->selected;
463 if (ap->delta && (ap->delta->format->flags & DELTA))
465 if (ap->format->event && (ap->format->events & PAX_EVENT_DELTA_EXTEND))
466 (*ap->format->event)(&state, ap, NiL, NiL, PAX_EVENT_DELTA_EXTEND);
468 putinfo(ap, NiL, ap->delta->index + 1, 0);
470 if (!ap->format->putepilogue || (boundary = (*ap->format->putepilogue)(&state, ap)) <= 0)
471 boundary = ap->io->count;
472 if (n = ((ap->io->count > boundary) ? roundof(ap->io->count, boundary) : boundary) - ap->io->count)
475 bwrite(ap, state.tmp.buffer, n);
477 bflushout(ap);
478 ap->volume++;
482 ap->io->count = ap->io->offset = 0;
483 ap->io->next = ap->io->buffer + ap->io->unread;
485 if (ap->format->done)
486 (*ap->format->done)(&state, ap);
494 getkeyid(Archive_t* ap, File_t* f, int index, uid_t* ip, int d)
501 if (op->entry == ap->entry)
515 getkeyname(Archive_t* ap, File_t* f, int index, char** sp, uid_t* ip, int d)
522 if (op->entry == ap->entry)
539 getkeysize(Archive_t* ap, File_t* f, int index, off_t* zp)
547 if (op->entry == ap->entry)
565 getkeytime(Archive_t* ap, File_t* f, int index)
573 message((-5, "getkeytime %s level=%d entry=%d:%d", op->name, op->level, op->entry, ap->entry));
576 if (op->entry == ap->entry)
613 getheader(register Archive_t* ap, register File_t* f)
619 ap->section = SECTION_CONTROL;
620 ap->sum++;
621 ap->entry++;
623 bsave(ap);
624 if (!ap->peek)
633 if (ap->peek)
634 ap->peek = 0;
644 if ((*ap->format->getheader)(&state, ap, f) <= 0)
646 ap->entry--;
651 error(3, "%s: %s format entry %d.%d name not set", ap->name, ap->type, ap->volume, ap->entry);
652 } while ((ap->checkdelta || ap->delta) && deltacheck(ap, f));
653 ap->entries++;
654 getkeysize(ap, f, OPT_size, &f->st->st_size);
655 getkeytime(ap, f, OPT_mtime);
656 getkeytime(ap, f, OPT_atime);
657 getkeytime(ap, f, OPT_ctime);
658 getkeyid(ap, f, OPT_gid, &f->st->st_gid, state.gid);
659 getkeyname(ap, f, OPT_gname, &f->gidname, &f->st->st_gid, state.gid);
660 getkeyname(ap, f, OPT_path, &f->name, NiL, 0);
661 getkeyname(ap, f, OPT_linkpath, &f->linkpath, NiL, 0);
662 getkeyid(ap, f, OPT_uid, &f->st->st_uid, state.uid);
663 getkeyname(ap, f, OPT_uname, &f->uidname, &f->st->st_uid, state.uid);
666 if (f->name != ap->stash.head.string)
667 f->name = stash(&ap->stash.head, f->name, 0);
668 if (ap->flags & DOS)
675 if ((ap->format->flags & SLASHDIR) && f->type == X_IFREG)
682 f->path = stash(&ap->path.name, f->name, 0);
683 f->name = map(ap, f->name);
689 f->linkpath = map(ap, f->linkpath);
696 getdeltaheader(ap, f);
705 message((-1, "archive=%s path=%s name=%s entry=%d.%d size=%I*u uncompressed=%I*u delta=%c%s", ap->name, f->path, f->name, ap->volume, ap->entry, sizeof(f->st->st_size), f->st->st_size, sizeof(f->uncompressed), f->uncompressed, f->delta.op ? f->delta.op : DELTA_nop, s));
708 if (ap->sum > 0)
710 if (ap->format->flags & SUM)
711 ap->memsum = FNV_INIT;
712 else if (!ap->delta || !ap->delta->trailer)
713 ap->memsum = 0;
714 ap->old.memsum = 0;
716 ap->section = SECTION_DATA;
717 ap->convert[ap->section].on = ap->convert[ap->section].f2t != 0;
726 putheader(register Archive_t* ap, register File_t* f)
733 setdeltaheader(ap, f);
734 ap->entry++;
735 ap->entries++;
737 ap->section = SECTION_CONTROL;
738 if ((n = (*ap->format->putheader)(&state, ap, f)) < 0)
742 if (!ap->incomplete)
744 ap->incomplete = 0;
745 if ((ap->io->count + f->st->st_size) > state.maxout)
751 putepilogue(ap);
752 newio(ap, 0, 0);
753 putprologue(ap, 0);
755 if ((n = (*ap->format->putheader)(&state, ap, f)) <= 0)
758 putdeltaheader(ap, f);
761 ap->section = SECTION_DATA;
762 ap->convert[ap->section].on = ap->convert[ap->section].f2t != 0;
787 gettrailer(register Archive_t* ap, File_t* f)
793 ap->section = SECTION_CONTROL;
794 if (ap->sum-- > 0)
796 ap->checksum ^= ap->memsum;
797 ap->old.checksum ^= ap->old.memsum;
799 if (ap->format->gettrailer)
800 (*ap->format->gettrailer)(&state, ap, f);
801 getdeltatrailer(ap, f);
802 if ((n = ap->format->align) && (n = roundof(ap->io->count, n) - ap->io->count))
803 bread(ap, state.tmp.buffer, (off_t)0, n, 1);
804 if (!(ap->format->flags & SUM) && ap->sum >= 0)
806 ap->memsum = 0;
807 ap->old.memsum = 0;
816 puttrailer(register Archive_t* ap, register File_t* f)
844 ap->section = SECTION_CONTROL;
845 putdeltatrailer(ap, f);
846 if (ap->format->puttrailer)
847 (*ap->format->puttrailer)(&state, ap, f);
848 if ((n = ap->format->align) && (n = roundof(ap->io->count, n) - ap->io->count))
851 bwrite(ap, state.tmp.buffer, n);