2024-02-06 01:08:04 +03:00
|
|
|
/* $NetBSD: tape.c,v 1.75 2024/02/05 22:08:04 andvar Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
1994-06-08 23:27:32 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-05-17 08:13:48 +04:00
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-17 08:13:48 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 12:04:28 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1997-09-16 17:44:12 +04:00
|
|
|
static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2024-02-06 01:08:04 +03:00
|
|
|
__RCSID("$NetBSD: tape.c,v 1.75 2024/02/05 22:08:04 andvar Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1994-05-17 08:13:48 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mtio.h>
|
|
|
|
#include <sys/stat.h>
|
2021-06-19 16:56:34 +03:00
|
|
|
#include <sys/extattr.h>
|
|
|
|
#define _ACL_PRIVATE
|
|
|
|
#include <sys/acl.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
|
2021-06-19 16:56:34 +03:00
|
|
|
#include <ufs/ufs/extattr.h>
|
1994-06-08 23:27:32 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
#include <protocols/dumprestore.h>
|
|
|
|
|
2004-10-23 02:38:38 +04:00
|
|
|
#include <err.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
#include <errno.h>
|
1997-04-15 11:12:19 +04:00
|
|
|
#include <paths.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-04-01 20:21:47 +04:00
|
|
|
#include <time.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2004-07-27 06:17:06 +04:00
|
|
|
#include <md5.h>
|
2006-10-30 04:21:53 +03:00
|
|
|
#include <rmd160.h>
|
2004-07-27 06:17:06 +04:00
|
|
|
#include <sha1.h>
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
#include "restore.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
1997-09-15 12:04:28 +04:00
|
|
|
static u_int32_t fssize = MAXBSIZE;
|
1994-05-17 08:13:48 +04:00
|
|
|
static int mt = -1;
|
|
|
|
static int pipein = 0;
|
|
|
|
static char magtape[BUFSIZ];
|
|
|
|
static int blkcnt;
|
|
|
|
static int numtrec;
|
|
|
|
static char *tapebuf;
|
|
|
|
static union u_spcl endoftapemark;
|
1997-09-15 12:04:28 +04:00
|
|
|
static int blksread; /* blocks read since last header */
|
|
|
|
static int tpblksread = 0; /* TP_BSIZE blocks read */
|
|
|
|
static int tapesread;
|
1994-05-17 08:13:48 +04:00
|
|
|
static jmp_buf restart;
|
|
|
|
static int gettingfile = 0; /* restart has a valid frame */
|
2003-03-27 17:11:51 +03:00
|
|
|
#ifdef RRESTORE
|
2005-06-27 05:55:52 +04:00
|
|
|
static const char *host = NULL;
|
2003-03-27 17:11:51 +03:00
|
|
|
#endif
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
static int ofile;
|
|
|
|
static char lnkbuf[MAXPATHLEN + 1];
|
|
|
|
static int pathlen;
|
|
|
|
|
|
|
|
int oldinofmt; /* old inode format conversion required */
|
|
|
|
int Bcvt; /* Swap Bytes (for CCI or sun) */
|
|
|
|
|
2004-07-27 06:17:06 +04:00
|
|
|
const struct digest_desc *ddesc;
|
|
|
|
|
|
|
|
static union digest_context {
|
2011-08-07 00:46:42 +04:00
|
|
|
MD5_CTX dc_MD5;
|
|
|
|
SHA1_CTX dc_SHA1;
|
|
|
|
RMD160_CTX dc_RMD160;
|
2004-07-27 06:17:06 +04:00
|
|
|
} dcontext;
|
|
|
|
|
2011-08-06 21:01:06 +04:00
|
|
|
/*
|
|
|
|
* 32 for md5; 40 for sha1 and rmd160
|
|
|
|
* plus a null terminator.
|
|
|
|
*/
|
|
|
|
#define DIGEST_BUFFER_SIZE (40 + 1)
|
2004-07-27 06:17:06 +04:00
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
#define FLUSHTAPEBUF() blkcnt = ntrec + 1
|
|
|
|
|
2021-06-19 16:56:34 +03:00
|
|
|
const char *namespace_names[] = EXTATTR_NAMESPACE_NAMES;
|
|
|
|
|
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
union u_ospcl {
|
|
|
|
char dummy[TP_BSIZE];
|
|
|
|
struct s_ospcl {
|
|
|
|
int32_t c_type;
|
|
|
|
int32_t c_date;
|
|
|
|
int32_t c_ddate;
|
|
|
|
int32_t c_volume;
|
|
|
|
int32_t c_tapea;
|
|
|
|
u_int16_t c_inumber;
|
|
|
|
int32_t c_magic;
|
|
|
|
int32_t c_checksum;
|
|
|
|
struct odinode {
|
|
|
|
unsigned short odi_mode;
|
|
|
|
u_int16_t odi_nlink;
|
|
|
|
u_int16_t odi_uid;
|
|
|
|
u_int16_t odi_gid;
|
|
|
|
int32_t odi_size;
|
|
|
|
int32_t odi_rdev;
|
|
|
|
char odi_addr[36];
|
|
|
|
int32_t odi_atime;
|
|
|
|
int32_t odi_mtime;
|
|
|
|
int32_t odi_ctime;
|
|
|
|
} c_odinode;
|
|
|
|
int32_t c_count;
|
|
|
|
char c_addr[256];
|
|
|
|
} s_ospcl;
|
|
|
|
};
|
|
|
|
|
2005-02-17 18:00:33 +03:00
|
|
|
static void accthdr(struct s_spcl *);
|
|
|
|
static int checksum(int *);
|
|
|
|
static void findinode(struct s_spcl *);
|
|
|
|
static void findtapeblksize(void);
|
2021-06-19 16:56:34 +03:00
|
|
|
static char *setupextattr(size_t);
|
|
|
|
static void xtrattr(char *, size_t);
|
|
|
|
static void skiphole(void (*)(char *, size_t), volatile size_t *);
|
2007-02-09 12:36:02 +03:00
|
|
|
static void getbitmap(char **);
|
2005-02-17 18:00:33 +03:00
|
|
|
static int gethead(struct s_spcl *);
|
|
|
|
static void readtape(char *);
|
|
|
|
static void setdumpnum(void);
|
|
|
|
static void terminateinput(void);
|
2021-06-19 16:56:34 +03:00
|
|
|
static void xtrfile(char *, size_t);
|
|
|
|
static void xtrlnkfile(char *, size_t);
|
|
|
|
__dead static void xtrlnkskip(char *, size_t);
|
|
|
|
static void xtrskip(char *, size_t);
|
2005-02-17 18:00:33 +03:00
|
|
|
static void swap_header(struct s_spcl *);
|
|
|
|
static void swap_old_header(struct s_ospcl *);
|
1994-05-17 08:13:48 +04:00
|
|
|
|
2011-08-07 00:46:42 +04:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// thunks for type correctness
|
|
|
|
|
|
|
|
#define WRAP(alg) \
|
|
|
|
static void \
|
|
|
|
do_##alg##Init(void *ctx) \
|
|
|
|
{ \
|
|
|
|
alg##Init(ctx); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void \
|
|
|
|
do_##alg##Update(union digest_context *ctx, \
|
|
|
|
const void *buf, unsigned len) \
|
|
|
|
{ \
|
|
|
|
alg##Update(&ctx->dc_##alg, buf, len); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static char * \
|
|
|
|
do_##alg##End(void *ctx, char *str) \
|
|
|
|
{ \
|
|
|
|
return alg##End(ctx, str); \
|
|
|
|
}
|
|
|
|
|
|
|
|
WRAP(MD5);
|
|
|
|
WRAP(SHA1);
|
|
|
|
WRAP(RMD160);
|
|
|
|
|
|
|
|
static const struct digest_desc digest_descs[] = {
|
|
|
|
{ "MD5",
|
|
|
|
do_MD5Init,
|
|
|
|
do_MD5Update,
|
|
|
|
do_MD5End, },
|
|
|
|
{ "SHA1",
|
|
|
|
do_SHA1Init,
|
|
|
|
do_SHA1Update,
|
|
|
|
do_SHA1End, },
|
|
|
|
{ "RMD160",
|
|
|
|
do_RMD160Init,
|
|
|
|
do_RMD160Update,
|
|
|
|
do_RMD160End, },
|
|
|
|
{ .dd_name = NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2004-07-27 06:17:06 +04:00
|
|
|
const struct digest_desc *
|
2005-02-17 18:00:33 +03:00
|
|
|
digest_lookup(const char *name)
|
2004-07-27 06:17:06 +04:00
|
|
|
{
|
|
|
|
const struct digest_desc *dd;
|
|
|
|
|
|
|
|
for (dd = digest_descs; dd->dd_name != NULL; dd++)
|
|
|
|
if (strcasecmp(dd->dd_name, name) == 0)
|
|
|
|
return (dd);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* Set up an input source
|
|
|
|
*/
|
|
|
|
void
|
2005-06-27 05:55:52 +04:00
|
|
|
setinput(const char *source)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2005-06-27 05:55:52 +04:00
|
|
|
char *cp;
|
1994-05-17 08:13:48 +04:00
|
|
|
FLUSHTAPEBUF();
|
|
|
|
if (bflag)
|
|
|
|
newtapebuf(ntrec);
|
|
|
|
else
|
|
|
|
newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
|
|
|
|
terminal = stdin;
|
|
|
|
|
|
|
|
#ifdef RRESTORE
|
2005-06-27 05:55:52 +04:00
|
|
|
if ((cp = strchr(source, ':')) != NULL) {
|
1994-05-17 08:13:48 +04:00
|
|
|
host = source;
|
2005-06-27 05:55:52 +04:00
|
|
|
/* Ok, because const strings don't have : */
|
|
|
|
*cp++ = '\0';
|
|
|
|
source = cp;
|
1994-05-17 08:13:48 +04:00
|
|
|
if (rmthost(host) == 0)
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (strcmp(source, "-") == 0) {
|
|
|
|
/*
|
|
|
|
* Since input is coming from a pipe we must establish
|
|
|
|
* our own connection to the terminal.
|
|
|
|
*/
|
|
|
|
terminal = fopen(_PATH_TTY, "r");
|
|
|
|
if (terminal == NULL) {
|
|
|
|
(void)fprintf(stderr, "cannot open %s: %s\n",
|
|
|
|
_PATH_TTY, strerror(errno));
|
|
|
|
terminal = fopen(_PATH_DEVNULL, "r");
|
|
|
|
if (terminal == NULL) {
|
|
|
|
(void)fprintf(stderr, "cannot open %s: %s\n",
|
|
|
|
_PATH_DEVNULL, strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pipein++;
|
|
|
|
}
|
|
|
|
(void) strcpy(magtape, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
newtapebuf(long size)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1998-03-30 06:13:35 +04:00
|
|
|
static int tapebufsize = -1;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
ntrec = size;
|
|
|
|
if (size <= tapebufsize)
|
|
|
|
return;
|
|
|
|
if (tapebuf != NULL)
|
|
|
|
free(tapebuf);
|
|
|
|
tapebuf = malloc(size * TP_BSIZE);
|
|
|
|
if (tapebuf == NULL) {
|
|
|
|
fprintf(stderr, "Cannot allocate space for tape buffer\n");
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
tapebufsize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the tape drive can be accessed and
|
|
|
|
* that it actually is a dump tape.
|
|
|
|
*/
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
setup(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
int i, j, *ip;
|
|
|
|
struct stat stbuf;
|
|
|
|
|
|
|
|
vprintf(stdout, "Verify tape and initialize maps\n");
|
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
2008-02-16 20:58:01 +03:00
|
|
|
mt = rmtopen(magtape, 0, 0);
|
1994-05-17 08:13:48 +04:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (pipein)
|
|
|
|
mt = 0;
|
|
|
|
else
|
|
|
|
mt = open(magtape, O_RDONLY, 0);
|
|
|
|
if (mt < 0) {
|
|
|
|
fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
volno = 1;
|
|
|
|
setdumpnum();
|
|
|
|
FLUSHTAPEBUF();
|
|
|
|
if (!pipein && !bflag)
|
|
|
|
findtapeblksize();
|
|
|
|
if (gethead(&spcl) == FAIL) {
|
|
|
|
blkcnt--; /* push back this block */
|
|
|
|
blksread--;
|
|
|
|
tpblksread--;
|
|
|
|
cvtflag++;
|
|
|
|
if (gethead(&spcl) == FAIL) {
|
|
|
|
fprintf(stderr, "Tape is not a dump tape\n");
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
fprintf(stderr, "Converting to new file system format.\n");
|
|
|
|
}
|
|
|
|
if (pipein) {
|
2003-04-02 14:39:19 +04:00
|
|
|
endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC :
|
|
|
|
FS_UFS2_MAGIC;
|
1994-05-17 08:13:48 +04:00
|
|
|
endoftapemark.s_spcl.c_type = TS_END;
|
|
|
|
ip = (int *)&endoftapemark;
|
|
|
|
j = sizeof(union u_spcl) / sizeof(int);
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
i += *ip++;
|
|
|
|
while (--j);
|
|
|
|
endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
|
|
|
|
}
|
|
|
|
if (vflag || command == 't')
|
|
|
|
printdumpinfo();
|
|
|
|
dumptime = spcl.c_ddate;
|
|
|
|
dumpdate = spcl.c_date;
|
|
|
|
if (stat(".", &stbuf) < 0) {
|
|
|
|
fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
1996-11-30 21:31:29 +03:00
|
|
|
if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
|
1994-05-17 08:13:48 +04:00
|
|
|
fssize = stbuf.st_blksize;
|
|
|
|
if (((fssize - 1) & fssize) != 0) {
|
|
|
|
fprintf(stderr, "bad block size %d\n", fssize);
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
if (spcl.c_volume != 1) {
|
|
|
|
fprintf(stderr, "Tape is not volume 1 of the dump\n");
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
if (gethead(&spcl) == FAIL) {
|
|
|
|
dprintf(stdout, "header read failed at %d blocks\n", blksread);
|
|
|
|
panic("no header after volume mark!\n");
|
|
|
|
}
|
|
|
|
findinode(&spcl);
|
|
|
|
if (spcl.c_type != TS_CLRI) {
|
|
|
|
fprintf(stderr, "Cannot find file removal list\n");
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
2007-02-09 12:36:02 +03:00
|
|
|
getbitmap(&usedinomap);
|
|
|
|
getbitmap(&dumpmap);
|
1994-12-28 05:21:43 +03:00
|
|
|
/*
|
|
|
|
* If there may be whiteout entries on the tape, pretend that the
|
|
|
|
* whiteout inode exists, so that the whiteout entries can be
|
|
|
|
* extracted.
|
|
|
|
*/
|
|
|
|
if (oldinofmt == 0)
|
2013-01-22 13:39:11 +04:00
|
|
|
SETINO(UFS_WINO, dumpmap);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prompt user to load a new dump volume.
|
|
|
|
* "Nextvol" is the next suggested volume to use.
|
|
|
|
* This suggested volume is enforced when doing full
|
2024-02-06 01:08:04 +03:00
|
|
|
* or incremental restores, but can be overridden by
|
1994-05-17 08:13:48 +04:00
|
|
|
* the user when only extracting a subset of the files.
|
|
|
|
*/
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
getvol(int nextvol)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-09-15 12:04:28 +04:00
|
|
|
int newvol, savecnt, wantnext, i;
|
1994-05-17 08:13:48 +04:00
|
|
|
union u_spcl tmpspcl;
|
|
|
|
# define tmpbuf tmpspcl.s_spcl
|
|
|
|
char buf[TP_BSIZE];
|
|
|
|
|
1997-09-15 12:04:28 +04:00
|
|
|
newvol = savecnt = wantnext = 0;
|
1994-05-17 08:13:48 +04:00
|
|
|
if (nextvol == 1) {
|
|
|
|
tapesread = 0;
|
|
|
|
gettingfile = 0;
|
|
|
|
}
|
|
|
|
if (pipein) {
|
|
|
|
if (nextvol != 1)
|
|
|
|
panic("Changing volumes on pipe input?\n");
|
|
|
|
if (volno == 1)
|
|
|
|
return;
|
|
|
|
goto gethdr;
|
|
|
|
}
|
|
|
|
savecnt = blksread;
|
|
|
|
again:
|
|
|
|
if (pipein)
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1); /* pipes do not get a second chance */
|
1994-05-17 08:13:48 +04:00
|
|
|
if (command == 'R' || command == 'r' || curfile.action != SKIP) {
|
|
|
|
newvol = nextvol;
|
|
|
|
wantnext = 1;
|
|
|
|
} else {
|
|
|
|
newvol = 0;
|
|
|
|
wantnext = 0;
|
|
|
|
}
|
|
|
|
while (newvol <= 0) {
|
|
|
|
if (tapesread == 0) {
|
|
|
|
fprintf(stderr, "%s%s%s%s%s",
|
|
|
|
"You have not read any tapes yet.\n",
|
|
|
|
"Unless you know which volume your",
|
|
|
|
" file(s) are on you should start\n",
|
|
|
|
"with the last volume and work",
|
1996-12-26 20:35:35 +03:00
|
|
|
" towards the first.\n");
|
1999-01-03 04:50:34 +03:00
|
|
|
fprintf(stderr,
|
|
|
|
"(Use 1 for the first volume/tape, etc.)\n");
|
1994-05-17 08:13:48 +04:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "You have read volumes");
|
|
|
|
strcpy(buf, ": ");
|
|
|
|
for (i = 1; i < 32; i++)
|
|
|
|
if (tapesread & (1 << i)) {
|
|
|
|
fprintf(stderr, "%s%d", buf, i);
|
|
|
|
strcpy(buf, ", ");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
fprintf(stderr, "Specify next volume #: ");
|
|
|
|
(void) fflush(stderr);
|
|
|
|
(void) fgets(buf, BUFSIZ, terminal);
|
|
|
|
} while (!feof(terminal) && buf[0] == '\n');
|
|
|
|
if (feof(terminal))
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
newvol = atoi(buf);
|
|
|
|
if (newvol <= 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Volume numbers are positive numerics\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newvol == volno) {
|
|
|
|
tapesread |= 1 << volno;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
closemt();
|
|
|
|
fprintf(stderr, "Mount tape volume %d\n", newvol);
|
|
|
|
fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
|
|
|
|
fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
|
|
|
|
(void) fflush(stderr);
|
|
|
|
(void) fgets(buf, BUFSIZ, terminal);
|
|
|
|
if (feof(terminal))
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
if (!strcmp(buf, "none\n")) {
|
|
|
|
terminateinput();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (buf[0] != '\n') {
|
|
|
|
(void) strcpy(magtape, buf);
|
|
|
|
magtape[strlen(magtape) - 1] = '\0';
|
|
|
|
}
|
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
2008-02-16 20:58:01 +03:00
|
|
|
mt = rmtopen(magtape, 0, 0);
|
1994-05-17 08:13:48 +04:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
mt = open(magtape, O_RDONLY, 0);
|
|
|
|
|
|
|
|
if (mt == -1) {
|
|
|
|
fprintf(stderr, "Cannot open %s\n", magtape);
|
|
|
|
volno = -1;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
gethdr:
|
|
|
|
volno = newvol;
|
|
|
|
setdumpnum();
|
|
|
|
FLUSHTAPEBUF();
|
|
|
|
if (gethead(&tmpbuf) == FAIL) {
|
|
|
|
dprintf(stdout, "header read failed at %d blocks\n", blksread);
|
|
|
|
fprintf(stderr, "tape is not dump tape\n");
|
|
|
|
volno = 0;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (tmpbuf.c_volume != volno) {
|
1999-01-03 04:50:34 +03:00
|
|
|
fprintf(stderr,
|
|
|
|
"Volume mismatch: expecting %d, tape header claims it is %d\n",
|
|
|
|
volno, tmpbuf.c_volume);
|
1994-05-17 08:13:48 +04:00
|
|
|
volno = 0;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) {
|
2001-12-23 17:40:42 +03:00
|
|
|
time_t ttime = tmpbuf.c_date;
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "Wrong dump date\n\tgot: %s",
|
2001-12-23 17:40:42 +03:00
|
|
|
ctime(&ttime));
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
|
|
|
|
volno = 0;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
tapesread |= 1 << volno;
|
|
|
|
blksread = savecnt;
|
|
|
|
/*
|
|
|
|
* If continuing from the previous volume, skip over any
|
|
|
|
* blocks read already at the end of the previous volume.
|
|
|
|
*
|
|
|
|
* If coming to this volume at random, skip to the beginning
|
|
|
|
* of the next record.
|
|
|
|
*/
|
|
|
|
dprintf(stdout, "read %ld recs, tape starts with %ld\n",
|
1997-09-15 12:04:28 +04:00
|
|
|
(long)tpblksread, (long)tmpbuf.c_firstrec);
|
1994-05-17 08:13:48 +04:00
|
|
|
if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
|
|
|
|
if (!wantnext) {
|
|
|
|
tpblksread = tmpbuf.c_firstrec;
|
|
|
|
for (i = tmpbuf.c_count; i > 0; i--)
|
|
|
|
readtape(buf);
|
|
|
|
} else if (tmpbuf.c_firstrec > 0 &&
|
|
|
|
tmpbuf.c_firstrec < tpblksread - 1) {
|
|
|
|
/*
|
|
|
|
* -1 since we've read the volume header
|
|
|
|
*/
|
|
|
|
i = tpblksread - tmpbuf.c_firstrec - 1;
|
|
|
|
dprintf(stderr, "Skipping %d duplicate record%s.\n",
|
|
|
|
i, i > 1 ? "s" : "");
|
|
|
|
while (--i >= 0)
|
|
|
|
readtape(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (curfile.action == USING) {
|
|
|
|
if (volno == 1)
|
|
|
|
panic("active file into volume 1\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Skip up to the beginning of the next record
|
|
|
|
*/
|
|
|
|
if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER))
|
|
|
|
for (i = tmpbuf.c_count; i > 0; i--)
|
|
|
|
readtape(buf);
|
|
|
|
(void) gethead(&spcl);
|
|
|
|
findinode(&spcl);
|
|
|
|
if (gettingfile) {
|
|
|
|
gettingfile = 0;
|
|
|
|
longjmp(restart, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle unexpected EOF.
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-17 18:00:33 +03:00
|
|
|
terminateinput(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (gettingfile && curfile.action == USING) {
|
|
|
|
printf("Warning: %s %s\n",
|
|
|
|
"End-of-input encountered while extracting", curfile.name);
|
|
|
|
}
|
|
|
|
curfile.name = "<name unknown>";
|
|
|
|
curfile.action = UNKNOWN;
|
2003-04-02 14:39:19 +04:00
|
|
|
curfile.mode = 0;
|
1994-05-17 08:13:48 +04:00
|
|
|
curfile.ino = maxino;
|
|
|
|
if (gettingfile) {
|
|
|
|
gettingfile = 0;
|
|
|
|
longjmp(restart, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle multiple dumps per tape by skipping forward to the
|
|
|
|
* appropriate one.
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-17 18:00:33 +03:00
|
|
|
setdumpnum(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
struct mtop tcom;
|
|
|
|
|
|
|
|
if (dumpnum == 1 || volno != 1)
|
|
|
|
return;
|
|
|
|
if (pipein) {
|
|
|
|
fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
tcom.mt_op = MTFSF;
|
|
|
|
tcom.mt_count = dumpnum - 1;
|
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
|
|
|
rmtioctl(MTFSF, dumpnum - 1);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (ioctl(mt, (int)MTIOCTOP, (char *)&tcom) < 0)
|
|
|
|
fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
printdumpinfo(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2001-12-23 17:40:42 +03:00
|
|
|
time_t ttime;
|
|
|
|
|
|
|
|
ttime = spcl.c_date;
|
|
|
|
fprintf(stdout, "Dump date: %s", ctime(&ttime));
|
|
|
|
ttime = spcl.c_ddate;
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stdout, "Dumped from: %s",
|
2001-12-23 17:40:42 +03:00
|
|
|
(spcl.c_ddate == 0) ? "the epoch\n" : ctime(&ttime));
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "Level %d dump of %s on %s:%s\n",
|
2000-01-27 18:25:00 +03:00
|
|
|
spcl.c_level, spcl.c_filesys,
|
|
|
|
*spcl.c_host? spcl.c_host: "[unknown]", spcl.c_dev);
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "Label: %s\n", spcl.c_label);
|
2004-10-23 02:38:38 +04:00
|
|
|
|
|
|
|
if (Mtreefile) {
|
|
|
|
ttime = spcl.c_date;
|
|
|
|
fprintf(Mtreefile, "#Dump date: %s", ctime(&ttime));
|
|
|
|
ttime = spcl.c_ddate;
|
|
|
|
fprintf(Mtreefile, "#Dumped from: %s",
|
|
|
|
(spcl.c_ddate == 0) ? "the epoch\n" : ctime(&ttime));
|
|
|
|
fprintf(Mtreefile, "#Level %d dump of %s on %s:%s\n",
|
|
|
|
spcl.c_level, spcl.c_filesys,
|
|
|
|
*spcl.c_host? spcl.c_host: "[unknown]", spcl.c_dev);
|
|
|
|
fprintf(Mtreefile, "#Label: %s\n", spcl.c_label);
|
|
|
|
fprintf(Mtreefile, "/set uname=root gname=wheel\n");
|
|
|
|
if (ferror(Mtreefile))
|
|
|
|
err(1, "error writing to mtree file");
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-02-17 18:00:33 +03:00
|
|
|
extractfile(char *name)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2011-08-06 21:01:06 +04:00
|
|
|
char dbuffer[DIGEST_BUFFER_SIZE];
|
2021-06-19 16:56:34 +03:00
|
|
|
u_int flags;
|
1997-10-09 02:51:27 +04:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
1994-12-28 05:21:43 +03:00
|
|
|
mode_t mode;
|
2021-06-19 16:56:34 +03:00
|
|
|
int extsize;
|
2015-03-02 06:17:24 +03:00
|
|
|
struct timespec mtimep[2], ctimep[2];
|
1994-05-17 08:13:48 +04:00
|
|
|
struct entry *ep;
|
2003-04-02 14:39:19 +04:00
|
|
|
int setbirth;
|
2021-06-19 16:56:34 +03:00
|
|
|
char *buf;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
curfile.name = name;
|
|
|
|
curfile.action = USING;
|
2003-04-02 14:39:19 +04:00
|
|
|
mtimep[0].tv_sec = curfile.atime_sec;
|
2015-03-02 06:17:24 +03:00
|
|
|
mtimep[0].tv_nsec = curfile.atime_nsec;
|
2003-04-02 14:39:19 +04:00
|
|
|
mtimep[1].tv_sec = curfile.mtime_sec;
|
2015-03-02 06:17:24 +03:00
|
|
|
mtimep[1].tv_nsec = curfile.mtime_nsec;
|
2003-04-02 14:39:19 +04:00
|
|
|
|
|
|
|
setbirth = curfile.birthtime_sec != 0;
|
|
|
|
|
|
|
|
if (setbirth) {
|
|
|
|
ctimep[0].tv_sec = curfile.atime_sec;
|
2015-03-02 06:17:24 +03:00
|
|
|
ctimep[0].tv_nsec = curfile.atime_nsec;
|
2003-04-02 14:39:19 +04:00
|
|
|
ctimep[1].tv_sec = curfile.birthtime_sec;
|
2015-03-02 06:17:24 +03:00
|
|
|
ctimep[1].tv_nsec = curfile.birthtime_nsec;
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
2021-06-19 16:56:34 +03:00
|
|
|
extsize = curfile.extsize;
|
2022-12-10 21:49:44 +03:00
|
|
|
uid = getuid();
|
|
|
|
if (uid == 0)
|
|
|
|
uid = curfile.uid;
|
2003-04-02 14:39:19 +04:00
|
|
|
gid = curfile.gid;
|
|
|
|
mode = curfile.mode;
|
|
|
|
flags = curfile.file_flags;
|
1994-05-17 08:13:48 +04:00
|
|
|
switch (mode & IFMT) {
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
|
|
|
|
skipfile();
|
|
|
|
return (FAIL);
|
|
|
|
|
|
|
|
case IFSOCK:
|
|
|
|
vprintf(stdout, "skipped socket %s\n", name);
|
|
|
|
skipfile();
|
|
|
|
return (GOOD);
|
|
|
|
|
|
|
|
case IFDIR:
|
|
|
|
if (mflag) {
|
|
|
|
ep = lookupname(name);
|
|
|
|
if (ep == NULL || ep->e_flags & EXTRACT)
|
|
|
|
panic("unextracted directory %s\n", name);
|
|
|
|
skipfile();
|
|
|
|
return (GOOD);
|
|
|
|
}
|
|
|
|
vprintf(stdout, "extract file %s\n", name);
|
|
|
|
return (genliteraldir(name, curfile.ino));
|
|
|
|
|
|
|
|
case IFLNK:
|
|
|
|
lnkbuf[0] = '\0';
|
|
|
|
pathlen = 0;
|
2021-06-19 16:56:34 +03:00
|
|
|
buf = setupextattr(extsize);
|
|
|
|
getfile(xtrlnkfile, xtrattr, xtrlnkskip);
|
1994-05-17 08:13:48 +04:00
|
|
|
if (pathlen == 0) {
|
|
|
|
vprintf(stdout,
|
|
|
|
"%s: zero length symbolic link (ignored)\n", name);
|
|
|
|
return (GOOD);
|
|
|
|
}
|
1998-06-24 23:56:11 +04:00
|
|
|
if (uflag)
|
|
|
|
(void) unlink(name);
|
1997-10-09 02:51:27 +04:00
|
|
|
if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
|
2003-04-02 14:39:19 +04:00
|
|
|
if (setbirth)
|
2015-03-02 06:17:24 +03:00
|
|
|
(void) lutimens(name, ctimep);
|
|
|
|
(void) lutimens(name, mtimep);
|
1997-10-19 17:29:22 +04:00
|
|
|
(void) lchown(name, uid, gid);
|
|
|
|
(void) lchmod(name, mode);
|
2022-12-12 19:53:30 +03:00
|
|
|
if (extsize > 0)
|
|
|
|
set_extattr(-1, name, buf, extsize, SXA_LINK);
|
2004-10-23 02:38:38 +04:00
|
|
|
if (Mtreefile) {
|
|
|
|
writemtree(name, "link",
|
|
|
|
uid, gid, mode, flags);
|
|
|
|
} else
|
|
|
|
(void) lchflags(name, flags);
|
1997-10-09 02:51:27 +04:00
|
|
|
return (GOOD);
|
|
|
|
}
|
|
|
|
return (FAIL);
|
1994-05-17 08:13:48 +04:00
|
|
|
|
1994-12-28 05:21:43 +03:00
|
|
|
case IFCHR:
|
|
|
|
case IFBLK:
|
|
|
|
vprintf(stdout, "extract special file %s\n", name);
|
1994-09-18 09:11:03 +04:00
|
|
|
if (Nflag) {
|
|
|
|
skipfile();
|
|
|
|
return (GOOD);
|
|
|
|
}
|
1998-06-24 23:56:11 +04:00
|
|
|
if (uflag)
|
|
|
|
(void) unlink(name);
|
1997-12-14 01:22:53 +03:00
|
|
|
if (mknod(name, (mode & (IFCHR | IFBLK)) | 0600,
|
2003-04-02 14:39:19 +04:00
|
|
|
(int)curfile.rdev) < 0) {
|
1994-12-28 05:21:43 +03:00
|
|
|
fprintf(stderr, "%s: cannot create special file: %s\n",
|
1994-09-18 09:11:03 +04:00
|
|
|
name, strerror(errno));
|
|
|
|
skipfile();
|
|
|
|
return (FAIL);
|
|
|
|
}
|
2022-12-12 19:53:30 +03:00
|
|
|
(void) chown(name, uid, gid);
|
|
|
|
(void) chmod(name, mode);
|
2021-06-19 16:56:34 +03:00
|
|
|
if (extsize == 0) {
|
|
|
|
skipfile();
|
|
|
|
} else {
|
|
|
|
buf = setupextattr(extsize);
|
|
|
|
getfile(xtrnull, xtrattr, xtrnull);
|
|
|
|
set_extattr(-1, name, buf, extsize, SXA_FILE);
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
if (setbirth)
|
2015-03-02 06:17:24 +03:00
|
|
|
(void) utimens(name, ctimep);
|
|
|
|
(void) utimens(name, mtimep);
|
2004-10-23 02:38:38 +04:00
|
|
|
if (Mtreefile) {
|
|
|
|
writemtree(name,
|
|
|
|
((mode & (S_IFBLK | IFCHR)) == IFBLK) ?
|
|
|
|
"block" : "char",
|
|
|
|
uid, gid, mode, flags);
|
|
|
|
} else
|
|
|
|
(void) chflags(name, flags);
|
1994-09-18 09:11:03 +04:00
|
|
|
return (GOOD);
|
|
|
|
|
1994-12-28 05:21:43 +03:00
|
|
|
case IFIFO:
|
|
|
|
vprintf(stdout, "extract fifo %s\n", name);
|
1994-05-17 08:13:48 +04:00
|
|
|
if (Nflag) {
|
|
|
|
skipfile();
|
|
|
|
return (GOOD);
|
|
|
|
}
|
1998-06-24 23:56:11 +04:00
|
|
|
if (uflag)
|
|
|
|
(void) unlink(name);
|
1997-11-18 06:08:21 +03:00
|
|
|
if (mkfifo(name, 0600) < 0) {
|
1994-12-28 05:21:43 +03:00
|
|
|
fprintf(stderr, "%s: cannot create fifo: %s\n",
|
1994-05-17 08:13:48 +04:00
|
|
|
name, strerror(errno));
|
|
|
|
skipfile();
|
|
|
|
return (FAIL);
|
|
|
|
}
|
2022-12-12 19:53:30 +03:00
|
|
|
(void) chown(name, uid, gid);
|
|
|
|
(void) chmod(name, mode);
|
2021-06-19 16:56:34 +03:00
|
|
|
if (extsize == 0) {
|
|
|
|
skipfile();
|
|
|
|
} else {
|
|
|
|
buf = setupextattr(extsize);
|
|
|
|
getfile(xtrnull, xtrattr, xtrnull);
|
|
|
|
set_extattr(-1, name, buf, extsize, SXA_FILE);
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
if (setbirth)
|
2015-03-02 06:17:24 +03:00
|
|
|
(void) utimens(name, ctimep);
|
|
|
|
(void) utimens(name, mtimep);
|
2004-10-23 02:38:38 +04:00
|
|
|
if (Mtreefile) {
|
|
|
|
writemtree(name, "fifo",
|
|
|
|
uid, gid, mode, flags);
|
|
|
|
} else
|
|
|
|
(void) chflags(name, flags);
|
1994-05-17 08:13:48 +04:00
|
|
|
return (GOOD);
|
|
|
|
|
|
|
|
case IFREG:
|
|
|
|
vprintf(stdout, "extract file %s\n", name);
|
1998-06-24 23:56:11 +04:00
|
|
|
if (uflag)
|
|
|
|
(void) unlink(name);
|
2004-07-27 06:17:06 +04:00
|
|
|
if (!Nflag && (ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
|
1997-11-18 05:56:35 +03:00
|
|
|
0600)) < 0) {
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "%s: cannot create file: %s\n",
|
|
|
|
name, strerror(errno));
|
|
|
|
skipfile();
|
|
|
|
return (FAIL);
|
|
|
|
}
|
2004-07-27 06:17:06 +04:00
|
|
|
if (Dflag)
|
|
|
|
(*ddesc->dd_init)(&dcontext);
|
2022-12-12 19:53:30 +03:00
|
|
|
(void) fchown(ofile, uid, gid);
|
|
|
|
(void) fchmod(ofile, mode);
|
2021-06-19 16:56:34 +03:00
|
|
|
buf = setupextattr(extsize);
|
|
|
|
getfile(xtrfile, xtrattr, xtrskip);
|
|
|
|
if (extsize > 0)
|
|
|
|
set_extattr(ofile, name, buf, extsize, SXA_FD);
|
2004-07-27 06:17:06 +04:00
|
|
|
if (Dflag) {
|
2011-08-06 21:01:06 +04:00
|
|
|
(*ddesc->dd_end)(&dcontext, dbuffer);
|
2004-07-27 06:17:06 +04:00
|
|
|
for (ep = lookupname(name); ep != NULL;
|
|
|
|
ep = ep->e_links)
|
|
|
|
fprintf(stdout, "%s (%s) = %s\n",
|
|
|
|
ddesc->dd_name, myname(ep),
|
2011-08-06 21:01:06 +04:00
|
|
|
dbuffer);
|
2004-07-27 06:17:06 +04:00
|
|
|
}
|
|
|
|
if (Nflag)
|
|
|
|
return (GOOD);
|
2003-04-02 14:39:19 +04:00
|
|
|
if (setbirth)
|
2015-03-02 06:17:24 +03:00
|
|
|
(void) futimens(ofile, ctimep);
|
|
|
|
(void) futimens(ofile, mtimep);
|
2004-10-23 02:38:38 +04:00
|
|
|
if (Mtreefile) {
|
|
|
|
writemtree(name, "file",
|
|
|
|
uid, gid, mode, flags);
|
|
|
|
} else
|
|
|
|
(void) fchflags(ofile, flags);
|
1994-05-17 08:13:48 +04:00
|
|
|
(void) close(ofile);
|
|
|
|
return (GOOD);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2021-06-19 16:56:34 +03:00
|
|
|
/*
|
|
|
|
* Set attributes on a file descriptor, link, or file.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
set_extattr(int fd, char *name, void *buf, int size, enum set_extattr_mode mode)
|
|
|
|
{
|
|
|
|
struct extattr *eap, *eaend;
|
|
|
|
const char *method;
|
|
|
|
ssize_t res;
|
|
|
|
int error;
|
|
|
|
char eaname[EXTATTR_MAXNAMELEN + 1];
|
|
|
|
|
|
|
|
vprintf(stdout, "Set attributes for %s:", name);
|
|
|
|
eaend = (void *)((char *)buf + size);
|
|
|
|
for (eap = buf; eap < eaend; eap = EXTATTR_NEXT(eap)) {
|
|
|
|
/*
|
|
|
|
* Make sure this entry is complete.
|
|
|
|
*/
|
|
|
|
if (EXTATTR_NEXT(eap) > eaend || eap->ea_length <= 0) {
|
|
|
|
dprintf(stdout, "\n\t%scorrupted",
|
|
|
|
eap == buf ? "" : "remainder ");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eap->ea_namespace == EXTATTR_NAMESPACE_EMPTY)
|
|
|
|
continue;
|
|
|
|
snprintf(eaname, sizeof(eaname), "%.*s",
|
|
|
|
(int)eap->ea_namelength, eap->ea_name);
|
|
|
|
vprintf(stdout, "\n\t%s, (%d bytes), %s",
|
|
|
|
namespace_names[eap->ea_namespace], eap->ea_length,
|
|
|
|
eaname);
|
|
|
|
/*
|
|
|
|
* First we try the general attribute setting interface.
|
|
|
|
* However, some attributes can only be set by root or
|
|
|
|
* by using special interfaces (for example, ACLs).
|
|
|
|
*/
|
|
|
|
switch (mode) {
|
|
|
|
case SXA_FD:
|
|
|
|
res = extattr_set_fd(fd, eap->ea_namespace,
|
|
|
|
eaname, EXTATTR_CONTENT(eap),
|
|
|
|
EXTATTR_CONTENT_SIZE(eap));
|
|
|
|
method = "extattr_set_fd";
|
|
|
|
break;
|
|
|
|
case SXA_LINK:
|
|
|
|
res = extattr_set_link(name, eap->ea_namespace,
|
|
|
|
eaname, EXTATTR_CONTENT(eap),
|
|
|
|
EXTATTR_CONTENT_SIZE(eap));
|
|
|
|
method = "extattr_set_link";
|
|
|
|
break;
|
|
|
|
case SXA_FILE:
|
|
|
|
res = extattr_set_file(name, eap->ea_namespace,
|
|
|
|
eaname, EXTATTR_CONTENT(eap),
|
|
|
|
EXTATTR_CONTENT_SIZE(eap));
|
|
|
|
method = "extattr_set_file";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (res != -1) {
|
|
|
|
dprintf(stdout, " (set using %s)", method);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the general interface refuses to set the attribute,
|
|
|
|
* then we try all the specialized interfaces that we
|
|
|
|
* know about.
|
|
|
|
*/
|
|
|
|
if (eap->ea_namespace == EXTATTR_NAMESPACE_SYSTEM &&
|
|
|
|
strcmp(eaname, POSIX1E_ACL_ACCESS_EXTATTR_NAME) == 0) {
|
|
|
|
switch (mode) {
|
|
|
|
case SXA_FD:
|
|
|
|
error = acl_set_fd(fd, EXTATTR_CONTENT(eap));
|
|
|
|
method = "acl_set_fd";
|
|
|
|
break;
|
|
|
|
case SXA_LINK:
|
|
|
|
error = acl_set_link_np(name, ACL_TYPE_ACCESS,
|
|
|
|
EXTATTR_CONTENT(eap));
|
|
|
|
method = "acl_set_link_np";
|
|
|
|
break;
|
|
|
|
case SXA_FILE:
|
|
|
|
error = acl_set_file(name, ACL_TYPE_ACCESS,
|
|
|
|
EXTATTR_CONTENT(eap));
|
|
|
|
method = "acl_set_file";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (error != -1) {
|
|
|
|
dprintf(stdout, " (set using %s)", method);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eap->ea_namespace == EXTATTR_NAMESPACE_SYSTEM &&
|
|
|
|
strcmp(eaname, POSIX1E_ACL_DEFAULT_EXTATTR_NAME) == 0) {
|
|
|
|
switch (mode) {
|
|
|
|
case SXA_FD:
|
|
|
|
error = acl_set_fd(fd, EXTATTR_CONTENT(eap));
|
|
|
|
method = "acl_set_fd";
|
|
|
|
break;
|
|
|
|
case SXA_LINK:
|
|
|
|
error = acl_set_link_np(name, ACL_TYPE_DEFAULT,
|
|
|
|
EXTATTR_CONTENT(eap));
|
|
|
|
method = "acl_set_link_np";
|
|
|
|
break;
|
|
|
|
case SXA_FILE:
|
|
|
|
error = acl_set_file(name, ACL_TYPE_DEFAULT,
|
|
|
|
EXTATTR_CONTENT(eap));
|
|
|
|
method = "acl_set_file";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (error != -1) {
|
|
|
|
dprintf(stdout, " (set using %s)", method);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vprintf(stdout, " (unable to set)");
|
|
|
|
}
|
|
|
|
vprintf(stdout, "\n");
|
|
|
|
}
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* skip over bit maps on the tape
|
|
|
|
*/
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
skipmaps(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
|
|
|
|
skipfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* skip over a file on the tape
|
|
|
|
*/
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
skipfile(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
curfile.action = SKIP;
|
2021-06-19 16:56:34 +03:00
|
|
|
getfile(xtrnull, xtrnull, xtrnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip a hole in an output file
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
skiphole(void (*skip)(char *, size_t), volatile size_t *seekpos)
|
|
|
|
{
|
|
|
|
char buf[MAXBSIZE];
|
|
|
|
size_t s = *seekpos;
|
|
|
|
|
|
|
|
if (s > 0) {
|
|
|
|
(*skip)(buf, s);
|
|
|
|
*seekpos = 0;
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
|
2007-02-09 12:36:02 +03:00
|
|
|
/*
|
|
|
|
* Extract a bitmap from the tape.
|
|
|
|
* The first bitmap sets maxino;
|
|
|
|
* other bitmaps must be of same size.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
getbitmap(char **map)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t volatile size = spcl.c_size;
|
|
|
|
size_t volatile mapsize = size;
|
|
|
|
char *mapptr;
|
|
|
|
|
|
|
|
curfile.action = USING;
|
|
|
|
if (spcl.c_type == TS_END)
|
|
|
|
panic("ran off end of tape\n");
|
|
|
|
if (spcl.c_magic != FS_UFS2_MAGIC)
|
|
|
|
panic("not at beginning of a file\n");
|
|
|
|
if (!gettingfile && setjmp(restart) != 0)
|
|
|
|
return;
|
|
|
|
gettingfile++;
|
|
|
|
mapptr = *map = malloc(size);
|
|
|
|
loop:
|
|
|
|
if (*map == NULL)
|
|
|
|
panic("no memory for %s\n", curfile.name);
|
|
|
|
for (i = 0; i < spcl.c_count && size >= TP_BSIZE; i++) {
|
|
|
|
readtape(mapptr);
|
|
|
|
mapptr += TP_BSIZE;
|
|
|
|
size -= TP_BSIZE;
|
|
|
|
}
|
|
|
|
if (size != 0 || i != spcl.c_count)
|
|
|
|
panic("%s: inconsistent map size\n", curfile.name);
|
|
|
|
if (gethead(&spcl) == GOOD && spcl.c_type == TS_ADDR) {
|
|
|
|
size = spcl.c_count * TP_BSIZE;
|
|
|
|
*map = realloc(*map, mapsize + size);
|
|
|
|
mapptr = *map + mapsize;
|
|
|
|
mapsize += size;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
if (maxino == 0)
|
|
|
|
maxino = mapsize * NBBY + 1;
|
|
|
|
else if (maxino != mapsize * NBBY + 1)
|
|
|
|
panic("%s: map size changed\n", curfile.name);
|
|
|
|
findinode(&spcl);
|
|
|
|
gettingfile = 0;
|
|
|
|
}
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* Extract a file from the tape.
|
|
|
|
* When an allocated block is found it is passed to the fill function;
|
|
|
|
* when an unallocated block (hole) is found, a zeroed buffer is passed
|
|
|
|
* to the skip function.
|
|
|
|
*/
|
|
|
|
void
|
2021-06-19 16:56:34 +03:00
|
|
|
getfile(void (*datafill)(char *, size_t), void (*attrfill)(char *, size_t),
|
|
|
|
void (*skip)(char *, size_t))
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-03-19 11:42:51 +03:00
|
|
|
int i;
|
2021-06-19 16:56:34 +03:00
|
|
|
volatile off_t size;
|
|
|
|
volatile size_t seekpos;
|
|
|
|
volatile int curblk, attrsize;
|
|
|
|
void (*fillit)(char *, size_t);
|
1994-05-17 08:13:48 +04:00
|
|
|
char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
|
|
|
|
char junk[TP_BSIZE];
|
|
|
|
|
2006-12-18 23:07:32 +03:00
|
|
|
curblk = 0;
|
|
|
|
size = spcl.c_size;
|
2021-06-19 16:56:34 +03:00
|
|
|
seekpos = 0;
|
|
|
|
attrsize = spcl.c_extsize;
|
1997-09-15 12:04:28 +04:00
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
if (spcl.c_type == TS_END)
|
|
|
|
panic("ran off end of tape\n");
|
2003-04-02 14:39:19 +04:00
|
|
|
if (spcl.c_magic != FS_UFS2_MAGIC)
|
1994-05-17 08:13:48 +04:00
|
|
|
panic("not at beginning of a file\n");
|
|
|
|
if (!gettingfile && setjmp(restart) != 0)
|
|
|
|
return;
|
|
|
|
gettingfile++;
|
2021-06-19 16:56:34 +03:00
|
|
|
fillit = datafill;
|
|
|
|
if (size == 0 && attrsize > 0) {
|
|
|
|
fillit = attrfill;
|
|
|
|
size = attrsize;
|
|
|
|
attrsize = 0;
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
loop:
|
|
|
|
for (i = 0; i < spcl.c_count; i++) {
|
2007-02-09 12:36:02 +03:00
|
|
|
if (spcl.c_addr[i]) {
|
1994-05-17 08:13:48 +04:00
|
|
|
readtape(&buf[curblk++][0]);
|
2009-04-07 16:38:12 +04:00
|
|
|
if ((uint32_t)curblk == fssize / TP_BSIZE) {
|
2021-06-19 16:56:34 +03:00
|
|
|
skiphole(skip, &seekpos);
|
|
|
|
(*fillit)((char *)buf, (long)(size > TP_BSIZE ?
|
1997-09-16 17:44:12 +04:00
|
|
|
fssize : (curblk - 1) * TP_BSIZE + size));
|
1994-05-17 08:13:48 +04:00
|
|
|
curblk = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (curblk > 0) {
|
2021-06-19 16:56:34 +03:00
|
|
|
skiphole(skip, &seekpos);
|
|
|
|
(*fillit)((char *)buf, (long)(size > TP_BSIZE ?
|
1997-09-16 17:44:12 +04:00
|
|
|
curblk * TP_BSIZE :
|
|
|
|
(curblk - 1) * TP_BSIZE + size));
|
1994-05-17 08:13:48 +04:00
|
|
|
curblk = 0;
|
|
|
|
}
|
2021-06-19 16:56:34 +03:00
|
|
|
/*
|
|
|
|
* We have a block of a hole. Don't skip it
|
|
|
|
* now, because there may be next adjacent
|
|
|
|
* block of the hole in the file. Postpone the
|
|
|
|
* seek until next file write.
|
|
|
|
*/
|
|
|
|
seekpos += (long)MIN(TP_BSIZE, size);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
if ((size -= TP_BSIZE) <= 0) {
|
2021-06-19 16:56:34 +03:00
|
|
|
if (size > -TP_BSIZE && curblk > 0) {
|
|
|
|
skiphole(skip, &seekpos);
|
|
|
|
(*fillit)((char *)buf,
|
|
|
|
(long)((curblk * TP_BSIZE) + size));
|
|
|
|
curblk = 0;
|
|
|
|
}
|
|
|
|
if (attrsize > 0) {
|
|
|
|
fillit = attrfill;
|
|
|
|
size = attrsize;
|
|
|
|
attrsize = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (spcl.c_count - i > 1)
|
|
|
|
dprintf(stdout, "skipping %d junk block(s)\n",
|
|
|
|
spcl.c_count - i - 1);
|
2007-02-09 12:36:02 +03:00
|
|
|
for (i++; i < spcl.c_count; i++)
|
|
|
|
if (spcl.c_addr[i])
|
|
|
|
readtape(junk);
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gethead(&spcl) == GOOD && size > 0) {
|
|
|
|
if (spcl.c_type == TS_ADDR)
|
|
|
|
goto loop;
|
|
|
|
dprintf(stdout,
|
|
|
|
"Missing address (header) block for %s at %d blocks\n",
|
|
|
|
curfile.name, blksread);
|
|
|
|
}
|
|
|
|
if (curblk > 0)
|
2022-05-05 10:45:43 +03:00
|
|
|
panic("getfile: lost data: %s\n", curfile.name);
|
2008-12-26 22:26:04 +03:00
|
|
|
/* Skip over Linux extended attributes. */
|
|
|
|
if (spcl.c_type == TS_INODE && (spcl.c_flags & DR_EXTATTRIBUTES)) {
|
|
|
|
for (i = 0; i < spcl.c_count; i++)
|
|
|
|
readtape(junk);
|
|
|
|
(void)gethead(&spcl);
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
findinode(&spcl);
|
|
|
|
gettingfile = 0;
|
|
|
|
}
|
|
|
|
|
2021-06-19 16:56:34 +03:00
|
|
|
/*
|
|
|
|
* These variables are shared between the next two functions.
|
|
|
|
*/
|
|
|
|
static size_t extbufsize = 0;
|
|
|
|
static char *extbuf;
|
|
|
|
static size_t extloc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a buffer into which to extract extended attributes.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
setupextattr(size_t extsize)
|
|
|
|
{
|
|
|
|
|
|
|
|
extloc = 0;
|
|
|
|
if (extsize <= extbufsize)
|
|
|
|
return (extbuf);
|
|
|
|
if (extbufsize > 0)
|
|
|
|
free(extbuf);
|
|
|
|
if ((extbuf = malloc(extsize)) != NULL) {
|
|
|
|
extbufsize = extsize;
|
|
|
|
return (extbuf);
|
|
|
|
}
|
|
|
|
extbufsize = 0;
|
|
|
|
extbuf = NULL;
|
|
|
|
fprintf(stderr, "Cannot extract %zu bytes %s for inode %ju, name %s\n",
|
|
|
|
extsize, "of extended attributes", (uintmax_t)curfile.ino,
|
|
|
|
curfile.name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the next block of extended attributes.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
xtrattr(char *buf, size_t size)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (extloc + size > extbufsize)
|
|
|
|
panic("overrun attribute buffer\n");
|
|
|
|
memmove(&extbuf[extloc], buf, size);
|
|
|
|
extloc += size;
|
|
|
|
}
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* Write out the next block of a file.
|
|
|
|
*/
|
|
|
|
static void
|
2021-06-19 16:56:34 +03:00
|
|
|
xtrfile(char *buf, size_t size)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
2004-07-27 06:17:06 +04:00
|
|
|
if (Dflag)
|
|
|
|
(*ddesc->dd_update)(&dcontext, buf, size);
|
1994-05-17 08:13:48 +04:00
|
|
|
if (Nflag)
|
|
|
|
return;
|
|
|
|
if (write(ofile, buf, (int) size) == -1) {
|
|
|
|
fprintf(stderr,
|
2021-06-19 16:56:34 +03:00
|
|
|
"write error extracting inode %ju, name %s\nwrite: %s\n",
|
|
|
|
(uintmax_t)curfile.ino, curfile.name,
|
2005-08-19 06:07:18 +04:00
|
|
|
strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over a hole in a file.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
2021-06-19 16:56:34 +03:00
|
|
|
xtrskip(char *buf, size_t size)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
2004-07-27 06:17:06 +04:00
|
|
|
if (Dflag)
|
|
|
|
(*ddesc->dd_update)(&dcontext, buf, size);
|
|
|
|
if (Nflag)
|
|
|
|
return;
|
1994-05-17 08:13:48 +04:00
|
|
|
if (lseek(ofile, size, SEEK_CUR) == -1) {
|
|
|
|
fprintf(stderr,
|
2021-06-19 16:56:34 +03:00
|
|
|
"seek error extracting inode %ju, name %s\nlseek: %s\n",
|
|
|
|
(uintmax_t)curfile.ino, curfile.name,
|
2005-08-19 06:07:18 +04:00
|
|
|
strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect the next block of a symbolic link.
|
|
|
|
*/
|
|
|
|
static void
|
2021-06-19 16:56:34 +03:00
|
|
|
xtrlnkfile(char *buf, size_t size)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
pathlen += size;
|
|
|
|
if (pathlen > MAXPATHLEN) {
|
|
|
|
fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
|
|
|
|
curfile.name, lnkbuf, buf, pathlen);
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
(void) strcat(lnkbuf, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over a hole in a symbolic link (should never happen).
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
2021-06-19 16:56:34 +03:00
|
|
|
xtrlnkskip(char *buf __unused, size_t size __unused)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "unallocated block in symbolic link %s\n",
|
|
|
|
curfile.name);
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Noop, when an extraction function is not needed.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
2021-06-19 16:56:34 +03:00
|
|
|
xtrnull(char *buf __unused, size_t size __unused)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read TP_BSIZE blocks from the input.
|
|
|
|
* Handle read errors, and end of media.
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-17 18:00:33 +03:00
|
|
|
readtape(char *buf)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-09-15 12:04:28 +04:00
|
|
|
int rd, newvol, i;
|
1994-05-17 08:13:48 +04:00
|
|
|
int cnt, seek_failed;
|
|
|
|
|
|
|
|
if (blkcnt < numtrec) {
|
1997-09-16 17:44:12 +04:00
|
|
|
memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
|
1994-05-17 08:13:48 +04:00
|
|
|
blksread++;
|
|
|
|
tpblksread++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ntrec; i++)
|
|
|
|
((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
|
|
|
|
if (numtrec == 0)
|
|
|
|
numtrec = ntrec;
|
|
|
|
cnt = ntrec * TP_BSIZE;
|
|
|
|
rd = 0;
|
|
|
|
getmore:
|
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
|
|
|
i = rmtread(&tapebuf[rd], cnt);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
i = read(mt, &tapebuf[rd], cnt);
|
|
|
|
/*
|
|
|
|
* Check for mid-tape short read error.
|
|
|
|
* If found, skip rest of buffer and start with the next.
|
|
|
|
*/
|
|
|
|
if (!pipein && numtrec < ntrec && i > 0) {
|
|
|
|
dprintf(stdout, "mid-media short read error.\n");
|
|
|
|
numtrec = ntrec;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Handle partial block read.
|
|
|
|
*/
|
|
|
|
if (pipein && i == 0 && rd > 0)
|
|
|
|
i = rd;
|
|
|
|
else if (i > 0 && i != ntrec * TP_BSIZE) {
|
|
|
|
if (pipein) {
|
|
|
|
rd += i;
|
|
|
|
cnt -= i;
|
|
|
|
if (cnt > 0)
|
|
|
|
goto getmore;
|
|
|
|
i = rd;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Short read. Process the blocks read.
|
|
|
|
*/
|
|
|
|
if (i % TP_BSIZE != 0)
|
|
|
|
vprintf(stdout,
|
|
|
|
"partial block read: %d should be %d\n",
|
|
|
|
i, ntrec * TP_BSIZE);
|
|
|
|
numtrec = i / TP_BSIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Handle read error.
|
|
|
|
*/
|
|
|
|
if (i < 0) {
|
|
|
|
fprintf(stderr, "Tape read error while ");
|
|
|
|
switch (curfile.action) {
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "trying to set up tape\n");
|
|
|
|
break;
|
|
|
|
case UNKNOWN:
|
|
|
|
fprintf(stderr, "trying to resynchronize\n");
|
|
|
|
break;
|
|
|
|
case USING:
|
|
|
|
fprintf(stderr, "restoring %s\n", curfile.name);
|
|
|
|
break;
|
|
|
|
case SKIP:
|
2021-06-19 16:56:34 +03:00
|
|
|
fprintf(stderr, "skipping over inode %ju\n",
|
|
|
|
(uintmax_t)curfile.ino);
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!yflag && !reply("continue"))
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
i = ntrec * TP_BSIZE;
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(tapebuf, 0, i);
|
1994-05-17 08:13:48 +04:00
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
|
|
|
seek_failed = (rmtseek(i, 1) < 0);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
|
|
|
|
|
|
|
|
if (seek_failed) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"continuation failed: %s\n", strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Handle end of tape.
|
|
|
|
*/
|
|
|
|
if (i == 0) {
|
|
|
|
vprintf(stdout, "End-of-tape encountered\n");
|
|
|
|
if (!pipein) {
|
|
|
|
newvol = volno + 1;
|
|
|
|
volno = 0;
|
|
|
|
numtrec = 0;
|
|
|
|
getvol(newvol);
|
|
|
|
readtape(buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rd % TP_BSIZE != 0)
|
|
|
|
panic("partial block read: %d should be %d\n",
|
|
|
|
rd, ntrec * TP_BSIZE);
|
|
|
|
terminateinput();
|
1997-09-16 17:44:12 +04:00
|
|
|
memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
blkcnt = 0;
|
1997-09-16 17:44:12 +04:00
|
|
|
memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
|
1994-05-17 08:13:48 +04:00
|
|
|
blksread++;
|
|
|
|
tpblksread++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-02-17 18:00:33 +03:00
|
|
|
findtapeblksize(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-03-19 11:42:51 +03:00
|
|
|
long i;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ntrec; i++)
|
|
|
|
((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
|
|
|
|
blkcnt = 0;
|
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
|
|
|
i = rmtread(tapebuf, ntrec * TP_BSIZE);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
i = read(mt, tapebuf, ntrec * TP_BSIZE);
|
|
|
|
|
|
|
|
if (i <= 0) {
|
|
|
|
fprintf(stderr, "tape read error: %s\n", strerror(errno));
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
if (i % TP_BSIZE != 0) {
|
1997-09-15 12:04:28 +04:00
|
|
|
fprintf(stderr, "Tape block size (%ld) %s (%ld)\n",
|
|
|
|
(long)i, "is not a multiple of dump block size",
|
|
|
|
(long)TP_BSIZE);
|
1995-02-20 22:43:51 +03:00
|
|
|
exit(1);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
ntrec = i / TP_BSIZE;
|
|
|
|
numtrec = ntrec;
|
|
|
|
vprintf(stdout, "Tape block size is %d\n", ntrec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-17 18:00:33 +03:00
|
|
|
closemt(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (mt < 0)
|
|
|
|
return;
|
|
|
|
#ifdef RRESTORE
|
|
|
|
if (host)
|
|
|
|
rmtclose();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
(void) close(mt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the next block from the tape.
|
|
|
|
* Check to see if it is one of several vintage headers.
|
|
|
|
* If it is an old style header, convert it to a new style header.
|
|
|
|
* If it is not any valid header, return an error.
|
|
|
|
*/
|
|
|
|
static int
|
2005-02-17 18:00:33 +03:00
|
|
|
gethead(struct s_spcl *buf)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
union u_ospcl u_ospcl;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
if (!cvtflag) {
|
|
|
|
readtape((char *)buf);
|
2003-04-02 14:39:19 +04:00
|
|
|
if (buf->c_magic != NFS_MAGIC &&
|
|
|
|
buf->c_magic != FS_UFS2_MAGIC) {
|
|
|
|
if (bswap32(buf->c_magic) != NFS_MAGIC &&
|
|
|
|
bswap32(buf->c_magic) != FS_UFS2_MAGIC)
|
1994-05-17 08:13:48 +04:00
|
|
|
return (FAIL);
|
|
|
|
if (!Bcvt) {
|
|
|
|
vprintf(stdout, "Note: Doing Byte swapping\n");
|
|
|
|
Bcvt = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checksum((int *)buf) == FAIL)
|
|
|
|
return (FAIL);
|
|
|
|
if (Bcvt)
|
2003-04-02 14:39:19 +04:00
|
|
|
swap_header(buf);
|
1994-05-17 08:13:48 +04:00
|
|
|
goto good;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
readtape((char *)(&u_ospcl.s_ospcl));
|
2003-04-02 14:39:19 +04:00
|
|
|
if (checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
|
|
|
|
return (FAIL);
|
|
|
|
if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC) {
|
|
|
|
if (bswap32(u_ospcl.s_ospcl.c_magic) != OFS_MAGIC)
|
|
|
|
return (FAIL);
|
|
|
|
if (!Bcvt) {
|
|
|
|
vprintf(stdout, "Note: Doing Byte swapping\n");
|
|
|
|
Bcvt = 1;
|
|
|
|
}
|
|
|
|
swap_old_header(&u_ospcl.s_ospcl);
|
|
|
|
}
|
|
|
|
|
2009-02-18 16:13:27 +03:00
|
|
|
memset(buf, 0, TP_BSIZE);
|
1994-05-17 08:13:48 +04:00
|
|
|
buf->c_type = u_ospcl.s_ospcl.c_type;
|
|
|
|
buf->c_date = u_ospcl.s_ospcl.c_date;
|
|
|
|
buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
|
|
|
|
buf->c_volume = u_ospcl.s_ospcl.c_volume;
|
|
|
|
buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
|
|
|
|
buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
|
|
|
|
buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
|
2003-04-02 14:39:19 +04:00
|
|
|
buf->c_mode = u_ospcl.s_ospcl.c_odinode.odi_mode;
|
|
|
|
buf->c_uid = u_ospcl.s_ospcl.c_odinode.odi_uid;
|
|
|
|
buf->c_gid = u_ospcl.s_ospcl.c_odinode.odi_gid;
|
|
|
|
buf->c_size = u_ospcl.s_ospcl.c_odinode.odi_size;
|
|
|
|
buf->c_rdev = u_ospcl.s_ospcl.c_odinode.odi_rdev;
|
|
|
|
buf->c_atime = u_ospcl.s_ospcl.c_odinode.odi_atime;
|
|
|
|
buf->c_mtime = u_ospcl.s_ospcl.c_odinode.odi_mtime;
|
1994-05-17 08:13:48 +04:00
|
|
|
buf->c_count = u_ospcl.s_ospcl.c_count;
|
1997-09-16 17:44:12 +04:00
|
|
|
memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
|
2003-04-02 14:39:19 +04:00
|
|
|
buf->c_magic = FS_UFS2_MAGIC;
|
1994-05-17 08:13:48 +04:00
|
|
|
good:
|
|
|
|
switch (buf->c_type) {
|
|
|
|
|
|
|
|
case TS_CLRI:
|
|
|
|
case TS_BITS:
|
|
|
|
/*
|
|
|
|
* Have to patch up missing information in bit map headers
|
|
|
|
*/
|
|
|
|
buf->c_inumber = 0;
|
2003-04-02 14:39:19 +04:00
|
|
|
buf->c_size = buf->c_count * TP_BSIZE;
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_TAPE:
|
|
|
|
if ((buf->c_flags & DR_NEWINODEFMT) == 0)
|
|
|
|
oldinofmt = 1;
|
|
|
|
/* fall through */
|
|
|
|
case TS_END:
|
|
|
|
buf->c_inumber = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_INODE:
|
2003-04-02 14:39:19 +04:00
|
|
|
if (buf->c_magic == NFS_MAGIC) {
|
|
|
|
buf->c_tapea = buf->c_old_tapea;
|
|
|
|
buf->c_firstrec = buf->c_old_firstrec;
|
|
|
|
buf->c_date = buf->c_old_date;
|
|
|
|
buf->c_ddate = buf->c_old_ddate;
|
|
|
|
buf->c_atime = buf->c_old_atime;
|
|
|
|
buf->c_mtime = buf->c_old_mtime;
|
|
|
|
buf->c_birthtime = 0;
|
|
|
|
buf->c_birthtimensec = 0;
|
|
|
|
buf->c_atimensec = buf->c_mtimensec = 0;
|
2021-06-19 16:56:34 +03:00
|
|
|
buf->c_extsize = 0;
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
case TS_ADDR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("gethead: unknown inode type %d\n", buf->c_type);
|
|
|
|
break;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
|
|
|
|
buf->c_magic = FS_UFS2_MAGIC;
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* If we are restoring a filesystem with old format inodes,
|
|
|
|
* copy the uid/gid to the new location.
|
|
|
|
*/
|
|
|
|
if (oldinofmt) {
|
2003-04-02 14:39:19 +04:00
|
|
|
buf->c_uid = buf->c_spare1[1];
|
|
|
|
buf->c_gid = buf->c_spare1[2];
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
if (dflag)
|
|
|
|
accthdr(buf);
|
|
|
|
return(GOOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that a header is where it belongs and predict the next header
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-17 18:00:33 +03:00
|
|
|
accthdr(struct s_spcl *header)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
static ino_t previno = 0x7fffffff;
|
|
|
|
static int prevtype;
|
|
|
|
static long predict;
|
|
|
|
long blks, i;
|
|
|
|
|
|
|
|
if (header->c_type == TS_TAPE) {
|
|
|
|
fprintf(stderr, "Volume header (%s inode format) ",
|
|
|
|
oldinofmt ? "old" : "new");
|
|
|
|
if (header->c_firstrec)
|
2003-04-02 14:39:19 +04:00
|
|
|
fprintf(stderr, "begins with record %lld",
|
|
|
|
(long long)header->c_firstrec);
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
previno = 0x7fffffff;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (previno == 0x7fffffff)
|
|
|
|
goto newcalc;
|
|
|
|
switch (prevtype) {
|
|
|
|
case TS_BITS:
|
1994-12-28 05:21:43 +03:00
|
|
|
fprintf(stderr, "Dumped inodes map header");
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
case TS_CLRI:
|
1994-12-28 05:21:43 +03:00
|
|
|
fprintf(stderr, "Used inodes map header");
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
case TS_INODE:
|
2021-06-19 16:56:34 +03:00
|
|
|
fprintf(stderr, "File header, ino %ju",
|
|
|
|
(uintmax_t)previno);
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
case TS_ADDR:
|
2021-06-19 16:56:34 +03:00
|
|
|
fprintf(stderr, "File continuation header, ino %ju",
|
|
|
|
(uintmax_t)previno);
|
1994-05-17 08:13:48 +04:00
|
|
|
break;
|
|
|
|
case TS_END:
|
|
|
|
fprintf(stderr, "End of tape header");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (predict != blksread - 1)
|
1997-09-15 12:04:28 +04:00
|
|
|
fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
|
|
|
|
(long)predict, (long)(blksread - 1));
|
1994-05-17 08:13:48 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
newcalc:
|
|
|
|
blks = 0;
|
2000-05-19 13:22:55 +04:00
|
|
|
switch (header->c_type) {
|
|
|
|
case TS_END:
|
|
|
|
break;
|
|
|
|
case TS_CLRI:
|
|
|
|
case TS_BITS:
|
|
|
|
blks = header->c_count;
|
|
|
|
break;
|
|
|
|
default:
|
1994-05-17 08:13:48 +04:00
|
|
|
for (i = 0; i < header->c_count; i++)
|
|
|
|
if (header->c_addr[i] != 0)
|
|
|
|
blks++;
|
2000-05-19 13:22:55 +04:00
|
|
|
break;
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
predict = blks;
|
|
|
|
blksread = 0;
|
|
|
|
prevtype = header->c_type;
|
|
|
|
previno = header->c_inumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find an inode header.
|
|
|
|
* Complain if had to skip, and complain is set.
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-17 18:00:33 +03:00
|
|
|
findinode(struct s_spcl *header)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
|
|
|
static long skipcnt = 0;
|
|
|
|
long i;
|
|
|
|
char buf[TP_BSIZE];
|
|
|
|
|
|
|
|
curfile.name = "<name unknown>";
|
|
|
|
curfile.action = UNKNOWN;
|
2003-04-02 14:39:19 +04:00
|
|
|
curfile.mode = 0;
|
1994-05-17 08:13:48 +04:00
|
|
|
curfile.ino = 0;
|
2002-02-19 22:16:38 +03:00
|
|
|
top:
|
1994-05-17 08:13:48 +04:00
|
|
|
do {
|
2003-04-02 14:39:19 +04:00
|
|
|
if (header->c_magic != FS_UFS2_MAGIC) {
|
2020-09-03 22:31:34 +03:00
|
|
|
skip:
|
1994-05-17 08:13:48 +04:00
|
|
|
skipcnt++;
|
|
|
|
while (gethead(header) == FAIL ||
|
|
|
|
header->c_date != dumpdate)
|
|
|
|
skipcnt++;
|
|
|
|
}
|
|
|
|
switch (header->c_type) {
|
|
|
|
|
|
|
|
case TS_ADDR:
|
|
|
|
/*
|
|
|
|
* Skip up to the beginning of the next record
|
|
|
|
*/
|
|
|
|
for (i = 0; i < header->c_count; i++)
|
|
|
|
if (header->c_addr[i])
|
|
|
|
readtape(buf);
|
|
|
|
while (gethead(header) == FAIL ||
|
|
|
|
header->c_date != dumpdate)
|
|
|
|
skipcnt++;
|
2002-02-19 22:16:38 +03:00
|
|
|
/* We've read a header; don't drop it. */
|
|
|
|
goto top;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
case TS_INODE:
|
2003-04-02 14:39:19 +04:00
|
|
|
curfile.mode = header->c_mode;
|
|
|
|
curfile.uid = header->c_uid;
|
|
|
|
curfile.gid = header->c_gid;
|
|
|
|
curfile.file_flags = header->c_file_flags;
|
|
|
|
curfile.rdev = header->c_rdev;
|
|
|
|
curfile.atime_sec = header->c_atime;
|
|
|
|
curfile.atime_nsec = header->c_atimensec;
|
|
|
|
curfile.mtime_sec = header->c_mtime;
|
|
|
|
curfile.mtime_nsec = header->c_mtimensec;
|
|
|
|
curfile.birthtime_sec = header->c_birthtime;
|
|
|
|
curfile.birthtime_nsec = header->c_birthtimensec;
|
2021-06-19 16:56:34 +03:00
|
|
|
curfile.extsize = header->c_extsize;
|
2003-04-02 14:39:19 +04:00
|
|
|
curfile.size = header->c_size;
|
1994-05-17 08:13:48 +04:00
|
|
|
curfile.ino = header->c_inumber;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_END:
|
|
|
|
curfile.ino = maxino;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_CLRI:
|
|
|
|
curfile.name = "<file removal list>";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_BITS:
|
|
|
|
curfile.name = "<file dump list>";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_TAPE:
|
|
|
|
panic("unexpected tape header\n");
|
2001-01-25 02:14:04 +03:00
|
|
|
break;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
panic("unknown tape header type %d\n", spcl.c_type);
|
2021-03-11 04:13:11 +03:00
|
|
|
fprintf(stderr, "skipping to next header\n");
|
2020-09-03 22:31:34 +03:00
|
|
|
goto skip;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
} while (header->c_type == TS_ADDR);
|
|
|
|
if (skipcnt > 0)
|
1997-09-15 12:04:28 +04:00
|
|
|
fprintf(stderr, "resync restore, skipped %ld blocks\n",
|
|
|
|
(long)skipcnt);
|
1994-05-17 08:13:48 +04:00
|
|
|
skipcnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-02-17 18:00:33 +03:00
|
|
|
checksum(int *buf)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-03-19 11:42:51 +03:00
|
|
|
int i, j;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
j = sizeof(union u_spcl) / sizeof(int);
|
|
|
|
i = 0;
|
|
|
|
if(!Bcvt) {
|
|
|
|
do
|
|
|
|
i += *buf++;
|
|
|
|
while (--j);
|
|
|
|
} else {
|
|
|
|
do
|
2003-04-02 14:39:19 +04:00
|
|
|
i += bswap32(*buf++);
|
1994-05-17 08:13:48 +04:00
|
|
|
while (--j);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != CHECKSUM) {
|
2021-06-19 16:56:34 +03:00
|
|
|
fprintf(stderr, "Checksum error %o, inode %ju file %s\n", i,
|
|
|
|
(uintmax_t)curfile.ino, curfile.name);
|
1994-05-17 08:13:48 +04:00
|
|
|
return(FAIL);
|
|
|
|
}
|
|
|
|
return(GOOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RRESTORE
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
msg(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2002-05-26 03:45:12 +04:00
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
#endif /* RRESTORE */
|
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
static void
|
|
|
|
swap_header(struct s_spcl *s)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
s->c_type = bswap32(s->c_type);
|
|
|
|
s->c_old_date = bswap32(s->c_old_date);
|
|
|
|
s->c_old_ddate = bswap32(s->c_old_ddate);
|
|
|
|
s->c_volume = bswap32(s->c_volume);
|
|
|
|
s->c_old_tapea = bswap32(s->c_old_tapea);
|
|
|
|
s->c_inumber = bswap32(s->c_inumber);
|
|
|
|
s->c_magic = bswap32(s->c_magic);
|
|
|
|
s->c_checksum = bswap32(s->c_checksum);
|
|
|
|
|
|
|
|
s->c_mode = bswap16(s->c_mode);
|
2021-06-19 16:56:34 +03:00
|
|
|
s->c_extsize = bswap64(s->c_extsize);
|
2003-04-02 14:39:19 +04:00
|
|
|
s->c_size = bswap64(s->c_size);
|
|
|
|
s->c_old_atime = bswap32(s->c_old_atime);
|
|
|
|
s->c_atimensec = bswap32(s->c_atimensec);
|
|
|
|
s->c_old_mtime = bswap32(s->c_old_mtime);
|
|
|
|
s->c_mtimensec = bswap32(s->c_mtimensec);
|
|
|
|
s->c_rdev = bswap32(s->c_rdev);
|
|
|
|
s->c_birthtimensec = bswap32(s->c_birthtimensec);
|
|
|
|
s->c_birthtime = bswap64(s->c_birthtime);
|
|
|
|
s->c_atime = bswap64(s->c_atime);
|
|
|
|
s->c_mtime = bswap64(s->c_mtime);
|
|
|
|
s->c_file_flags = bswap32(s->c_file_flags);
|
|
|
|
s->c_uid = bswap32(s->c_uid);
|
|
|
|
s->c_gid = bswap32(s->c_gid);
|
|
|
|
|
|
|
|
s->c_count = bswap32(s->c_count);
|
|
|
|
s->c_level = bswap32(s->c_level);
|
|
|
|
s->c_flags = bswap32(s->c_flags);
|
|
|
|
s->c_old_firstrec = bswap32(s->c_old_firstrec);
|
|
|
|
|
|
|
|
s->c_date = bswap64(s->c_date);
|
|
|
|
s->c_ddate = bswap64(s->c_ddate);
|
|
|
|
s->c_tapea = bswap64(s->c_tapea);
|
|
|
|
s->c_firstrec = bswap64(s->c_firstrec);
|
1994-05-17 08:13:48 +04:00
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
/*
|
|
|
|
* These are ouid and ogid.
|
|
|
|
*/
|
|
|
|
s->c_spare1[1] = bswap16(s->c_spare1[1]);
|
|
|
|
s->c_spare1[2] = bswap16(s->c_spare1[2]);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
static void
|
|
|
|
swap_old_header(struct s_ospcl *os)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
os->c_type = bswap32(os->c_type);
|
|
|
|
os->c_date = bswap32(os->c_date);
|
|
|
|
os->c_ddate = bswap32(os->c_ddate);
|
|
|
|
os->c_volume = bswap32(os->c_volume);
|
|
|
|
os->c_tapea = bswap32(os->c_tapea);
|
|
|
|
os->c_inumber = bswap16(os->c_inumber);
|
|
|
|
os->c_magic = bswap32(os->c_magic);
|
|
|
|
os->c_checksum = bswap32(os->c_checksum);
|
|
|
|
|
|
|
|
os->c_odinode.odi_mode = bswap16(os->c_odinode.odi_mode);
|
|
|
|
os->c_odinode.odi_nlink = bswap16(os->c_odinode.odi_nlink);
|
|
|
|
os->c_odinode.odi_uid = bswap16(os->c_odinode.odi_uid);
|
|
|
|
os->c_odinode.odi_gid = bswap16(os->c_odinode.odi_gid);
|
|
|
|
|
|
|
|
os->c_odinode.odi_size = bswap32(os->c_odinode.odi_size);
|
|
|
|
os->c_odinode.odi_rdev = bswap32(os->c_odinode.odi_rdev);
|
|
|
|
os->c_odinode.odi_atime = bswap32(os->c_odinode.odi_atime);
|
|
|
|
os->c_odinode.odi_mtime = bswap32(os->c_odinode.odi_mtime);
|
|
|
|
os->c_odinode.odi_ctime = bswap32(os->c_odinode.odi_ctime);
|
|
|
|
|
|
|
|
os->c_count = bswap32(os->c_count);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|