Init
This commit is contained in:
58
etc/dump/Makefile
Normal file
58
etc/dump/Makefile
Normal file
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# Copyright (c) 1980 Regents of the University of California.
|
||||
# All rights reserved. The Berkeley software License Agreement
|
||||
# specifies the terms and conditions for redistribution.
|
||||
#
|
||||
# @(#)Makefile 1.1 92/07/30 SMI; from UCB 5.4 5/28/86
|
||||
#
|
||||
# dump.h header file
|
||||
# dumpitime.c reads /etc/dumpdates
|
||||
# dumpmain.c driver
|
||||
# dumpoptr.c operator interface
|
||||
# dumptape.c handles the mag tape and opening/closing
|
||||
# dumptraverse.c traverses the file system
|
||||
# lftw.c fixed version of ftw(3)
|
||||
# partial.c partial filesystem dump support
|
||||
# unctime.c undo ctime
|
||||
#
|
||||
# CPPFLAGS:
|
||||
# DEBUG use local directory to find ddate and dumpdates
|
||||
# PARTIAL enable partial filesystem dump support
|
||||
# TDEBUG trace out the process forking
|
||||
#
|
||||
BINS= dump
|
||||
PARTOBJ= partial.o lftw.o
|
||||
OBJS= dumpitime.o dumpmain.o dumpoptr.o dumprmt.o dumptape.o \
|
||||
dumptraverse.o unctime.o $(PARTOBJ)
|
||||
SRCS= $(OBJS:.o=.c)
|
||||
HDRS= dump.h
|
||||
|
||||
FLAGS= -DPARTIAL
|
||||
OPTIM= -O
|
||||
CFLAGS= $(FLAGS) $(OPTIM)
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
.INIT: $(HDRS)
|
||||
|
||||
all: $(BINS)
|
||||
|
||||
$(BINS): $(OBJS)
|
||||
$(LINK.c) -o $@ $(OBJS)
|
||||
|
||||
install: $(BINS)
|
||||
install -d $(DESTDIR)/usr/etc
|
||||
install -s -m 6755 -g tty $(BINS) $(DESTDIR)/usr/etc
|
||||
$(RM) $(DESTDIR)/usr/etc/rdump
|
||||
ln -s dump $(DESTDIR)/usr/etc/rdump
|
||||
install -d $(DESTDIR)/etc
|
||||
install -m 664 -g operator /dev/null $(DESTDIR)/etc/dumpdates
|
||||
|
||||
clean:
|
||||
$(RM) $(BINS) $(OBJS)
|
||||
|
||||
lint: $(SRCS)
|
||||
$(LINT.c) $(SRCS)
|
||||
|
||||
print: $(HDRS) $(SRCS)
|
||||
pr /usr/include/protocols/dumprestore.h $(HDRS) $(SRCS) | lpr
|
||||
162
etc/dump/dump.h
Normal file
162
etc/dump/dump.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/* @(#)dump.h 1.1 92/07/30 SMI; from UCB 5.2 5/28/86 */
|
||||
|
||||
#define NI 16
|
||||
#define MAXINOPB (MAXBSIZE / sizeof(struct dinode))
|
||||
#define MAXNINDIR (MAXBSIZE / sizeof(daddr_t))
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/wait.h>
|
||||
#include <ufs/inode.h>
|
||||
#include <ufs/fs.h>
|
||||
#include <protocols/dumprestore.h>
|
||||
#include <ufs/fsdir.h>
|
||||
#include <utmp.h>
|
||||
#include <signal.h>
|
||||
#include <fstab.h>
|
||||
|
||||
#define MWORD(m,i) (m[(unsigned)(i-1)/NBBY])
|
||||
#define MBIT(i) (1<<((unsigned)(i-1)%NBBY))
|
||||
#define BIS(i,w) (MWORD(w,i) |= MBIT(i))
|
||||
#define BIC(i,w) (MWORD(w,i) &= ~MBIT(i))
|
||||
#define BIT(i,w) (MWORD(w,i) & MBIT(i))
|
||||
|
||||
u_int msiz;
|
||||
char *clrmap;
|
||||
char *dirmap;
|
||||
char *nodmap;
|
||||
|
||||
/*
|
||||
* All calculations done in 0.1" units!
|
||||
*/
|
||||
|
||||
char *disk; /* name of the disk file */
|
||||
char *tape; /* name of the tape file */
|
||||
char *increm; /* name of the file containing incremental information*/
|
||||
char *temp; /* name of the file for doing rewrite of increm */
|
||||
char lastincno; /* increment number of previous dump */
|
||||
char incno; /* increment number */
|
||||
int uflag; /* update flag */
|
||||
int fi; /* disk file descriptor */
|
||||
int to; /* tape file descriptor */
|
||||
int pipeout; /* true => output to standard output */
|
||||
ino_t ino; /* current inumber; used globally */
|
||||
int nsubdir;
|
||||
int newtape; /* new tape flag */
|
||||
int nadded; /* number of added sub directories */
|
||||
int dadded; /* directory added flag */
|
||||
int density; /* density in 0.1" units */
|
||||
long tsize; /* tape size in 0.1" units */
|
||||
long esize; /* estimated tape size, blocks */
|
||||
long asize; /* number of 0.1" units written on current tape */
|
||||
int etapes; /* estimated number of tapes */
|
||||
|
||||
int verify; /* verify each volume */
|
||||
int doingverify; /* true => doing a verify pass */
|
||||
int archive; /* true => saving a archive in archivefile */
|
||||
char *archivefile; /* name of archivefile */
|
||||
int notify; /* notify operator flag */
|
||||
int writing_eom; /* true if writing end of media record */
|
||||
int diskette; /* true if dumping to a diskette */
|
||||
|
||||
int blockswritten; /* number of blocks written on current tape */
|
||||
int tapeno; /* current tape number */
|
||||
time_t telapsed; /* time spent writing previous tapes */
|
||||
time_t tstart_writing; /* when we started writing the latest tape */
|
||||
struct fs *sblock; /* the file system super block */
|
||||
char buf[MAXBSIZE];
|
||||
|
||||
time_t time();
|
||||
char *malloc(), *calloc();
|
||||
char *ctime();
|
||||
char *prdate();
|
||||
long atol();
|
||||
int mark();
|
||||
int add();
|
||||
int dirdump();
|
||||
int dump();
|
||||
int tapsrec();
|
||||
int dmpspc();
|
||||
int dsrch();
|
||||
int nullf();
|
||||
char *getsuffix();
|
||||
char *rawname();
|
||||
struct dinode *getino();
|
||||
|
||||
void interrupt(); /* in case operator bangs on console */
|
||||
void dumpabort();
|
||||
|
||||
#define HOUR (60L*60L)
|
||||
#define DAY (24L*HOUR)
|
||||
#define YEAR (365L*DAY)
|
||||
|
||||
/*
|
||||
* Exit status codes
|
||||
*/
|
||||
#define X_FINOK 0 /* normal exit */
|
||||
#define X_REWRITE 2 /* restart writing from the check point */
|
||||
#define X_ABORT 3 /* abort all of dump; don't attempt checkpointing */
|
||||
#define X_VERIFY 4 /* verify the reel just written */
|
||||
|
||||
#define NINCREM "/etc/dumpdates" /*new format incremental info*/
|
||||
#define TEMP "/etc/dtmp" /*output temp file*/
|
||||
|
||||
#define TAPE "/dev/rmt8" /* default tape device */
|
||||
#define RTAPE "dumphost:/dev/rmt8" /* default tape device */
|
||||
#define OPGRENT "operator" /* group entry to notify */
|
||||
#define DIALUP "ttyd" /* prefix for dialups */
|
||||
|
||||
/*
|
||||
* diskette size == sides * sectors per cylinder side * cylinders * sector size
|
||||
*/
|
||||
#ifdef i386
|
||||
/* 1 cylinder is reserved for bad block information */
|
||||
#define DISKETTE_DSIZE (2*18*(80-1)*512)
|
||||
#else i386
|
||||
#define DISKETTE_DSIZE (2*18*(80)*512)
|
||||
#endif i386
|
||||
#define DISKETTE "/dev/rfd0c"
|
||||
|
||||
|
||||
struct fstab *fstabsearch(); /* search in fs_file and fs_spec */
|
||||
|
||||
/*
|
||||
* The contents of the file NINCREM is maintained both on
|
||||
* a linked list, and then (eventually) arrayified.
|
||||
*/
|
||||
struct idates {
|
||||
char id_name[MAXNAMLEN+3];
|
||||
char id_incno;
|
||||
time_t id_ddate;
|
||||
};
|
||||
|
||||
struct itime{
|
||||
struct idates it_value;
|
||||
struct itime *it_next;
|
||||
};
|
||||
|
||||
struct itime *ithead; /* head of the list version */
|
||||
int nidates; /* number of records (might be zero) */
|
||||
int idates_in; /* we have read the increment file */
|
||||
struct idates **idatev; /* the arrayfied version */
|
||||
#define ITITERATE(i, ip) for (i = 0,ip = idatev[0]; i < nidates; i++, ip = idatev[i])
|
||||
|
||||
/*
|
||||
* We catch these interrupts
|
||||
*/
|
||||
void sighup();
|
||||
void sigquit();
|
||||
void sigill();
|
||||
void sigtrap();
|
||||
void sigfpe();
|
||||
void sigkill();
|
||||
void sigbus();
|
||||
void sigsegv();
|
||||
void sigsys();
|
||||
void sigalrm();
|
||||
void sigterm();
|
||||
280
etc/dump/dumpitime.c
Normal file
280
etc/dump/dumpitime.c
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (c) 1980 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumpitime.c 1.1 92/07/30 SMI"; /* from UCB 5.2 5/28/86 */
|
||||
#endif not lint
|
||||
|
||||
#include "dump.h"
|
||||
#include <errno.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
char *prdate(d)
|
||||
time_t d;
|
||||
{
|
||||
char *p;
|
||||
|
||||
if(d == 0)
|
||||
return ("the epoch");
|
||||
p = ctime(&d);
|
||||
p[24] = 0;
|
||||
return (p);
|
||||
}
|
||||
|
||||
struct idates **idatev = 0;
|
||||
int nidates = 0;
|
||||
int idates_in = 0;
|
||||
struct itime *ithead = 0;
|
||||
|
||||
inititimes()
|
||||
{
|
||||
FILE *df;
|
||||
extern int errno;
|
||||
|
||||
if ((df = fopen(increm, "r")) == NULL) {
|
||||
if (errno == ENOENT)
|
||||
msg("warning - no %s file\n", increm);
|
||||
else {
|
||||
perror(increm);
|
||||
dumpabort();
|
||||
}
|
||||
return;
|
||||
}
|
||||
(void) flock(fileno(df), LOCK_SH);
|
||||
readitimes(df);
|
||||
fclose(df);
|
||||
}
|
||||
|
||||
readitimes(df)
|
||||
FILE *df;
|
||||
{
|
||||
register int i;
|
||||
register struct itime *itwalk;
|
||||
|
||||
for (;;) {
|
||||
itwalk = (struct itime *)calloc(1, sizeof (struct itime));
|
||||
if (getrecord(df, &(itwalk->it_value)) < 0)
|
||||
break;
|
||||
nidates++;
|
||||
itwalk->it_next = ithead;
|
||||
ithead = itwalk;
|
||||
}
|
||||
|
||||
idates_in = 1;
|
||||
/*
|
||||
* arrayify the list, leaving enough room for the additional
|
||||
* record that we may have to add to the idate structure
|
||||
*/
|
||||
idatev = (struct idates **)calloc((u_int)nidates + 1,
|
||||
sizeof (struct idates *));
|
||||
itwalk = ithead;
|
||||
for (i = nidates - 1; i >= 0; i--, itwalk = itwalk->it_next)
|
||||
idatev[i] = &itwalk->it_value;
|
||||
}
|
||||
|
||||
getitime()
|
||||
{
|
||||
register struct idates *ip;
|
||||
register int i;
|
||||
char *fname;
|
||||
|
||||
fname = disk;
|
||||
#ifdef FDEBUG
|
||||
msg("Looking for name %s in increm = %s for delta = %c\n",
|
||||
fname, increm, incno);
|
||||
#endif
|
||||
spcl.c_ddate = 0;
|
||||
lastincno = '0';
|
||||
|
||||
inititimes();
|
||||
if (idatev == 0)
|
||||
return;
|
||||
/*
|
||||
* Go find the entry with the same name for a lower increment
|
||||
* and older date
|
||||
*/
|
||||
ITITERATE(i, ip) {
|
||||
if (strncmp(fname, ip->id_name, sizeof (ip->id_name)) != 0)
|
||||
continue;
|
||||
if (ip->id_incno >= incno)
|
||||
continue;
|
||||
if (ip->id_ddate <= spcl.c_ddate)
|
||||
continue;
|
||||
spcl.c_ddate = ip->id_ddate;
|
||||
lastincno = ip->id_incno;
|
||||
}
|
||||
}
|
||||
|
||||
putitime()
|
||||
{
|
||||
FILE *df;
|
||||
register struct idates *itwalk;
|
||||
register int i;
|
||||
int fd;
|
||||
char *fname;
|
||||
|
||||
if(uflag == 0)
|
||||
return;
|
||||
if ((df = fopen(increm, "r+")) == NULL) {
|
||||
fd = open(increm, O_RDWR | O_CREAT, 0664);
|
||||
if (fd == -1) {
|
||||
perror(increm);
|
||||
dumpabort();
|
||||
}
|
||||
df = fdopen(fd, "r+");
|
||||
if (df == NULL) {
|
||||
perror(increm);
|
||||
dumpabort();
|
||||
}
|
||||
msg("creating %s\n", increm);
|
||||
}
|
||||
fd = fileno(df);
|
||||
(void) flock(fd, LOCK_EX);
|
||||
fname = disk;
|
||||
if (idatev != 0)
|
||||
free((char *)idatev);
|
||||
idatev = 0;
|
||||
nidates = 0;
|
||||
ithead = 0;
|
||||
idates_in = 0;
|
||||
readitimes(df);
|
||||
if (fseek(df,0L,0) < 0) { /* rewind() was redefined in dumptape.c */
|
||||
perror("fseek");
|
||||
dumpabort();
|
||||
}
|
||||
spcl.c_ddate = 0;
|
||||
ITITERATE(i, itwalk){
|
||||
if (strncmp(fname, itwalk->id_name,
|
||||
sizeof (itwalk->id_name)) != 0)
|
||||
continue;
|
||||
if (itwalk->id_incno != incno)
|
||||
continue;
|
||||
goto found;
|
||||
}
|
||||
/*
|
||||
* construct the new upper bound;
|
||||
* Enough room has been allocated.
|
||||
*/
|
||||
itwalk = idatev[nidates] =
|
||||
(struct idates *)calloc(1, sizeof(struct idates));
|
||||
nidates += 1;
|
||||
found:
|
||||
strncpy(itwalk->id_name, fname, sizeof (itwalk->id_name));
|
||||
itwalk->id_incno = incno;
|
||||
itwalk->id_ddate = spcl.c_date;
|
||||
|
||||
ITITERATE(i, itwalk){
|
||||
recout(df, itwalk);
|
||||
}
|
||||
if (ftruncate(fd, ftell(df))) {
|
||||
perror("ftruncate");
|
||||
dumpabort();
|
||||
}
|
||||
(void) fclose(df);
|
||||
msg("level %c dump on %s\n", incno, prdate(spcl.c_date));
|
||||
}
|
||||
|
||||
recout(file, what)
|
||||
FILE *file;
|
||||
struct idates *what;
|
||||
{
|
||||
fprintf(file, DUMPOUTFMT,
|
||||
what->id_name,
|
||||
what->id_incno,
|
||||
ctime(&(what->id_ddate))
|
||||
);
|
||||
}
|
||||
|
||||
int recno;
|
||||
int getrecord(df, idatep)
|
||||
FILE *df;
|
||||
struct idates *idatep;
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
|
||||
recno = 0;
|
||||
if ( (fgets(buf, BUFSIZ, df)) != buf)
|
||||
return (-1);
|
||||
recno++;
|
||||
if (makeidate(idatep, buf) < 0)
|
||||
msg("Unknown intermediate format in %s, line %d\n",
|
||||
increm, recno);
|
||||
|
||||
#ifdef FDEBUG
|
||||
msg("getrecord: %s %c %s\n",
|
||||
idatep->id_name, idatep->id_incno, prdate(idatep->id_ddate));
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
time_t unctime();
|
||||
|
||||
int makeidate(ip, buf)
|
||||
struct idates *ip;
|
||||
char *buf;
|
||||
{
|
||||
char un_buf[128];
|
||||
|
||||
sscanf(buf, DUMPINFMT, ip->id_name, &ip->id_incno, un_buf);
|
||||
ip->id_ddate = unctime(un_buf);
|
||||
if (ip->id_ddate < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an estimation of the number of TP_BSIZE blocks in the file.
|
||||
* It estimates the number of blocks in files with holes by assuming
|
||||
* that all of the blocks accounted for by di_blocks are data blocks
|
||||
* (when some of the blocks are usually used for indirect pointers);
|
||||
* hence the estimate may be high.
|
||||
*/
|
||||
est(ip)
|
||||
struct dinode *ip;
|
||||
{
|
||||
long s, t;
|
||||
|
||||
/*
|
||||
* ip->di_size is the size of the file in bytes.
|
||||
* ip->di_blocks stores the number of sectors actually in the file.
|
||||
* If there are more sectors than the size would indicate, this just
|
||||
* means that there are indirect blocks in the file or unused
|
||||
* sectors in the last file block; we can safely ignore these
|
||||
* (s = t below).
|
||||
* If the file is bigger than the number of sectors would indicate,
|
||||
* then the file has holes in it. In this case we must use the
|
||||
* block count to estimate the number of data blocks used, but
|
||||
* we use the actual size for estimating the number of indirect
|
||||
* dump blocks (t vs. s in the indirect block calculation).
|
||||
*/
|
||||
esize++;
|
||||
s = howmany(dbtob(ip->di_blocks), TP_BSIZE);
|
||||
t = howmany(ip->di_size, TP_BSIZE);
|
||||
if ( s > t )
|
||||
s = t;
|
||||
if (ip->di_size > sblock->fs_bsize * NDADDR) {
|
||||
/* calculate the number of indirect blocks on the dump tape */
|
||||
s += howmany(t - NDADDR * sblock->fs_bsize / TP_BSIZE,
|
||||
TP_NINDIR);
|
||||
}
|
||||
esize += s;
|
||||
}
|
||||
|
||||
bmapest(map)
|
||||
char *map;
|
||||
{
|
||||
register i, n;
|
||||
|
||||
n = -1;
|
||||
for (i = 0; i < msiz; i++)
|
||||
if(map[i])
|
||||
n = i;
|
||||
if(n < 0)
|
||||
return;
|
||||
n++;
|
||||
esize++;
|
||||
esize += howmany(n * sizeof map[0], TP_BSIZE);
|
||||
}
|
||||
520
etc/dump/dumpmain.c
Normal file
520
etc/dump/dumpmain.c
Normal file
@@ -0,0 +1,520 @@
|
||||
/*
|
||||
* Copyright (c) 1980 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumpmain.c 1.1 92/07/30 SMI"; /* from UCB 5.5 10/21/86 */
|
||||
#endif not lint
|
||||
|
||||
#include "dump.h"
|
||||
#include <sys/label.h>
|
||||
#include <sys/audit.h>
|
||||
|
||||
int notify = 0; /* notify operator flag */
|
||||
int blockswritten = 0; /* number of blocks written on current tape */
|
||||
int tapeno = 0; /* current tape number */
|
||||
int density = 0; /* density in bytes/0.1" */
|
||||
int tenthsperirg; /* inter-record-gap in 0.1"'s */
|
||||
int ntrec = 0; /* # tape blocks in each tape record */
|
||||
int cartridge = 0; /* assume non-cartridge tape */
|
||||
int tracks; /* # tracks on a cartridge tape */
|
||||
int diskette = 0; /* assume not dumping to a diskette */
|
||||
char *host;
|
||||
char *mb();
|
||||
char *index(), *rindex();
|
||||
int anydskipped; /* set true in mark() if any directories are skipped */
|
||||
/* this lets us avoid map pass 2 in some cases */
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *arg;
|
||||
int bflag = 0, i, error = 0;
|
||||
float fetapes;
|
||||
register struct fstab *dt;
|
||||
|
||||
/*
|
||||
* Put out an audit message to reflect the parameters passed
|
||||
*/
|
||||
audit_args(AU_ADMIN, argc, argv);
|
||||
time(&(spcl.c_date));
|
||||
|
||||
tsize = 0; /* Default later, based on 'c' option for cart tapes */
|
||||
writing_eom = 0;
|
||||
if (arg = rindex(argv[0], '/'))
|
||||
arg++;
|
||||
else
|
||||
arg = argv[0];
|
||||
if (*arg == 'r')
|
||||
tape = RTAPE;
|
||||
else
|
||||
tape = TAPE;
|
||||
disk = NULL;
|
||||
increm = NINCREM;
|
||||
temp = TEMP;
|
||||
if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) {
|
||||
msg("TP_BSIZE must be a multiple of DEV_BSIZE\n");
|
||||
dumpabort();
|
||||
}
|
||||
incno = '9';
|
||||
uflag = 0;
|
||||
arg = "u";
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
arg = *argv;
|
||||
if (*arg == '-')
|
||||
argc++;
|
||||
}
|
||||
while(*arg)
|
||||
switch (*arg++) {
|
||||
case 'w':
|
||||
lastdump('w'); /* tell us only what has to be done */
|
||||
exit(0);
|
||||
break;
|
||||
case 'W': /* what to do */
|
||||
lastdump('W'); /* tell us the current state of what has been done */
|
||||
exit(0); /* do nothing else */
|
||||
break;
|
||||
|
||||
case 'f': /* output file */
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
tape = *argv;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd': /* density, in bits per inch */
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
density = atoi(*argv) / 10;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's': /* tape size, feet */
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
tsize = atol(*argv);
|
||||
}
|
||||
break;
|
||||
|
||||
case 't': /* tracks */
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
tracks = atol(*argv);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'b': /* blocks per tape write */
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
bflag++;
|
||||
ntrec = atol(*argv);
|
||||
if (ntrec <= 0 || (ntrec&1)) {
|
||||
msg("Block size must be a positive, even integer\n");
|
||||
dumpabort();
|
||||
}
|
||||
ntrec /= 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c': /* Tape is cart. not 9-track */
|
||||
case 'C': /* 'C' to be consistent with 'D' */
|
||||
cartridge++;
|
||||
break;
|
||||
|
||||
case '0': /* dump level */
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
incno = arg[-1];
|
||||
break;
|
||||
|
||||
case 'u': /* update /etc/dumpdates */
|
||||
uflag++;
|
||||
break;
|
||||
|
||||
case 'n': /* notify operators */
|
||||
notify++;
|
||||
break;
|
||||
|
||||
case 'a': /* create archive file */
|
||||
archive = 1;
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
archivefile = *argv;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verify++;
|
||||
doingverify++;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
diskette++;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "dump: bad key '%c%'\n", arg[-1]);
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
if (argc > 1) {
|
||||
argv++;
|
||||
argc--;
|
||||
disk = *argv;
|
||||
}
|
||||
if (strcmp(tape, "-") == 0) {
|
||||
pipeout++;
|
||||
tape = "standard output";
|
||||
}
|
||||
if (disk == NULL) {
|
||||
fprintf(stderr,
|
||||
"Usage: dump [0123456789fustdWwnDCcb [argument]] filesystem\n");
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
if (cartridge && diskette) {
|
||||
error = 1;
|
||||
fprintf(stderr,
|
||||
"dump: cannot select both cartridge and diskette\n");
|
||||
}
|
||||
if (density && diskette) {
|
||||
error = 1;
|
||||
fprintf(stderr,
|
||||
"dump: cannot select density of diskette\n");
|
||||
}
|
||||
if (tracks && diskette) {
|
||||
error = 1;
|
||||
fprintf(stderr,
|
||||
"dump: cannot select number of tracks of diskette\n");
|
||||
}
|
||||
if (error) {
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine how to default tape size and density
|
||||
*
|
||||
* density tape size
|
||||
* 9-track 1600 bpi (160 bytes/.1") 2300 ft.
|
||||
* 9-track 6250 bpi (625 bytes/.1") 2300 ft.
|
||||
*
|
||||
* Most Sun-2's came with 4 track (20MB) cartridge tape drives,
|
||||
* while most other machines (Sun-3's and non-Sun's) come with
|
||||
* 9 track (45MB) cartridge tape drives. Some Sun-2's came with
|
||||
* 9 track drives, but there is no way for the software to detect
|
||||
* which drive type is installed. Sigh... We make the gross
|
||||
* assumption that #ifdef mc68010 will test for a Sun-2.
|
||||
*
|
||||
* cartridge 8000 bpi (100 bytes/.1") 425 * tracks ft.
|
||||
*/
|
||||
if (density == 0)
|
||||
density = cartridge ? 100 : 160;
|
||||
if (tracks == 0)
|
||||
#ifdef mc68010
|
||||
tracks = 4;
|
||||
#else
|
||||
tracks = 9;
|
||||
#endif
|
||||
if (!bflag) {
|
||||
if (cartridge)
|
||||
ntrec = CARTRIDGETREC;
|
||||
else if (density >= 625)
|
||||
ntrec = HIGHDENSITYTREC;
|
||||
else
|
||||
ntrec = NTREC;
|
||||
}
|
||||
if (diskette) {
|
||||
#ifndef i386
|
||||
/* if not already set, set diskette to default */
|
||||
if (strcmp(tape, TAPE) == 0)
|
||||
tape = DISKETTE;
|
||||
#endif
|
||||
if (tsize == 0)
|
||||
tsize = DISKETTE_DSIZE / DEV_BSIZE / 2;
|
||||
tsize -= tsize % ntrec + 2 * ntrec;
|
||||
} else {
|
||||
if (tsize == 0)
|
||||
tsize = cartridge ? 425L*120L : 2300L*120L;
|
||||
else
|
||||
tsize *= 12L*10L;
|
||||
if (cartridge)
|
||||
tsize *= tracks;
|
||||
}
|
||||
if (index(tape, ':')) {
|
||||
if (diskette) {
|
||||
fprintf(stderr,
|
||||
"dump: cannot do remote dump to diskette\n");
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
host = tape;
|
||||
tape = index(host, ':');
|
||||
*tape++ = 0;
|
||||
if (rmthost() == 0)
|
||||
exit(X_ABORT);
|
||||
}
|
||||
setuid(getuid()); /* rmthost() is the only reason to be setuid */
|
||||
if (signal(SIGHUP, sighup) == SIG_IGN)
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
if (signal(SIGTRAP, sigtrap) == SIG_IGN)
|
||||
signal(SIGTRAP, SIG_IGN);
|
||||
if (signal(SIGFPE, sigfpe) == SIG_IGN)
|
||||
signal(SIGFPE, SIG_IGN);
|
||||
if (signal(SIGBUS, sigbus) == SIG_IGN)
|
||||
signal(SIGBUS, SIG_IGN);
|
||||
if (signal(SIGSEGV, sigsegv) == SIG_IGN)
|
||||
signal(SIGSEGV, SIG_IGN);
|
||||
if (signal(SIGTERM, sigterm) == SIG_IGN)
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
|
||||
|
||||
if (signal(SIGINT, interrupt) == SIG_IGN)
|
||||
signal(SIGINT, SIG_IGN);
|
||||
|
||||
set_operators(); /* /etc/group snarfed */
|
||||
getfstab(); /* /etc/fstab snarfed */
|
||||
|
||||
/*
|
||||
* disk can be either the full special file name,
|
||||
* the suffix of the special file name,
|
||||
* the special name missing the leading '/',
|
||||
* the file system name with or without the leading '/'.
|
||||
*/
|
||||
dt = fstabsearch(disk);
|
||||
if (dt != 0) {
|
||||
disk = rawname(dt->fs_spec);
|
||||
strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
|
||||
strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
|
||||
} else {
|
||||
strncpy(spcl.c_dev, disk, NAMELEN);
|
||||
#ifdef PARTIAL
|
||||
/* check for partial filesystem dump */
|
||||
partial_check();
|
||||
dt = fstabsearch(disk);
|
||||
if (dt != 0) {
|
||||
disk = rawname(dt->fs_spec);
|
||||
strncpy(spcl.c_filesys,
|
||||
"a partial file system", NAMELEN);
|
||||
}
|
||||
else
|
||||
#endif PARTIAL
|
||||
strncpy(spcl.c_filesys, "an unlisted file system", NAMELEN);
|
||||
}
|
||||
strcpy(spcl.c_label, "none");
|
||||
gethostname(spcl.c_host, NAMELEN);
|
||||
spcl.c_level = incno - '0';
|
||||
getitime(); /* /etc/dumpdates snarfed */
|
||||
|
||||
msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date));
|
||||
msg("Date of last level %c dump: %s\n",
|
||||
lastincno, prdate(spcl.c_ddate));
|
||||
msg("Dumping %s ", disk);
|
||||
if (dt != 0)
|
||||
msgtail("(%s) ", dt->fs_file);
|
||||
msgtail("to %s", tape);
|
||||
if (host)
|
||||
msgtail(" on host %s", host);
|
||||
msgtail("\n");
|
||||
|
||||
fi = open(disk, 0);
|
||||
if (fi < 0) {
|
||||
msg("Cannot open %s\n", disk);
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
esize = 0;
|
||||
sblock = (struct fs *)buf;
|
||||
sync();
|
||||
bread(SBLOCK, (char *)sblock, (long)SBSIZE);
|
||||
if (sblock->fs_magic != FS_MAGIC) {
|
||||
msg("bad sblock magic number\n");
|
||||
dumpabort();
|
||||
}
|
||||
msiz = roundup(howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY),
|
||||
TP_BSIZE);
|
||||
clrmap = (char *)calloc(msiz, sizeof (char));
|
||||
dirmap = (char *)calloc(msiz, sizeof (char));
|
||||
nodmap = (char *)calloc(msiz, sizeof (char));
|
||||
|
||||
anydskipped = 0;
|
||||
msg("mapping (Pass I) [regular files]\n");
|
||||
|
||||
#ifdef PARTIAL
|
||||
if (partial_mark(argc, argv))
|
||||
#endif PARTIAL
|
||||
pass(mark, (char *)NULL); /* mark updates esize */
|
||||
|
||||
if (anydskipped) {
|
||||
do {
|
||||
msg("mapping (Pass II) [directories]\n");
|
||||
nadded = 0;
|
||||
pass(add, dirmap);
|
||||
} while(nadded);
|
||||
} else /* keep the operators happy */
|
||||
msg("mapping (Pass II) [directories]\n");
|
||||
|
||||
bmapest(clrmap);
|
||||
bmapest(nodmap);
|
||||
|
||||
if (cartridge) {
|
||||
/*
|
||||
* Estimate number of tapes, assuming streaming stops at
|
||||
* the end of each block written, and not in mid-block.
|
||||
* Assume no erroneous blocks; this can be compensated for
|
||||
* with an artificially low tape size.
|
||||
*/
|
||||
tenthsperirg = 16; /* actually 15.48, says Archive */
|
||||
fetapes =
|
||||
( esize /* blocks */
|
||||
* TP_BSIZE /* bytes/block */
|
||||
* (1.0/density) /* 0.1" / byte */
|
||||
+
|
||||
esize /* blocks */
|
||||
* (1.0/ntrec) /* streaming-stops per block */
|
||||
* tenthsperirg /* 0.1" / streaming-stop */
|
||||
) * (1.0 / tsize ); /* tape / 0.1" */
|
||||
} else {
|
||||
/* Estimate number of tapes, for old fashioned 9-track tape */
|
||||
#ifdef sun
|
||||
/* sun has long irg's */
|
||||
tenthsperirg = (density == 625) ? 6 : 12;
|
||||
#else
|
||||
tenthsperirg = (density == 625) ? 5 : 8;
|
||||
#endif
|
||||
fetapes =
|
||||
( esize /* blocks */
|
||||
* TP_BSIZE /* bytes / block */
|
||||
* (1.0/density) /* 0.1" / byte */
|
||||
+
|
||||
esize /* blocks */
|
||||
* (1.0/ntrec) /* IRG's / block */
|
||||
* tenthsperirg /* 0.1" / IRG */
|
||||
) * (1.0 / tsize ); /* tape / 0.1" */
|
||||
}
|
||||
|
||||
if (diskette) {
|
||||
esize += i + ntrec; /* headers + ntrec trailer blocks */
|
||||
fetapes = ((float)esize*DEV_BSIZE/(tsize*TP_BSIZE));
|
||||
etapes = fetapes; /* truncating assignment */
|
||||
etapes++;
|
||||
/* count the nodemap on each additional tape */
|
||||
for (i = 1; i < etapes; i++)
|
||||
bmapest(nodmap);
|
||||
msg("estimated %ld blocks (%s) on %3.2f Diskette(s).\n",
|
||||
esize*2, mb(esize), fetapes*2);
|
||||
} else {
|
||||
etapes = fetapes; /* truncating assignment */
|
||||
etapes++;
|
||||
/* count the nodemap on each additional tape */
|
||||
for (i = 1; i < etapes; i++)
|
||||
bmapest(nodmap);
|
||||
esize += i + ntrec; /* headers + ntrec trailer blocks */
|
||||
msg("estimated %ld blocks (%s) on %3.2f tape(s).\n",
|
||||
esize*2, mb(esize), fetapes);
|
||||
}
|
||||
|
||||
alloctape(); /* Allocate tape buffer */
|
||||
|
||||
otape(1); /* bitmap is the first to tape write */
|
||||
telapsed = 0;
|
||||
(void)time(&tstart_writing);
|
||||
bitmap(clrmap, TS_CLRI);
|
||||
|
||||
if (!doingverify)
|
||||
msg("dumping (Pass III) [directories]\n");
|
||||
pass(dirdump, dirmap);
|
||||
|
||||
if (!doingverify)
|
||||
msg("dumping (Pass IV) [regular files]\n");
|
||||
pass(dump, nodmap);
|
||||
|
||||
spcl.c_type = TS_END;
|
||||
for (i = 0; i < ntrec; i++)
|
||||
spclrec();
|
||||
|
||||
putitime();
|
||||
rewind();
|
||||
if (verify && !doingverify) {
|
||||
msg("Finished writing last dump volume\n");
|
||||
Exit(X_VERIFY);
|
||||
}
|
||||
msg("%ld blocks (%s) on %d volume%s\n",
|
||||
spcl.c_tapea*2, mb(spcl.c_tapea), spcl.c_volume,
|
||||
spcl.c_volume > 1 ? "s" : "");
|
||||
msg("DUMP IS DONE\n");
|
||||
broadcast("DUMP IS DONE!\7\7\n");
|
||||
if (archive)
|
||||
msg("Archiving dump to %s\n", archivefile);
|
||||
Exit(X_FINOK);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();}
|
||||
void sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();}
|
||||
void sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();}
|
||||
void sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();}
|
||||
void sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();}
|
||||
void sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();}
|
||||
void sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();}
|
||||
|
||||
sigAbort()
|
||||
{
|
||||
if (pipeout) {
|
||||
msg("Unknown signal, cannot recover\n");
|
||||
dumpabort();
|
||||
}
|
||||
msg("Rewriting attempted as response to unknown signal.\n");
|
||||
fflush(stderr);
|
||||
fflush(stdout);
|
||||
close_rewind();
|
||||
exit(X_REWRITE);
|
||||
}
|
||||
|
||||
char *
|
||||
rawname(cp)
|
||||
char *cp;
|
||||
{
|
||||
char *rawbuf, *dp;
|
||||
extern char *malloc();
|
||||
|
||||
rawbuf = malloc(strlen(cp) + 2);
|
||||
if (rawbuf == 0)
|
||||
return (0);
|
||||
|
||||
dp = rindex(cp, '/');
|
||||
if (dp == 0)
|
||||
return (0);
|
||||
*dp = 0;
|
||||
strcpy(rawbuf, cp);
|
||||
*dp = '/';
|
||||
strcat(rawbuf, "/r");
|
||||
strcat(rawbuf, dp+1);
|
||||
return (rawbuf);
|
||||
}
|
||||
|
||||
static char *
|
||||
mb(blks)
|
||||
long blks;
|
||||
{
|
||||
static char buf[16];
|
||||
|
||||
if (blks < 1024)
|
||||
sprintf(buf, "%ldKB", blks);
|
||||
else
|
||||
sprintf(buf, "%.2fMB", ((double)blks) / 1024.);
|
||||
return (buf);
|
||||
}
|
||||
430
etc/dump/dumpoptr.c
Normal file
430
etc/dump/dumpoptr.c
Normal file
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* Copyright (c) 1980 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumpoptr.c 1.1 92/07/30 SMI"; /* from UCB 5.1 6/5/85 */
|
||||
#endif not lint
|
||||
|
||||
#include "dump.h"
|
||||
#include <grp.h>
|
||||
|
||||
void alarmcatch();
|
||||
|
||||
/*
|
||||
* Query the operator; This fascist piece of code requires
|
||||
* an exact response.
|
||||
* It is intended to protect dump aborting by inquisitive
|
||||
* people banging on the console terminal to see what is
|
||||
* happening which might cause dump to croak, destroying
|
||||
* a large number of hours of work.
|
||||
*
|
||||
* Every 2 minutes we reprint the message, alerting others
|
||||
* that dump needs attention.
|
||||
*/
|
||||
int timeout;
|
||||
char *attnmessage; /* attention message */
|
||||
query(question)
|
||||
char *question;
|
||||
{
|
||||
char replybuffer[64];
|
||||
int back;
|
||||
FILE *mytty;
|
||||
time_t now;
|
||||
|
||||
if ( (mytty = fopen("/dev/tty", "r")) == NULL){
|
||||
msg("fopen on /dev/tty fails\n");
|
||||
dumpabort();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
attnmessage = question;
|
||||
timeout = 0;
|
||||
now = time((time_t *)0);
|
||||
telapsed += now - tstart_writing;
|
||||
alarmcatch();
|
||||
for(;;){
|
||||
if ( fgets(replybuffer, 63, mytty) == NULL){
|
||||
if (ferror(mytty)){
|
||||
clearerr(mytty);
|
||||
continue;
|
||||
}
|
||||
} else if ( (strcmp(replybuffer, "yes\n") == 0) ||
|
||||
(strcmp(replybuffer, "Yes\n") == 0)){
|
||||
back = 1;
|
||||
goto done;
|
||||
} else if ( (strcmp(replybuffer, "no\n") == 0) ||
|
||||
(strcmp(replybuffer, "No\n") == 0)){
|
||||
back = 0;
|
||||
goto done;
|
||||
} else {
|
||||
msg("\"Yes\" or \"No\"?\n");
|
||||
alarmcatch();
|
||||
}
|
||||
}
|
||||
done:
|
||||
/*
|
||||
* Turn off the alarm, and reset the signal to trap out..
|
||||
*/
|
||||
alarm(0);
|
||||
if (signal(SIGALRM, sigalrm) == SIG_IGN)
|
||||
signal(SIGALRM, SIG_IGN);
|
||||
fclose(mytty);
|
||||
tstart_writing = time((time_t *)0);
|
||||
return(back);
|
||||
}
|
||||
/*
|
||||
* Alert the console operator, and enable the alarm clock to
|
||||
* sleep for 2 minutes in case nobody comes to satisfy dump
|
||||
*/
|
||||
void
|
||||
alarmcatch()
|
||||
{
|
||||
if (timeout)
|
||||
msgtail("\n");
|
||||
msg("NEEDS ATTENTION: %s: (\"yes\" or \"no\") ",
|
||||
attnmessage);
|
||||
signal(SIGALRM, alarmcatch);
|
||||
alarm(120);
|
||||
timeout = 1;
|
||||
}
|
||||
/*
|
||||
* Here if an inquisitive operator interrupts the dump program
|
||||
*/
|
||||
void
|
||||
interrupt()
|
||||
{
|
||||
msg("Interrupt received.\n");
|
||||
if (query("Do you want to abort dump?"))
|
||||
dumpabort();
|
||||
signal(SIGINT, interrupt);
|
||||
}
|
||||
|
||||
/*
|
||||
* The following variables and routines manage alerting
|
||||
* operators to the status of dump.
|
||||
* This works much like wall(1) does.
|
||||
*/
|
||||
struct group *gp;
|
||||
|
||||
/*
|
||||
* Get the names from the group entry "operator" to notify.
|
||||
*/
|
||||
set_operators()
|
||||
{
|
||||
if (!notify) /*not going to notify*/
|
||||
return;
|
||||
gp = getgrnam(OPGRENT);
|
||||
endgrent();
|
||||
if (gp == (struct group *)0){
|
||||
msg("No entry in /etc/group for %s.\n",
|
||||
OPGRENT);
|
||||
notify = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
struct tm *localtime();
|
||||
struct tm *localclock;
|
||||
|
||||
/*
|
||||
* We fork a child to do the actual broadcasting, so
|
||||
* that the process control groups are not messed up
|
||||
*/
|
||||
broadcast(message)
|
||||
char *message;
|
||||
{
|
||||
time_t clock;
|
||||
FILE *f_utmp;
|
||||
struct utmp utmp;
|
||||
char **np;
|
||||
int pid;
|
||||
|
||||
switch (pid = fork()) {
|
||||
case -1:
|
||||
return;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
while (wait((union wait *)0) != pid)
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!notify || gp == 0)
|
||||
exit(0);
|
||||
clock = time((time_t *)0);
|
||||
localclock = localtime(&clock);
|
||||
|
||||
if((f_utmp = fopen("/etc/utmp", "r")) == NULL) {
|
||||
msg("Cannot open /etc/utmp\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (!feof(f_utmp)){
|
||||
if (fread((char *)&utmp, sizeof (struct utmp), 1, f_utmp) != 1)
|
||||
break;
|
||||
if (utmp.ut_name[0] == 0)
|
||||
continue;
|
||||
for (np = gp->gr_mem; *np; np++){
|
||||
if (strncmp(*np, utmp.ut_name, sizeof (utmp.ut_name)) != 0)
|
||||
continue;
|
||||
/*
|
||||
* Do not send messages to operators on dialups
|
||||
*/
|
||||
if (strncmp(utmp.ut_line, DIALUP, strlen(DIALUP)) == 0)
|
||||
continue;
|
||||
#ifdef DEBUG
|
||||
msg("Message to %s at %s\n",
|
||||
utmp.ut_name, utmp.ut_line);
|
||||
#endif DEBUG
|
||||
sendmes(utmp.ut_line, message);
|
||||
}
|
||||
}
|
||||
fclose(f_utmp);
|
||||
Exit(0); /* the wait in this same routine will catch this */
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
sendmes(tty, message)
|
||||
char *tty, *message;
|
||||
{
|
||||
char t[50], buf[BUFSIZ];
|
||||
register char *cp;
|
||||
register int c, ch;
|
||||
int msize;
|
||||
FILE *f_tty;
|
||||
|
||||
msize = strlen(message);
|
||||
strcpy(t, "/dev/");
|
||||
strcat(t, tty);
|
||||
|
||||
if((f_tty = fopen(t, "w")) != NULL) {
|
||||
setbuf(f_tty, buf);
|
||||
fprintf(f_tty, "\nMessage from the dump program to all operators at %d:%02d ...\r\n\n"
|
||||
,localclock->tm_hour
|
||||
,localclock->tm_min);
|
||||
for (cp = message, c = msize; c-- > 0; cp++) {
|
||||
ch = *cp;
|
||||
if (ch == '\n')
|
||||
putc('\r', f_tty);
|
||||
putc(ch, f_tty);
|
||||
}
|
||||
fclose(f_tty);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* print out an estimate of the amount of time left to do the dump
|
||||
*/
|
||||
|
||||
time_t tschedule = 0;
|
||||
|
||||
timeest()
|
||||
{
|
||||
time_t tnow, deltat;
|
||||
|
||||
time (&tnow);
|
||||
if (tnow >= tschedule) {
|
||||
tschedule = tnow + 300;
|
||||
if (blockswritten < 500)
|
||||
return;
|
||||
deltat = (telapsed + (tnow - tstart_writing))
|
||||
* ((double)esize / blockswritten - 1.0);
|
||||
msg("%3.2f%% done, finished in %d:%02d\n",
|
||||
(blockswritten*100.0)/esize,
|
||||
deltat/3600, (deltat%3600)/60);
|
||||
}
|
||||
}
|
||||
|
||||
#include <varargs.h>
|
||||
|
||||
/* VARARGS */
|
||||
msg(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list args;
|
||||
char *fmt;
|
||||
|
||||
va_start(args);
|
||||
fprintf(stderr," DUMP: ");
|
||||
#ifdef TDEBUG
|
||||
fprintf(stderr,"pid=%d ", getpid());
|
||||
#endif
|
||||
fmt = va_arg(args, char *);
|
||||
vfprintf(stderr, fmt, args);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/* VARARGS */
|
||||
msgtail(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list args;
|
||||
char *fmt;
|
||||
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
/*
|
||||
* Tell the operator what has to be done;
|
||||
* we don't actually do it
|
||||
*/
|
||||
|
||||
struct fstab *
|
||||
allocfsent(fs)
|
||||
register struct fstab *fs;
|
||||
{
|
||||
register struct fstab *new;
|
||||
register char *cp;
|
||||
|
||||
new = (struct fstab *)malloc(sizeof (*fs));
|
||||
cp = malloc((u_int)strlen(fs->fs_file) + 1);
|
||||
strcpy(cp, fs->fs_file);
|
||||
new->fs_file = cp;
|
||||
cp = malloc((u_int)strlen(fs->fs_type) + 1);
|
||||
strcpy(cp, fs->fs_type);
|
||||
new->fs_type = cp;
|
||||
cp = malloc((u_int)strlen(fs->fs_spec) + 1);
|
||||
strcpy(cp, fs->fs_spec);
|
||||
new->fs_spec = cp;
|
||||
new->fs_passno = fs->fs_passno;
|
||||
new->fs_freq = fs->fs_freq;
|
||||
return (new);
|
||||
}
|
||||
|
||||
struct pfstab {
|
||||
struct pfstab *pf_next;
|
||||
struct fstab *pf_fstab;
|
||||
};
|
||||
|
||||
static struct pfstab *table = NULL;
|
||||
|
||||
getfstab()
|
||||
{
|
||||
register struct fstab *fs;
|
||||
register struct pfstab *pf;
|
||||
|
||||
if (setfsent() == 0) {
|
||||
msg("Can't open %s for dump table information.\n", FSTAB);
|
||||
return;
|
||||
}
|
||||
while (fs = getfsent()) {
|
||||
if (strcmp(fs->fs_type, FSTAB_RW) &&
|
||||
strcmp(fs->fs_type, FSTAB_RO) &&
|
||||
strcmp(fs->fs_type, FSTAB_RQ))
|
||||
continue;
|
||||
fs = allocfsent(fs);
|
||||
pf = (struct pfstab *)malloc(sizeof (*pf));
|
||||
pf->pf_fstab = fs;
|
||||
pf->pf_next = table;
|
||||
table = pf;
|
||||
}
|
||||
endfsent();
|
||||
}
|
||||
|
||||
/*
|
||||
* Search in the fstab for a file name.
|
||||
* This file name can be either the special or the path file name.
|
||||
*
|
||||
* The entries in the fstab are the BLOCK special names, not the
|
||||
* character special names.
|
||||
* The caller of fstabsearch assures that the character device
|
||||
* is dumped (that is much faster)
|
||||
*
|
||||
* The file name can omit the leading '/'.
|
||||
*/
|
||||
struct fstab *
|
||||
fstabsearch(key)
|
||||
char *key;
|
||||
{
|
||||
register struct pfstab *pf;
|
||||
register struct fstab *fs;
|
||||
char *s;
|
||||
char *rawname();
|
||||
|
||||
if (table == NULL)
|
||||
return ((struct fstab *)0);
|
||||
for (pf = table; pf; pf = pf->pf_next) {
|
||||
fs = pf->pf_fstab;
|
||||
if (strcmp(fs->fs_file, key) == 0)
|
||||
return (fs);
|
||||
if (strcmp(fs->fs_spec, key) == 0)
|
||||
return (fs);
|
||||
if ((s = rawname(fs->fs_spec)) != NULL && strcmp(s, key) == 0)
|
||||
return (fs);
|
||||
if (key[0] != '/'){
|
||||
if (*fs->fs_spec == '/' &&
|
||||
strcmp(fs->fs_spec + 1, key) == 0)
|
||||
return (fs);
|
||||
if (*fs->fs_file == '/' &&
|
||||
strcmp(fs->fs_file + 1, key) == 0)
|
||||
return (fs);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell the operator what to do
|
||||
*/
|
||||
lastdump(arg)
|
||||
char arg; /* w ==> just what to do; W ==> most recent dumps */
|
||||
{
|
||||
char *lastname;
|
||||
char *date;
|
||||
register int i;
|
||||
time_t tnow;
|
||||
register struct fstab *dt;
|
||||
int dumpme;
|
||||
register struct idates *itwalk;
|
||||
|
||||
int idatesort();
|
||||
|
||||
time(&tnow);
|
||||
getfstab(); /* /etc/fstab input */
|
||||
inititimes(); /* /etc/dumpdates input */
|
||||
qsort((char *)idatev, nidates, sizeof (struct idates *), idatesort);
|
||||
|
||||
if (arg == 'w')
|
||||
fprintf(stdout, "Dump these file systems:\n");
|
||||
else
|
||||
fprintf(stdout, "Last dump(s) done (Dump '>' file systems):\n");
|
||||
lastname = "??";
|
||||
ITITERATE(i, itwalk){
|
||||
if (strncmp(lastname, itwalk->id_name, sizeof (itwalk->id_name)) == 0)
|
||||
continue;
|
||||
date = (char *)ctime(&itwalk->id_ddate);
|
||||
date[16] = '\0'; /* blast away seconds and year */
|
||||
lastname = itwalk->id_name;
|
||||
dt = fstabsearch(itwalk->id_name);
|
||||
dumpme = ( (dt != 0)
|
||||
&& (dt->fs_freq != 0)
|
||||
&& (itwalk->id_ddate < tnow - (dt->fs_freq*DAY)));
|
||||
if ( (arg != 'w') || dumpme)
|
||||
fprintf(stdout,"%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
|
||||
dumpme && (arg != 'w') ? '>' : ' ',
|
||||
itwalk->id_name,
|
||||
dt ? dt->fs_file : "",
|
||||
itwalk->id_incno,
|
||||
date
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int idatesort(p1, p2)
|
||||
struct idates **p1, **p2;
|
||||
{
|
||||
int diff;
|
||||
|
||||
diff = strncmp((*p1)->id_name, (*p2)->id_name, sizeof ((*p1)->id_name));
|
||||
if (diff == 0)
|
||||
return ((*p2)->id_ddate - (*p1)->id_ddate);
|
||||
else
|
||||
return (diff);
|
||||
}
|
||||
286
etc/dump/dumprmt.c
Normal file
286
etc/dump/dumprmt.c
Normal file
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright (c) 1980 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumprmt.c 1.1 92/07/30 SMI"; /* from UCB 5.4 12/11/85 */
|
||||
#endif not lint
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mtio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <ufs/inode.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <netdb.h>
|
||||
#include <protocols/dumprestore.h>
|
||||
|
||||
#define TS_CLOSED 0
|
||||
#define TS_OPEN 1
|
||||
|
||||
static int rmtstate = TS_CLOSED;
|
||||
int rmtape;
|
||||
void rmtconnaborted();
|
||||
char *rmtpeer;
|
||||
|
||||
extern char *rindex();
|
||||
extern char *host;
|
||||
|
||||
extern int ntrec; /* blocking factor on tape */
|
||||
|
||||
rmthost()
|
||||
{
|
||||
|
||||
rmtpeer = host;
|
||||
signal(SIGPIPE, rmtconnaborted);
|
||||
rmtgetconn();
|
||||
if (rmtape < 0)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
rmtconnaborted()
|
||||
{
|
||||
|
||||
fprintf(stderr, "rdump: Lost connection to remote host.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rmtgetconn()
|
||||
{
|
||||
static struct servent *sp = 0;
|
||||
static struct passwd *pwd = 0;
|
||||
char *tuser;
|
||||
int size;
|
||||
|
||||
if (sp == 0) {
|
||||
sp = getservbyname("shell", "tcp");
|
||||
if (sp == 0) {
|
||||
fprintf(stderr, "rdump: shell/tcp: unknown service\n");
|
||||
exit(1);
|
||||
}
|
||||
pwd = getpwuid(getuid());
|
||||
if (pwd == 0) {
|
||||
fprintf(stderr, "rdump: who are you?\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
host = rindex(rmtpeer, '@');
|
||||
if (host) {
|
||||
tuser = rmtpeer;
|
||||
*host++ = 0;
|
||||
rmtpeer = host;
|
||||
if (!okname(tuser))
|
||||
exit(1);
|
||||
} else {
|
||||
host = rmtpeer;
|
||||
tuser = pwd->pw_name;
|
||||
}
|
||||
rmtape = rcmd(&rmtpeer, (u_short)sp->s_port, pwd->pw_name,
|
||||
tuser, "/etc/rmt", (int *)0);
|
||||
size = ntrec * TP_BSIZE;
|
||||
while (size > TP_BSIZE &&
|
||||
setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) < 0)
|
||||
size -= TP_BSIZE;
|
||||
}
|
||||
|
||||
static int
|
||||
okname(cp0)
|
||||
char *cp0;
|
||||
{
|
||||
register char *cp;
|
||||
register int c;
|
||||
|
||||
for (cp = cp0; *cp; cp++) {
|
||||
c = *cp;
|
||||
if (!isascii(c) || !(isalnum(c) || c == '_' || c == '-')) {
|
||||
fprintf(stderr, "rdump: invalid user name %s\n", cp0);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
rmtopen(tape, mode)
|
||||
char *tape;
|
||||
int mode;
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
sprintf(buf, "O%s\n%d\n", tape, mode);
|
||||
rmtstate = TS_OPEN;
|
||||
return (rmtcall(tape, buf));
|
||||
}
|
||||
|
||||
rmtclose()
|
||||
{
|
||||
|
||||
if (rmtstate != TS_OPEN)
|
||||
return;
|
||||
rmtcall("close", "C\n");
|
||||
rmtstate = TS_CLOSED;
|
||||
}
|
||||
|
||||
rmtread(buf, count)
|
||||
char *buf;
|
||||
int count;
|
||||
{
|
||||
char line[30];
|
||||
int n, i, cc;
|
||||
extern errno;
|
||||
|
||||
sprintf(line, "R%d\n", count);
|
||||
n = rmtcall("read", line);
|
||||
if (n < 0) {
|
||||
errno = n;
|
||||
return (-1);
|
||||
}
|
||||
for (i = 0; i < n; i += cc) {
|
||||
cc = read(rmtape, buf+i, n - i);
|
||||
if (cc <= 0) {
|
||||
rmtconnaborted();
|
||||
}
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
rmtwrite(buf, count)
|
||||
char *buf;
|
||||
int count;
|
||||
{
|
||||
char line[30];
|
||||
|
||||
sprintf(line, "W%d\n", count);
|
||||
write(rmtape, line, strlen(line));
|
||||
write(rmtape, buf, count);
|
||||
return (rmtreply("write"));
|
||||
}
|
||||
|
||||
rmtwrite0(count)
|
||||
int count;
|
||||
{
|
||||
char line[30];
|
||||
|
||||
sprintf(line, "W%d\n", count);
|
||||
write(rmtape, line, strlen(line));
|
||||
}
|
||||
|
||||
rmtwrite1(buf, count)
|
||||
char *buf;
|
||||
int count;
|
||||
{
|
||||
|
||||
write(rmtape, buf, count);
|
||||
}
|
||||
|
||||
rmtwrite2()
|
||||
{
|
||||
return (rmtreply("write"));
|
||||
}
|
||||
|
||||
rmtseek(offset, pos)
|
||||
int offset, pos;
|
||||
{
|
||||
char line[80];
|
||||
|
||||
sprintf(line, "L%d\n%d\n", offset, pos);
|
||||
return (rmtcall("seek", line));
|
||||
}
|
||||
|
||||
struct mtget mts;
|
||||
|
||||
struct mtget *
|
||||
rmtstatus()
|
||||
{
|
||||
register int i;
|
||||
register char *cp;
|
||||
|
||||
if (rmtstate != TS_OPEN)
|
||||
return (0);
|
||||
rmtcall("status", "S\n");
|
||||
for (i = 0, cp = (char *)&mts; i < sizeof (mts); i++)
|
||||
*cp++ = rmtgetb();
|
||||
return (&mts);
|
||||
}
|
||||
|
||||
rmtioctl(cmd, count)
|
||||
int cmd, count;
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
if (count < 0)
|
||||
return (-1);
|
||||
sprintf(buf, "I%d\n%d\n", cmd, count);
|
||||
return (rmtcall("ioctl", buf));
|
||||
}
|
||||
|
||||
rmtcall(cmd, buf)
|
||||
char *cmd, *buf;
|
||||
{
|
||||
|
||||
if (write(rmtape, buf, strlen(buf)) != strlen(buf))
|
||||
rmtconnaborted();
|
||||
return (rmtreply(cmd));
|
||||
}
|
||||
|
||||
rmtreply(cmd)
|
||||
char *cmd;
|
||||
{
|
||||
char code[30], emsg[BUFSIZ];
|
||||
|
||||
rmtgets(code, sizeof (code));
|
||||
if (*code == 'E' || *code == 'F') {
|
||||
rmtgets(emsg, sizeof (emsg));
|
||||
/* don't print error message for ioctl */
|
||||
if (strcmp(cmd, "ioctl") != 0)
|
||||
msg("%s: %s\n", cmd, emsg, code + 1);
|
||||
if (*code == 'F') {
|
||||
rmtstate = TS_CLOSED;
|
||||
return (-1);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
if (*code != 'A') {
|
||||
msg("Protocol to remote tape server botched (code %s?).\n",
|
||||
code);
|
||||
rmtconnaborted();
|
||||
}
|
||||
return (atoi(code + 1));
|
||||
}
|
||||
|
||||
rmtgetb()
|
||||
{
|
||||
char c;
|
||||
|
||||
if (read(rmtape, &c, 1) != 1)
|
||||
rmtconnaborted();
|
||||
return (c);
|
||||
}
|
||||
|
||||
rmtgets(cp, len)
|
||||
char *cp;
|
||||
int len;
|
||||
{
|
||||
|
||||
while (len > 1) {
|
||||
*cp = rmtgetb();
|
||||
if (*cp == '\n') {
|
||||
cp[1] = 0;
|
||||
return;
|
||||
}
|
||||
cp++;
|
||||
len--;
|
||||
}
|
||||
msg("Protocol to remote tape server botched (in rmtgets).\n");
|
||||
rmtconnaborted();
|
||||
}
|
||||
788
etc/dump/dumptape.c
Normal file
788
etc/dump/dumptape.c
Normal file
@@ -0,0 +1,788 @@
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumptape.c 1.1 92/07/30 SMI"; /* from Caltech 5.4 7/1/86 */
|
||||
#endif
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <errno.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <sun/dkio.h> /* for FDKEJECT */
|
||||
#include <sys/mtio.h>
|
||||
#include "dump.h"
|
||||
|
||||
static char (*tblock)[TP_BSIZE];/* pointer to malloc()ed buffer for tape */
|
||||
static int writesize; /* size of malloc()ed buffer for tape */
|
||||
static long lastspclrec = -1; /* tape block number of last written header */
|
||||
static int dumptoarchive = 1; /* mark records to be archived */
|
||||
static int trecno = 0; /* next record to write in current block */
|
||||
static int arch; /* descriptor to which to write archive file */
|
||||
static long inos[TP_NINOS]; /* starting inodes on each tape */
|
||||
extern int ntrec; /* blocking factor on tape */
|
||||
extern int tenthsperirg; /* tenths of an inch per inter-record gap */
|
||||
extern int read(), write();
|
||||
extern char *host;
|
||||
|
||||
/*
|
||||
* Concurrent dump mods (Caltech) - disk block reading and tape writing
|
||||
* are exported to several slave processes. While one slave writes the
|
||||
* tape, the others read disk blocks; they pass control of the tape in
|
||||
* a ring via signals. The parent process traverses the filesystem and
|
||||
* sends spclrec()'s and lists of daddr's to the slaves via pipes.
|
||||
*/
|
||||
struct req { /* instruction packets sent to slaves */
|
||||
short count;
|
||||
short flag;
|
||||
daddr_t dblk;
|
||||
} *req;
|
||||
static int reqsiz;
|
||||
|
||||
#define SLAVES 3 /* 1 reading pipe, 1 reading disk, 1 writing */
|
||||
static int slavefd[SLAVES]; /* pipes from master to each slave */
|
||||
static int slavepid[SLAVES]; /* used by killall() */
|
||||
static int rotor; /* next slave to be instructed */
|
||||
static int master; /* pid of master, for sending error signals */
|
||||
static int bufrecs; /* tape records (not blocks) per buffer */
|
||||
union u_spcl *nextspcl; /* where to copy next taprec record */
|
||||
|
||||
/*
|
||||
* Allocate tape buffer, on page boundary for tape write() efficiency,
|
||||
* with array of req packets immediately preceeding it so both can be
|
||||
* written together by flusht().
|
||||
*/
|
||||
alloctape()
|
||||
{
|
||||
int pgoff = getpagesize() - 1; /* pagesize better be power of 2 */
|
||||
char *buf, *malloc();
|
||||
|
||||
writesize = ntrec * TP_BSIZE;
|
||||
|
||||
if (diskette) {
|
||||
bufrecs = ntrec;
|
||||
} else {
|
||||
bufrecs = ntrec + (20/ntrec)*ntrec;
|
||||
}
|
||||
|
||||
reqsiz = (bufrecs+1) * sizeof (struct req);
|
||||
buf = malloc((u_int)(reqsiz + bufrecs * TP_BSIZE + pgoff));
|
||||
if (buf == NULL)
|
||||
return (0);
|
||||
|
||||
tblock = (char (*)[TP_BSIZE]) (((long)buf + reqsiz + pgoff) &~ pgoff);
|
||||
nextspcl = (union u_spcl *)tblock;
|
||||
req = (struct req *) (tblock[0] - reqsiz);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start a process to collect the bitmap and directory information
|
||||
* being written to the front of the tape. When the pipe to this
|
||||
* process is closed, it writes out the collected data to the
|
||||
* requested file.
|
||||
*/
|
||||
setuparchive()
|
||||
{
|
||||
struct list {
|
||||
struct list *next;
|
||||
char *data;
|
||||
long size;
|
||||
} bufhead;
|
||||
register struct list *blp, *nblp;
|
||||
int cmd[2], pid, fd, punt = 0;
|
||||
char *buf;
|
||||
|
||||
if (pipe(cmd) < 0 || (pid = fork()) < 0) {
|
||||
perror(" DUMP: cannot create child to write archive file");
|
||||
return (0);
|
||||
}
|
||||
if (pid > 0) {
|
||||
/* parent process */
|
||||
close(cmd[0]);
|
||||
arch = cmd[1];
|
||||
return (pid);
|
||||
}
|
||||
/* child process */
|
||||
close(cmd[1]);
|
||||
for (blp = &bufhead; blp->size > 0; ) {
|
||||
nblp = (struct list *)malloc(sizeof (struct list));
|
||||
buf = (char *)malloc((u_int)writesize);
|
||||
if (nblp == 0 || buf == 0) {
|
||||
if (!punt)
|
||||
msg("Out of memory to create archive file %s\n",
|
||||
archivefile);
|
||||
punt++;
|
||||
if (blp == &bufhead)
|
||||
dumpabort();
|
||||
blp->next = 0;
|
||||
} else {
|
||||
nblp->data = buf;
|
||||
blp->next = nblp;
|
||||
blp = nblp;
|
||||
}
|
||||
blp->size = atomic(read, cmd[0], blp->data, writesize);
|
||||
}
|
||||
if (punt)
|
||||
Exit(X_ABORT);
|
||||
close(cmd[0]);
|
||||
if ((fd = open(archivefile, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
|
||||
msg("Cannot create archive file %s: ", archivefile);
|
||||
perror("");
|
||||
}
|
||||
for (blp = bufhead.next; blp && blp->size == writesize; blp = blp->next)
|
||||
if (write(fd, blp->data, writesize) != writesize)
|
||||
perror(archivefile);
|
||||
close(fd);
|
||||
Exit(X_FINOK);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
spclrec()
|
||||
{
|
||||
register int s, i, *ip;
|
||||
|
||||
if (spcl.c_type == TS_END) {
|
||||
spcl.c_flags |= DR_INODEINFO;
|
||||
bcopy((char *)inos, (char *)spcl.c_inos, sizeof inos);
|
||||
}
|
||||
spcl.c_inumber = ino;
|
||||
spcl.c_magic = NFS_MAGIC;
|
||||
spcl.c_checksum = 0;
|
||||
ip = (int *)&spcl;
|
||||
s = 0;
|
||||
i = sizeof (union u_spcl) / (4 * sizeof (int));
|
||||
while (--i >= 0) {
|
||||
s += *ip++; s += *ip++;
|
||||
s += *ip++; s += *ip++;
|
||||
}
|
||||
spcl.c_checksum = CHECKSUM - s;
|
||||
if (spcl.c_type == TS_END && archive && !doingverify &&
|
||||
write(arch, (char *)&spcl, TP_BSIZE) != TP_BSIZE) {
|
||||
msg("Cannot write archive file %s", archivefile);
|
||||
perror("");
|
||||
}
|
||||
taprec((char *)&spcl);
|
||||
if (spcl.c_type == TS_END)
|
||||
spcl.c_flags &=~ DR_INODEINFO;
|
||||
}
|
||||
|
||||
taprec(dp)
|
||||
char *dp;
|
||||
{
|
||||
struct s_spcl *spclp;
|
||||
|
||||
spclp = &((union u_spcl *)dp)->s_spcl;
|
||||
if (spclp->c_type == TS_INODE &&
|
||||
(spclp->c_dinode.di_mode & IFMT) != IFDIR)
|
||||
dumptoarchive = 0;
|
||||
req[trecno].flag = dumptoarchive;
|
||||
req[trecno].dblk = (daddr_t)0;
|
||||
req[trecno].count = 1;
|
||||
*nextspcl++ = *(union u_spcl *)dp; /* block move */
|
||||
lastspclrec = spcl.c_tapea;
|
||||
trecno++;
|
||||
spcl.c_tapea++;
|
||||
if (trecno >= bufrecs ||
|
||||
(spcl.c_type == TS_EOM || spcl.c_type == TS_END) &&
|
||||
trecno % ntrec == 0)
|
||||
flusht();
|
||||
}
|
||||
|
||||
dmpblk(blkno, size)
|
||||
daddr_t blkno;
|
||||
long size;
|
||||
{
|
||||
register int avail, tpblks;
|
||||
daddr_t dblkno;
|
||||
|
||||
dblkno = fsbtodb(sblock, blkno);
|
||||
tpblks = size / TP_BSIZE;
|
||||
while ((avail = MIN(tpblks, bufrecs - trecno)) > 0) {
|
||||
req[trecno].dblk = dblkno;
|
||||
req[trecno].count = avail;
|
||||
req[trecno].flag = dumptoarchive;
|
||||
trecno += avail;
|
||||
spcl.c_tapea += avail;
|
||||
if (trecno >= bufrecs)
|
||||
flusht();
|
||||
dblkno += avail * (TP_BSIZE / DEV_BSIZE);
|
||||
tpblks -= avail;
|
||||
}
|
||||
}
|
||||
|
||||
static int nogripe = 0;
|
||||
|
||||
void
|
||||
tperror()
|
||||
{
|
||||
|
||||
if (pipeout) {
|
||||
msg("Write error on %s\n", tape);
|
||||
msg("Cannot recover\n");
|
||||
dumpabort();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (!doingverify) {
|
||||
if (diskette)
|
||||
msg("Diskette write error %ld blocks into volume %d\n",
|
||||
asize*2, tapeno);
|
||||
else
|
||||
msg("Tape write error %ld feet into tape %d\n",
|
||||
asize/120L, tapeno);
|
||||
broadcast("WRITE ERROR!\n");
|
||||
if (!query("Do you want to restart?"))
|
||||
dumpabort();
|
||||
if (!diskette) {
|
||||
msg("This tape will rewind. After it is rewound,\n");
|
||||
msg("replace the faulty tape with a new one;\n");
|
||||
msg("this dump volume will be rewritten.\n");
|
||||
}
|
||||
killall();
|
||||
nogripe = 1;
|
||||
close_rewind();
|
||||
Exit(X_REWRITE);
|
||||
} else {
|
||||
msg("Tape verification error %ld feet into tape %d\n",
|
||||
asize/120L, tapeno);
|
||||
broadcast("TAPE VERIFICATION ERROR!\n");
|
||||
if (!query("Do you want to rewrite?"))
|
||||
dumpabort();
|
||||
msg("This tape will be rewritten and then verified\n");
|
||||
killall();
|
||||
rewind();
|
||||
Exit(X_REWRITE);
|
||||
}
|
||||
}
|
||||
|
||||
/* compatibility routine */
|
||||
tflush(i)
|
||||
int i;
|
||||
{
|
||||
|
||||
for (i = 0; i < ntrec; i++)
|
||||
spclrec();
|
||||
}
|
||||
|
||||
flusht()
|
||||
{
|
||||
int siz = (char *)nextspcl - (char *)req;
|
||||
|
||||
req[trecno].count = 0; /* Sentinel */
|
||||
if (atomic(write, slavefd[rotor], (char *)req, siz) != siz) {
|
||||
perror(" DUMP: error writing command pipe");
|
||||
dumpabort();
|
||||
}
|
||||
if (++rotor >= SLAVES)
|
||||
rotor = 0;
|
||||
nextspcl = (union u_spcl *)tblock;
|
||||
if (diskette)
|
||||
asize += trecno; /* asize == blocks written to diskette */
|
||||
else
|
||||
asize += (writesize/density + tenthsperirg) * trecno / ntrec;
|
||||
blockswritten += trecno;
|
||||
trecno = 0;
|
||||
|
||||
/* prevent infinite loops while writing end of media record */
|
||||
if (writing_eom)
|
||||
return;
|
||||
|
||||
if (!pipeout && asize > tsize) {
|
||||
if (verify && !doingverify)
|
||||
rewind();
|
||||
else {
|
||||
if (diskette)
|
||||
write_end_of_media();
|
||||
close_rewind();
|
||||
}
|
||||
otape(0);
|
||||
}
|
||||
timeest();
|
||||
}
|
||||
|
||||
rewind()
|
||||
{
|
||||
int f;
|
||||
|
||||
for (f = 0; f < SLAVES; f++)
|
||||
close(slavefd[f]);
|
||||
while (wait((union wait *)NULL) >= 0)
|
||||
; /* wait for any signals from slaves */
|
||||
if (pipeout)
|
||||
return;
|
||||
if (diskette) {
|
||||
/* blindly toss diskette */
|
||||
(void)ioctl( to, FDKEJECT, 0 );
|
||||
} else {
|
||||
if (doingverify) {
|
||||
/*
|
||||
* Space to the end of the tape.
|
||||
* Backup first in case we already read the EOF.
|
||||
*/
|
||||
if (host) {
|
||||
(void) rmtioctl(MTBSR, 1);
|
||||
if (rmtioctl(MTEOM, 1) < 0)
|
||||
(void) rmtioctl(MTFSF, 1);
|
||||
} else {
|
||||
static struct mtop bsr = { MTBSR, 1 };
|
||||
static struct mtop eom = { MTEOM, 1 };
|
||||
static struct mtop fsf = { MTFSF, 1 };
|
||||
|
||||
(void) ioctl(to, MTIOCTOP, &bsr);
|
||||
if (ioctl(to, MTIOCTOP, &eom) < 0)
|
||||
(void) ioctl(to, MTIOCTOP, &fsf);
|
||||
}
|
||||
}
|
||||
msg("Tape rewinding\n");
|
||||
if (host) {
|
||||
rmtclose();
|
||||
while (rmtopen(tape, 0) < 0)
|
||||
sleep(10);
|
||||
rmtclose();
|
||||
} else {
|
||||
close(to);
|
||||
while ((f = open(tape, 0)) < 0)
|
||||
sleep(10);
|
||||
close(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close_rewind()
|
||||
{
|
||||
|
||||
rewind();
|
||||
|
||||
if (!nogripe) {
|
||||
msg("Change Volumes: Mount volume #%d\n", tapeno+1);
|
||||
broadcast("CHANGE VOLUMES!\7\7\n");
|
||||
}
|
||||
while (!query("Is the new volume mounted and ready to go?"))
|
||||
if (query ("Do you want to abort?")) {
|
||||
dumpabort();
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We implement taking and restoring checkpoints on the tape level.
|
||||
* When each tape is opened, a new process is created by forking; this
|
||||
* saves all of the necessary context in the parent. The child
|
||||
* continues the dump; the parent waits around, saving the context.
|
||||
* If the child returns X_REWRITE, then it had problems writing that tape;
|
||||
* this causes the parent to fork again, duplicating the context, and
|
||||
* everything continues as if nothing had happened.
|
||||
*/
|
||||
otape(top)
|
||||
int top;
|
||||
{
|
||||
int parentpid;
|
||||
int childpid;
|
||||
int status;
|
||||
int waitpid, killedpid;
|
||||
long blks, i;
|
||||
static int archivepid = 0;
|
||||
void (*interrupt)() = signal(SIGINT, SIG_IGN);
|
||||
|
||||
parentpid = getpid();
|
||||
|
||||
if (verify) {
|
||||
if (doingverify)
|
||||
doingverify = 0;
|
||||
else
|
||||
Exit(X_VERIFY);
|
||||
}
|
||||
restore_check_point:
|
||||
if (archive && top && !doingverify) {
|
||||
killedpid = archivepid;
|
||||
if (archivepid)
|
||||
kill(archivepid, SIGKILL);
|
||||
archivepid = setuparchive();
|
||||
}
|
||||
|
||||
(void)signal(SIGINT, interrupt);
|
||||
fflush(stderr);
|
||||
/*
|
||||
* All signals are inherited...
|
||||
*/
|
||||
childpid = fork();
|
||||
if (childpid < 0) {
|
||||
msg("Context save fork fails in parent %d\n", parentpid);
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
if (childpid != 0) {
|
||||
/*
|
||||
* PARENT:
|
||||
* save the context by waiting
|
||||
* until the child doing all of the work returns.
|
||||
* don't catch the interrupt
|
||||
*/
|
||||
(void)signal(SIGINT, SIG_IGN);
|
||||
#ifdef TDEBUG
|
||||
msg("Volume: %d; parent process: %d child process %d\n",
|
||||
tapeno+1, parentpid, childpid);
|
||||
#endif TDEBUG
|
||||
for (;;) {
|
||||
waitpid = wait((union wait *)&status);
|
||||
if (waitpid == childpid)
|
||||
break;
|
||||
if (waitpid == killedpid)
|
||||
continue;
|
||||
msg("Parent %d waiting for child %d has another child %d return\n",
|
||||
parentpid, childpid, waitpid);
|
||||
}
|
||||
if (status & 0xFF) {
|
||||
msg("Child %d returns LOB status %d\n",
|
||||
childpid, status&0xFF);
|
||||
}
|
||||
status = (status >> 8) & 0xFF;
|
||||
#ifdef TDEBUG
|
||||
switch (status) {
|
||||
case X_FINOK:
|
||||
msg("Child %d finishes X_FINOK\n", childpid);
|
||||
break;
|
||||
case X_ABORT:
|
||||
msg("Child %d finishes X_ABORT\n", childpid);
|
||||
break;
|
||||
case X_REWRITE:
|
||||
msg("Child %d finishes X_REWRITE\n", childpid);
|
||||
break;
|
||||
case X_VERIFY:
|
||||
msg("Child %d finishes X_VERIFY\n", childpid);
|
||||
break;
|
||||
default:
|
||||
msg("Child %d finishes unknown %d\n", childpid, status);
|
||||
break;
|
||||
}
|
||||
#endif TDEBUG
|
||||
switch (status) {
|
||||
case X_FINOK:
|
||||
close(arch);
|
||||
while (wait((union wait *)NULL) >= 0)
|
||||
; /* wait for archive process */
|
||||
Exit(X_FINOK);
|
||||
case X_ABORT:
|
||||
Exit(X_ABORT);
|
||||
case X_VERIFY:
|
||||
doingverify++;
|
||||
goto restore_check_point;
|
||||
case X_REWRITE:
|
||||
if (archive && !top && dumptoarchive)
|
||||
Exit(X_REWRITE);
|
||||
doingverify = 0;
|
||||
goto restore_check_point;
|
||||
default:
|
||||
msg("Bad return code from dump: %d\n", status);
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
} else { /* we are the child; just continue */
|
||||
#ifdef TDEBUG
|
||||
sleep(4); /* allow time for parent's message to get out */
|
||||
msg("Child on Volume %d has parent %d, my pid = %d\n",
|
||||
tapeno+1, parentpid, getpid());
|
||||
#endif
|
||||
while ((to = host ? rmtopen(tape, 2) :
|
||||
pipeout ? 1 :
|
||||
doingverify ? open(tape, 0) : creat(tape, 0666)) < 0)
|
||||
if (!query("Cannot open volume. Do you want to retry the open?"))
|
||||
dumpabort();
|
||||
|
||||
if (doingverify) {
|
||||
/*
|
||||
* If we're using the non-rewinding tape device,
|
||||
* the tape will be left positioned after the
|
||||
* EOF mark. We need to back up to the beginning
|
||||
* of this tape file (cross two tape marks in the
|
||||
* reverse direction and one in the forward
|
||||
* direction) before the verify pass.
|
||||
*/
|
||||
if (host) {
|
||||
if (rmtioctl(MTBSF, 2) >= 0)
|
||||
(void) rmtioctl(MTFSF, 1);
|
||||
else
|
||||
(void) rmtioctl(MTNBSF, 1);
|
||||
} else {
|
||||
static struct mtop bsf = { MTBSF, 2 };
|
||||
static struct mtop fsf = { MTFSF, 1 };
|
||||
static struct mtop nbsf = { MTNBSF, 1 };
|
||||
|
||||
if (ioctl(to, MTIOCTOP, &bsf) >= 0)
|
||||
(void) ioctl(to, MTIOCTOP, &fsf);
|
||||
else
|
||||
(void) ioctl(to, MTIOCTOP, &nbsf);
|
||||
}
|
||||
}
|
||||
|
||||
enslave(); /* Share open tape file descriptor with slaves */
|
||||
asize = 0;
|
||||
tapeno++; /* current tape sequence */
|
||||
newtape++; /* new tape signal */
|
||||
blks = 0;
|
||||
if (spcl.c_type != TS_END)
|
||||
for (i = 0; i < spcl.c_count; i++)
|
||||
if (spcl.c_addr[i] != 0)
|
||||
blks++;
|
||||
spcl.c_count = blks + 1 - spcl.c_tapea + lastspclrec;
|
||||
spcl.c_volume++;
|
||||
if (tapeno == 1)
|
||||
inos[1] = 2;
|
||||
else if (tapeno < TP_NINOS)
|
||||
inos[tapeno] = ino;
|
||||
spcl.c_type = TS_TAPE;
|
||||
spcl.c_flags |= DR_NEWHEADER;
|
||||
spclrec();
|
||||
spcl.c_flags &=~ DR_NEWHEADER;
|
||||
if (doingverify)
|
||||
msg("Starting verify pass\n");
|
||||
else if (tapeno > 1)
|
||||
msg("Volume %d begins with blocks from ino %d\n",
|
||||
tapeno, ino);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dumpabort()
|
||||
{
|
||||
|
||||
if (master != 0 && master != getpid())
|
||||
kill(master, SIGTERM); /* Signals master to call dumpabort */
|
||||
else {
|
||||
killall();
|
||||
msg("The ENTIRE dump is aborted.\n");
|
||||
}
|
||||
Exit(X_ABORT);
|
||||
}
|
||||
|
||||
Exit(status)
|
||||
{
|
||||
|
||||
#ifdef TDEBUG
|
||||
msg("pid = %d exits with status %d\n", getpid(), status);
|
||||
#endif TDEBUG
|
||||
exit(status);
|
||||
}
|
||||
|
||||
void
|
||||
sigpipe()
|
||||
{
|
||||
|
||||
msg("Broken pipe\n");
|
||||
dumpabort();
|
||||
}
|
||||
|
||||
killall()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < SLAVES; i++)
|
||||
if (slavepid[i] > 0)
|
||||
kill(slavepid[i], SIGKILL);
|
||||
}
|
||||
|
||||
static int ready, caught;
|
||||
static jmp_buf jbuf;
|
||||
|
||||
void
|
||||
proceed()
|
||||
{
|
||||
|
||||
if (ready)
|
||||
longjmp(jbuf, 1);
|
||||
caught++;
|
||||
}
|
||||
|
||||
enslave()
|
||||
{
|
||||
int cmd[2]; /* file descriptors */
|
||||
register int i, j;
|
||||
|
||||
master = getpid();
|
||||
(void)signal(SIGTERM, dumpabort); /* Slave sends SIGTERM on dumpabort() */
|
||||
(void)signal(SIGPIPE, sigpipe);
|
||||
(void)signal(SIGIOT, tperror); /* Slave sends SIGIOT on tape errors */
|
||||
(void)signal(SIGTRAP, proceed);
|
||||
for (i = 0; i < SLAVES; i++) {
|
||||
if (pipe(cmd) < 0 || (slavepid[i] = fork()) < 0) {
|
||||
perror(" DUMP: can't create child");
|
||||
dumpabort();
|
||||
}
|
||||
slavefd[i] = cmd[1];
|
||||
if (slavepid[i] == 0) { /* Slave starts up here */
|
||||
int next; /* pid of neighbor */
|
||||
#ifdef TDEBUG
|
||||
sleep(4); /* allow time for parent's message to get out */
|
||||
msg("Neighbor has pid = %d\n", getpid());
|
||||
#endif
|
||||
|
||||
for (j = 0; j <= i; j++)
|
||||
close(slavefd[j]);
|
||||
close(fi); /* Need our own seek ptr */
|
||||
if ((fi = open(disk, 0)) < 0) {
|
||||
perror(" DUMP: can't reopen disk");
|
||||
dumpabort();
|
||||
}
|
||||
signal(SIGINT, SIG_IGN); /* Master handles this */
|
||||
atomic(read, cmd[0], (char *)&next, sizeof (next));
|
||||
doslave(cmd[0], next, i);
|
||||
Exit(X_FINOK);
|
||||
}
|
||||
close(cmd[0]);
|
||||
}
|
||||
for (i = 0; i < SLAVES; i++)
|
||||
atomic(write, slavefd[i],
|
||||
(char *)&slavepid[(i + 1) % SLAVES], sizeof (int));
|
||||
kill(slavepid[0], SIGTRAP);
|
||||
master = 0;
|
||||
rotor = 0;
|
||||
}
|
||||
|
||||
doslave(cmd, next, mynum)
|
||||
int cmd, next, mynum;
|
||||
{
|
||||
int nread;
|
||||
char *rbuf;
|
||||
long archivesize, size;
|
||||
|
||||
if (doingverify) {
|
||||
rbuf = (char *)malloc((u_int)writesize);
|
||||
if (rbuf == 0) {
|
||||
kill(master, SIGIOT); /* Restart from checkpoint */
|
||||
pause();
|
||||
}
|
||||
}
|
||||
while ((nread = atomic(read, cmd, (char *)req, reqsiz)) == reqsiz) {
|
||||
register struct req *p;
|
||||
register int nrec = 0, trec;
|
||||
register char *tp;
|
||||
|
||||
for (p = req, trecno = 0; p->count > 0;
|
||||
trecno += p->count, p += p->count) {
|
||||
if (p->dblk == 0)
|
||||
trec = trecno - nrec++;
|
||||
}
|
||||
if (nrec > 0 &&
|
||||
atomic(read, cmd, (char *)tblock[trec], nrec*TP_BSIZE) !=
|
||||
nrec*TP_BSIZE) {
|
||||
msg("Master/slave protocol botched\n");
|
||||
dumpabort();
|
||||
}
|
||||
archivesize = 0;
|
||||
for (p = req, trecno = 0; p->count > 0;
|
||||
trecno += p->count, p += p->count) {
|
||||
size = p->count * TP_BSIZE;
|
||||
if (p->flag)
|
||||
archivesize += size;
|
||||
if (p->dblk)
|
||||
bread(p->dblk, tblock[trecno], size);
|
||||
else if (trecno < trec)
|
||||
*(union u_spcl *)tblock[trecno] =
|
||||
*(union u_spcl *)tblock[trec++];
|
||||
}
|
||||
if (setjmp(jbuf) == 0) {
|
||||
ready = 1;
|
||||
if (!caught)
|
||||
pause();
|
||||
}
|
||||
ready = caught = 0;
|
||||
for (tp = tblock[0]; (trecno -= ntrec) >= 0; tp += writesize) {
|
||||
if (archive && !doingverify && archivesize > 0) {
|
||||
size = archivesize < writesize ?
|
||||
archivesize : writesize;
|
||||
archivesize -= size;
|
||||
if (write(arch, tp, (int)size) != size) {
|
||||
msg("Cannot write archive file %s",
|
||||
archivefile);
|
||||
perror("");
|
||||
archive = 0;
|
||||
}
|
||||
}
|
||||
if (host) { /* prime the pipeline */
|
||||
if (!doingverify) {
|
||||
rmtwrite0(writesize);
|
||||
rmtwrite1(tp, writesize);
|
||||
if (mynum == 0) {
|
||||
--mynum;
|
||||
continue;
|
||||
}
|
||||
if (rmtwrite2() == writesize)
|
||||
continue;
|
||||
rmtwrite2(); /* ignore 2nd error */
|
||||
} else {
|
||||
if (rmtread(rbuf, writesize) ==
|
||||
writesize &&
|
||||
!bcmp(rbuf, tp, writesize))
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!doingverify) {
|
||||
if (write(to, tp, writesize) ==
|
||||
writesize)
|
||||
continue;
|
||||
} else {
|
||||
if (read(to, rbuf, writesize) ==
|
||||
writesize &&
|
||||
!bcmp(rbuf, tp, writesize))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
kill(master, SIGIOT); /* Restart from checkpoint */
|
||||
pause();
|
||||
}
|
||||
kill(next, SIGTRAP); /* Next slave's turn */
|
||||
}
|
||||
if (nread != 0) {
|
||||
perror(" DUMP: error reading command pipe");
|
||||
dumpabort();
|
||||
}
|
||||
if (host) {
|
||||
if (setjmp(jbuf) == 0) {
|
||||
ready++;
|
||||
if (!caught)
|
||||
pause();
|
||||
}
|
||||
ready = caught = 0;
|
||||
if (mynum < 0 && rmtwrite2() != writesize) {
|
||||
kill(master, SIGIOT);
|
||||
pause();
|
||||
}
|
||||
kill(next, SIGTRAP);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Since a read from a pipe may not return all we asked for,
|
||||
* or a write may not write all we ask if we get a signal,
|
||||
* loop until the count is satisfied (or error).
|
||||
*/
|
||||
atomic(func, fd, buf, count)
|
||||
int (*func)(), fd, count;
|
||||
char *buf;
|
||||
{
|
||||
int got, need = count;
|
||||
extern int errno;
|
||||
|
||||
while (need > 0) {
|
||||
got = (*func)(fd, buf, MIN(need, 4096));
|
||||
if (got < 0 && errno == EINTR)
|
||||
continue;
|
||||
if (got <= 0)
|
||||
break;
|
||||
buf += got;
|
||||
need -= got;
|
||||
}
|
||||
return ( (count-=need) == 0 ? got : count);
|
||||
}
|
||||
|
||||
int
|
||||
write_end_of_media()
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* prevent flusht() from calling write_end_of_media()
|
||||
* recursively while writing end of media record
|
||||
*/
|
||||
writing_eom = 1;
|
||||
spcl.c_type = TS_EOM;
|
||||
for (i=trecno; i < ntrec; i++)
|
||||
spclrec();
|
||||
writing_eom = 0;
|
||||
}
|
||||
334
etc/dump/dumptraverse.c
Normal file
334
etc/dump/dumptraverse.c
Normal file
@@ -0,0 +1,334 @@
|
||||
/*
|
||||
* Copyright (c) 1980 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumptraverse.c 1.1 92/07/30 SMI"; /* from UCB 5.3 1/9/86 */
|
||||
#endif not lint
|
||||
|
||||
#include "dump.h"
|
||||
#include <sys/file.h>
|
||||
|
||||
pass(fn, map)
|
||||
register int (*fn)();
|
||||
register char *map;
|
||||
{
|
||||
register int bits;
|
||||
ino_t maxino;
|
||||
|
||||
maxino = sblock->fs_ipg * sblock->fs_ncg - 1;
|
||||
for (ino = 0; ino < maxino; ) {
|
||||
if ((ino % NBBY) == 0) {
|
||||
bits = ~0;
|
||||
if (map != NULL)
|
||||
bits = *map++;
|
||||
}
|
||||
ino++;
|
||||
if (bits & 1)
|
||||
(*fn)(getino(ino));
|
||||
bits >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
mark(ip)
|
||||
struct dinode *ip;
|
||||
{
|
||||
register int f;
|
||||
extern int anydskipped;
|
||||
|
||||
f = ip->di_mode & IFMT;
|
||||
if (f == 0)
|
||||
return;
|
||||
BIS(ino, clrmap);
|
||||
if (f == IFDIR)
|
||||
BIS(ino, dirmap);
|
||||
if ((ip->di_mtime >= spcl.c_ddate || ip->di_ctime >= spcl.c_ddate) &&
|
||||
!BIT(ino, nodmap)) {
|
||||
BIS(ino, nodmap);
|
||||
if (f != IFREG && f != IFDIR && f != IFLNK) {
|
||||
esize += 1;
|
||||
return;
|
||||
}
|
||||
est(ip);
|
||||
} else if (f == IFDIR)
|
||||
anydskipped = 1;
|
||||
}
|
||||
|
||||
add(ip)
|
||||
register struct dinode *ip;
|
||||
{
|
||||
register int i;
|
||||
long filesize;
|
||||
|
||||
if(BIT(ino, nodmap))
|
||||
return;
|
||||
nsubdir = 0;
|
||||
dadded = 0;
|
||||
filesize = roundup(ip->di_size, DEV_BSIZE);
|
||||
for (i = 0; i < NDADDR; i++) {
|
||||
if (ip->di_db[i] != 0)
|
||||
dsrch(ip->di_db[i], dblksize(sblock, ip, i), filesize);
|
||||
filesize -= sblock->fs_bsize;
|
||||
}
|
||||
for (i = 0; i < NIADDR; i++) {
|
||||
if (ip->di_ib[i] != 0)
|
||||
indir(ip->di_ib[i], i, &filesize);
|
||||
}
|
||||
if(dadded) {
|
||||
nadded++;
|
||||
if (!BIT(ino, nodmap)) {
|
||||
BIS(ino, nodmap);
|
||||
est(ip);
|
||||
}
|
||||
}
|
||||
if(nsubdir == 0)
|
||||
if(!BIT(ino, nodmap))
|
||||
BIC(ino, dirmap);
|
||||
}
|
||||
|
||||
indir(d, n, filesize)
|
||||
daddr_t d;
|
||||
int n;
|
||||
long *filesize;
|
||||
{
|
||||
register i;
|
||||
daddr_t idblk[MAXNINDIR];
|
||||
|
||||
bread(fsbtodb(sblock, d), (char *)idblk, sblock->fs_bsize);
|
||||
if(n <= 0) {
|
||||
for(i=0; i < NINDIR(sblock); i++) {
|
||||
d = idblk[i];
|
||||
if(d != 0)
|
||||
dsrch(d, sblock->fs_bsize, *filesize);
|
||||
*filesize -= sblock->fs_bsize;
|
||||
}
|
||||
} else {
|
||||
n--;
|
||||
for(i=0; i < NINDIR(sblock); i++) {
|
||||
d = idblk[i];
|
||||
if(d != 0)
|
||||
indir(d, n, filesize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dirdump(ip)
|
||||
struct dinode *ip;
|
||||
{
|
||||
/* watchout for dir inodes deleted and maybe reallocated */
|
||||
if ((ip->di_mode & IFMT) != IFDIR)
|
||||
return;
|
||||
dump(ip);
|
||||
}
|
||||
|
||||
dump(ip)
|
||||
struct dinode *ip;
|
||||
{
|
||||
register int i;
|
||||
long size;
|
||||
|
||||
if(newtape) {
|
||||
newtape = 0;
|
||||
bitmap(nodmap, TS_BITS);
|
||||
}
|
||||
BIC(ino, nodmap);
|
||||
spcl.c_dinode = *ip;
|
||||
spcl.c_type = TS_INODE;
|
||||
spcl.c_count = 0;
|
||||
i = ip->di_mode & IFMT;
|
||||
if (i == 0) /* free inode */
|
||||
return;
|
||||
if ((i != IFDIR && i != IFREG && i != IFLNK) || ip->di_size == 0) {
|
||||
spclrec();
|
||||
return;
|
||||
}
|
||||
if (ip->di_size > NDADDR * sblock->fs_bsize)
|
||||
i = NDADDR * sblock->fs_frag;
|
||||
else
|
||||
i = howmany(ip->di_size, sblock->fs_fsize);
|
||||
blksout(&ip->di_db[0], i);
|
||||
size = ip->di_size - NDADDR * sblock->fs_bsize;
|
||||
if (size <= 0)
|
||||
return;
|
||||
for (i = 0; i < NIADDR; i++) {
|
||||
dmpindir(ip->di_ib[i], i, &size);
|
||||
if (size <= 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dmpindir(blk, lvl, size)
|
||||
daddr_t blk;
|
||||
int lvl;
|
||||
long *size;
|
||||
{
|
||||
int i, cnt;
|
||||
daddr_t idblk[MAXNINDIR];
|
||||
|
||||
if (blk != 0)
|
||||
bread(fsbtodb(sblock, blk), (char *)idblk, sblock->fs_bsize);
|
||||
else
|
||||
bzero((char *)idblk, (int)sblock->fs_bsize);
|
||||
if (lvl <= 0) {
|
||||
if (*size < NINDIR(sblock) * sblock->fs_bsize)
|
||||
cnt = howmany(*size, sblock->fs_fsize);
|
||||
else
|
||||
cnt = NINDIR(sblock) * sblock->fs_frag;
|
||||
*size -= NINDIR(sblock) * sblock->fs_bsize;
|
||||
blksout(&idblk[0], cnt);
|
||||
return;
|
||||
}
|
||||
lvl--;
|
||||
for (i = 0; i < NINDIR(sblock); i++) {
|
||||
dmpindir(idblk[i], lvl, size);
|
||||
if (*size <= 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
blksout(blkp, frags)
|
||||
daddr_t *blkp;
|
||||
int frags;
|
||||
{
|
||||
int i, j, count, blks, tbperdb;
|
||||
|
||||
blks = howmany(frags * sblock->fs_fsize, TP_BSIZE);
|
||||
tbperdb = sblock->fs_bsize / TP_BSIZE;
|
||||
for (i = 0; i < blks; i += TP_NINDIR) {
|
||||
if (i + TP_NINDIR > blks)
|
||||
count = blks;
|
||||
else
|
||||
count = i + TP_NINDIR;
|
||||
for (j = i; j < count; j++)
|
||||
if (blkp[j / tbperdb] != 0)
|
||||
spcl.c_addr[j - i] = 1;
|
||||
else
|
||||
spcl.c_addr[j - i] = 0;
|
||||
spcl.c_count = count - i;
|
||||
spclrec();
|
||||
for (j = i; j < count; j += tbperdb)
|
||||
if (blkp[j / tbperdb] != 0)
|
||||
if (j + tbperdb <= count)
|
||||
dmpblk(blkp[j / tbperdb],
|
||||
sblock->fs_bsize);
|
||||
else
|
||||
dmpblk(blkp[j / tbperdb],
|
||||
(long)((count - j) * TP_BSIZE));
|
||||
spcl.c_type = TS_ADDR;
|
||||
}
|
||||
}
|
||||
|
||||
bitmap(map, typ)
|
||||
char *map;
|
||||
{
|
||||
register int i;
|
||||
char *cp;
|
||||
|
||||
spcl.c_type = typ;
|
||||
spcl.c_count = howmany(msiz * sizeof(map[0]), TP_BSIZE);
|
||||
spclrec();
|
||||
for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE)
|
||||
taprec(cp);
|
||||
}
|
||||
|
||||
dsrch(d, size, filesize)
|
||||
daddr_t d;
|
||||
long size, filesize;
|
||||
{
|
||||
register struct direct *dp;
|
||||
long loc;
|
||||
char dblk[MAXBSIZE];
|
||||
|
||||
if(dadded)
|
||||
return;
|
||||
if (filesize > size)
|
||||
filesize = size;
|
||||
bread(fsbtodb(sblock, d), dblk, filesize);
|
||||
for (loc = 0; loc < filesize; ) {
|
||||
dp = (struct direct *)(dblk + loc);
|
||||
if (dp->d_reclen == 0) {
|
||||
msg("corrupted directory, inumber %d\n", ino);
|
||||
break;
|
||||
}
|
||||
loc += dp->d_reclen;
|
||||
if(dp->d_ino == 0)
|
||||
continue;
|
||||
if(dp->d_name[0] == '.') {
|
||||
if(dp->d_name[1] == '\0')
|
||||
continue;
|
||||
if(dp->d_name[1] == '.' && dp->d_name[2] == '\0')
|
||||
continue;
|
||||
}
|
||||
if(BIT(dp->d_ino, nodmap)) {
|
||||
dadded++;
|
||||
return;
|
||||
}
|
||||
if(BIT(dp->d_ino, dirmap))
|
||||
nsubdir++;
|
||||
}
|
||||
}
|
||||
|
||||
struct dinode *
|
||||
getino(ino)
|
||||
ino_t ino;
|
||||
{
|
||||
static ino_t minino, maxino;
|
||||
static struct dinode itab[MAXINOPB];
|
||||
|
||||
if (ino >= minino && ino < maxino) {
|
||||
return (&itab[ino - minino]);
|
||||
}
|
||||
bread(fsbtodb(sblock, itod(sblock, ino)),
|
||||
(char *)itab, sblock->fs_bsize);
|
||||
minino = ino - (ino % INOPB(sblock));
|
||||
maxino = minino + INOPB(sblock);
|
||||
return (&itab[ino - minino]);
|
||||
}
|
||||
|
||||
int breaderrors = 0;
|
||||
#define BREADEMAX 32
|
||||
|
||||
bread(da, ba, cnt)
|
||||
daddr_t da;
|
||||
char *ba;
|
||||
long cnt;
|
||||
{
|
||||
int n;
|
||||
|
||||
loop:
|
||||
if (lseek(fi, (long)(da * DEV_BSIZE), L_SET) < 0){
|
||||
msg("bread: lseek fails\n");
|
||||
}
|
||||
n = read(fi, ba, (int)cnt);
|
||||
if (n == cnt)
|
||||
return;
|
||||
if (da + (cnt / DEV_BSIZE) > fsbtodb(sblock, sblock->fs_size)) {
|
||||
/*
|
||||
* Trying to read the final fragment.
|
||||
*
|
||||
* NB - dump only works in TP_BSIZE blocks, hence
|
||||
* rounds DEV_BSIZE fragments up to TP_BSIZE pieces.
|
||||
* It should be smarter about not actually trying to
|
||||
* read more than it can get, but for the time being
|
||||
* we punt and scale back the read only when it gets
|
||||
* us into trouble. (mkm 9/25/83)
|
||||
*/
|
||||
cnt -= DEV_BSIZE;
|
||||
goto loop;
|
||||
}
|
||||
msg("(This should not happen)bread from %s [block %d]: count=%d, got=%d\n",
|
||||
disk, da, cnt, n);
|
||||
if (++breaderrors > BREADEMAX){
|
||||
msg("More than %d block read errors from %d\n",
|
||||
BREADEMAX, disk);
|
||||
broadcast("DUMP IS AILING!\n");
|
||||
msg("This is an unrecoverable error.\n");
|
||||
if (!query("Do you want to attempt to continue?")){
|
||||
dumpabort();
|
||||
/*NOTREACHED*/
|
||||
} else
|
||||
breaderrors = 0;
|
||||
}
|
||||
}
|
||||
219
etc/dump/lftw.c
Normal file
219
etc/dump/lftw.c
Normal file
@@ -0,0 +1,219 @@
|
||||
#if !defined(lint) && !defined(NOID)
|
||||
static char sccsid[] = "@(#)lftw.c 1.1 92/07/30 SMI"; /* from S5R2 1.2 */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright 1989, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*LINTLIBRARY*/
|
||||
/***************************************************************
|
||||
* ftw - file tree walk
|
||||
*
|
||||
* int ftw (path, fn, depth) char *path; int (*fn)(); int depth;
|
||||
*
|
||||
* Given a path name, ftw starts from the file given by that path
|
||||
* name and visits each file and directory in the tree beneath
|
||||
* that file. If a single file has multiple links within the
|
||||
* structure, it will be visited once for each such link.
|
||||
* For each object visited, fn is called with three arguments.
|
||||
* The first contains the path name of the object, the second
|
||||
* contains a pointer to a stat buffer which will usually hold
|
||||
* appropriate information for the object and the third will
|
||||
* contain an integer value giving additional information about
|
||||
*
|
||||
* FTW_F The object is a file for which stat was
|
||||
* successful. It does not guarantee that the
|
||||
* file can actually be read.
|
||||
*
|
||||
* FTW_D The object is a directory for which stat and
|
||||
* open for read were both successful.
|
||||
*
|
||||
* FTW_DNR The object is a directory for which stat
|
||||
* succeeded, but which cannot be read. Because
|
||||
* the directory cannot be read, fn will not be
|
||||
* called for any descendants of this directory.
|
||||
*
|
||||
* FTW_NS Stat failed on the object because of lack of
|
||||
* appropriate permission. This indication will
|
||||
* be given, for example, for each file in a
|
||||
* directory with read but no execute permission.
|
||||
* Because stat failed, it is not possible to
|
||||
* determine whether this object is a file or a
|
||||
* directory. The stat buffer passed to fn will
|
||||
* contain garbage. Stat failure for any reason
|
||||
* other than lack of permission will be
|
||||
* considered an error and will cause ftw to stop
|
||||
* and return -1 to its caller.
|
||||
*
|
||||
* If fn returns nonzero, ftw stops and returns the same value
|
||||
* to its caller. If ftw gets into other trouble along the way,
|
||||
* it returns -1 and leaves an indication of the cause in errno.
|
||||
*
|
||||
* The third argument to ftw does not limit the depth to which
|
||||
* ftw will go. Rather, it limits the depth to which ftw will
|
||||
* go before it starts recycling file descriptors. In general,
|
||||
* it is necessary to use a file descriptor for each level of the
|
||||
* tree, but they can be recycled for deep trees by saving the
|
||||
* position, closing, re-opening, and seeking. It is possible
|
||||
* to start recycling file descriptors by sensing when we have
|
||||
* run out, but in general this will not be terribly useful if
|
||||
* fn expects to be able to open files. We could also figure out
|
||||
* how many file descriptors are available and guarantee a certain
|
||||
* number to fn, but we would not know how many to guarantee,
|
||||
* and we do not want to impose the extra overhead on a caller who
|
||||
* knows how many are available without having to figure it out.
|
||||
*
|
||||
* It is possible for ftw to die with a memory fault in the event
|
||||
* of a file system so deeply nested that the stack overflows.
|
||||
**************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/dir.h>
|
||||
#include <errno.h>
|
||||
#include <ftw.h>
|
||||
|
||||
#define NULL 0
|
||||
|
||||
extern char *malloc(), *strcpy();
|
||||
extern void free();
|
||||
extern int errno;
|
||||
|
||||
ftw(path, fn, depth)
|
||||
char *path;
|
||||
int (*fn)();
|
||||
int depth;
|
||||
{
|
||||
extern int stat();
|
||||
|
||||
return xftw(path, fn, depth, stat);
|
||||
}
|
||||
|
||||
lftw(path, fn, depth)
|
||||
char *path;
|
||||
int (*fn)();
|
||||
int depth;
|
||||
{
|
||||
extern int lstat();
|
||||
|
||||
return xftw(path, fn, depth, lstat);
|
||||
}
|
||||
|
||||
static int
|
||||
xftw(path, fn, depth, statfn)
|
||||
char *path;
|
||||
int (*fn)();
|
||||
int depth;
|
||||
int (*statfn)();
|
||||
{
|
||||
int rc, n;
|
||||
DIR *dirp;
|
||||
char *subpath, *component;
|
||||
struct stat sb;
|
||||
struct direct *dp;
|
||||
|
||||
/* Try to get file status.
|
||||
If unsuccessful, errno will say why. */
|
||||
if((*statfn)(path, &sb) < 0)
|
||||
return(errno == EACCES? (*fn)(path, &sb, FTW_NS): -1);
|
||||
|
||||
/*
|
||||
* The stat succeeded, so we know the object exists.
|
||||
* If not a directory, call the user function and return.
|
||||
*/
|
||||
if((sb.st_mode & S_IFMT) != S_IFDIR)
|
||||
return((*fn)(path, &sb, FTW_F));
|
||||
|
||||
/*
|
||||
* The object was a directory.
|
||||
*
|
||||
* Open a file to read the directory
|
||||
*/
|
||||
dirp = opendir(path);
|
||||
|
||||
/*
|
||||
* Call the user function, telling it whether
|
||||
* the directory can be read. If it can't be read
|
||||
* call the user function or indicate an error,
|
||||
* depending on the reason it couldn't be read.
|
||||
*/
|
||||
if(dirp == NULL)
|
||||
return(errno == EACCES? (*fn)(path, &sb, FTW_DNR): -1);
|
||||
|
||||
/* We could read the directory. Call user function. */
|
||||
rc = (*fn)(path, &sb, FTW_D);
|
||||
if(rc != 0)
|
||||
return(rc);
|
||||
|
||||
/* Allocate a buffer to hold generated pathnames. */
|
||||
n = strlen(path);
|
||||
subpath = malloc((unsigned)(n+MAXNAMLEN+2));
|
||||
if(subpath == NULL) {
|
||||
closedir(dirp);
|
||||
errno = ENOMEM;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Create a prefix to which we will append component names */
|
||||
(void)strcpy(subpath, path);
|
||||
if(subpath[0] != '\0' && subpath[n-1] != '/')
|
||||
subpath[n++] = '/';
|
||||
component = &subpath[n];
|
||||
|
||||
/*
|
||||
* Read the directory one component at a time.
|
||||
* We must ignore "." and "..", but other than that,
|
||||
* just create a path name and call self to check it out.
|
||||
*/
|
||||
while((dp = readdir(dirp)) != NULL) {
|
||||
if(strcmp(dp->d_name, ".") != 0 &&
|
||||
strcmp(dp->d_name, "..") != 0) {
|
||||
long here;
|
||||
|
||||
/* Append component name to the working path */
|
||||
(void)strcpy(component, dp->d_name);
|
||||
|
||||
/*
|
||||
* If we are about to exceed our depth,
|
||||
* remember where we are and close a file.
|
||||
*/
|
||||
if(depth <= 1) {
|
||||
here = telldir(dirp);
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Do a recursive call to process the file.
|
||||
* (watch this, sports fans)
|
||||
*/
|
||||
rc = xftw(subpath, fn, depth-1, statfn);
|
||||
if(rc != 0) {
|
||||
free(subpath);
|
||||
if(depth > 1)
|
||||
closedir(dirp);
|
||||
return(rc);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we closed the file, try to reopen it.
|
||||
*/
|
||||
if(depth <= 1) {
|
||||
dirp = opendir(path);
|
||||
if(dirp == NULL) {
|
||||
free(subpath);
|
||||
return(-1);
|
||||
}
|
||||
seekdir(dirp, here);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We got out of the subdirectory loop. The return from
|
||||
* the final readdir is in dp. Clean up.
|
||||
*/
|
||||
free(subpath);
|
||||
closedir(dirp);
|
||||
return(0);
|
||||
}
|
||||
178
etc/dump/partial.c
Normal file
178
etc/dump/partial.c
Normal file
@@ -0,0 +1,178 @@
|
||||
#if !defined(lint) && !defined(NOID)
|
||||
static char sccsid[] = "@(#)partial.c 1.1 92/07/30 SMI";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright 1989, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "dump.h"
|
||||
#include <ftw.h>
|
||||
|
||||
static dev_t blockdev;
|
||||
static int partial;
|
||||
static char realdisk[32];
|
||||
|
||||
extern int errno;
|
||||
extern char *estrdup();
|
||||
extern char *strcpy(), *strcat(), *rindex();
|
||||
|
||||
static int ftw_check();
|
||||
static int ftw_mark();
|
||||
static char *strerror();
|
||||
|
||||
|
||||
partial_check()
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(disk, &st) < 0 ||
|
||||
(st.st_mode & S_IFMT) == S_IFCHR ||
|
||||
(st.st_mode & S_IFMT) == S_IFBLK)
|
||||
return;
|
||||
|
||||
blockdev = st.st_dev;
|
||||
|
||||
if (lftw("/dev", ftw_check, 0) <= 0) {
|
||||
msg("Cannot find block device %d, %d\n",
|
||||
major(blockdev), minor(blockdev));
|
||||
dumpabort();
|
||||
}
|
||||
|
||||
disk = strcpy(realdisk, rawname(realdisk));
|
||||
|
||||
partial = 1;
|
||||
incno = '0';
|
||||
uflag = 0;
|
||||
}
|
||||
|
||||
static
|
||||
ftw_check(name, st, flag)
|
||||
char *name;
|
||||
struct stat *st;
|
||||
int flag;
|
||||
{
|
||||
if (flag == FTW_F &&
|
||||
(st->st_mode & S_IFMT) == S_IFBLK &
|
||||
st->st_rdev == blockdev) {
|
||||
(void) strcpy(realdisk, name);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
partial_mark(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *path;
|
||||
struct stat st;
|
||||
|
||||
if (partial == 0)
|
||||
return 1;
|
||||
|
||||
while (--argc >= 0) {
|
||||
path = *argv++;
|
||||
|
||||
if (stat(path, &st) < 0 ||
|
||||
st.st_dev != blockdev) {
|
||||
msg("%s is not on device %s\n",
|
||||
path, disk);
|
||||
dumpabort();
|
||||
}
|
||||
|
||||
if (mark_root(blockdev, path)) {
|
||||
msg("Cannot find filesystem mount point for %s\n",
|
||||
path);
|
||||
dumpabort();
|
||||
}
|
||||
|
||||
if (lftw(path, ftw_mark, getdtablesize() / 2) < 0) {
|
||||
msg("Error in ftw (%s)\n", strerror(errno));
|
||||
dumpabort();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mark directories between target and root */
|
||||
static
|
||||
mark_root(dev, path)
|
||||
dev_t dev;
|
||||
char *path;
|
||||
{
|
||||
struct stat st;
|
||||
char dotdot[MAXPATHLEN + 16];
|
||||
char *slash;
|
||||
|
||||
strcpy(dotdot, path);
|
||||
|
||||
if (stat(dotdot, &st) < 0)
|
||||
return 1;
|
||||
|
||||
/* if target is a regular file, find directory */
|
||||
if ((st.st_mode & S_IFMT) != S_IFDIR)
|
||||
if (slash = rindex(dotdot, '/'))
|
||||
/* "/file" -> "/" */
|
||||
if (slash == dotdot)
|
||||
slash[1] = 0;
|
||||
/* "dir/file" -> "dir" */
|
||||
else
|
||||
slash[0] = 0;
|
||||
else
|
||||
/* "file" -> "." */
|
||||
strcpy(dotdot, ".");
|
||||
|
||||
/* keep marking parent until we hit mount point */
|
||||
do {
|
||||
if (stat(dotdot, &st) < 0 ||
|
||||
(st.st_mode & S_IFMT) != S_IFDIR ||
|
||||
st.st_dev != dev)
|
||||
return 1;
|
||||
markino(st.st_ino);
|
||||
strcat(dotdot, "/..");
|
||||
} while (st.st_ino != 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static
|
||||
ftw_mark(name, st, flag)
|
||||
char *name;
|
||||
struct stat *st;
|
||||
int flag;
|
||||
{
|
||||
if (flag != FTW_NS)
|
||||
markino(st->st_ino);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
markino(i)
|
||||
ino_t i;
|
||||
{
|
||||
struct dinode *dp;
|
||||
|
||||
dp = getino(ino = i);
|
||||
mark(dp);
|
||||
}
|
||||
|
||||
static char *
|
||||
strerror(err)
|
||||
int err;
|
||||
{
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
|
||||
static char errmsg[32];
|
||||
|
||||
if (err >= 0 && err < sys_nerr)
|
||||
return sys_errlist[sys_nerr];
|
||||
|
||||
(void) sprintf(errmsg, "Error %d", err);
|
||||
return errmsg;
|
||||
}
|
||||
118
etc/dump/unctime.c
Normal file
118
etc/dump/unctime.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 1980 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)unctime.c 1.1 92/07/30 SMI"; /* from UCB 5.1 6/5/85 */
|
||||
#endif not lint
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
/*
|
||||
* Convert a ctime(3) format string into a system format date.
|
||||
* Return the date thus calculated.
|
||||
*
|
||||
* Return -1 if the string is not in ctime format.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Offsets into the ctime string to various parts.
|
||||
*/
|
||||
|
||||
#define E_MONTH 4
|
||||
#define E_DAY 8
|
||||
#define E_HOUR 11
|
||||
#define E_MINUTE 14
|
||||
#define E_SECOND 17
|
||||
#define E_YEAR 20
|
||||
|
||||
time_t unctime(str)
|
||||
char *str;
|
||||
{
|
||||
struct tm then;
|
||||
char dbuf[30];
|
||||
time_t emitl();
|
||||
|
||||
if (strlen(str) != 25)
|
||||
str[25] = 0;
|
||||
strcpy(dbuf, str);
|
||||
dbuf[E_MONTH+3] = 0;
|
||||
if ( (then.tm_mon = lookup(&dbuf[E_MONTH])) < 0) {
|
||||
return(-1);;
|
||||
}
|
||||
then.tm_mday = atoi(&dbuf[E_DAY]);
|
||||
then.tm_hour = atoi(&dbuf[E_HOUR]);
|
||||
then.tm_min = atoi(&dbuf[E_MINUTE]);
|
||||
then.tm_sec = atoi(&dbuf[E_SECOND]);
|
||||
then.tm_year = atoi(&dbuf[E_YEAR]) - 1900;
|
||||
return(emitl(&then));
|
||||
}
|
||||
|
||||
static char months[] =
|
||||
"JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
|
||||
static
|
||||
lookup(str)
|
||||
char *str;
|
||||
{
|
||||
register char *cp, *cp2;
|
||||
|
||||
for (cp = months, cp2 = str; *cp != 0; cp += 3)
|
||||
if (strncmp(cp, cp2, 3) == 0)
|
||||
return((cp-months) / 3);
|
||||
return(-1);
|
||||
}
|
||||
/*
|
||||
* Routine to convert a localtime(3) format date back into
|
||||
* a system format date.
|
||||
*
|
||||
* Use a binary search.
|
||||
*/
|
||||
|
||||
struct tm *localtime();
|
||||
|
||||
time_t emitl(dp)
|
||||
struct tm *dp;
|
||||
{
|
||||
time_t conv;
|
||||
register int i, bit;
|
||||
struct tm dcopy;
|
||||
|
||||
dcopy = *dp;
|
||||
dp = &dcopy;
|
||||
conv = 0;
|
||||
for (i = 30; i >= 0; i--) {
|
||||
bit = 1 << i;
|
||||
conv |= bit;
|
||||
if (dcmp(localtime(&conv), dp) > 0)
|
||||
conv &= ~bit;
|
||||
}
|
||||
return(conv);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare two localtime dates, return result.
|
||||
*/
|
||||
|
||||
#define DECIDE(a) \
|
||||
if (dp->a > dp2->a) \
|
||||
return(1); \
|
||||
if (dp->a < dp2->a) \
|
||||
return(-1)
|
||||
|
||||
static
|
||||
dcmp(dp, dp2)
|
||||
register struct tm *dp, *dp2;
|
||||
{
|
||||
|
||||
DECIDE(tm_year);
|
||||
DECIDE(tm_mon);
|
||||
DECIDE(tm_mday);
|
||||
DECIDE(tm_hour);
|
||||
DECIDE(tm_min);
|
||||
DECIDE(tm_sec);
|
||||
return(0);
|
||||
}
|
||||
Reference in New Issue
Block a user