1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
|
/*
dds2tar Digital-Data-Storage Extract Tool
This tool makes use of the fast seek command of DAT devices.
Files from a selected file archive can be extracted within
one minute.
J"org Weule weule@cs.uni-duesseldorf.de
Fon: +49 211 751409
----------------------------------------------------------------------------
LICENSE
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
----------------------------------------------------------------------------
To anyone in Germany I declare the following:
! Ich werde gegen jede Verbreitung dieser Software rechtlich !
! vorgehen, welche die Lizenzbestimmungen nicht einh"alt. !
Wie f"ur jede andere Software gilt auch hier:
Schon mit dem Kopieren oder Benutzen von Teilen dieser Software
werden die Lizenzbedingungen stillschweigend akzeptiert. Lesen Sie
also die Lizenzbedingungen sorgf"altig! Unkenntnis sch"utzt nicht
vor Strafe.
*/
/*-------------------------------------------------------------------------*/
#include <stdlib.h> /* getenv() */
#include <stdio.h>
#include <string.h> /* strcmp() strlen() strstr() */
#include <sys/types.h> /* open() stat() */
#include <sys/stat.h> /* stat() */
#include <fcntl.h> /* open() */
#include <unistd.h> /* open() */
#include <time.h> /* ctime() */
#include "dds2tar.h"
#include "dds_tape.h"
#include "zf-cre-open.h"
char vendor[9] = "\0\0\0\0\0\0\0\0\0" ;
int vid; /* vendor id */
/*-------------------------------------------------------------------------*/
static const char help_text_dds2index[] =
"This is dds2index, a tool for fast tape access.\n"
"Choose one of the following\n"
"-t,--table-of-contents F get file location from file F\n"
"-z,--compress filter location file through gzip\n"
"--z,--no-compress don't filter location file through gzip\n"
"-f,--device F read the archive from device F\n"
"-b,--block-size # set block size (non HP/SONY)\n"
"-B,--Block-size # set block size (HP or SONY)\n"
"-q,--quick don't extract parent directories from tape\n"
"-v,--verbose verbose mode\n"
"--hash-mode hash mode\n"
"--force force nochk\n"
"--help get help\n"
"-V,--version print version number\n"
"\n"
"Environment:\n"
"TAPE specifies the tape device\n"
"DDS2TAR=[--compress] [-z] [-s #] [-b #]\n"
" set some defaults\n"
;
static const char help_text_dds2tar[] =
"This is dds2tar, a tool for fast tape access.\n"
"Usage: dds2tar [options... ] -t index [pathname ...] | tar -f - ...\n"
"\n"
"dds2tar is a tool to read some tar-records from tape and write them\n"
"as a tar archive to stdout. You have to use tar to extract the\n"
"selected files. The index can either be created by dds2tar or tar.\n"
"\n"
"Choose one of the following\n"
"-t,--table-of-contents F get file location from file F\n"
"-z,--compress filter location file through gzip\n"
"--z,--no-compress don't filter location file through gzip\n"
"-f,--device F read the archive from device F\n"
"-o,--output F write output to archive file\n"
"-b,--block-size # set block size (non HP/SONY)\n"
"-B,--Block-size # set block size (HP or SONY)\n"
"-s,--first_block # set number of the first block\n"
"--body print only the contents of the first file an quit\n"
"-v,--verbose verbose mode\n"
"--help get help\n"
"-V,--version print version number\n"
"\n"
"Environment:\n"
"TAPE specifies the tape device\n"
"DDS2TAR=[--compress] [-z] [-s #] [-b #]\n"
" set some defaults\n"
;
static const char help_text_mt_dds[] =
"This is mt-dds, a tool to control the dds-device.\n"
"Usage: mt-dds [-f device] <action>\n"
"\n"
"Choose one or none of the following actions:\n"
#ifdef HPDAT
"comp-on set compression mode on\n"
"comp-off set compression mode off\n"
"comp-query query compression mode\n"
"comp-log print compression log page\n"
#endif
"-b set the buffer size\n"
"blksize print the block size of the archive with format\n"
"tell print current location and blocksize\n"
"where print current location\n"
"label print the label of the current archive\n"
" if it begins at the current position\n"
"filename print the filename of the current record\n"
" if a header record is found at the current position\n"
"ts print the timestamp of the current archive\n"
"date print the date of the current archive\n"
"scsi2logical select mode scsi2logical first\n"
" if it begins at the current position\n"
"date <timestamp> convert the stamp to a string\n"
;
static const char help_text_dds_dd[] =
"This is dds-dd, a tool to read the dds-device.\n"
"Usage: dds-dd` [-f device] | tar -f - -[x|t] ... \n";
/*-------------------------------------------------------------------------*/
static const char version[] =
"Version " VERSION " -- last change 1994 Dez 22." ;
/*-------------------------------------------------------------------------*/
/* This is the source for dds2tar, dds2index and mt-dds. The program will
use the variable pg to decide witch version is running. The default
can be set in the Makefile and is overwritten by the value of argv[0].
If you give --dds2tar, --dds2index or --mt-dds as an option, the
program will run instead of these.
*/
#define DDS2TAR name_dds2tar
static char const name_dds2tar[] = "dds2tar";
#define DDS2INDEX name_dds2index
static char const name_dds2index[] = "dds2index";
#define MTDDS name_mtdds
static char const name_mtdds[] = "mt-dds";
#define DDS_DD name_dds_dd
static char const name_dds_dd[] = "dds-dd";
#if ( PROGRAM == DDS2TAR )
char const *pg = name_dds2tar;
char const *help_text = help_text_dds2tar;
#elif ( PROGRAM == DDS2INDEX )
char const *pg = name_dds2index;
char const *help_text = help_text_dds2index;
#elif ( PROGRAM == DDS2TAR )
char const *pg = name_mtdds;
char const *help_text = help_text_mt_dds;
#elif ( PROGRAM == DDS_DD )
char const *pg = name_dds_dd;
char const *help_text = help_text_dds_dd;
#else
char const *pg = name_dds2tar;
char *help_text = help_text_dds2tar;
#endif
#define LOCATION 1
#define EXTRACT 2
/*-------------------------------------------------------------------------*/
char const dds_old_headline[] =
"magic record blk: size name\n";
char const dds_old_index_format[] =
"%6s%7d%3d:%9d %s\n";
/* magic blkno recno: size name */
char const dds_old_index_scan_format[] =
"%6c%7d%3d:%9d\n";
char const dds_headline[] =
"magic record blk: size name\n";
char const dds_index_format[] =
"%6s%7d%4d:%9d %s\n";
/* magic blkno recno: size name */
char const dds_index_scan_format[] =
"%6c%7d%4d:%9d\n";
/* magic blkno recno: size name */
char const dds_loctext[] =
"first block number is %d\n"
"block size is %d\n" "block length is %d\n";
char const dds_locline1[] =
"loc number of the first block is %d\n";
char const dds_locline2[] =
"loc block length is %d bytes = %d * 512 bytes\n";
/* to handle long link and long file names */
int long_name_len = 0 ;
char long_name[MAXPATHLEN<<2] = { '\0' };
int
rt_loc_line(void)
{
int i;
if ((i = strncmp(cur_line, dds_locline1, 45)) == 0) {
tar_fb = atoi(cur_line + 45);
} else if ((i = strncmp(cur_line, "first block number is", 21)) == 0) {
tar_fb = atoi(cur_line + 21);
} else if ((i = strncmp(cur_line, dds_locline2, 31)) == 0) {
tar_n = atoi(cur_line + 31);
tar_bs = tar_n >> 9;
} else if ((i = strncmp(cur_line, "block size is", 13)) == 0) {
tar_bs = atoi(cur_line + 13);
tar_n = tar_bs << 9;
} else
return 1;
if ( buf_n < tar_n ) {
cur_block = realloc ( cur_block , buf_n = tar_n );
if ( cur_block == NULL ) {
fprintf(stderr, "%s: No memory available.\n", pg);
exit(2);
}
}
return 0;
}
/*-------------------------------------------------------------------------*/
int verbose = 0;
int hash_mode = 0;
int list_only = 0; /* print only the matched names */
int quick_mode = 0; /* don't extract parent directories also */
int device; /* file number of the device */
int write_body = 0 ; /* write only the body of the first file */
int get_label = 0 ; /* get the label of the archive */
int get_filename = 0 ; /* get the filename of the current record */
int get_blocksize = 0 ; /* get the blocksize of the current record */
int get_timestamp = 0 ; /* get the timestamp of the archive */
int get_date = 0 ; /* get the date of the archive */
int get_fileno = 0 ; /* get the number of the current */
int force_nochk = 0 ; /* force tape read, no check of headers */
/* file io */
FILE *index_fp = NULL;
/* archive location as set by arguments or index file */
int tar_fb = 0; /* first block of the archive */
int tar_bs = 20; /* block size in records of 512 bytes */
int tar_n = 10240; /* block length in bytes */
/* archive buffer and location as set by tape access */
tar_record *cur_block;
int cur_blkno = -1;
int next_blkno = -1 ;
int cur_bs;
int cur_n;
int buf_n = ST_BUFFER_BLOCKS << 10 ;
/* line buffer to scan the index file */
char *cur_line;
/*-------------------------------------------------------------------------*/
/********
* input: name of the device ( e.g. /dev/nst0, /dev/nrmt0 or NULL )
* open mode of the device ( e.g. O_RDONLY or O_WRONLY )
* verbose flag to indicate the logging mode (integer)
* output: channel number ( integer ) for use with 'read()' or 'write()'
*
* side effects: none
*
**********************************************************************/
static int
open_device(char const *pathname, int const open_mode)
{
int fd;
int i = 1;
char const *p = "next try to open the tape %s\n";
{
int i ;
struct stat s ;
FILE *f ;
char cmd[100];
i = stat(pathname,&s);
if ( i < 0 ) perror("dds2tar"),exit(1);
sprintf(cmd,"scsi_vendor tape %d",(int)(s.st_rdev&0x7f)+1);
f = popen(cmd,"r");
fread(vendor,1,8,f);
fclose(f);
for ( i = 0 ; i < 8 ; i++ )
( vendor[i] < 0x20 ) && ( vendor[i] = '\0' ) ;
if ( !strcmp(vendor,"HP") ) vid = HP ;
if ( !strcmp(vendor,"SONY") ) vid = SONY ;
if ( !strcmp(vendor,"ARCHIVE") ) vid = ARCHIVE ;
if ( !strcmp(vendor,"SEGATE") ) vid = SEGATE ;
if ( !strcmp(vendor,"EXABYTE") ) vid = EXABYTE ;
}
do {
if ((fd = open(pathname, open_mode)) >= 0)
break;
sleep(2);
if (verbose)
fprintf(stderr, p, pathname);
} while ((++i) <= 15);
if (fd < 0) {
perror("tape busy?");
exit(1);
} /* else dds_has_partitions(fd); */
return fd;
}
/*-------------------------------------------------------------------------*/
int
strprefix(char**s,char*p,char*q){
while ( p != 0 ) {
char *t = *s ; while (( *p != 0 ) && ( *p == *t )) p++ , t++ ;
if ( *p == 0 ) { *s = t ; return 1 ; }
p = q ; q = NULL ;
} return 0 ;
}
/*-------------------------------------------------------------------------*/
/*
* dds2tar
*/
int
main(int argc, char const *const *argv)
{
#ifndef DEVICE
#define DEVICE "/dev/rmt0"
#endif
int density = 0 ;
int n = 1;
int l = strlen(argv[0]);
int compressed_mode = T_MODE;
char *p;
int child_proc = -1;/* child not running */
char const *index_file = NULL;
int print_location = 0;
int print_blksize = 0;
int mt_action = DDSCM_NULL; /* turn compression on/off */
int mode = 0; /* mode of dds2tar */
char const *const *pattern_list = NULL;
char const *device_name = DEVICE;
if ((p = getenv("TAPE")) != NULL)
device_name = p;
if (!strcmp(argv[0] + l - 7, "dds2tar")) {
pg = DDS2TAR;
help_text = help_text_dds2tar;
}
if (!strcmp(argv[0] + l - 9, "dds2index")) {
pg = DDS2INDEX;
help_text = help_text_dds2index;
}
if (!strcmp(argv[0] + l - 6, "mt-dds")) {
pg = MTDDS;
help_text = help_text_mt_dds;
}
if (!strcmp(argv[0] + l - 6, "dds-dd")) {
pg = DDS_DD;
help_text = help_text_dds_dd;
}
/*
* Scanning the environment.
*/
p = getenv("DDS2TAR");
while (p != NULL) {
int count = 0 ;
if (*p == ' ') p++;
if ( *p == '\0' ) p = NULL ;
else if (strprefix(&p, "-z","--compress")) {
compressed_mode = C_MODE;
} else if (strprefix(&p, "--first-block ","-s")) {
sscanf(p, "%d%n", &tar_fb, &count);
p += count;
} else if (strprefix(&p, "--block-size ","-b ")){
sscanf(p, "%d%n", &tar_bs, &count);
tar_n = tar_bs * 512 ;
buf_n = tar_n ;
p += count;
} else if (strprefix(&p, "--Block-size ","-B ")){
sscanf(p, "%d%n", &tar_bs, &count);
tar_n = tar_bs * 512 ;
buf_n = tar_n ;
p += count;
density = tar_n ;
} else
p = NULL;
}
/*
* scan arguments
*/
while (n < argc) {
/*
* Macros to test arguments ...
*/
#define T1(s) if((!strcmp(argv[n],(s))))
#define T(s) else if((!strcmp(argv[n],(s))))
#define TT(s,t) else if((!strcmp(argv[n],(s)))||(!strcmp(argv[n],(t))))
#define ELSE else
#define ELSEIF(s) else if(s)
/*
* Now scanning the arguments ...
*/
T1("-0") {
fprintf(stdout, "dds2tar: %s\n", argv[0]);
exit(0);
}
/*
* misc
*/
T("--help") {
fprintf(stdout, help_text);
exit(0);
}
TT("--version", "-V") {
fprintf(stdout, "%s: %s\n", pg, version);
exit(0);
}
/*
* Some more options ...
*/
TT("--verbose", "-v") verbose = 1;
T("--hash-mode") hash_mode = 1;
T("--force") force_nochk = 1;
/*
* device name
*/
T("-f") device_name = argv[++n];
/*
* index file
*/
TT("-z", "--compress") compressed_mode = C_MODE;
TT("--z", "--no-compress") compressed_mode = T_MODE;
TT("-t", "--table-of-contents") {
index_file = argv[++n];
/*
* The format of the index is checked by the program.
*/
}
/*
* Location of the file
*/
TT("-s", "--first-block") {
tar_fb = atoi(argv[++n]);
}
TT("-b", "--block-size") {
tar_bs = atoi(argv[++n]);
tar_n = tar_bs * 512 ;
buf_n = tar_n ;
}
TT("-B", "--Block-size") {
tar_bs = atoi(argv[++n]);
tar_n = tar_bs * 512 ;
buf_n = tar_n ;
density = tar_n ;
}
TT("-m", "--buffer-size") {
fprintf(stderr,"buffer size is %d records, %d bytes\n",
buf_n>>9,buf_n);
exit(0);
}
ELSEIF(pg == DDS2TAR) {
/*
* Mode of the program.
*
* If you install dds2tar as mt-dds, the program will
* act as mt-dds. Since for some operations you need
* root permissions on mt-dds, it would not be a good
* idea to let the user switch to dds2index or dds2tar
* in this case.
*/
T1("--dds2index") {
pg = DDS2INDEX;
help_text = help_text_dds2index;
}
T("--mt-dds") {
pg = MTDDS;
help_text = help_text_mt_dds;
}
T("--dds-dd") {
pg = DDS_DD;
help_text = help_text_dds_dd;
}
/*
* Mode of extraction ...
*
* The location list an experimental mode.
*/
#ifdef EXP_STUFF
T("--location-list") {
pattern_list = argv + n + 1;
mode = LOCATION;
break;
}
#endif
/*
* Select a file for the output.
*
* Since mt-dds may be run as root, we write on screen
* in this case. Writing to a file is supported for
* dds2tar.
*/
TT("-o", "--output") {
reopen(1, argv[++n], O_WRONLY | O_CREAT, 0660);
}
/*
* Do not read anything from tape.
*/
TT("-l", "--list") {
list_only = 1;
if (verbose)
fputs("--list\n", stderr);
}
/*
* Write only the body of the file.
*/
T("--body"){
write_body = 1 ;
}
/*
* Don't extract the parent directories from the tape.
*/
TT("-q","--quick"){
quick_mode = 1 ;
}
/*
* Pipe the output to tar -x.
*
* This is for testing only.
*/
T("--test") {
static char const *const a[5] =
{
"/bin/tar", "tfb", "-", "1", NULL
};
child_proc = creopen(1, 0, a[0], a);
}
T("--test-verbose") {
static char const *const a[5] =
{
"/bin/tar", "tfbv", "-", "1", NULL
};
child_proc = creopen(1, 0, a[0], a);
}
T("--extract") {
static char const *const a[5] =
{
"/bin/tar", "xfb", "-", "1", NULL
};
child_proc = creopen(1, 0, a[0], a);
}
ELSE {
pattern_list = argv + n;
if (verbose)
fprintf(stderr,
"first pattern is '%s'\n",
*pattern_list
);
mode = EXTRACT;
break;
}
}
ELSEIF(pg == MTDDS) {
/*
* Tape actions ...
*/
T1("tell") print_location = 1;
T("label") get_label = 1 ;
T("filename") get_filename = 1 ;
T("bs") get_blocksize = 1 ;
T("date") {
get_date = 1 ;
if ( argc > 2 ) {
int j = atoi(argv[2]);
fputs(ctime((time_t*)&j),stdout);
exit(0);
}
}
T("ts") get_timestamp = 1 ;
T("blksize") print_blksize = 1 ;
#ifdef HPDAT
#define R(c) if ( 0 != geteuid() ) { fprintf(stderr,\
"You have to be root to do this : %s\n",c);exit(1);}
T("comp-on") {
R("comp-on");
mt_action = DDSCM_ON;
}
T("comp-off") {
R("comp-off");
mt_action = DDSCM_OFF;
}
T("comp-query") {
R("comp-query");
mt_action = DDSCM_QUERY;
}
T("comp-log") {
R("comp-log");
mt_action = DDSCM_LOG;
}
T("load") {
R("comp-load");
mt_action = DDSCM_LOAD;
}
T("unload") {
R("comp-unload");
mt_action = DDSCM_UNLOAD;
}
T("where") {
mt_action = DDSCM_WHERE;
}
/*
* Set mode scsi2logical first
*/
T("scsi2logical"){
mt_action = DDSCM_LOGICAL;
}
#endif
#ifdef EXP_STUFF
/*
* tar-dds will handle the arguments in a very different way.
*/
}
ELSEIF(pg == TAR_DDS) {
break;
#endif
}
/*
* Next argument ...
*/
n++;
}
cur_block = malloc(buf_n);
cur_line = malloc(MAXPATHLEN<<2);
if (cur_block == NULL || cur_line == NULL) {
fprintf(stderr, "%s: No memory available.\n", pg);
exit(2);
}
/*
* Switch the program mode ... dds2tar, dds2index or mt-dds ...
*/
/*---------------------MT-DDS--------------------------------*/
if (pg == MTDDS) {
#ifdef HPDAT
/*
* Is setting of compression mode or log page selected ?
*
* I think you have to run this as root.
*/
if (mt_action != DDSCM_NULL) {
device = open_device(device_name, O_WRONLY);
if ( mt_action == DDSCM_LOGICAL )
dds_scsi2logical();
else
if ( mt_action == DDSCM_WHERE ) {
tar_fb = dds_getpos(device);
printf(" -s %d \n", tar_fb);
close(device);
return 0;
} else
set_compression_mode(device, mt_action);
} else
#endif
/*
* Print the current position (tree lines).
*/
{
device = open_device(device_name, O_RDONLY);
if ( vid == HP ){
tar_fb = dds_getpos(device);
dds_read_next_block();
/* dds_seek(device, tar_fb); */
dds_bsr();
} else {
tar_fb = dds_getpos(device);
cur_n = tar_n ;
}
tar_bs = cur_n >> 9;
if (( get_label || get_timestamp ||
get_date || get_filename ) &&
( dds_is_tar_header_record(cur_block) != 0 )) {
if ( cur_block->hdr.linkflag == 'V' ) {
int i , j = 0 ;
char*p=cur_block->hdr.mtime ;
for ( i = 0 ; i < 12 ; i++ ) {
if ((p[i]>='0')&&(p[i]<='7')) {
j <<= 3 ;
j += p[i] - '0' ;
}
}
if ( get_label )
puts(cur_block->hdr.name);
else if ( get_timestamp ){
printf("%d\n",j);
} else /* get_date */ {
fputs(ctime((time_t*)&j),stdout);
}
} else
if ( get_filename ) puts(cur_block->hdr.name);
} else
if (print_location != 0) {
printf(dds_loctext, tar_fb, tar_bs, cur_n);
} else
if ( print_blksize != 0 ) {
printf("%d\n",tar_bs);
} else {
/*
* Print the current position (one line).
*/
printf(" -s %d -b %d \n", tar_fb, tar_bs);
}
}
close(device);
/*---------------------DDS2TAR-------------------------------*/
} else if (pg == DDS2TAR) {
if (pattern_list == NULL)
return 0;
if (list_only != 1) {
device = open_device(device_name, O_RDONLY);
if ( density ) dds_set_bs(density);
}
index_fp = zfopen(index_file, compressed_mode, "r");
switch (mode) {
#ifdef EXP_STUFF
case LOCATION:
extract_loc(pattern_list);
break;
#endif
case EXTRACT:
dds_cmp(pattern_list);
break;
default:
fprintf(stderr, "nothing to do ? Try --help\n");
}
if (list_only != 1)
close(device);
if (child_proc != -1)
cclose(1);
/*---------------------DDS2INDEX-----------------------------*/
} else if (pg == DDS2INDEX) {
device = open_device(device_name, O_RDONLY);
if ( density ) dds_set_bs(density);
index_fp = zfopen(index_file, compressed_mode, "w");
dds_index();
close(device);
/*-----------------------------------------------------------*/
} else if ( pg == DDS_DD ) {
device = open_device(device_name, O_RDONLY);
if ( density ) dds_set_bs(density);
if ( verbose ) fprintf(stderr,"dds-dd ...\n");
while ( dds_read_next_block() , cur_n )
fwrite(cur_block,1,cur_n,stdout);
} else {
fprintf(stderr, "no program mode \n");
/*-----------------------------------------------------------*/
}
return 0;
}
|