-
-#if 0
-/* pax_rd is derived from ustar_rd NOT tar_rd */
-/*
- * tar_rd()
- * extract the values out of block already determined to be a tar header.
- * store the values in the ARCHD parameter.
- * Return:
- * 0
- */
-
-int
-tar_rd(ARCHD *arcn, char *buf)
-{
- HD_TAR *hd;
- char *pt;
-
- /*
- * we only get proper sized buffers passed to us
- */
- if (tar_id(buf, BLKMULT) < 0)
- return(-1);
- memset(arcn, 0, sizeof(*arcn));
- arcn->org_name = arcn->name;
- arcn->sb.st_nlink = 1;
-
- /*
- * copy out the name and values in the stat buffer
- */
- hd = (HD_TAR *)buf;
- if (hd->linkflag != LONGLINKTYPE && hd->linkflag != LONGNAMETYPE) {
- arcn->nlen = expandname(arcn->name, sizeof(arcn->name),
- &gnu_name_string, hd->name, sizeof(hd->name));
- arcn->ln_nlen = expandname(arcn->ln_name, sizeof(arcn->ln_name),
- &gnu_link_string, hd->linkname, sizeof(hd->linkname));
- }
- arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode,sizeof(hd->mode),OCT) &
- 0xfff);
- arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT);
- arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT);
-#ifdef LONG_OFF_T
- arcn->sb.st_size = (off_t)asc_ul(hd->size, sizeof(hd->size), OCT);
-#else
- arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT);
-#endif
- arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT);
- arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-
- /*
- * have to look at the last character, it may be a '/' and that is used
- * to encode this as a directory
- */
- pt = &(arcn->name[arcn->nlen - 1]);
- arcn->pad = 0;
- arcn->skip = 0;
- switch (hd->linkflag) {
- case SYMTYPE:
- /*
- * symbolic link, need to get the link name and set the type in
- * the st_mode so -v printing will look correct.
- */
- arcn->type = PAX_SLK;
- arcn->sb.st_mode |= S_IFLNK;
- break;
- case LNKTYPE:
- /*
- * hard link, need to get the link name, set the type in the
- * st_mode and st_nlink so -v printing will look better.
- */
- arcn->type = PAX_HLK;
- arcn->sb.st_nlink = 2;
-
- /*
- * no idea of what type this thing really points at, but
- * we set something for printing only.
- */
- arcn->sb.st_mode |= S_IFREG;
- break;
- case LONGLINKTYPE:
- case LONGNAMETYPE:
- /*
- * GNU long link/file; we tag these here and let the
- * pax internals deal with it -- too ugly otherwise.
- */
- arcn->type =
- hd->linkflag == LONGLINKTYPE ? PAX_GLL : PAX_GLF;
- arcn->pad = TAR_PAD(arcn->sb.st_size);
- arcn->skip = arcn->sb.st_size;
- break;
- case DIRTYPE:
- /*
- * It is a directory, set the mode for -v printing
- */
- arcn->type = PAX_DIR;
- arcn->sb.st_mode |= S_IFDIR;
- arcn->sb.st_nlink = 2;
- break;
- case AREGTYPE:
- case REGTYPE:
- default:
- /*
- * If we have a trailing / this is a directory and NOT a file.
- */
- arcn->ln_name[0] = '\0';
- arcn->ln_nlen = 0;
- if (*pt == '/') {
- /*
- * it is a directory, set the mode for -v printing
- */
- arcn->type = PAX_DIR;
- arcn->sb.st_mode |= S_IFDIR;
- arcn->sb.st_nlink = 2;
- } else {
- /*
- * have a file that will be followed by data. Set the
- * skip value to the size field and calculate the size
- * of the padding.
- */
- arcn->type = PAX_REG;
- arcn->sb.st_mode |= S_IFREG;
- arcn->pad = TAR_PAD(arcn->sb.st_size);
- arcn->skip = arcn->sb.st_size;
- }
- break;
- }
-
- /*
- * strip off any trailing slash.
- */
- if (*pt == '/') {
- *pt = '\0';
- --arcn->nlen;
- }
- return(0);
-}
-
-/* pax_wr is derived from ustar_wr NOT tar_wr */
-/*
- * tar_wr()
- * write a tar header for the file specified in the ARCHD to the archive.
- * Have to check for file types that cannot be stored and file names that
- * are too long. Be careful of the term (last arg) to ul_oct, each field
- * of tar has it own spec for the termination character(s).
- * ASSUMED: space after header in header block is zero filled
- * Return:
- * 0 if file has data to be written after the header, 1 if file has NO
- * data to write after the header, -1 if archive write failed
- */
-
-int
-tar_wr(ARCHD *arcn)
-{
- HD_TAR *hd;
- int len;
- char hdblk[sizeof(HD_TAR)];
-
- /*
- * check for those file system types which tar cannot store
- */
- switch (arcn->type) {
- case PAX_DIR:
- /*
- * user asked that dirs not be written to the archive
- */
- if (tar_nodir)
- return(1);
- break;
- case PAX_CHR:
- paxwarn(1, "Tar cannot archive a character device %s",
- arcn->org_name);
- return(1);
- case PAX_BLK:
- paxwarn(1, "Tar cannot archive a block device %s", arcn->org_name);
- return(1);
- case PAX_SCK:
- paxwarn(1, "Tar cannot archive a socket %s", arcn->org_name);
- return(1);
- case PAX_FIF:
- paxwarn(1, "Tar cannot archive a fifo %s", arcn->org_name);
- return(1);
- case PAX_SLK:
- case PAX_HLK:
- case PAX_HRG:
- if (arcn->ln_nlen > sizeof(hd->linkname)) {
- paxwarn(1,"Link name too long for tar %s", arcn->ln_name);
- return(1);
- }
- break;
- case PAX_REG:
- case PAX_CTG:
- default:
- break;
- }
-
- /*
- * check file name len, remember extra char for dirs (the / at the end)
- */
- len = arcn->nlen;
- if (arcn->type == PAX_DIR)
- ++len;
- if (len >= sizeof(hd->name)) {
- paxwarn(1, "File name too long for tar %s", arcn->name);
- return(1);
- }
-
- /*
- * Copy the data out of the ARCHD into the tar header based on the type
- * of the file. Remember, many tar readers want all fields to be
- * padded with zero so we zero the header first. We then set the
- * linkflag field (type), the linkname, the size, and set the padding
- * (if any) to be added after the file data (0 for all other types,
- * as they only have a header).
- */
- memset(hdblk, 0, sizeof(hdblk));
- hd = (HD_TAR *)hdblk;
- strlcpy(hd->name, arcn->name, sizeof(hd->name));
- arcn->pad = 0;
-
- if (arcn->type == PAX_DIR) {
- /*
- * directories are the same as files, except have a filename
- * that ends with a /, we add the slash here. No data follows
- * dirs, so no pad.
- */
- hd->linkflag = AREGTYPE;
- hd->name[len-1] = '/';
- if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1))
- goto out;
- } else if (arcn->type == PAX_SLK) {
- /*
- * no data follows this file, so no pad
- */
- hd->linkflag = SYMTYPE;
- strlcpy(hd->linkname, arcn->ln_name, sizeof(hd->linkname));
- if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1))
- goto out;
- } else if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG)) {
- /*
- * no data follows this file, so no pad
- */
- hd->linkflag = LNKTYPE;
- strlcpy(hd->linkname, arcn->ln_name, sizeof(hd->linkname));
- if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1))
- goto out;
- } else {
- /*
- * data follows this file, so set the pad
- */
- hd->linkflag = AREGTYPE;
-# ifdef LONG_OFF_T
- if (ul_oct((u_long)arcn->sb.st_size, hd->size,
- sizeof(hd->size), 1)) {
-# else
- if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size,
- sizeof(hd->size), 1)) {
-# endif
- paxwarn(1,"File is too large for tar %s", arcn->org_name);
- return(1);
- }
- arcn->pad = TAR_PAD(arcn->sb.st_size);
- }
-
- /*
- * copy those fields that are independent of the type
- */
- if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 0) ||
- ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 0) ||
- ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 0) ||
- ul_oct((u_long)arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 1))
- goto out;
-
- /*
- * calculate and add the checksum, then write the header. A return of
- * 0 tells the caller to now write the file data, 1 says no data needs
- * to be written
- */
- if (ul_oct(tar_chksm(hdblk, sizeof(HD_TAR)), hd->chksum,
- sizeof(hd->chksum), 3))
- goto out;
- if (wr_rdbuf(hdblk, sizeof(HD_TAR)) < 0)
- return(-1);
- if (wr_skip((off_t)(BLKMULT - sizeof(HD_TAR))) < 0)
- return(-1);
- if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG))
- return(0);
- return(1);
-
- out:
- /*
- * header field is out of range
- */
- paxwarn(1, "Tar header field is too small for %s", arcn->org_name);
- return(1);
-}
-#endif
-
-#if 0
-/*
- * Routines for POSIX ustar
- */
-
-/*
- * ustar_strd()
- * initialization for ustar read
- * Return:
- * 0 if ok, -1 otherwise
- */
-
-int
-ustar_strd(void)
-{
- if ((usrtb_start() < 0) || (grptb_start() < 0))
- return(-1);
- return(0);
-}
-
-/*
- * ustar_stwr()
- * initialization for ustar write
- * Return:
- * 0 if ok, -1 otherwise
- */
-
-int
-ustar_stwr(void)
-{
- if ((uidtb_start() < 0) || (gidtb_start() < 0))
- return(-1);
- return(0);
-}
-#endif
-
-int