void create_archive() { register char *p; open_archive(0); /* Open for writing */ while (p = name_next()) { dump_file(p, -1); } write_eot(); close_archive(); name_close(); }
void create_archive() { register char *p; char *name_from_list(); open_archive(0); /* Open for writing */ if(f_gnudump) { char buf[MAXNAMLEN],*q,*bufp; collect_and_sort_names(); while(p=name_from_list()) dump_file(p,-1); /* if(!f_dironly) { */ blank_name_list(); while(p=name_from_list()) { strcpy(buf,p); if(p[strlen(p)-1]!='/') strcat(buf,"/"); bufp=buf+strlen(buf); for(q=gnu_list_name->dir_contents;*q;q+=strlen(q)+1) { if(*q=='Y') { strcpy(bufp,q+1); dump_file(buf,-1); } } } /* } */ } else { while (p = name_next(1)) { dump_file(p, -1); } } write_eot(); close_archive(); name_close(); }
void delete_archive_members (void) { enum read_header logical_status = HEADER_STILL_UNREAD; enum read_header previous_status = HEADER_STILL_UNREAD; /* FIXME: Should clean the routine before cleaning these variables :-( */ struct name *name; int blocks_to_skip = 0; int blocks_to_keep = 0; int kept_blocks_in_record; name_gather (); open_archive (ACCESS_UPDATE); while (logical_status == HEADER_STILL_UNREAD) { enum read_header status = read_header (); switch (status) { case HEADER_STILL_UNREAD: abort (); case HEADER_SUCCESS: if (name = name_scan (current_file_name), !name) { set_next_block_after (current_header); if (current_header->oldgnu_header.isextended) skip_extended_headers (); skip_file ((long) (current_stat.st_size)); break; } name->found = 1; logical_status = HEADER_SUCCESS; break; case HEADER_ZERO_BLOCK: case HEADER_END_OF_FILE: logical_status = HEADER_END_OF_FILE; break; case HEADER_FAILURE: set_next_block_after (current_header); switch (previous_status) { case HEADER_STILL_UNREAD: WARN ((0, 0, _("This does not look like a tar archive"))); /* Fall through. */ case HEADER_SUCCESS: case HEADER_ZERO_BLOCK: ERROR ((0, 0, _("Skipping to next header"))); /* Fall through. */ case HEADER_FAILURE: break; case HEADER_END_OF_FILE: abort (); } break; } previous_status = status; } if (logical_status != HEADER_SUCCESS) { write_eot (); close_archive (); names_notfound (); return; } write_archive_to_stdout = 0; new_record = (union block *) xmalloc ((size_t) record_size); /* Save away blocks before this one in this record. */ new_blocks = current_block - record_start; blocks_needed = blocking_factor - new_blocks; if (new_blocks) memcpy ((void *) new_record, (void *) record_start, (size_t) (new_blocks * BLOCKSIZE)); #if 0 /* FIXME: Old code, before the goto was inserted. To be redesigned. */ set_next_block_after (current_header); if (current_header->oldgnu_header.isextended) skip_extended_headers (); skip_file ((long) (current_stat.st_size)); #endif logical_status = HEADER_STILL_UNREAD; goto flush_file; /* FIXME: Solaris 2.4 Sun cc (the ANSI one, not the old K&R) says: "delete.c", line 223: warning: loop not entered at top Reported by Bruno Haible. */ while (1) { enum read_header status; /* Fill in a record. */ if (current_block == record_end) { flush_archive (); records_read++; } status = read_header (); if (status == HEADER_ZERO_BLOCK && ignore_zeros_option) { set_next_block_after (current_header); continue; } if (status == HEADER_END_OF_FILE || status == HEADER_ZERO_BLOCK) { logical_status = HEADER_END_OF_FILE; memset (new_record[new_blocks].buffer, 0, (size_t) (BLOCKSIZE * blocks_needed)); new_blocks += blocks_needed; blocks_needed = 0; write_record (0); break; } if (status == HEADER_FAILURE) { ERROR ((0, 0, _("Deleting non-header from archive"))); set_next_block_after (current_header); continue; } /* Found another header. */ if (name = name_scan (current_file_name), name) { name->found = 1; flush_file: set_next_block_after (current_header); blocks_to_skip = (current_stat.st_size + BLOCKSIZE - 1) / BLOCKSIZE; while (record_end - current_block <= blocks_to_skip) { blocks_to_skip -= (record_end - current_block); flush_archive (); records_read++; } current_block += blocks_to_skip; blocks_to_skip = 0; continue; } /* Copy header. */ new_record[new_blocks] = *current_header; new_blocks++; blocks_needed--; blocks_to_keep = (current_stat.st_size + BLOCKSIZE - 1) / BLOCKSIZE; set_next_block_after (current_header); if (blocks_needed == 0) write_record (1); /* Copy data. */ kept_blocks_in_record = record_end - current_block; if (kept_blocks_in_record > blocks_to_keep) kept_blocks_in_record = blocks_to_keep; while (blocks_to_keep) { int count; if (current_block == record_end) { flush_read (); records_read++; current_block = record_start; kept_blocks_in_record = blocking_factor; if (kept_blocks_in_record > blocks_to_keep) kept_blocks_in_record = blocks_to_keep; } count = kept_blocks_in_record; if (count > blocks_needed) count = blocks_needed; memcpy ((void *) (new_record + new_blocks), (void *) current_block, (size_t) (count * BLOCKSIZE)); new_blocks += count; blocks_needed -= count; current_block += count; blocks_to_keep -= count; kept_blocks_in_record -= count; if (blocks_needed == 0) write_record (1); } } write_eot (); close_archive (); names_notfound (); }
/* Implement the 'r' (add files to end of archive), and 'u' (add files to end of archive if they aren't there, or are more up to date than the version in the archive) commands. */ void update_archive (void) { enum read_header previous_status = HEADER_STILL_UNREAD; bool found_end = false; name_gather (); open_archive (ACCESS_UPDATE); xheader_write_global (); while (!found_end) { enum read_header status = read_header (false); switch (status) { case HEADER_STILL_UNREAD: case HEADER_SUCCESS_EXTENDED: abort (); case HEADER_SUCCESS: { struct name *name; decode_header (current_header, ¤t_stat_info, ¤t_format, 0); archive_format = current_format; if (subcommand_option == UPDATE_SUBCOMMAND && (name = name_scan (current_stat_info.file_name)) != NULL) { struct stat s; chdir_do (name->change_dir); if (deref_stat (dereference_option, current_stat_info.file_name, &s) == 0 && s.st_mtime <= current_stat_info.stat.st_mtime) add_avoided_name (current_stat_info.file_name); } skip_member (); break; } case HEADER_ZERO_BLOCK: current_block = current_header; found_end = true; break; case HEADER_END_OF_FILE: found_end = true; break; case HEADER_FAILURE: set_next_block_after (current_header); switch (previous_status) { case HEADER_STILL_UNREAD: WARN ((0, 0, _("This does not look like a tar archive"))); /* Fall through. */ case HEADER_SUCCESS: case HEADER_ZERO_BLOCK: ERROR ((0, 0, _("Skipping to next header"))); /* Fall through. */ case HEADER_FAILURE: break; case HEADER_END_OF_FILE: case HEADER_SUCCESS_EXTENDED: abort (); } break; } tar_stat_destroy (¤t_stat_info); xheader_destroy (&extended_header); previous_status = status; } reset_eof (); time_to_start_writing = true; output_start = current_block->buffer; { char *file_name; while ((file_name = name_from_list ()) != NULL) { if (excluded_name (file_name)) continue; if (interactive_option && !confirm ("add", file_name)) continue; if (subcommand_option == CAT_SUBCOMMAND) append_file (file_name); else dump_file (file_name, 1, (dev_t) 0); } } write_eot (); close_archive (); names_notfound (); }
int proc_rule(struct htx_data *phtx_info, struct ruleinfo *prule_info, char *wbuf, char *rbuf, struct blk_num_typ *pblk_num) { int dlen, loop, rc; char msg[220], path[100]; unsigned short seed[3]; rc = 0; init_seed(seed); /* initialize seed for random number generator */ dlen = prule_info->num_blks * BLK_SIZE; /* initialize length of data */ /*-------------------------------*/ /* initialize the write buffer */ /*-------------------------------*/ if ( (prule_info->pattern_id[0] != '#') && (prule_info->pattern_id[0] != 0) ) { path[0] ='\0'; if ( (int) htx_strlen((char *) htx_strcpy(path, getenv("HTXPATTERNS"))) == 0 ) htx_strcpy(path, "../pattern/"); /* default ONLY */ htx_strcat (path, prule_info->pattern_id); rc = hxfpat(path, wbuf, dlen); if ( rc == 1 ) { sprintf(msg, "cannot open pattern file - %s\n", path); hxfmsg(phtx_info, 0, SYSERR, msg); return(1); } if ( rc == 2 ) { sprintf(msg, "cannot read pattern file - %s\n", path); hxfmsg(phtx_info, 0, SYSERR, msg); return(1); } } else if ( prule_info->pattern_id[0] == '#' ) bldbuf((unsigned short*)wbuf, dlen, prule_info->pattern_id, pblk_num); pblk_num->in_rule = 0; /* initialize block number within current rule */ rc = 0; tape_error_code = 0; for ( loop = 1; loop <= prule_info->num_oper; loop++ ) { if ( strcmp(prule_info->oper, "R") == 0 ) { rc = read_tape(phtx_info, prule_info, loop, pblk_num, rbuf); } else if ( strcmp(prule_info->oper, "W") == 0 ) { rc = write_tape(phtx_info, prule_info, loop, pblk_num, wbuf); } else if ( strcmp(prule_info->oper, "RC") == 0 ) { rc = read_tape(phtx_info, prule_info, loop, pblk_num, rbuf); if ( rc >= 0 ) rc = cmpbuf(phtx_info, prule_info, loop, pblk_num, wbuf, rbuf); } else if ( strcmp(prule_info->oper, "RW") == 0 ) { rc = rewind_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "WEOF") == 0 ) { rc = weof_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "SF") == 0 ) { rc = search_file(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "SR") == 0 ) { rc = search_rec(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "D") == 0 ) { rc = diag_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "E") == 0 ) { rc = erase_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "S") == 0 ) { rc = do_sleep(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "CO") == 0 ) { rc = close_open(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "C") == 0 ) { rc = tclose(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "O") == 0 ) { rc = topen(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "WEOT") == 0 ) { rc = write_eot(phtx_info, prule_info,loop, pblk_num, wbuf); } else if ( strcmp(prule_info->oper, "RCEOT") == 0 ) { rc = read_eot(phtx_info, prule_info, loop,pblk_num, wbuf, rbuf); } else if ( strcmp(prule_info->oper, "REOT") == 0 ) { rc = read_teot(phtx_info, prule_info, loop, pblk_num, wbuf, rbuf); } else if ( strcmp(prule_info->oper, "RS") == 0 ) { rc = prt_req_sense(phtx_info, prule_info, loop, pblk_num); } #ifndef __HTX_LINUX__ else if ( strcmp(prule_info->oper, "ML") == 0 ) { rc = medium_load(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "MUL") == 0 ) { rc = medium_unload(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "RES") == 0 ) { rc = read_status(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "IE") == 0 ) { rc = init_element(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "RP") == 0 ) { rc = read_posit(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "LB") == 0 ) { rc = loc_block(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "ASF") == 0 ) { rc = asearch_file(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "ASR") == 0 ) { rc = asearch_rec(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "ADUL") == 0 ) { rc = write_unload(phtx_info, prule_info, loop, pblk_num, wbuf); } else if ( strcmp(prule_info->oper, "TWIE") == 0 ) { rc = twin_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "TWPE") == 0 ) { rc = twps_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "TWRE") == 0 ) { rc = twrd_stat(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "TWMM") == 0 ) { rc = twmv_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "TWUL") == 0 ) { rc = unload_write(phtx_info, prule_info, loop, pblk_num, wbuf); } else if ( strcmp(prule_info->oper, "WUL") == 0 ) { rc = tape_unload(phtx_info, prule_info, loop, pblk_num, wbuf); } else if ( strcmp(prule_info->oper, "CDRE") == 0 ) { rc = cdrd_stat(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "CDMM") == 0 ) { rc = cdmv_tape(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "HUNL") == 0 ) { rc = himove(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "HINI") == 0 ) { rc = hiinit(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "HREL") == 0 ) { rc = hielem(phtx_info, prule_info, loop, pblk_num); } else if ( strcmp(prule_info->oper, "HWUN") == 0 ) { rc = hidal_unload(phtx_info, prule_info, loop, pblk_num, wbuf); } else if ( strcmp(prule_info->oper, "DBUG") == 0 ) { rc = set_dbug(phtx_info, prule_info, pblk_num); } #endif else if ( strcmp(prule_info->oper, "XCMD") == 0 ) { rc = do_cmd(phtx_info, prule_info, pblk_num); } else { ; } hxfupdate(UPDATE, phtx_info); if ( phtx_info->run_type[0] == 'O' ) { info_msg(phtx_info, prule_info, loop, pblk_num, msg); hxfmsg(phtx_info, 0, INFO, msg); } if ( rc != 0 ) break; } return(rc); }
/* Implement the 'r' (add files to end of archive), and 'u' (add files to end of archive if they arent there, or are more up to date than the version in the archive.) commands.*/ void update_archive () { int found_end = 0; int status = 3; int prev_status; char *p; struct name *name; extern void dump_file (); name_gather (); if (cmd_mode == CMD_UPDATE) name_expand (); open_archive (2); /* Open for updating */ do { prev_status = status; status = read_header (); switch (status) { case EOF: found_end = 1; break; case 0: /* A bad record */ userec (head); switch (prev_status) { case 3: msg ("This doesn't look like a tar archive."); /* FALL THROUGH */ case 2: case 1: msg ("Skipping to next header"); case 0: break; } break; /* A good record */ case 1: /* printf("File %s\n",head->header.name); */ /* head->header.name[NAMSIZ-1]='\0'; */ if (cmd_mode == CMD_UPDATE && (name = name_scan (current_file_name))) { /* struct stat hstat; */ struct stat nstat; int head_standard; decode_header (head, &hstat, &head_standard, 0); if (stat (current_file_name, &nstat) < 0) { msg_perror ("can't stat %s:", current_file_name); } else { if (hstat.st_mtime >= nstat.st_mtime) name->found++; } } userec (head); if (head->header.isextended) skip_extended_headers (); skip_file ((long) hstat.st_size); break; case 2: ar_record = head; found_end = 1; break; } } while (!found_end); reset_eof (); time_to_start_writing = 1; output_start = ar_record->charptr; while (p = name_from_list ()) { if (f_confirm && !confirm ("add", p)) continue; if (cmd_mode == CMD_CAT) append_file (p); else dump_file (p, -1, 1); } write_eot (); close_archive (); names_notfound (); }