diff -Nur taper-7.0pre-1/Makefile.common taper-7.0pre-1-AES/Makefile.common --- taper-7.0pre-1/Makefile.common 2003-09-18 11:14:33.000000000 +0200 +++ taper-7.0pre-1-AES/Makefile.common 2003-09-18 11:07:57.000000000 +0200 @@ -57,7 +57,7 @@ EXTRA_LIBS=-lefence endif -LINKLIB = +LINKLIB = -lmtcrypt CURSES = ncurses FORM = form diff -Nur taper-7.0pre-1/backup.c taper-7.0pre-1-AES/backup.c --- taper-7.0pre-1/backup.c 2003-09-18 11:16:33.000000000 +0200 +++ taper-7.0pre-1-AES/backup.c 2003-09-18 11:09:56.000000000 +0200 @@ -153,7 +153,7 @@ } -_errstat write_nameinfo(struct file_info *fi, char *cp) +_errstat write_nameinfo(const struct mtcrypt_context *mtc, struct file_info *fi, char *cp) { /* An error writing to the backup device is a fatal error Returns 0 if all OK @@ -162,11 +162,11 @@ char l[MAX_FNAME+50]; sprintf(l, "Writing info & filename for %s", cp); - if (tape_write_fi(fi) == -1) { + if (tape_write_fi(mtc, fi) == -1) { write_fatal_log(l); /* write info */ return -1; } - if (tape_write((char *) cp, fi->name_len) == -1) {/* write filename */ + if (tape_write(mtc, (char *) cp, fi->name_len) == -1) {/* write filename */ write_fatal_log(l); return -1; } @@ -174,7 +174,7 @@ } -_errstat backup_file(WINDOW *mes, struct info_file_data *i_data) +_errstat backup_file(const struct mtcrypt_context *mtc, WINDOW *mes, struct info_file_data *i_data) { /* Backup the file pointed to by cp and update cp * An error writing to the backup device is a fatal error @@ -205,12 +205,12 @@ fi->size = strlen(tmpf)+1+sizeof(_s32); sprintf(l, "Writing link name for %s [%s]", fn, tmpf); if (log_level > 1) write_log(l); - if (write_nameinfo( fi, fn) == -1) { + if (write_nameinfo(mtc, fi, fn) == -1) { write_fatal_log(l); return -1; } x = strlen(tmpf)+1; - if (tape_write_namelen(tmpf) == -1) { + if (tape_write_namelen(mtc, tmpf) == -1) { write_fatal_log(l); return -1; } @@ -221,7 +221,7 @@ fi->checksum = 0; sprintf(l, "Storing directory %s", fn); if (log_level > 1) write_log(l); - return write_nameinfo( fi, fn); /* file, only write out name */ + return write_nameinfo(mtc, fi, fn); /* file, only write out name */ } cf = NULL; /* must be a regular file */ @@ -273,7 +273,7 @@ write_error_log(l); unlink(cf); /* compressed file, delete it */ fi->checksum = -1; /* mark file as invalid */ - return write_nameinfo( fi, fn); + return write_nameinfo(mtc, fi, fn); } sprintf(l, "Getting compressed file status info for %s", cf); if (log_level > 2) write_log(l); @@ -282,7 +282,7 @@ fi->checksum = -1; /* mark file as invalid */ close(fd); unlink(cf); - return write_nameinfo( fi, fn); + return write_nameinfo(mtc, fi, fn); } fi->compressed = compression; /* file is compressed */ @@ -296,7 +296,7 @@ if (fd == -1) { write_error_log(l); fi->checksum = -1; /* mark file as invalid */ - return write_nameinfo( fi, fn); + return write_nameinfo(mtc, fi, fn); } sprintf(l, "Getting file status info for %s", fn); if (log_level > 2) write_log(l); @@ -304,7 +304,7 @@ write_error_log(l); fi->checksum = -1; /* mark file as invalid */ close(fd); - return write_nameinfo( fi, fn); + return write_nameinfo(mtc, fi, fn); } fi->act_size = sbuf.st_size; /* update file info */ } @@ -314,7 +314,7 @@ sprintf(l, "Backing up file %s; actual size %qd, on tape size %qd.", fn, fi->size, fi->act_size); if (log_level > 1) write_log(l); - if (write_nameinfo(fi, fn) == -1) { /* couldn't */ + if (write_nameinfo(mtc, fi, fn) == -1) { /* couldn't */ write_fatal_log(l); close(fd); if (*tmpf) unlink(tmpf); @@ -333,7 +333,7 @@ if (x == -1) { write_error_log("Error reading file while transferring data to backup device"); while (totalwrite < fi->act_size) - totalwrite += tape_write((char *) tr_buffer, min(max_tr_size,/* pad rubbish data to the end so */ + totalwrite += tape_write(mtc, (char *) tr_buffer, min(max_tr_size,/* pad rubbish data to the end so */ fi->act_size - totalwrite)); totalread = totalwrite; break; /* so that the archive integrity is maintained */ @@ -341,7 +341,7 @@ totalread += x; if (totalwrite < fi->act_size) { /* don't write too much data to buffer */ - if ((x = tape_write((char *) tr_buffer, min(x, fi->act_size-totalwrite))) == -1) { + if ((x = tape_write(mtc, (char *) tr_buffer, min(x, fi->act_size-totalwrite))) == -1) { close(fd); return -1; } @@ -360,7 +360,7 @@ return 0; } -_errstat write_volume_header(_s32 no_files) +_errstat write_volume_header(const struct mtcrypt_context *mtc, _s32 no_files) { /* Writes the volume header to the tape and appends volume header * information to the block in memory. @@ -396,7 +396,7 @@ } vh.size_header = sz; ifd.size_volume_headers += sz; /* update size */ - if (tape_write_volheader(&vh) == -1) return -1; + if (tape_write_volheader(mtc, &vh) == -1) return -1; vol_headers = my_realloc(vol_headers, ifd.size_volume_headers); if (vol_headers == NULL) return do_exit(ERROR_MEMORY); @@ -416,14 +416,14 @@ se=sel_files; /* write file selections */ for (c=0; ci.name) + 1; /* file name */ - if (tape_write_namelen(se->i.name) == -1) + if (tape_write_namelen(mtc, se->i.name) == -1) return -1; memcpy(cur_pos, &c1, sizeof(_s32)); /* filename length */ cur_pos += sizeof(_s32); /* advance to filename pos */ strcpy(cur_pos, se->i.name); cur_pos += c1; /* past filename */ c1 = 0+1; /* filter */ - if (tape_write_namelen(&null_string) == -1) + if (tape_write_namelen(mtc, &null_string) == -1) return -1; memcpy(cur_pos, &c1, sizeof(_s32)); cur_pos += sizeof(_s32); @@ -436,14 +436,14 @@ sname[0] = '!'; strcpy(&sname[1], se->i.name); c1 = strlen(sname) + 1; /* file name */ - if (tape_write_namelen(sname) == -1) + if (tape_write_namelen(mtc, sname) == -1) return -1; memcpy(cur_pos, &c1, sizeof(_s32)); /* filename length */ cur_pos += sizeof(_s32); /* advance to filename pos */ strcpy(cur_pos, sname); cur_pos += c1; /* past filename */ c1 = 0+1; /* filter */ - if (tape_write_namelen(&null_string) == -1) + if (tape_write_namelen(mtc, &null_string) == -1) return -1; memcpy(cur_pos, &c1, sizeof(_s32)); cur_pos += sizeof(_s32); @@ -548,7 +548,7 @@ } -_errstat do_backup(void) { +_errstat do_backup(const struct mtcrypt_context *mtc) { /* For aborting a backup, * * fi.checksum = -2 is written - this means a backup @@ -591,7 +591,7 @@ org_files = no_old_files; if (!append) { if (tape_open(O_RDWR) == -1) return -1; - if (write_tape_header(&tdh) == -1) + if (write_tape_header(mtc, &tdh) == -1) return -1; } else { @@ -599,7 +599,7 @@ if (tape_eom() == -1) return -1; } else { - if (goto_end_vol(s_mes, 3, ifd.number_volumes, 1, TRUE, O_RDWR) == -1)/* goto end of */ + if (goto_end_vol(mtc, s_mes, 3, ifd.number_volumes, 1, TRUE, O_RDWR) == -1)/* goto end of */ return -1; /* previous volume */ } } @@ -616,7 +616,7 @@ return -1; status_box(s_mes, "", 1, FALSE, 1); - if (write_volume_header(ifd.no_in_archive-no_old_files) == -1) return -1;/* write volume header */ + if (write_volume_header(mtc, ifd.no_in_archive-no_old_files) == -1) return -1;/* write volume header */ /* free superflous memory */ sel_files = my_realloc(sel_files, 1); @@ -707,7 +707,7 @@ fi->checksum = -2; if (write_info_rec(count, &i_data) == -1) return do_exit(ERROR_WRITING_INFO); /* don't need to reindex */ - write_nameinfo(fi, ""); /* because haven't changed index field */ + write_nameinfo(mtc, fi, ""); /* because haven't changed index field */ ifd.no_in_archive = no_old_files;/* correct info file */ memcpy(&v, get_vh(vol_headers, ifd.number_volumes), sizeof(struct volume_header)); /* this needed to */ v.no_in_volume = no_written; /* ensure aligned access */ @@ -724,8 +724,8 @@ s_tcurrent = time(NULL); no_old_files++; i_data.f.pos_in_archive = no_old_files; - if (backup_file(s_mes, &i_data) == -1) { - tape_close(); /* rewinding device so will auto update headers */ + if (backup_file(mtc, s_mes, &i_data) == -1) { + tape_close(mtc); /* rewinding device so will auto update headers */ backup_stop_child(); if (*cfile) unlink(cfile); waitpid(backup_child, NULL, WNOHANG); @@ -753,7 +753,7 @@ status_box(s_mes, "", 7, FALSE, 1); status_box(s_mes, "", 8, FALSE, 1); status_box(s_mes, "Updating header segments", 3, FALSE, 1); - tape_close(); /* rewinding device so will auto update headers */ + tape_close(mtc); /* rewinding device so will auto update headers */ vti.blocks_on_last_tape = blocks_passed; vti.end_tape = ifd.number_tapes; memcpy(vt_info+ifd.number_volumes-1, &vti, sizeof(vti)); @@ -915,7 +915,7 @@ } _errstat utils_write_nullheader(WINDOW **mes); -_errstat check_backup(void) { +_errstat check_backup(const struct mtcrypt_context *mtc) { /* Make sure backup is a valid device and confirm with use about an erase if it has been requested. */ int x, fd; @@ -935,7 +935,7 @@ } else { rmtclose(fd); - x= do_read_vol_dir(-1, tape, O_RDWR, append, FALSE, TRUE); + x= do_read_vol_dir(mtc, -1, tape, O_RDWR, append, FALSE, TRUE); } if (x==-1) return -1; if (x == BAD_MAGIC) { @@ -979,7 +979,7 @@ else { oldarch = tdh.archive_id; utils_write_nullheader(&mes); - tape_close(); + tape_close(mtc); } strcpy(info_file, taper_info_files); /* look for information file */ if (info_file[strlen(info_file)-1] != '/') /* associated with this archive */ @@ -1010,7 +1010,7 @@ -void taper_backup(int argc, char *argv[]) +void taper_backup(const struct mtcrypt_context *mtc, int argc, char *argv[]) { int x; int old_append; @@ -1035,7 +1035,7 @@ if (check_device_names() == -1) goto endbackup;/* check devices & other parms */ if (backrest_do_mallocs() == -1) /* couldn't allocate memory */ goto endbackup; - if (check_backup() > 0) { + if (check_backup(mtc) > 0) { if (!append) { /* no archive */ tdh.archive_id = time(NULL); /* set defaults */ ifd.archive_id = tdh.archive_id; @@ -1058,8 +1058,8 @@ getcwd(cur_dir, sizeof(cur_dir)); backrest_kill_windows(); print_my_name(); - if (x > 0) do_backup(); - if (dv > 0) tape_close(); + if (x > 0) do_backup(mtc); + if (dv > 0) tape_close(mtc); if (!no_windows) close_statusbox(mes_box); } diff -Nur taper-7.0pre-1/common.c taper-7.0pre-1-AES/common.c --- taper-7.0pre-1/common.c 2003-09-18 11:15:02.000000000 +0200 +++ taper-7.0pre-1-AES/common.c 2003-09-18 11:08:22.000000000 +0200 @@ -13,7 +13,7 @@ #include "taper.h" - +#include _s8 check_selected(_u32 rec) { @@ -595,7 +595,7 @@ } -_errstat do_read_vol_dir(_u32 archive_id, char *tape, int mode, _s8 rvdir, _s8 must_exist, _s8 open_recnum) { +_errstat do_read_vol_dir(const struct mtcrypt_context *mtc, _u32 archive_id, char *tape, int mode, _s8 rvdir, _s8 must_exist, _s8 open_recnum) { /* Closes the backup device after use If archive_id == -1, then tries to read the current tape for info file to read. @@ -613,8 +613,8 @@ if (!no_windows) mes = status_box(mes, "Rewinding tape", 1, TRUE, 1); if (archive_id == -1) { - err = get_tape_header(mes, 1, &tdh, O_RDONLY); - tape_close(); + err = get_tape_header(mtc, mes, 1, &tdh, O_RDONLY); + tape_close(mtc); if (err == -1) {close_statusbox(mes); return -1;} if ((err == TAPE_EXIST) & (!must_exist)) { if (!no_windows) { @@ -895,7 +895,7 @@ } -_errstat traverse_volume(file_passed_action action, _s32 no_in_vol, +_errstat traverse_volume(const struct mtcrypt_context *mtc, file_passed_action action, _s32 no_in_vol, time_t t_start, WINDOW *mes_box, _s8 full_traverse, print_status ps, _s32 *cur_in_vol, _s8 use_info, chksum_err ce) @@ -945,7 +945,7 @@ } (*cur_in_vol)++; sprintf(l, "Reading in file info & filename"); - if (tape_read_fi(&fi) == -1) return -1; + if (tape_read_fi(mtc, &fi) == -1) return -1; if (use_info) { /* find which info file */ while (info_pos < no_in_archive) { /* look for this file in volume dir */ if (read_info_rec(info_pos, &i_data) == -1) @@ -977,7 +977,7 @@ write_log("Incorrect file count in volume. Fudged to overcome"); /* and also aborted backups */ break; /* assume that this is now EOF */ } - if (tape_read(fn, fi.name_len) != fi.name_len) /* skip past filename */ + if (tape_read(mtc, fn, fi.name_len) != fi.name_len) /* skip past filename */ return -1; if (use_info) /* use filename from */ strcpy(fn, i_data.name); /* info file */ @@ -988,7 +988,7 @@ ps(mes_box, *cur_in_vol, no_in_vol, abs(fi.volume), fi.act_size, fn, t_start, t_current); /* let caller print status box */ } - a = (action == NULL) ? 0 : action(&fi, fn, &i_data); + a = (action == NULL) ? 0 : action(mtc, &fi, fn, &i_data); if (a==-1) return -1; /* error */ if ((a == -2) && (!full_traverse)) return (*cur_in_vol == no_in_vol); /* finish traverse */ @@ -1005,7 +1005,7 @@ if (S_ISLNK(fi.mode)) { sprintf(l, "Passing link info for %s", fn); if (log_level > 2) write_log(l); - if (tape_read_namelen(fn) == -1) return -1; + if (tape_read_namelen(mtc, fn) == -1) return -1; continue; } @@ -1018,7 +1018,7 @@ chk = 0; while (1) { /* copy file accross */ tr = min(sz, max_tr_size); - x = tape_read(tr_buffer, tr); /* to device file */ + x = tape_read(mtc, tr_buffer, tr); /* to device file */ if (!x) break; if (x == -1) return -1; @@ -1754,7 +1754,7 @@ } -_errstat read_into_temp(struct file_info *fi, char *tmpf, char *fn) +_errstat read_into_temp(const struct mtcrypt_context *mtc, struct file_info *fi, char *tmpf, char *fn) { /* Read the file next on the tape to a temporary file @@ -1783,7 +1783,7 @@ c1=0; while (1) { /* copy file accross */ tr = min(sz, max_tr_size); - x = tape_read(tr_buffer, tr); /* from device file */ + x = tape_read(mtc, tr_buffer, tr); /* from device file */ if (!x) break; if (x == -1) { c1 = -1; diff -Nur taper-7.0pre-1/common.h taper-7.0pre-1-AES/common.h --- taper-7.0pre-1/common.h 2003-09-18 11:15:04.000000000 +0200 +++ taper-7.0pre-1-AES/common.h 2003-09-18 11:08:25.000000000 +0200 @@ -3,6 +3,7 @@ $Id: common.h,v 1.49 2002/05/18 18:34:27 yusuf Exp $ */ +#include /* Functions in common.c */ extern char *trunc_filename(char *org, char *s, int c); @@ -23,7 +24,7 @@ extern _errstat check_device_names(void); extern dev_t get_file_info(char *file, struct file_info *fi, _s8 chk, struct stat *ob); extern _errstat process_info(WINDOW *mes, int line, _s8 calc_strip); -extern _errstat do_read_vol_dir(_u32 archive_id, char *tape, int mode, _s8 rvdir, _s8 exist, _s8 open_index); +extern _errstat do_read_vol_dir(const struct mtcrypt_context *mtc, _u32 archive_id, char *tape, int mode, _s8 rvdir, _s8 exist, _s8 open_index); extern char *convtime(char *s, time_t t1, time_t t2); extern _s32 calc_checksum(int fd); extern _s32 mem_calc_checksum(char *m, _s32 sz); @@ -33,9 +34,9 @@ extern void write_error_log(char *s); extern void write_warning_log(char *); extern void write_fatal_log(char *s); -extern _errstat read_volheader(struct volume_header *vh, _s8 read_vh, _s8 into_mem); +extern _errstat read_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh, _s8 read_vh, _s8 into_mem); extern char *get_vh(struct volume_header *svh, _s32 vol); -extern _errstat traverse_volume(file_passed_action action, _s32 no_in_vol, +extern _errstat traverse_volume(const struct mtcrypt_context *mtc, file_passed_action action, _s32 no_in_vol, time_t t_start, WINDOW *mes_box, _s8 full_traverse, print_status ps, _s32 *files_passed, _s8 use_info, chksum_err ce); @@ -78,8 +79,8 @@ extern void free_comp_buffers(void); extern void taper_tmpnam(char *s); extern _errstat setowners(char *s, _errstat ret, struct file_info *fi); -extern _errstat do_write_block(_s8 *buf_to_write, _s32 old_length, _s8 fc); -extern _errstat read_into_temp(struct file_info *fi, char *tmpf, char *fn); +extern _errstat do_write_block(const struct mtcrypt_context *mtc, _s8 *buf_to_write, _s32 old_length, _s8 fc); +extern _errstat read_into_temp(const struct mtcrypt_context *mtc, struct file_info *fi, char *tmpf, char *fn); extern _errstat read_u32(int fd, _u32 *x); extern _errstat read_u64(int fd, _u64 *x); extern _errstat write_u64(int fd, _u64 *x); diff -Nur taper-7.0pre-1/config.h taper-7.0pre-1-AES/config.h --- taper-7.0pre-1/config.h 2003-09-18 11:15:56.000000000 +0200 +++ taper-7.0pre-1-AES/config.h 2003-09-18 11:09:19.000000000 +0200 @@ -6,9 +6,9 @@ #ifndef __CONFIG_H__ -#ifdef GLIBC_2 -#define umode_t mode_t -#endif +//#ifdef GLIBC_2 +//#define umode_t mode_t +//#endif #define NULL ((void *)0) diff -Nur taper-7.0pre-1/mkinfo.c taper-7.0pre-1-AES/mkinfo.c --- taper-7.0pre-1/mkinfo.c 2003-09-18 11:17:08.000000000 +0200 +++ taper-7.0pre-1-AES/mkinfo.c 2003-09-18 11:10:35.000000000 +0200 @@ -15,7 +15,7 @@ PUBLIC _u64 mktr, mktrc; -PRIVATE _errstat mkinfo_action(struct file_info *fi, char *fn, struct info_file_data *dummy) +PRIVATE _errstat mkinfo_action(const struct mtcrypt_context *mtc, struct file_info *fi, char *fn, struct info_file_data *dummy) { char l[MAX_FNAME]; _s32 x, p=0; @@ -30,7 +30,7 @@ sprintf(l, "Adding length of link to %s", fn); write_log(l); } - tape_read_namelen(l); + tape_read_namelen(mtc, l); fi->act_size = strlen(l)+1+sizeof(_s32); fi->size = strlen(l)+1+sizeof(_s32); p = 1; @@ -139,7 +139,7 @@ } -int advance_volume(WINDOW *mes_box) +int advance_volume(const struct mtcrypt_context *mtc, WINDOW *mes_box) { /* Advances tape by one volume returns -1 if error, 0 otherwise @@ -152,21 +152,21 @@ status_box(mes_box, "Looking for next volume", 3, FALSE, 1); if (fast_fsf) { if (log_level > 2) write_log("Doing a fast FSF"); - if (tape_fsf(1, TRUE) == -1) /* unable */ + if (tape_fsf(mtc, 1, TRUE) == -1) /* unable */ return -1; /* assume EOT */ read_offset = -1; } else { /* slow fsf */ - tape_close(); /* reposition tape */ + tape_close(mtc); /* reposition tape */ /* should rewind since we expect a rewinding to be open */ if (ntape_open(O_RDONLY) == -1) { /* it's a pity that we have to rewind */ write_fatal_log("Opening non-rewinding device to do fsf"); return -1; } vols_passed++; /* passed another vol on this tape */ - if (tape_fsf(vols_passed, TRUE) == -1)/* couldn't fsf - assume end of data */ + if (tape_fsf(mtc, vols_passed, TRUE) == -1)/* couldn't fsf - assume end of data */ return -1; - tape_close(); + tape_close(mtc); if (tape_open(O_RDONLY) == -1) {/* open rewinding */ write_fatal_log("Reopening device after repositioning"); return -1; @@ -183,7 +183,7 @@ PRIVATE _time_t t_start, t_current; -PUBLIC _errstat mkinfo_loop(file_passed_action action, print_status ps) +PUBLIC _errstat mkinfo_loop(const struct mtcrypt_context *mtc, file_passed_action action, print_status ps) { /* This loops through the archive. It calls action for each file * in encounters. @@ -214,10 +214,10 @@ nodelay(mes_box, TRUE); status_box(mes_box, "Identifying tape", 3, FALSE, 1); ifd.magic = INFO_MAGIC; - if (check_tape(mes_box, 3, 1) == -1) goto err;/* make sure first tape in drive */ + if (check_tape(mtc, mes_box, 3, 1) == -1) goto err;/* make sure first tape in drive */ cur_vol = 0; t_start = time(NULL); - if (read_volheader(&vh, 1, 1) == -1) goto err; + if (read_volheader(mtc, &vh, 1, 1) == -1) goto err; ifd.size_volume_headers = vh.size_header; ifd.number_volumes = 0; while (1) { @@ -228,10 +228,10 @@ vi->start_tape = tdh.tape_number; if (vh.volume_magic == VOLUME_MAGIC_INFO) { /* this volume is an info file - skip it */ status_box(mes_box, "Skipping past info file", 3, FALSE, 1); - if (tape_read(&ifs, sizeof(_u32)) == -1) goto err; /* read size of info file */ + if (tape_read(mtc, &ifs, sizeof(_u32)) == -1) goto err; /* read size of info file */ tr = 0; while (tr < ifs) { /* skip past info file */ - if (tape_read(tr_buffer, min(ifs-tr, max_tr_size)) == -1) return -1; + if (tape_read(mtc, tr_buffer, min(ifs-tr, max_tr_size)) == -1) return -1; tr += min(ifs-tr, max_tr_size); } } @@ -242,7 +242,7 @@ write_log(s); } set_1s_timer(); signal(SIGALRM, mkinfo_alarm); - if (traverse_volume(action, vh.no_in_volume, t_start, + if (traverse_volume(mtc, action, vh.no_in_volume, t_start, mes_box, 1, ps, &in_vol, FALSE, (action == mkinfo_action) ? mkinfoce : NULL) < 0) /* traverse this volume */ goto err; @@ -255,9 +255,9 @@ vi->end_tape = tdh.tape_number; vi->blocks_on_last_tape = blocks_passed; oldtsi = ifd.number_tsi; - if (advance_volume(mes_box) == -1) break; + if (advance_volume(mtc, mes_box) == -1) break; memset(&vh, 0, sizeof(vh)); - if (tape_read_volheader(&vh, 1) == -1) break; + if (tape_read_volheader(mtc, &vh, 1) == -1) break; if ((vh.volume_magic != VOLUME_MAGIC) && (vh.volume_magic != VOLUME_64_MAGIC)) /* not magic */ break; /* therefore assume eot */ @@ -265,7 +265,7 @@ if (log_level > 2) write_log("Previously erased volumes detected"); break; } - if (read_volheader(&vh, 0, 1) == -1) goto err; + if (read_volheader(mtc, &vh, 0, 1) == -1) goto err; ifd.size_volume_headers += vh.size_header; /* update size of volume headers */ } @@ -280,7 +280,7 @@ } -PRIVATE _errstat recreate(void) +PRIVATE _errstat recreate(const struct mtcrypt_context *mtc) { WINDOW *mes_box=NULL; @@ -290,7 +290,7 @@ if (tape_rewind() == -1) goto err; status_box(mes_box, "Identifying tape", 2, FALSE, 1); if (tape_open(O_RDONLY) == -1) goto err; /* open rewinding device */ - if (tape_readheader(&tdh, 0, O_RDONLY) == -1) goto err; + if (tape_readheader(mtc, &tdh, 0, O_RDONLY) == -1) goto err; if ((tdh.magic != TAPER_MAGIC_NUMBER) && (tdh.magic != TAPER_64_MAGIC)) { if (tdh.magic == TAPER_4_MAGIC_NUMBER) message_box("Sorry, taper 4 archives are not compatible", MB_OK); @@ -309,7 +309,7 @@ vt_info->volume = 1; /* first volume always on tape 1 */ vt_info->start_tape = 1; - if (mkinfo_loop(mkinfo_action, mkinfo_print_status) == -1) { + if (mkinfo_loop(mtc, mkinfo_action, mkinfo_print_status) == -1) { if (log_level > 2) write_log("Mkinfo loop returned an error"); goto err; } @@ -347,7 +347,7 @@ } -void taper_mkinfo(void) +void taper_mkinfo(const struct mtcrypt_context *mtc) { _s32 x; char sa[9][150]; @@ -358,8 +358,8 @@ if (mkinfo_do_mallocs() == -1) return; if (open_logfile("Mkinfo") == -1) return; if (check_device_names() == -1) return; /* check devices & other parms */ - recreate(); - tape_close(); + recreate(mtc); + tape_close(mtc); touchwin(win_main); wrefresh(win_main); t_current = time(NULL); x = t_current - t_start; diff -Nur taper-7.0pre-1/restore.c taper-7.0pre-1-AES/restore.c --- taper-7.0pre-1/restore.c 2003-09-18 11:17:03.000000000 +0200 +++ taper-7.0pre-1-AES/restore.c 2003-09-18 11:10:29.000000000 +0200 @@ -19,7 +19,7 @@ /* Functions for using mkinfo to do total restores */ extern PUBLIC _s32 file_no; /* for cumulative */ extern PUBLIC _u64 mktr, mktrc; -PUBLIC _errstat mkinfo_loop(file_passed_action action, print_status ps); +PUBLIC _errstat mkinfo_loop(const struct mtcrypt_context *mtc, file_passed_action action, print_status ps); PUBLIC void mkinfo_print_status(WINDOW *mes_box, _s32 cur_in_vol, _s32 no_in_vol, _s32 vol, _u64 file_size, char *fn, @@ -76,7 +76,7 @@ PRIVATE _u64 rtotal_read; PRIVATE _u64 rtotal_processed; PRIVATE _u32 rtotal_files; -PUBLIC _errstat restore_action(struct file_info *fi, char *fn, struct info_file_data *i_data) +PUBLIC _errstat restore_action(const struct mtcrypt_context *mtc, struct file_info *fi, char *fn, struct info_file_data *i_data) /* Acts on the restore loop finding filename fn * Action returns 1 if it advanced past file (ie. it read it in) * or 0 if it didn't read it in @@ -167,7 +167,7 @@ if (S_ISLNK(fi->mode)) { /* soft link */ sprintf(l, "Reading in link info for %s", s); if (log_level > 2) write_log(l); - if (tape_read_namelen(tmpf) == -1) /* read link name */ + if (tape_read_namelen(mtc, tmpf) == -1) /* read link name */ return -1; if (restore_mode == RESTORE_VERIFY) return (ret == -3) ? -2 : 1; /* we passed file */ @@ -209,7 +209,7 @@ write_log(l); } - x = read_into_temp(fi, tmpf, s); + x = read_into_temp(mtc, fi, tmpf, s); if (x == -1) fifo_send_error (fdfifo); /* couldn't create temp file */ if (x == -2) { @@ -267,7 +267,7 @@ } -PRIVATE _errstat restore_devs_dirs(void) +PRIVATE _errstat restore_devs_dirs(const struct mtcrypt_context *mtc) /* This routine restores anything other than regular files & links. It doesn't need to go through the archive for these - it has the information in the info file @@ -282,7 +282,7 @@ if (check_selected(i_data.recnum)) if (!(S_ISREG(i_data.f.mode) || S_ISLNK(i_data.f.mode))) { strcpy(fn, i_data.name); - if (restore_action(&i_data.f, fn, &i_data) == -1) + if (restore_action(mtc, &i_data.f, fn, &i_data) == -1) return -1; } } @@ -355,7 +355,7 @@ } -PUBLIC _errstat start_restore(WINDOW *mes_box) +PUBLIC _errstat start_restore(const struct mtcrypt_context *mtc, WINDOW *mes_box) { /* Does the initial things for restore: * @@ -370,14 +370,14 @@ if (tape_rewind() == -1) return -1; /* rewind tape */ if (tape_open(O_RDONLY) == -1) /* open rewinding */ return -1; - if (tape_readheader(&tdh, 0, O_RDONLY) == -1) return -1; /* read tape header */ + if (tape_readheader(mtc, &tdh, 0, O_RDONLY) == -1) return -1; /* read tape header */ if ((tdh.magic != TAPER_MAGIC_NUMBER) && (tdh.magic != TAPER_64_MAGIC)) return do_exit(ERROR_MAGIC); return restore_start_child(mes_box); } -PUBLIC void end_restore(void) +PUBLIC void end_restore(const struct mtcrypt_context *mtc) { /* Closes tape, tells child we are finished etc.. */ @@ -388,7 +388,7 @@ if (restore_child) waitpid(restore_child, NULL, 0);/* wait for child to finish */ restore_child = 0; t_current = time(NULL); - tape_close(); + tape_close(mtc); touchwin(win_main); wrefresh(win_main); } @@ -479,7 +479,7 @@ } -PRIVATE void do_restore(void) +PRIVATE void do_restore(const struct mtcrypt_context *mtc) { WINDOW *mes_box=NULL; char l[200]; @@ -499,10 +499,10 @@ mes_box = status_box(mes_box, " ", 2, TRUE, 5);/* create window */ nodelay(mes_box, TRUE); status_box(mes_box, "Restoring devices/directories", 2, FALSE, 1); - if (restore_devs_dirs() == -1) return; + if (restore_devs_dirs(mtc) == -1) return; find_first_file(&z, &i_data); /* get first file to restore */ if (z==-1) return; /* no files to restore */ - if (start_restore(mes_box) == -1) return; /* do initial things */ + if (start_restore(mtc, mes_box) == -1) return; /* do initial things */ at_vol = 1; lpos = -1; @@ -514,11 +514,11 @@ if (calc_file_pos(&lpos, &cur_d, &i_data, &tape, &block, &offset, at_vol != i_data.f.volume))/* work out exactly where this file is */ at_vol = i_data.f.volume; - if (check_tape(mes_box, 3, tape) == -1) goto fin; + if (check_tape(mtc, mes_box, 3, tape) == -1) goto fin; if (at_vol != i_data.f.volume) /* position on correct volume */ - if (goto_end_vol(mes_box, 3, i_data.f.volume-1, at_vol, 0, O_RDONLY) == -1) goto fin; + if (goto_end_vol(mtc, mes_box, 3, i_data.f.volume-1, at_vol, 0, O_RDONLY) == -1) goto fin; at_vol = i_data.f.volume; - if (tape_goto_block(mes_box, 3, block) == -1) goto fin; + if (tape_goto_block(mtc, mes_box, 3, block) == -1) goto fin; if ((read_offset != offset) && (offset)) { if (read_offset > offset) { sprintf(l, "INTERNAL ERROR: At offset %d but want to go to %d", @@ -530,14 +530,14 @@ sprintf(l, "Offset is %d", offset - ((read_offset == -1) ? 0 : read_offset)); write_log(l); } - if (tape_read(write_buffer, offset - + if (tape_read(mtc, write_buffer, offset - ((read_offset == -1) ? 0 : read_offset)) == -1) goto fin; } restore_print_status(mes_box, 0, 0, at_vol, i_data.f.size, i_data.name, t_start, t_current); - if (tape_read_fi(&fi) == -1) goto fin; - if (tape_read(fn, fi.name_len) == -1) goto fin; - restore_action(&fi, fn, &i_data); + if (tape_read_fi(mtc, &fi) == -1) goto fin; + if (tape_read(mtc, fn, fi.name_len) == -1) goto fin; + restore_action(mtc, &fi, fn, &i_data); } status_box(mes_box, "", 0, FALSE, 1); @@ -549,7 +549,7 @@ status_box(mes_box, "", 7, FALSE, 1); fin:; - end_restore(); + end_restore(mtc); sprintf(sa[0], "Restore Finished"); strcpy(sa[1], ""); sprintf(sa[2], "Restored: %d files, %s", rtotal_files, @@ -570,9 +570,9 @@ -PUBLIC _errstat read_vol_dir(_u32 archive_id) /* also in utils.c */ +PUBLIC _errstat read_vol_dir(const struct mtcrypt_context *mtc, _u32 archive_id) /* also in utils.c */ { - if (do_read_vol_dir(archive_id, tape, O_RDONLY, TRUE, TRUE, TRUE) == TAPE_EXIST) + if (do_read_vol_dir(mtc, archive_id, tape, O_RDONLY, TRUE, TRUE, TRUE) == TAPE_EXIST) return 1; return -1; } @@ -776,7 +776,7 @@ } -PRIVATE void full_restore(void) +PRIVATE void full_restore(const struct mtcrypt_context *mtc) { char sam[8][150]; char s2[50], s3[50]; @@ -787,13 +787,13 @@ print_my_name(); mes_box = status_box(mes_box, "Rewinding tape", 2, TRUE, 5);/* create window */ nodelay(mes_box, TRUE); - if (start_restore(mes_box) == -1) return; + if (start_restore(mtc, mes_box) == -1) return; ifd.archive_id = tdh.archive_id; /* so that title line prints correctly */ ifd.number_tapes = -1; /* don't bother with updating etc.. */ strcpy(ifd.archive_title, tdh.archive_title); print_title_line(); /* refresh title line */ - mkinfo_loop(restore_action, mkinfo_print_status); - end_restore(); + mkinfo_loop(mtc, restore_action, mkinfo_print_status); + end_restore(mtc); close_statusbox(mes_box); sprintf(sam[0], "%s Finished", (restore_mode == RESTORE_VERIFY) ? "Verify": "Restore"); @@ -824,7 +824,7 @@ } -PUBLIC _errstat select_archive(_u32 *archive_id, char noinfo) /* also used in utils.c */ +PUBLIC _errstat select_archive(const struct mtcrypt_context *mtc, _u32 *archive_id, char noinfo) /* also used in utils.c */ { /* Returns 0 if found archive * Returns -1 if error @@ -848,8 +848,8 @@ if (gdh) { if (!no_windows) mes = status_box(mes, "Rewinding tape", 1, TRUE, 1); /* see what tape is */ - ret = get_tape_header(mes, 1, &th, O_RDONLY); /* in drive */ - tape_close(); + ret = get_tape_header(mtc, mes, 1, &th, O_RDONLY); /* in drive */ + tape_close(mtc); if (mes) close_statusbox(mes); if (ret == -1) goto selfile; /* error getting tape */ if ((ret == TAPE_NOEXIST) && (!prompt_archive)) return do_exit(ERROR_OPENING_BACKUP); @@ -901,7 +901,7 @@ } -PUBLIC void taper_restore(void) +PUBLIC void taper_restore(const struct mtcrypt_context *mtc) { _s32 x; @@ -916,7 +916,7 @@ if (no_windows) prompt_archive = 0; if (restore_mode != RESTORE_VERIFY) { - sa = select_archive(&arch, TRUE); /* ?which archive */ + sa = select_archive(mtc, &arch, TRUE); /* ?which archive */ if (sa == -1) goto end; restore_mode = (sa == -2) ? RESTORE_FULL : RESTORE_NORMAL; } @@ -926,19 +926,19 @@ backrest_clear_screen(); } if (restore_mode != RESTORE_NORMAL) { /* full restore */ - full_restore(); + full_restore(mtc); goto end; } - if (read_vol_dir(arch) == -1) + if (read_vol_dir(mtc, arch) == -1) goto end; /* Read volume dir */ if (pr_dir) { print_voldir(); - tape_close(); + tape_close(mtc); } else if (diff_id) { print_diff(); - tape_close(); + tape_close(mtc); } else { print_title_line(); @@ -969,7 +969,7 @@ backrest_kill_windows(); print_my_name(); chdir(original_cur_dir); /* change directory to ensure */ - if (x) do_restore(); /* restore to proper place */ + if (x) do_restore(mtc); /* restore to proper place */ } end:; @@ -983,11 +983,11 @@ } -PUBLIC void taper_verify(void) +PUBLIC void taper_verify(const struct mtcrypt_context *mtc) { if (!message_box("Insert tape in drive", MB_OKCANCEL)) return; restore_mode = RESTORE_VERIFY; - taper_restore(); + taper_restore(mtc); } diff -Nur taper-7.0pre-1/select_box.h taper-7.0pre-1-AES/select_box.h --- taper-7.0pre-1/select_box.h 2003-09-18 11:14:29.000000000 +0200 +++ taper-7.0pre-1-AES/select_box.h 2003-09-18 11:07:45.000000000 +0200 @@ -16,6 +16,7 @@ #include #include #include +#include #endif #include "memory.h" diff -Nur taper-7.0pre-1/structs.h taper-7.0pre-1-AES/structs.h --- taper-7.0pre-1/structs.h 2003-09-18 11:14:37.000000000 +0200 +++ taper-7.0pre-1-AES/structs.h 2003-09-18 11:08:02.000000000 +0200 @@ -5,6 +5,7 @@ */ #include +#include /* Tape header */ struct tape_header { @@ -202,7 +203,7 @@ }; -typedef _errstat (*file_passed_action) (struct file_info *fi, char * fn, struct info_file_data *i_data); +typedef _errstat (*file_passed_action) (const struct mtcrypt_context *mtc, struct file_info *fi, char * fn, struct info_file_data *i_data); typedef void (*print_status) (WINDOW *mes_box, _s32 cur_in_vol, _s32 no_in_vol, _s32 vol, _u64 file_size, diff -Nur taper-7.0pre-1/tapeio.c taper-7.0pre-1-AES/tapeio.c --- taper-7.0pre-1/tapeio.c 2003-09-18 11:16:42.000000000 +0200 +++ taper-7.0pre-1-AES/tapeio.c 2003-09-18 11:10:07.000000000 +0200 @@ -12,6 +12,9 @@ #include "taper.h" +//#include "crypt/cryptlib.h" +#include +#include char pipetoc[MAX_FNAME]; FILE *fd_pipetoc=NULL; @@ -23,31 +26,51 @@ char *overflow_buffer; void paint_main(void); /* in taper.c */ -ssize_t raw_read(int fd, char *data, ssize_t count, int allowerr) +ssize_t raw_read(const struct mtcrypt_context *blub, int fd, char *data, ssize_t count, int allowerr, int iv) { /* Does a read from the tape */ ssize_t x, x1, rc; int serr; char *m; - + char *crypt = malloc(block_size); + rc = 0; while (1) { - x = rmtread(fd, data+rc, count-rc); + x = rmtread(fd, crypt, count-rc); + + mtcrypt_transfer(blub, READ_BUF, crypt, &data[rc], block_size, iv); + serr = errno; if (x != -1) x += rc; /* adjust for already got */ - if (x == count) return x; /* got all data */ + if (x == count) { + free(crypt); + return x; /* got all data */ + } if (x == -1) { /* error reading */ - if (errno == ENOSPC) return 0; /* end of tape */ - if (errno == ENODATA) return 0; /* no data = end of tape */ - if (allowerr) return -1; /* error allowed */ + if (errno == ENOSPC) { + free(crypt); + return 0; /* end of tape */ + } + if (errno == ENODATA) { + free(crypt); + return 0; /* no data = end of tape */ + } + if (allowerr) { + free(crypt); + return -1; /* error allowed */ + } if (retryabort("reading from tape") == -1) { errno = serr; + free(crypt); return -1; } continue; } - if (x == 0) return 0; /* 0 return == end of tape */ + if (x == 0) { + free(crypt); + return 0; /* 0 return == end of tape */ + } /* We have a short read: two possibilites a. end of tape b. i/o error @@ -68,19 +91,30 @@ if (illegal_eot) /* end of tape properly so can't */ - if (message_box("Problem reading from tape. End of tape?", MB_YESNO)) /* distinguish b/w two conditions */ + if (message_box("Problem reading from tape. End of tape?", MB_YESNO)) {/* distinguish b/w two conditions */ + free(crypt); return x; /* tape drive doesn't handle */ + } rc = x; /* rc = how much got */ m = alloca(block_size); while (rc < count) { x1 = rmtread(fd, m, block_size); - if (x1 == 0) return rc; /* must assume end of tape */ + + mtcrypt_transfer(blub, READ_BUF, crypt, m, block_size, iv); + + if (x1 == 0) { + free(crypt); + return rc; /* must assume end of tape */ + } if (x1 == -1) { /* good - error condition */ - if ((errno == ENOSPC) || (errno == ENODATA)) /* correct - end of tape */ + if ((errno == ENOSPC) || (errno == ENODATA)) {/* correct - end of tape */ + free(crypt); return rc; + } if (retryabort("reading from tape") == -1) { /* a real error */ errno = serr; + free(crypt); return -1; } continue; @@ -94,13 +128,17 @@ memcpy(overflow_buffer, m+block_size-(rc-block_size), rc-block_size); overflow_count = rc-block_size; } - if (rc >= count) return count; /* got all data */ + if (rc >= count) { + free(crypt); + return count; /* got all data */ + } } + free(crypt); return -1; /* Should never get here */ } -ssize_t raw_write(int fd, char *data, ssize_t count) +ssize_t raw_write(const struct mtcrypt_context *blub, int fd, char *data, ssize_t count, int iv) { /* Does a write to the tape @@ -114,14 +152,26 @@ ssize_t x, x1, rc; char s[200]; int serr; - + char *crypt = malloc(block_size); + rc = 0; while (1) { - x = rmtwrite(fd, data+rc, count-rc); + + mtcrypt_transfer(blub, WRITE_BUF, crypt, &data[rc], block_size, iv); + + x = rmtwrite(fd, crypt, count-rc); + if (x != -1) x += rc; /* adjust for already got */ - if (x == count) return x; /* got all data */ + if (x == count) { + free(crypt); + return x; /* got all data */ + } if (x == -1) { /* error writing */ - if (errno == ENOSPC) return 0; /* was no space */ + if (errno == ENOSPC) { + free(crypt); + return 0; /* was no space */ + } + free(crypt); return -(count+1); } /* We have a short write : two possibilites @@ -132,26 +182,45 @@ if for some reason, data is succesfully written, then we are stuffed and totally out of sync. But this should never occur (unless of course, nothing could be written above) -*/ +*/ + + rc = x; while (rc < count) { - x1 = rmtwrite(fd, data+rc, block_size); /* write a block */ + + mtcrypt_transfer(blub, WRITE_BUF, crypt, &data[rc], block_size, iv); + + x1 = rmtwrite(fd, crypt, block_size); /* write a block */ serr = errno; + if (log_level > 3) { sprintf(s, "W:Writing in error loop - rc=%d, count=%d, x1=%d", rc, count, x1); write_log(s); } - if (x1 == 0) return rc; /* must assume end of tape */ + if (x1 == 0) { + free(crypt); + return rc; /* must assume end of tape */ + } if (x1 == -1) { /* good - error condition */ - if ((serr == ENOSPC) || (serr == ENODATA)) /* correct - end of tape */ + if ((serr == ENOSPC) || (serr == ENODATA)) {/* correct - end of tape */ + free(crypt); return rc; /* correct - end of tape */ - if (rc == 0) return -(count+1); /* none written */ + } + if (rc == 0) { + free(crypt); + return -(count+1); /* none written */ + } + free(crypt); return -rc; /* real error - wrote rc bytes */ } rc += x1; } - if (rc >= count) return count; /* got all data */ + if (rc >= count) { + free(crypt); + return count; /* got all data */ + } } + free(crypt); return -(count+1); /* Should never get here */ } @@ -167,7 +236,7 @@ } -_errstat tape_fsf(int count, int allowerr) +_errstat tape_fsf(const struct mtcrypt_context *mtc, int count, int allowerr) { /* If allowerr = 1, errors allowed */ struct mtop m; @@ -179,8 +248,8 @@ /* When doing fsf, must flush buffers */ if (write_offset != -1) { - flush_buffers(); - wait_finish_writing(); + flush_buffers(mtc); + wait_finish_writing(mtc); } read_offset = -1; /* discard rest of block */ sprintf(l, "Advancing %d volumes", count); @@ -201,7 +270,7 @@ } -_errstat tape_eom() +_errstat tape_eom(const struct mtcrypt_context *mtc) { struct mtop m; char l[200]; @@ -212,8 +281,8 @@ /* When doing eom, must flush buffers */ if (write_offset != -1) { - flush_buffers(); - wait_finish_writing(); + flush_buffers(mtc); + wait_finish_writing(mtc); } read_offset = -1; /* discard rest of block */ sprintf(l, "Advancing to end of tape"); @@ -286,7 +355,7 @@ } -_errstat tape_goto_block(WINDOW *mes, int line, _s32 block) +_errstat tape_goto_block(const struct mtcrypt_context *mtc, WINDOW *mes, int line, _s32 block) { /* Positions tape at block 'block' * @@ -307,7 +376,7 @@ if (log_level > 2) write_log("Couln't ioctl seek - trying manually"); read_offset = -1; while (c < block) { - if (raw_read(dv, read_buffer, block_size, FALSE) != block_size) + if (raw_read(mtc, dv, read_buffer, block_size, FALSE, blocks_passed) != block_size) return do_exit(ERROR_TAPE_GOTO); blocks_passed++; c++; @@ -316,7 +385,7 @@ } -_errstat tape_read_u16(_u16 *x) +_errstat tape_read_u16(const struct mtcrypt_context *mtc, _u16 *x) { /* Reads an unsigned 16 bit integer from the tape * @@ -326,13 +395,13 @@ */ char s[sizeof(_u16)]; - if (tape_read(s, sizeof(s)) != sizeof(s)) return -1; + if (tape_read(mtc, s, sizeof(s)) != sizeof(s)) return -1; *x = little2machu16((_u16 *) s); return 0; } -_errstat tape_read_s32(_s32 *x) +_errstat tape_read_s32(const struct mtcrypt_context *mtc, _s32 *x) { /* Reads a signed 32 bit integer from the tape * @@ -342,13 +411,13 @@ */ char s[sizeof(_s32)]; - if (tape_read(s, sizeof(s)) != sizeof(s)) return -1; + if (tape_read(mtc, s, sizeof(s)) != sizeof(s)) return -1; *x = little2machs32((_s32 *) s); return 0; } -_errstat tape_read_u64(_u64 *x) +_errstat tape_read_u64(const struct mtcrypt_context *mtc, _u64 *x) { /* Reads a 64 bit integer from the tape * @@ -358,13 +427,13 @@ */ char s[sizeof(_u64)]; - if (tape_read(s, sizeof(s)) != sizeof(s)) return -1; + if (tape_read(mtc, s, sizeof(s)) != sizeof(s)) return -1; *x = little2machu64((_u64 *) s); return 0; } -_errstat tape_readheader(struct tape_header *t, _s8 allowz, int mode) +_errstat tape_readheader(const struct mtcrypt_context *mtc, struct tape_header *t, _s8 allowz, int mode) { /* Reads the tape header. It assumes that the tape is at the * beginning and no data has been read in as yet. @@ -391,7 +460,7 @@ while (1) { memset(t, 0, sizeof(*t)); if (log_level > 2) write_log("Reading in block for tape header"); - read_buffer_count = raw_read(dv, read_buffer, block_size, allowz); + read_buffer_count = raw_read(mtc, dv, read_buffer, block_size, allowz, blocks_passed); blocks_passed=1; if (read_buffer_count != block_size) { /* read in a block */ if (tape_type == TAPE_TYPE_ZFTAPE) { /* zftape has a problem sometimes, so read again to double check */ @@ -399,7 +468,7 @@ if ((read_buffer_count == -1) && (errno == EINVAL)) { /* correct block size initially */ if (tape_get_blk_size(dv) == -1) return (allowz) ? 0 : -1; if (log_level > 2) write_log("Rereading tape header block"); - read_buffer_count = raw_read(dv, read_buffer, block_size, allowz); + read_buffer_count = raw_read(mtc, dv, read_buffer, block_size, allowz, blocks_passed); if (read_buffer_count != block_size) { if (allowz) return 0; /* errors allowed */ write_fatal_log("reading in tape header block"); @@ -454,7 +523,7 @@ if (m == NULL) do_exit(ERROR_MEMORY); sprintf(s, "Special zftape. Reading %d, Read %ld",((28672/block_size+1)*block_size), - (long) raw_read(dv, m, (28672/block_size+1)*block_size, allowz)); /* read more than 28K */ + (long) raw_read(mtc, dv, m, (28672/block_size+1)*block_size, allowz, blocks_passed)); /* read more than 28K */ if (log_level > 2) write_log(s); free(m); mt.mt_op = MTREW; @@ -479,7 +548,7 @@ } -_errstat check_tape(WINDOW *mes, int line, _s32 tape_required) +_errstat check_tape(const struct mtcrypt_context *mtc, WINDOW *mes, int line, _s32 tape_required) { /* Prompts user for tape_required tape on archive in ifd.archive_id Also makes sure correct archive id is in tape @@ -499,7 +568,7 @@ write(mf, l, strlen(l)); return -1; } - tape_close(); + tape_close(mtc); sprintf(l, "Prompting for insertion of tape %d", tape_required); if (log_level > 2) write_log(l); sprintf(l, "Please insert tape %d of archive %u in tape drive", tape_required, ifd.archive_id); @@ -520,7 +589,7 @@ while (1) { touchwin(mymes); status_box(mymes, "Identifying tape", line, FALSE, 1); - tape_close(); + tape_close(mtc); sprintf(l, "Opening tape to ensure that tape #%d of archive %d is in drive", tape_required, ifd.archive_id); if (log_level > 2) write_log(l); @@ -529,7 +598,7 @@ continue; vols_passed = 0; /* no volumes passed on this tape */ tdh1.magic = 0; - tape_readheader(&tdh1, 0, O_RDONLY); + tape_readheader(mtc, &tdh1, 0, O_RDONLY); if ((tdh1.magic != TAPER_MAGIC_NUMBER) && (tdh1.magic != TAPER_64_MAGIC)) { if (!message_box("This tape doesn't contain taper data", MB_OKCANCEL)) return -1; @@ -800,15 +869,15 @@ } -_errstat tape_close_engine(_s8 flush) +_errstat tape_close_engine(const struct mtcrypt_context *mtc, _s8 flush) { _errstat ret; /* closes tape device */ if ((dv==-1) || (dv == 0)) return 0; /* not open */ if (flush) { - flush_buffers(); - wait_finish_writing(); + flush_buffers(mtc); + wait_finish_writing(mtc); } if (write_pid) { kill(write_pid, SIGTERM); @@ -830,13 +899,13 @@ } -_errstat tape_close() +_errstat tape_close(const struct mtcrypt_context *mtc) { - return tape_close_engine(1); + return tape_close_engine(mtc, 1); } -int read_from_buf(char *buf, ssize_t count, int allowerr) +int read_from_buf(const struct mtcrypt_context *mtc, char *buf, ssize_t count, int allowerr) { /* Before asking for more data to be read in, it checks to see if there is any data in the overflow buffer */ @@ -856,7 +925,7 @@ return 0; } } - read_buffer_count = raw_read(dv, read_buffer, block_size, allowerr); /* read in a block */ + read_buffer_count = raw_read(mtc, dv, read_buffer, block_size, allowerr, blocks_passed); /* read in a block */ if (read_buffer_count == -1) { if (log_level) write_log("reading data from tape"); return -1; @@ -887,7 +956,7 @@ overflow_count = 0; } else { - read_buffer_count = raw_read(dv, read_buffer, block_size, FALSE); + read_buffer_count = raw_read(mtc, dv, read_buffer, block_size, FALSE, blocks_passed); if (read_buffer_count == -1) { if (log_level) write_log("reading data from tape"); return -1; @@ -906,7 +975,7 @@ } -_errstat write_tape_header(struct tape_header *tdh) +_errstat write_tape_header(const struct mtcrypt_context *mtc, struct tape_header *tdh) { /* Writes the tape header. Assumes that the tape is at the * beginning. Also assumes that there may be valid data waiting @@ -951,7 +1020,7 @@ memcpy(my_write_buffer+sizeof(struct tape_header), write_buffer, block_size - sizeof(struct tape_header)); while (1) { - if (raw_write(dv, my_write_buffer, block_size) < block_size) { + if (raw_write(mtc, dv, my_write_buffer, block_size, blocks_passed) < block_size) { if (retryabort("writing tape header to tape") == -1) { write_fatal_log("writing tape header block"); my_free(my_write_buffer); @@ -973,7 +1042,7 @@ -_errstat do_write_block(_s8 *buf_to_write, _s32 old_length, _s8 fc) +_errstat do_write_block(const struct mtcrypt_context *mtc, _s8 *buf_to_write, _s32 old_length, _s8 fc) { /* Writes the buffer at buf_to_write of old_length out to * the tape. If fc, then will write out the last partial @@ -1031,7 +1100,7 @@ goto pr; } - c = raw_write(dv, write_buffer, block_size);/* write data */ + c = raw_write(mtc, dv, write_buffer, block_size, blocks_passed);/* write data */ if (log_level > 2) { sprintf(s, "Wrote block to tape [%d bytes]", c); write_log(s); @@ -1081,7 +1150,7 @@ -_errstat do_next_tape(void) +_errstat do_next_tape(const struct mtcrypt_context *mtc) { /* The child ran out of space while trying to write. Must * be end of tape. Get new tape and write out what's left @@ -1109,7 +1178,7 @@ tsi[ifd.number_tsi-1].volume = ifd.number_volumes; tsi[ifd.number_tsi-1].blocks = blocks_passed; tsi[ifd.number_tsi-1].lb_bytes_short = bytes_short; - tape_close_engine(0); + tape_close_engine(mtc, 0); buf_to_write = w_current_writing; /* buffer child was writing to */ my_wbuf = my_malloc(block_size); if (my_wbuf == NULL) return do_exit(ERROR_MEMORY); @@ -1134,8 +1203,8 @@ if (tape_open_engine(O_RDWR, 0) == -1) /* must be RDWR since called */ continue; /* by wriet child */ tdh1.magic = 0; - tape_readheader(&tdh1, 1, O_RDWR); - tape_close_engine(0); + tape_readheader(mtc, &tdh1, 1, O_RDWR); + tape_close_engine(mtc, 0); if ((tdh1.magic == TAPER_MAGIC_NUMBER) || (tdh1.magic == TAPER_64_MAGIC)) { if (tdh1.archive_id == 0) break; @@ -1158,7 +1227,7 @@ } tape_erase(); /* erase tape */ status_box(mes, "Rewinding tape & writing tape header", 1, FALSE, 1); - tape_close_engine(0); + tape_close_engine(mtc, 0); if (log_level > 2) write_log("Opening new tape for data writing"); if (tape_open_engine(O_RDWR, 0) == -1) { @@ -1170,7 +1239,7 @@ tape_set_blk_size(); tdh.tape_number++; memcpy(write_buffer, my_wbuf, block_size); /* restore contents of write buffer */ - if (write_tape_header(&tdh) == -1) { + if (write_tape_header(mtc, &tdh) == -1) { c=-1; goto end; } @@ -1179,7 +1248,7 @@ sprintf(l, "Writing rest of buffer %d to new tape", ((buf_to_write == w_buffer_1) ? 1 : 2)); if (log_level > 2) write_log(l); - c=do_write_block(buf_to_write+left_tr, + c=do_write_block(mtc, buf_to_write+left_tr, ((buf_to_write == w_buffer_1) ? buf_length_1 : buf_length_2) - left_tr, ((buf_to_write == w_buffer_1) ? for_close_1 : for_close_2)); @@ -1212,7 +1281,7 @@ } -void do_write_child(void) +void do_write_child(const struct mtcrypt_context *mtc) { /* This is the child process that runs in the background. It * sleeps until it write_buf_no becomes non-null. It then @@ -1254,7 +1323,7 @@ '0'+((write_buf_no == w_buffer_1) ? for_close_1 : for_close_2)); write_log(s); } - ret = do_write_block((_s8 *) write_buf_no, + ret = do_write_block(mtc, (_s8 *) write_buf_no, ((write_buf_no == w_buffer_1) ? buf_length_1 : buf_length_2), ((write_buf_no == w_buffer_1) ? for_close_1 : for_close_2) ); write_buf_no = NULL; /* this will ensure that all bytes of write_buf_no are zero */ @@ -1273,7 +1342,7 @@ } -_errstat wait_finish_writing() +_errstat wait_finish_writing(const struct mtcrypt_context *mtc) { /* Waits for child to finish writing current buffer. If child returns * an error, prompts user for abort/retry. If user wants to retry, @@ -1314,14 +1383,14 @@ #endif if (write_buf_no == (char *) -2) { /* child returned end of tape */ write_buf_no = NULL; - if (do_next_tape() == -1) return -1; + if (do_next_tape(mtc) == -1) return -1; return -2; } /* Child returned -1 (ie. couldn't write) * Therefore, we will try to finish the writing */ while (1) { /* try and write out block child missed */ if (log_level > 2) write_log("Child couldn't write - main trying to"); - x = do_write_block(w_current_writing, + x = do_write_block(mtc, w_current_writing, ((w_current_writing == w_buffer_1) ? buf_length_1 : buf_length_2), ((w_current_writing == w_buffer_1) ? for_close_1 : for_close_2)); if (x == 0) { /* successful write */ @@ -1340,7 +1409,7 @@ } if (x == -2) { /* end of tape reached while writing block */ write_buf_no = NULL; - if (do_next_tape() == -1) return -1; + if (do_next_tape(mtc) == -1) return -1; return -2; } } @@ -1356,7 +1425,7 @@ } -_errstat flush_buffers() +_errstat flush_buffers(const struct mtcrypt_context *mtc) { /* Flushes the write buffer * @@ -1393,7 +1462,7 @@ memset(w_current_buffer+w_cur_pos, 0, DOUBLE_BUFFER_SIZE-w_cur_pos); } - x = wait_finish_writing(); /* wait for child to finish writing */ + x = wait_finish_writing(mtc); /* wait for child to finish writing */ if (x == -1) { /* it will also take care of end of tapes */ if (log_level > 2) write_log("wait_finish returned error"); w_cur_pos = 0; write_offset = 0; left_tr = 0; @@ -1418,7 +1487,7 @@ if (log_level > 3) write_log("W:Write child forked off"); fd_pipefc = fopen(pipefc, "w"); fd_pipetoc = fopen(pipetoc, "r"); - do_write_child(); /* do child loop */ + do_write_child(mtc); /* do child loop */ } if (f == -1) { /* we are in the parent */ if (log_level > 1) write_warning_log("Unable to fork - not triple buffering"); @@ -1447,7 +1516,7 @@ write_buf_no = NULL; /* ensure all bytes are zero */ #ifdef TRIPLE_BUFFER write_buf_no = (write_pid) ? w_current_buffer : - (_vptr) (_s32) do_write_block(w_current_buffer, w_cur_pos, (w_cur_pos != DOUBLE_BUFFER_SIZE)); + (_vptr) (_s32) do_write_block(mtc, w_current_buffer, w_cur_pos, (w_cur_pos != DOUBLE_BUFFER_SIZE)); if (write_pid) { fprintf(fd_pipetoc, "Data\n"); /* tell child data is ready */ fflush(fd_pipetoc); @@ -1469,7 +1538,7 @@ -ssize_t tape_write(_vptr buf, ssize_t count) +ssize_t tape_write(const struct mtcrypt_context *mtc, _vptr buf, ssize_t count) { ssize_t tr_bytes; ssize_t fit_in; @@ -1481,13 +1550,13 @@ w_cur_pos += fit_in; tr_bytes += fit_in; if (w_cur_pos >= DOUBLE_BUFFER_SIZE) - if (flush_buffers() == -1) + if (flush_buffers(mtc) == -1) return -1; } return tr_bytes; } -ssize_t tape_read_engine(_vptr buf, ssize_t count, int allowerr) +ssize_t tape_read_engine(const struct mtcrypt_context *mtc, _vptr buf, ssize_t count, int allowerr) { /* An end of tape is assumed if we get an return code=-1 and errno=ENOSPC --OR-- * the count returned is less than we asked for @@ -1497,7 +1566,7 @@ */ ssize_t c; - c = read_from_buf(buf, count, allowerr); + c = read_from_buf(mtc, buf, count, allowerr); if (c == count) return c; /* OK - written what we asked for */ if (c == -1) { /* error */ if (errno != ENOSPC) /* make sure not an end of tape error */ @@ -1517,19 +1586,19 @@ tsi[ifd.number_tsi-1].lb_bytes_short = bytes_short; } if (c == 0) return 0; /* end of tape */ - if (check_tape(NULL, 0, tdh.tape_number+1) == -1)/* get next tape */ + if (check_tape(mtc, NULL, 0, tdh.tape_number+1) == -1)/* get next tape */ return -1; - return read_from_buf((char *) buf+c, count-c, allowerr)+c;/* return data */ + return read_from_buf(mtc, (char *) buf+c, count-c, allowerr)+c;/* return data */ } -ssize_t tape_read(_vptr buf, ssize_t count) +ssize_t tape_read(const struct mtcrypt_context *mtc, _vptr buf, ssize_t count) { - return tape_read_engine(buf, count, FALSE); + return tape_read_engine(mtc, buf, count, FALSE); } -_errstat tape_read_namelen(char *s) +_errstat tape_read_namelen(const struct mtcrypt_context *mtc, char *s) { /* Reads a name from the tape. The first is a name len * which is an signed 32 bit then the length @@ -1538,13 +1607,13 @@ */ _s32 x; - if (tape_read_s32(&x) == -1) return -1; - if (tape_read(s, min(x, MAX_FNAME)) != min(x, MAX_FNAME)) return -1; + if (tape_read_s32(mtc, &x) == -1) return -1; + if (tape_read(mtc, s, min(x, MAX_FNAME)) != min(x, MAX_FNAME)) return -1; return 0; } -_errstat tape_read_fi(struct file_info *fi) +_errstat tape_read_fi(const struct mtcrypt_context *mtc, struct file_info *fi) { /* Reads a file_info from the tape. Converts anything to big endian * if required @@ -1553,13 +1622,13 @@ */ struct file_info fi1; - if (tape_read((char *) &fi1, sizeof(fi1)) != sizeof(fi1)) return -1; + if (tape_read(mtc, (char *) &fi1, sizeof(fi1)) != sizeof(fi1)) return -1; fi_endianize2mach(&fi1, fi); return 0; } -_errstat tape_write_s32(_s32 *x) +_errstat tape_write_s32(const struct mtcrypt_context *mtc, _s32 *x) { /* Writes signed 32 bit integer from the tape * @@ -1570,12 +1639,12 @@ _s32 s; s = mach2littles32(x); - if (tape_write((char *) &s, sizeof(s)) != sizeof(s)) return -1; + if (tape_write(mtc, (char *) &s, sizeof(s)) != sizeof(s)) return -1; return 0; } -_errstat tape_write_namelen(char *s) +_errstat tape_write_namelen(const struct mtcrypt_context *mtc, char *s) { /* Reads a name from the tape. The first is a name len * which is an signed 32 bit then the length @@ -1585,13 +1654,13 @@ _s32 x; x = strlen(s)+1; - if (tape_write_s32(&x) == -1) return -1; - if (tape_write(s, x) != x) return -1; + if (tape_write_s32(mtc, &x) == -1) return -1; + if (tape_write(mtc, s, x) != x) return -1; return 0; } -_errstat tape_write_fi(struct file_info *fi) +_errstat tape_write_fi(const struct mtcrypt_context *mtc, struct file_info *fi) { /* Reads a file_info from the tape. Converts anything to big endian * if required @@ -1601,12 +1670,12 @@ struct file_info fi1; fi_endianize2little(fi, &fi1); - if (tape_write((char *) &fi1, sizeof(fi1)) != sizeof(fi1)) return -1; + if (tape_write(mtc, (char *) &fi1, sizeof(fi1)) != sizeof(fi1)) return -1; return 0; } -_errstat get_tape_header(WINDOW *mess, int line, struct tape_header *tdh, int mode) +_errstat get_tape_header(const struct mtcrypt_context *mtc, WINDOW *mess, int line, struct tape_header *tdh, int mode) { /* Tries to get the tape header of the tape currently in the drive. * @@ -1627,7 +1696,7 @@ if (tape_open(mode) == -1) /* open rewinding device */ return -1; - if (tape_readheader(tdh, 1, mode) == -1) /* could open but can't */ + if (tape_readheader(mtc, tdh, 1, mode) == -1) /* could open but can't */ return BAD_MAGIC; /* read - therefore is bad magic */ if ((tdh->magic != TAPER_MAGIC_NUMBER) && (tdh->magic != TAPER_64_MAGIC)) { @@ -1643,18 +1712,18 @@ } -_errstat tape_write_volheader(struct volume_header *vh) +_errstat tape_write_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh) { struct volume_header vh1; volheader_endianize2little(*vh, &vh1); - if (tape_write((char *) &vh1, sizeof(struct volume_header)) == -1) + if (tape_write(mtc, (char *) &vh1, sizeof(struct volume_header)) == -1) return -1; return 0; } -_errstat tape_read_volheader(struct volume_header *vh, int allower) +_errstat tape_read_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh, int allower) { /* Reads a volume header. * @@ -1666,7 +1735,7 @@ char s[256]; if (log_level > 2) write_log("Reading in volume header"); - if (tape_read_engine((char *) &vh1, sizeof(struct volume_header), TRUE) != sizeof(struct volume_header)) { /* volume magic number */ + if (tape_read_engine(mtc, (char *) &vh1, sizeof(struct volume_header), TRUE) != sizeof(struct volume_header)) { /* volume magic number */ if (allower) { if (log_level > 2) write_log("Allowable error reading in volume header"); return 0; @@ -1681,7 +1750,7 @@ } -_errstat read_volheader(struct volume_header *vh, _s8 read_vh, _s8 into_mem) +_errstat read_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh, _s8 read_vh, _s8 into_mem) { /* Reads in volume header. If into_mem, places the information into * memory, otherwise discards it. If read_vh, then expects to read @@ -1694,7 +1763,7 @@ if (read_vh) { if (log_level > 2) write_log("Reading in volume header"); - if (tape_read_volheader(vh, 0) == -1) return -1; + if (tape_read_volheader(mtc, vh, 0) == -1) return -1; } if ((vh->volume_magic != VOLUME_MAGIC) && /* volume magic doesn't agree - warning */ (vh->volume_magic != VOLUME_64_MAGIC)) @@ -1705,19 +1774,19 @@ if (vol_headers == NULL) return do_exit(ERROR_MEMORY); memcpy( ((char *) vol_headers)+ifd.size_volume_headers, vh, sizeof(struct volume_header)); - if (tape_read(((char *) vol_headers)+ifd.size_volume_headers+sizeof(*vh), vh->size_header-sizeof(*vh)) == -1) + if (tape_read(mtc, ((char *) vol_headers)+ifd.size_volume_headers+sizeof(*vh), vh->size_header-sizeof(*vh)) == -1) return -1; return 0; } z = my_malloc(vh->size_header); /* skip past header details */ if (z == NULL) return do_exit(ERROR_MEMORY); - x = tape_read(z, vh->size_header-sizeof(*vh)); + x = tape_read(mtc, z, vh->size_header-sizeof(*vh)); my_free(z); return x; } -_errstat goto_end_vol(WINDOW *mes, int ln, _s32 vol, _s32 at_vol, _s8 get_th, int mode) +_errstat goto_end_vol(const struct mtcrypt_context *mtc, WINDOW *mes, int ln, _s32 vol, _s32 at_vol, _s8 get_th, int mode) { /* Positions tape at beginning of volume 'vol'+1. Assumes at at_vol * Prints status on line 'ln' of box 'mes' @@ -1757,7 +1826,7 @@ if (get_th) /* only get if user wants */ while (1) { /* use to get tape header */ - c = get_tape_header(mes, ln, &tdh, mode); + c = get_tape_header(mtc, mes, ln, &tdh, mode); at_vol = 1; if (c==-1) return -1; if (c==BAD_MAGIC) { @@ -1767,25 +1836,25 @@ if (c==TAPE_EXIST) break; } - if (check_tape(mes, ln, want_tape) == -1) /* make sure correct tape in drive */ + if (check_tape(mtc, mes, ln, want_tape) == -1) /* make sure correct tape in drive */ return -1; /* user aborted or error */ sprintf(s, "Advancing to volume %d", vol+1); status_box(mes, s, ln, FALSE, 1); if (have_fsf) { if (!fast_fsf) { - tape_close(); /* close rewinding device opened earlier */ + tape_close(mtc); /* close rewinding device opened earlier */ if ((dv = ntape_open(mode)) == -1) /* now open non-rewinding so we can position */ return -1; - if (tape_fsf(pass_vols, FALSE) == -1)/* reposition */ + if (tape_fsf(mtc, pass_vols, FALSE) == -1)/* reposition */ return do_exit(ERROR_TAPE_FSF); - tape_close(); /* close it to effect change */ + tape_close(mtc); /* close it to effect change */ if ((dv = tape_open(mode)) == -1) /* reopen at new position (rewinding device)*/ return -1; return pass_vols+1; } else { /* have a fast fsf */ if (!(pass_vols-at_vol+1)) return 0; - if (tape_fsf(pass_vols-at_vol+1, FALSE) == -1) + if (tape_fsf(mtc, pass_vols-at_vol+1, FALSE) == -1) return -1; } clear_buffer_pointers(); @@ -1795,7 +1864,7 @@ if (blocks_passed < pass_blocks) { /* ?need to advance */ for (c=blocks_passed; c + extern char *make_tt(char tt); -extern _errstat tape_readheader(struct tape_header *t, _s8 allowz, int mode); -extern _errstat check_tape(WINDOW *mes, int line, _s32 tape_required); +extern _errstat tape_readheader(const struct mtcrypt_context *mtc, struct tape_header *t, _s8 allowz, int mode); +extern _errstat check_tape(const struct mtcrypt_context *mtc, WINDOW *mes, int line, _s32 tape_required); extern _errstat tape_rewind_engine(int opendevice); extern _errstat tape_rewind(void); extern _errstat tape_tell(_u64 *pos); extern _errstat tape_seek(int toblock, char must_seek); extern _errstat tape_eom(); -extern _errstat tape_fsf(int count, int allowerr); +extern _errstat tape_fsf(const struct mtcrypt_context *mtc, int count, int allowerr); extern _errstat tape_erase(void); -extern _errstat tape_goto_block(WINDOW *mes, int line, _s32 block); +extern _errstat tape_goto_block(const struct mtcrypt_context *mtc, WINDOW *mes, int line, _s32 block); extern _errstat ntape_open(int mode); extern _errstat tape_open(int mode); -extern _errstat write_tape_header(struct tape_header *tdh); -extern _errstat wait_finish_writing(void); -extern _errstat flush_buffers(void); -extern ssize_t tape_read(_vptr buf, ssize_t count); -extern ssize_t tape_write(_vptr buf, ssize_t count); -extern _errstat tape_read_s32(_s32 *x); -extern _errstat tape_read_u64(_u64 *x); -extern _errstat tape_read_namelen(char *s); -extern _errstat tape_read_fi(struct file_info *fi); -extern _errstat tape_read_volheader(struct volume_header *vh, int allower); -extern _errstat tape_write_fi(struct file_info *fi); -extern _errstat tape_write_namelen(char *s); -extern _errstat tape_write_volheader(struct volume_header *vh); -extern _errstat tape_close(void); -extern _errstat get_tape_header(WINDOW *mess, int line, struct tape_header *tdh, int mode); +extern _errstat write_tape_header(const struct mtcrypt_context *mtc, struct tape_header *tdh); +extern _errstat wait_finish_writing(const struct mtcrypt_context *mtc); +extern _errstat flush_buffers(const struct mtcrypt_context *mtc); +extern ssize_t tape_read(const struct mtcrypt_context *mtc, _vptr buf, ssize_t count); +extern ssize_t tape_write(const struct mtcrypt_context *mtc, _vptr buf, ssize_t count); +extern _errstat tape_read_s32(const struct mtcrypt_context *mtc, _s32 *x); +extern _errstat tape_read_u64(const struct mtcrypt_context *mtc, _u64 *x); +extern _errstat tape_read_namelen(const struct mtcrypt_context *mtc, char *s); +extern _errstat tape_read_fi(const struct mtcrypt_context *mtc, struct file_info *fi); +extern _errstat tape_read_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh, int allower); +extern _errstat tape_write_fi(const struct mtcrypt_context *mtc, struct file_info *fi); +extern _errstat tape_write_namelen(const struct mtcrypt_context *mtc, char *s); +extern _errstat tape_write_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh); +extern _errstat tape_close(const struct mtcrypt_context *mtc); +extern _errstat get_tape_header(const struct mtcrypt_context *mtc, WINDOW *mess, int line, struct tape_header *tdh, int mode); extern _errstat is_regfile(int d); extern _errstat tape_get_blk_size(_s32); extern void tape_set_blk_size(void); -extern _errstat read_volheader(struct volume_header *vh, _s8 read_vh, _s8 into_mem); -extern _errstat goto_end_vol(WINDOW *mes, int line, _s32 vol, _s32 at_vol, _s8 get_th, int mode); +extern _errstat read_volheader(const struct mtcrypt_context *mtc, struct volume_header *vh, _s8 read_vh, _s8 into_mem); +extern _errstat goto_end_vol(const struct mtcrypt_context *mtc, WINDOW *mes, int line, _s32 vol, _s32 at_vol, _s8 get_th, int mode); diff -Nur taper-7.0pre-1/taper.c taper-7.0pre-1-AES/taper.c --- taper-7.0pre-1/taper.c 2003-09-18 11:14:49.000000000 +0200 +++ taper-7.0pre-1-AES/taper.c 2003-09-18 11:35:43.000000000 +0200 @@ -20,7 +20,7 @@ */ #include "taper.h" - +#include PRIVATE void usage(void) { @@ -1446,10 +1446,10 @@ } -void taper_backup(int, char **); -void taper_restore(void); -void taper_verify(void); -void taper_mkinfo(void); +void taper_backup(const struct mtcrypt_context *mtc, int, char **); +void taper_restore(const struct mtcrypt_context *mtc); +void taper_verify(const struct mtcrypt_context *mtc); +void taper_mkinfo(const struct mtcrypt_context *mtc); int main(int argc, char *argv[]) { @@ -1460,6 +1460,14 @@ "Utilities", "Change Preferences", "Save preferences", "Exit", NULL}; + struct mtcrypt_context *blub; + char pass[32]; + char hash_pass[64]; + char keysize[4]; + int keysizeN = 0; + char iter[8]; + int iterN = 0; + char *endp; read_buffer = NULL; tr_buffer = NULL; @@ -1479,29 +1487,149 @@ signal(SIGABRT, my_sf_sig); /* trap seg fault signal */ getcwd(cur_dir, sizeof(cur_dir)); /* save current directory for backup */ getcwd(original_cur_dir, sizeof(original_cur_dir)); /* for restore */ +/* + * FIXME: taper_restore() and taper_backup() needs a mtcrypt_context here. + */ + +/* if (no_windows) { init_common_vars(); if ((pr_dir) || (diff_id)) taper_restore(); if (unattended) taper_backup(argc, argv); } else { +*/ my_init_windows(); /* initialise windows for subsystems */ + while (!fin) { clear_main(); init_common_vars(); /* set all vars */ switch (select_menu(win_main, menu, &in_op)) { case 0: /* backup */ - taper_backup(argc, argv); + get_string(win_main, pass, sizeof(pass), "Passphrase"); + get_string(win_main, keysize, sizeof(keysize), "Keysize"); + get_string(win_main, iter, sizeof(iter), "Iteration Count"); + + keysizeN = strtol(keysize, &endp, 10); + iterN = strtol(iter, &endp, 10); + + switch (keysizeN) { + case 16: + case 128: + mtcrypt_sha256_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha256_iter(pass, hash_pass, hash_pass, iterN); + case 24: + case 192: + mtcrypt_sha384_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha384_iter(pass, hash_pass, hash_pass, iterN); + case 32: + case 256: + default: + mtcrypt_sha512_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha512_iter(pass, hash_pass, hash_pass, iterN); + } + + blub = aes_init(hash_pass, keysizeN); + + memset(pass, 0, sizeof(pass)); + memset(hash_pass, 0, sizeof(hash_pass)); + + taper_backup(blub, argc, argv); break; case 1: /* restore */ restore_mode = RESTORE_FULL; - taper_restore(); + + get_string(win_main, pass, sizeof(pass), "Passphrase"); + get_string(win_main, keysize, sizeof(keysize), "Keysize"); + get_string(win_main, iter, sizeof(iter), "Iteration Count"); + + keysizeN = strtol(keysize, &endp, 10); + iterN = strtol(iter, &endp, 10); + + switch (keysizeN) { + case 16: + case 128: + mtcrypt_sha256_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha256_iter(pass, hash_pass, hash_pass, iterN); + case 24: + case 192: + mtcrypt_sha384_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha384_iter(pass, hash_pass, hash_pass, iterN); + case 32: + case 256: + default: + mtcrypt_sha512_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha512_iter(pass, hash_pass, hash_pass, iterN); + } + + blub = aes_init(hash_pass, keysizeN); + + memset(pass, 0, sizeof(pass)); + memset(hash_pass, 0, sizeof(hash_pass)); + + taper_restore(blub); break; case 2: /* mkinfo */ - taper_mkinfo(); + get_string(win_main, pass, sizeof(pass), "Passphrase"); + get_string(win_main, keysize, sizeof(keysize), "Keysize"); + get_string(win_main, iter, sizeof(iter), "Iteration Count"); + + keysizeN = strtol(keysize, &endp, 10); + iterN = strtol(iter, &endp, 10); + + switch (keysizeN) { + case 16: + case 128: + mtcrypt_sha256_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha256_iter(pass, hash_pass, hash_pass, iterN); + case 24: + case 192: + mtcrypt_sha384_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha384_iter(pass, hash_pass, hash_pass, iterN); + case 32: + case 256: + default: + mtcrypt_sha512_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha512_iter(pass, hash_pass, hash_pass, iterN); + } + + blub = aes_init(hash_pass, keysizeN); + + memset(pass, 0, sizeof(pass)); + memset(hash_pass, 0, sizeof(hash_pass)); + + taper_mkinfo(blub); break; case 3: - taper_verify(); + get_string(win_main, pass, sizeof(pass), "Passphrase"); + get_string(win_main, keysize, sizeof(keysize), "Keysize"); + get_string(win_main, iter, sizeof(iter), "Iteration Count"); + + keysizeN = strtol(keysize, &endp, 10); + iterN = strtol(iter, &endp, 10); + + switch (keysizeN) { + case 16: + case 128: + mtcrypt_sha256_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha256_iter(pass, hash_pass, hash_pass, iterN); + case 24: + case 192: + mtcrypt_sha384_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha384_iter(pass, hash_pass, hash_pass, iterN); + case 32: + case 256: + default: + mtcrypt_sha512_hash(pass, strlen(pass), hash_pass, sizeof(hash_pass)); + mtcrypt_sha512_iter(pass, hash_pass, hash_pass, iterN); + } + + blub = aes_init(hash_pass, keysizeN); + + memset(pass, 0, sizeof(pass)); + memset(hash_pass, 0, sizeof(hash_pass)); + + taper_verify(blub); break; case 4: utilities(); @@ -1535,7 +1663,9 @@ delwin(win_main); delwin(title); delwin(bottom); endwin(); curs_set(1); +/* } + */ if (shm) if (write_pid) kill(write_pid, SIGTERM); /* old write child still going */ free_buffers(); diff -Nur taper-7.0pre-1/taper.h taper-7.0pre-1-AES/taper.h --- taper-7.0pre-1/taper.h 2003-09-18 11:14:51.000000000 +0200 +++ taper-7.0pre-1-AES/taper.h 2003-09-18 11:08:13.000000000 +0200 @@ -56,6 +56,6 @@ #include -#include +//#include #include diff -Nur taper-7.0pre-1/utils.c taper-7.0pre-1-AES/utils.c --- taper-7.0pre-1/utils.c 2003-09-18 11:16:51.000000000 +0200 +++ taper-7.0pre-1-AES/utils.c 2003-09-18 11:10:15.000000000 +0200 @@ -45,7 +45,7 @@ } -PUBLIC void utils_mktape(void) +PUBLIC void utils_mktape(const struct mtcrypt_context *mtc) { WINDOW *mes=NULL; @@ -58,7 +58,7 @@ } utils_write_nullheader(&mes); - tape_close(); + tape_close(mtc); final_message("Make tape"); close_statusbox(mes); close_logfile("Make tape"); @@ -66,7 +66,7 @@ } -PUBLIC void utils_testfast_fsf(void) +PUBLIC void utils_testfast_fsf(const struct mtcrypt_context *mtc) { WINDOW *mes=NULL; char *m=NULL; @@ -81,26 +81,26 @@ } m = my_malloc(block_size*10); if (utils_write_nullheader(&mes) != -1) { - tape_close(); + tape_close(mtc); if (tape_open(O_RDWR) == -1) goto err; status_box(mes, "Writing data", 1, FALSE, 1); strcpy(m, "Volume#1"); - if (tape_write(m, block_size*10) != block_size * 10) goto err; - tape_close(); + if (tape_write(mtc, m, block_size*10) != block_size * 10) goto err; + tape_close(mtc); status_box(mes, "Advancing a volume", 1, FALSE, 1); if (ntape_open(O_RDWR) == -1) goto err; - if (tape_fsf(1, FALSE) == -1) goto err; - tape_close(); + if (tape_fsf(mtc, 1, FALSE) == -1) goto err; + tape_close(mtc); status_box(mes, "Writing to second volume", 1, FALSE, 1); if (tape_open(O_RDWR) == -1) goto err; strcpy(m, "Volume#2"); - if (tape_write(m, block_size*10) != block_size*10) goto err; - tape_close(); + if (tape_write(mtc, m, block_size*10) != block_size*10) goto err; + tape_close(mtc); status_box(mes, "Re-reading a bit of volume 1", 1, FALSE, 1); if (tape_open(O_RDWR) == -1) goto err; memset(m, 0, block_size*3); - if (tape_read(m, block_size*3) != block_size*3) goto err; + if (tape_read(mtc, m, block_size*3) != block_size*3) goto err; if (strcmp(m, "Volume#1")) { if (log_level) write_log("Could read 'volume#1' from volume 1"); @@ -110,11 +110,11 @@ status_box(mes, "Trying to do a fast fsf", 1, FALSE, 1); old_hfsf = have_fsf; /* force tape drive to have fsf */ have_fsf = 1; - if (tape_fsf(1, FALSE) == -1) {have_fsf = old_hfsf; goto err;} + if (tape_fsf(mtc, 1, FALSE) == -1) {have_fsf = old_hfsf; goto err;} have_fsf = old_hfsf; status_box(mes, "Trying Reading in a bit of volume 2", 1, FALSE, 1); memset(m, 0, block_size*3); - if (tape_read(m, block_size*3) != block_size*3) goto err; + if (tape_read(mtc, m, block_size*3) != block_size*3) goto err; message_box((strcmp(m, "Volume#2")) ? "Your tape drive can't do a fast fsf" : "Your tape drive can do a fast fsf", MB_OK); @@ -127,7 +127,7 @@ err:; if (m) my_free(m); - tape_close(); + tape_close(mtc); final_message("Test fast fsf"); close_statusbox(mes); close_logfile("Test fast fsf"); @@ -135,7 +135,7 @@ } -PUBLIC void utils_test_can_seek(void) +PUBLIC void utils_test_can_seek(const struct mtcrypt_context *mtc) { char *m=NULL; WINDOW *mes=NULL; @@ -157,27 +157,27 @@ can_seek = 1; if (utils_write_nullheader(&mes) != -1) { - tape_close(); + tape_close(mtc); if (tape_open(O_RDWR) == -1) goto fin; status_box(mes, "Writing data", 1, FALSE, 1); /* write out ten blocks */ for (c=0; c<10; c++) { sprintf(m, "Volume#1 - block #%d", c); - if (tape_write(m, block_size) != block_size) goto fin; + if (tape_write(mtc, m, block_size) != block_size) goto fin; } if (have_fsf) { - tape_close(); + tape_close(mtc); status_box(mes, "Advancing a volume", 1, FALSE, 1); if (ntape_open(O_RDWR) == -1) goto fin; - if (tape_fsf(1, FALSE) == -1) goto fin; - tape_close(); + if (tape_fsf(mtc, 1, FALSE) == -1) goto fin; + tape_close(mtc); if (tape_open(O_RDWR) == -1) goto fin; } status_box(mes, "Writing to second volume", 1, FALSE, 1); for (c=0; c<10; c++) { sprintf(m, "Volume#2 - block #%d", c); - if (tape_write(m, block_size) != block_size) goto fin; + if (tape_write(mtc, m, block_size) != block_size) goto fin; } - tape_close(); + tape_close(mtc); status_box(mes, "Testing seek on volume #1", 1, FALSE, 1); if (tape_open(O_RDWR) == -1) goto fin; if (log_level > 2) write_log("Reading block #3"); @@ -186,7 +186,7 @@ sprintf(m, "Tell returned block %qd", tl); if (log_level > 2) write_log(m); memset(m, 0, block_size); - if (tape_read(m, block_size) != block_size) goto fin; + if (tape_read(mtc, m, block_size) != block_size) goto fin; if (log_level > 2) { sprintf(s, "Read %100s", m); write_log(s); @@ -198,7 +198,7 @@ sprintf(m, "Tell returned block %qd", tl); if (log_level > 2) write_log(m); memset(m, 0, block_size); - if (tape_read(m, block_size) != block_size) goto fin; + if (tape_read(mtc, m, block_size) != block_size) goto fin; if (log_level > 2) { sprintf(s, "Read %100s", m); write_log(s); @@ -206,17 +206,17 @@ if (strcmp(m, "Volume#1 - block #7")) cant=1; status_box(mes, "Advancing to volume #2", 1, FALSE, 1); if (log_level > 2) write_log("Advancing to vol #2"); - tape_close(); + tape_close(mtc); if (ntape_open(O_RDWR) == -1) goto fin; if (have_fsf) { - if (tape_fsf(1, FALSE) == -1) goto fin; - tape_close(); + if (tape_fsf(mtc, 1, FALSE) == -1) goto fin; + tape_close(mtc); if (tape_open(O_RDWR) == -1) goto fin; } else { if (log_level > 2) write_log("fsf not supported - doing manually"); for (c=0; c<10; c++) - if (tape_read(m, block_size) != block_size) goto fin; + if (tape_read(mtc, m, block_size) != block_size) goto fin; blocks_passed = 0; /* on new volume */ } @@ -227,7 +227,7 @@ sprintf(m, "Tell returned block %qd", tl); if (log_level > 2) write_log(m); memset(m, 0, block_size); - if (tape_read(m, block_size) != block_size) goto fin; + if (tape_read(mtc, m, block_size) != block_size) goto fin; if (log_level > 2) { sprintf(s, "Read %100s", m); write_log(s); @@ -239,7 +239,7 @@ sprintf(m, "Tell returned block %qd", tl); if (log_level > 2) write_log(m); memset(m, 0, block_size); - if (tape_read(m, block_size) != block_size) goto fin; + if (tape_read(mtc, m, block_size) != block_size) goto fin; if (log_level > 2) { sprintf(s, "Read %100s", m); write_log(s); @@ -260,7 +260,7 @@ can_seek = old_cseek; touchwin(mes); status_box(mes, "Closing tape", 1, FALSE, 1); - tape_close(); + tape_close(mtc); final_message("Test can seek"); close_statusbox(mes); close_logfile("Test can seek"); @@ -269,7 +269,7 @@ -PUBLIC void utils_test_eot(void) +PUBLIC void utils_test_eot(const struct mtcrypt_context *mtc) { char *m=NULL; WINDOW *mes=NULL; @@ -289,7 +289,7 @@ if (log_level) write_log("Writing data"); while (1) /* fill tape with data */ if (rmtwrite(dv, m, block_size)