#define MWORD(m,i) (m[(unsigned)(i-1)/MLEN])
#define MBIT(i) (1<<((unsigned)(i-1)%MLEN))
#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))
char tapename
[] = "/dev/rmt1";
char *magtape
= tapename
;
char dirfile
[] = "rstXXXXXX";
if (argc
>=3 && *argv
[0] == 'f')
df
= fopen(dirfile
, "w");
printf("dumpdir: %s - cannot create directory temporary\n", dirfile
);
if ((mt
= open(magtape
, 0)) < 0) {
printf("%s: cannot open tape\n", magtape
);
if (readhdr(&spcl
) == 0) {
printf("Tape is not a dump tape\n");
printf("Dump date: %s", ctime(&spcl
.c_date
));
printf("Dumped from: %s", ctime(&spcl
.c_ddate
));
if (checkvol(&spcl
, 1) == 0) {
printf("Tape is not volume 1 of the dump\n");
pass1(); /* This sets the various maps on the way by */
freopen(dirfile
, "r", df
);
printem(prebuf
, (ino_t
) 2);
* Read the tape, bulding up a directory structure for extraction
while (gethead(&spcl
) == 0) {
printf("Can't find directory header!\n");
if (checktype(&spcl
, TS_BITS
) == 1) {
if (checktype(&spcl
, TS_CLRI
) == 1) {
if (checktype(&spcl
, TS_INODE
) == 0) {
inotab
[ipos
].t_ino
= spcl
.c_inumber
;
inotab
[ipos
++].t_seekpt
= seekpt
;
getfile(spcl
.c_inumber
, putdir
, null
, spcl
.c_dinode
.di_size
);
for (i
= 0; i
< MAXINO
; i
++)
if (inotab
[i
].t_ino
== inum
) {
printf("PANIC - can't find directory %d\n", inum
);
mseek(inotab
[i
].t_seekpt
);
if (direq(dir
.d_name
, "/"))
if (search(dir
.d_ino
) != 0 && direq(dir
.d_name
, ".") == 0 && direq(dir
.d_name
, "..") == 0) {
df
= fopen(dirfile
, "r");
strncat(prefix
, dir
.d_name
, sizeof(dir
.d_name
));
printem(prefix
, dir
.d_ino
);
if (BIT(dir
.d_ino
, dumpmap
))
printf("%5d %s%-.14s\n", dir
.d_ino
, prefix
, dir
.d_name
);
* Do the file extraction, calling the supplied functions
if (gethead(&addrblock
) == 0) {
printf("Missing address (header) block\n");
if (checktype(&addrblock
, TS_ADDR
) == 0) {
for (i
= 0; i
< addrblock
.c_count
; i
++) {
if (addrblock
.c_addr
[i
]) {
(*f1
)(buf
, size
> BSIZE
? (long) BSIZE
: size
);
(*f2
)(buf
, size
> BSIZE
? (long) BSIZE
: size
);
if ((size
-= BSIZE
) <= 0) {
while (gethead(&spcl
) == 0)
if (checktype(&spcl
, TS_ADDR
) == 1)
* Do the tape i\/o, dealling with volume changes
for (i
= 0; i
< NTREC
; i
++)
((struct spcl
*)&tbf
[i
*BSIZE
])->c_magic
= 0;
if ((i
= read(mt
, tbf
, NTREC
*BSIZE
)) < 0) {
printf("Mount volume %d\n", volno
);
while (getchar() != '\n')
if ((mt
= open(magtape
, 0)) == -1) {
printf("Cannot open tape!\n");
if (readhdr(&tmpbuf
) == 0) {
printf("Not a dump tape.Try again\n");
if (checkvol(&tmpbuf
, volno
) == 0) {
printf("Wrong tape. Try again\n");
copy(&tbf
[(bct
++*BSIZE
)], b
, BSIZE
);
* Put and get the directory entries from the compressed
for (i
= 0; i
< sizeof(ino_t
); i
++)
for (i
= 0; i
< DIRSIZ
; i
++) {
for (i
= 0; i
< sizeof(ino_t
); i
++)
for (i
= 0; i
< DIRSIZ
; i
++)
if ((*bf
++ = readc()) == 0)
* read/write te directory file
* search the directory inode ino
register low
, high
, probe
;
probe
= (high
- low
+ 1)/2 + low
;
printf("low = %d, high = %d, probe = %d, ino = %d, inum = %d\n", low, high, probe, inum, inotab[probe].t_ino);
if (inum
>= inotab
[probe
].t_ino
)
return(inum
== inotab
[low
].t_ino
);
for (i
= 0; i
< DIRSIZ
; i
++)
* read the tape into buf, then return whether or
* or not it is a header block.
if (buf
->c_magic
!= MAGIC
|| checksum((int *) buf
) == 0)
* return whether or not the buffer contains a header block
printf("Checksum error %o\n", i
);
if (checktype(b
, TS_TAPE
) == 0)
register struct direct
*dp
;
for (dp
= (struct direct
*) b
, i
= 0; i
< BSIZE
; dp
++, i
+= sizeof(*dp
)) {
* read a bit mask from the tape into m.
m
+= (BSIZE
/(MLEN
/BITS
));
while (gethead(&spcl
) == 0)