void zft_reset_position(zft_position *pos) { TRACE_FUN(ft_t_flow); pos->seg_byte_pos = pos->volume_pos = 0; if (zft_header_read) { /* need to keep track of the volume table and * compression map. We therefor simply * position at the beginning of the first * volume. This covers old ftape archives as * well has various flavours of the * compression map segments. The worst case is * that the compression map shows up as a * additional volume in front of all others. */ pos->seg_pos = zft_find_volume(0)->start_seg; pos->tape_pos = zft_calc_tape_pos(pos->seg_pos); } else { pos->tape_pos = 0; pos->seg_pos = -1; } zft_just_before_eof = 0; zft_deblock_segment = -1; zft_io_state = zft_idle; zft_zap_read_buffers(); zft_prevent_flush(); /* unlock the compresison module if it is loaded. * The zero arg means not to try to load the module. */ if (zft_cmpr_lock(0) == 0) { (*zft_cmpr_ops->reset)(); /* unlock */ } TRACE_EXIT; }
int zft_verify_write_segments(unsigned int segment, __u8 *data, size_t size, __u8 *buffer) { int result; __u8 *write_buf; __u8 *src_buf; int single; int seg_pos; int seg_sz; int remaining; ft_write_mode_t write_mode; TRACE_FUN(ft_t_flow); seg_pos = segment; seg_sz = zft_get_seg_sz(seg_pos); src_buf = data; single = size <= seg_sz; remaining = size; do { TRACE(ft_t_noise, "\n" KERN_INFO "remaining: %d\n" KERN_INFO "seg_sz : %d\n" KERN_INFO "segment : %d", remaining, seg_sz, seg_pos); if (remaining == seg_sz) { write_buf = src_buf; write_mode = single ? FT_WR_SINGLE : FT_WR_MULTI; remaining = 0; } else if (remaining > seg_sz) { write_buf = src_buf; write_mode = FT_WR_ASYNC; /* don't start tape */ remaining -= seg_sz; } else { /* remaining < seg_sz */ write_buf = buffer; memcpy(write_buf, src_buf, remaining); memset(&write_buf[remaining],'\0',seg_sz-remaining); write_mode = single ? FT_WR_SINGLE : FT_WR_MULTI; remaining = 0; } if ((result = ftape_write_segment(seg_pos, write_buf, write_mode)) != seg_sz) { TRACE(ft_t_err, "Error: " "Couldn't write segment %d", seg_pos); TRACE_EXIT result < 0 ? result : -EIO; /* bail out */ } zft_written_segments ++; seg_sz = zft_get_seg_sz(++seg_pos); src_buf += result; } while (remaining > 0); if (ftape_get_status()->fti_state == writing) { TRACE_CATCH(ftape_loop_until_writes_done(),); TRACE_CATCH(ftape_abort_operation(),); zft_prevent_flush(); }