|
|
1.1 ! root 1: // ! 2: // In this file are routines to perform operations on archive files. ! 3: // They do this by determining the type of the archive and calling a ! 4: // corresponding type-specific routine. ! 5: // ! 6: ! 7: #include <stdlib.h> ! 8: #include <stdio.h> ! 9: #include <tar.h> ! 10: #include <string.h> ! 11: #include "buf.h" ! 12: #include "psxarc.h" ! 13: #include "tarhead.h" ! 14: #include "cpio.h" ! 15: #include "links.h" ! 16: ! 17: // ! 18: // These should be in an include file. ! 19: // ! 20: ! 21: extern void CpioList(), CpioRead(), CpioWrite(); ! 22: extern void TarList(), TarRead(), TarWrite(); ! 23: extern void cpio_itoa(); ! 24: ! 25: void ! 26: ListArchive(PBUF pb) ! 27: { ! 28: PCPIO_HEAD cp; ! 29: PTAR_HEAD tp; ! 30: ! 31: InitLinkList(); ! 32: ! 33: bfill(pb); ! 34: cp = (PCPIO_HEAD)pb->data; ! 35: ! 36: if (0 == strncmp(cp->c_magic, MAGIC, strlen(MAGIC))) { ! 37: CpioList(pb); ! 38: return; ! 39: } ! 40: ! 41: tp = (PTAR_HEAD)pb->data; ! 42: ! 43: if (0 == strncmp(tp->s.magic, TMAGIC, strlen(TMAGIC))) { ! 44: TarList(pb); ! 45: return; ! 46: } ! 47: fprintf(stderr, "%s: unknown archive type\n", progname); ! 48: exit(4); ! 49: } ! 50: ! 51: void ! 52: WriteArchive(PBUF pb, int format, char **files, int count) ! 53: { ! 54: InitLinkList(); ! 55: ! 56: if (FORMAT_CPIO == format) { ! 57: int len, i; ! 58: CPIO_HEAD h; ! 59: ! 60: CpioWrite(pb, files, count); ! 61: ! 62: // write the trailer. ! 63: (void)strncpy(h.c_magic, MAGIC, strlen(MAGIC)); ! 64: cpio_itoa(C_ISREG, h.c_mode, sizeof(h.c_mode)); ! 65: cpio_itoa(sizeof(LASTFILENAME), h.c_namesize, ! 66: sizeof(h.c_namesize)); ! 67: cpio_itoa(0, h.c_filesize, sizeof(h.c_namesize)); ! 68: ! 69: for (i = 0; i < sizeof(h); ++i) { ! 70: bputc(pb, ((char *)&h)[i]); ! 71: } ! 72: ! 73: // "sizeof" so we get the nul, too ! 74: len = sizeof(LASTFILENAME); ! 75: for (i = 0; i < len; ++i) { ! 76: bputc(pb, LASTFILENAME[i]); ! 77: } ! 78: bflush(pb); ! 79: return; ! 80: } ! 81: if (FORMAT_TAR == format) { ! 82: TarWrite(pb, files, count); ! 83: ! 84: // a tar archive is terminated by two blocks of zeroes. ! 85: memset(pb->data, 0, sizeof(pb->data)); ! 86: bflush(pb); ! 87: bflush(pb); ! 88: return; ! 89: } ! 90: // shouldn't get here. ! 91: exit(10); ! 92: } ! 93: ! 94: void ! 95: ReadArchive(PBUF pb) ! 96: { ! 97: PCPIO_HEAD cp; ! 98: PTAR_HEAD tp; ! 99: ! 100: InitLinkList(); ! 101: ! 102: bfill(pb); ! 103: cp = (PCPIO_HEAD)pb->data; ! 104: ! 105: if (0 == strncmp(cp->c_magic, MAGIC, strlen(MAGIC))) { ! 106: CpioRead(pb); ! 107: return; ! 108: } ! 109: ! 110: tp = (PTAR_HEAD)pb->data; ! 111: ! 112: if (0 == strncmp(tp->s.magic, TMAGIC, strlen(TMAGIC))) { ! 113: TarRead(pb); ! 114: return; ! 115: } ! 116: fprintf(stderr, "%s: unknown archive type\n", progname); ! 117: exit(4); ! 118: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.