static void callback_common(unsigned num,rgba *pixels) { if( flatspec.transmap_filename ) { if( flatspec.partial_transparency_mode == ALLOW_PARTIAL_TRANSPARENCY ) { unsigned i ; if( transfile == NULL ) start_writing(&transfile,5); for( i=0; i < num; i++ ) putc( ALPHA(pixels[i]), transfile ); } else { if( transfile == NULL ) { start_writing(&transfile,4); } /* Partial transparency should have been caught in the flattener, * so just extract a single byte. */ put_pbm_row(transfile,num,pixels,(rgba)1 << ALPHA_SHIFT); } } else if( ALPHA(flatspec.default_pixel) < 128 ) { unsigned i ; for( i=0; i < num; i++ ) if( !FULLALPHA(pixels[i]) ) FatalGeneric(100,_("Transparency found, but -a option not given")); } xcffree(pixels) ; }
static void read_completed(BOOL resultOk, DWORD length, SocketState* socketState, WSAOVERLAPPED* ovl) { if (resultOk) { if (length > 0) { printf("* read operation completed, %d bytes read\n", length); // starts another write socketState->length = length; start_writing(socketState, ovl); } else // length == 0 { printf("* connection closed by client\n"); destroy_connection(socketState, ovl); } } else // !resultOk, assumes connection was reset { int err = GetLastError(); printf("* error %d in recv, assuming connection was reset by client\n", err); destroy_connection(socketState, ovl); } }
int update_header_segment(unsigned segment, byte * buffer) { TRACE_FUN(5, "update_header_segment"); int result = 0; int status; if (buffer == NULL) { TRACE(5, "no input buffer specified"); buffer = deblock_buffer; result = read_segment(used_header_segment, buffer, &status, 0); if (bad_sector_map_changed) { store_bad_sector_map(buffer); } if (failed_sector_log_changed) { update_failed_sector_log(buffer); } } if (result >= 0 && GET4(buffer, 0) != 0xaa55aa55) { TRACE(1, "wrong header signature found, aborting"); result = -EIO; } if (result >= 0) { result = _write_segment(segment, buffer, 0); if (result >= 0 && runner_status == idle) { /* Force flush for single segment instead of relying on * flush in read_segment for multiple segments. */ result = start_writing(WRITE_SINGLE); if (result >= 0 && ftape_state == writing) { result = loop_until_writes_done(); prevent_flush(); } } #ifdef VERIFY_HEADERS if (result >= 0) { /* read back and verify */ result = read_segment(segment, scratch_buffer, &status, 0); /* Should retry if soft error during read ! * TO BE IMPLEMENTED */ if (result >= 0) { if (memcmp(buffer, scratch_buffer, sizeof(buffer)) == 0) { result = 0; /* verified */ TRACE(5, "verified"); } else { result = -EIO; /* verify failed */ TRACE(5, "verify failed"); } } } #endif } TRACE_EXIT; return result; }
static void pbm_callback(unsigned num,rgba *pixels) { if( outfile == NULL ) start_writing(&outfile,4); if( !put_pbm_row(outfile,num,pixels, ((rgba)255 << RED_SHIFT) + ((rgba)255 << GREEN_SHIFT) + ((rgba)255 << BLUE_SHIFT)) ) FatalGeneric(103,_("Monochrome output selected, but not all pixels " "are black or white")); callback_common(num,pixels); }
static void ppm_callback(unsigned num,rgba *pixels) { unsigned i ; if( outfile == NULL ) start_writing(&outfile,6); for( i=0; i < num; i++ ) { putc( (pixels[i] >> RED_SHIFT) & 0xFF , outfile ); putc( (pixels[i] >> GREEN_SHIFT) & 0xFF , outfile ); putc( (pixels[i] >> BLUE_SHIFT) & 0xFF , outfile ); } callback_common(num,pixels); }
int loop_until_writes_done(void) { TRACE_FUN(5, "loop_until_writes_done"); int i; int result = 0; /* * Wait until all data is actually written to tape. */ while (ftape_state == writing && buffer[head].status != done) { TRACEx2(7, "tail: %d, head: %d", tail, head); for (i = 0; i < NR_BUFFERS; ++i) { TRACEx3(8, "buffer[ %d] segment_id: %d, status: %d", i, buffer[i].segment_id, buffer[i].status); } result = fdc_interrupt_wait(5 * SECOND); if (result < 0) { TRACE(1, "fdc_interrupt_wait failed"); last_write_failed = 1; break; } if (buffer[head].status == error) { /* Allow escape from loop when signaled ! */ if (current->signal & _DONT_BLOCK) { TRACE(2, "interrupted by signal"); TRACE_EXIT; result = -EINTR; /* is this the right return value ? */ break; } if (buffer[head].hard_error_map != 0) { /* Implement hard write error recovery here */ } buffer[head].status = waiting; /* retry this one */ if (runner_status == aborting) { ftape_dumb_stop(); runner_status = idle; } if (runner_status != idle) { TRACE(1, "unexpected state: runner_status != idle"); result = -EIO; break; } start_writing(WRITE_MULTI); } TRACE(5, "looping until writes done"); result = 0; /* normal exit status */ } TRACE_EXIT; return result; }
static void pgm_callback(unsigned num,rgba *pixels) { unsigned i ; if( outfile == NULL ) start_writing(&outfile,5); for( i=0; i < num; i++ ) { int gray = degrayPixel(pixels[i]) ; if( gray == -1 ) FatalGeneric(103, _("Grayscale output selected, but colored pixel(s) found")); putc( gray, outfile ); } callback_common(num,pixels); }
int ftape_flush_buffers(void) { TRACE_FUN(5, "ftape_flush_buffers"); int result; int pad_count; int data_remaining; static int active = 0; if (active) { TRACE(5, "nested call, abort"); TRACE_EXIT; return 0; } active = 1; TRACEi(5, "entered, ftape_state =", ftape_state); if (ftape_state != writing && !need_flush) { active = 0; TRACE(5, "no need for flush"); TRACE_EXIT; return 0; } data_remaining = buf_pos_wr; buf_pos_wr = 0; /* prevent further writes if this fails */ TRACE(5, "flushing write buffers"); if (last_write_failed) { ftape_zap_write_buffers(); active = 0; TRACE_EXIT; return write_protected ? -EROFS : -EIO; } /* * If there is any data not written to tape yet, append zero's * up to the end of the sector. Then write the segment(s) to tape. */ if (data_remaining > 0) { int written; do { TRACEi(4, "remaining in buffer:", data_remaining); pad_count = sizeof(deblock_buffer) - data_remaining; TRACEi(7, "flush, padding count:", pad_count); memset(deblock_buffer + data_remaining, 0, pad_count); /* pad buffer */ result = _write_segment(ftape_seg_pos, deblock_buffer, 1); if (result < 0) { if (result != -ENOSPC) { last_write_failed = 1; } active = 0; TRACE_EXIT; return result; } written = result; clear_eof_mark_if_set(ftape_seg_pos, written); TRACEi(7, "flush, moved out buffer:", written); if (written > 0) { data_remaining -= written; if (data_remaining > 0) { /* Need another segment for remaining data, move the remainder * to the beginning of the buffer */ memmove(deblock_buffer, deblock_buffer + written, data_remaining); } } ++ftape_seg_pos; } while (data_remaining > 0); /* Data written to last segment == data_remaining + written * value is in range [1..29K]. */ TRACEx2(4, "last write: %d, netto pad-count: %d", data_remaining + written, -data_remaining); if (-1024 < data_remaining && data_remaining <= 0) { /* Last sector of segment was used for data, so put eof mark * in next segment and position at second file mark. */ if (ftape_weof(2, ftape_seg_pos, 1) >= 0) { ++ftape_seg_pos; /* position between file marks */ } } else { /* Put eof mark in previous segment after data and position * at second file mark. */ ftape_weof(2, ftape_seg_pos - 1, 1 + ((SECTOR_SIZE - 1 + result + data_remaining) / SECTOR_SIZE)); } } else { TRACE(7, "deblock_buffer empty"); if (ftape_weof(2, ftape_seg_pos, 1) >= 0) { ++ftape_seg_pos; /* position between file marks */ } start_writing(WRITE_MULTI); } TRACE(7, "waiting"); result = loop_until_writes_done(); if (result < 0) { TRACE(1, "flush buffers failed"); } ftape_state = idle; last_write_failed = 0; need_flush = 0; active = 0; TRACE_EXIT; return result; }
/* Write given segment from buffer at address onto tape. */ int write_segment(unsigned segment_id, byte * address, int flushing) { TRACE_FUN(5, "write_segment"); int result = 0; int bytes_written = 0; TRACEi(5, "segment_id =", segment_id); if (ftape_state != writing) { if (ftape_state == reading) { TRACE(5, "calling ftape_abort_operation"); result = ftape_abort_operation(); if (result < 0) { TRACE(1, "ftape_abort_operation failed"); } } ftape_zap_read_buffers(); ftape_zap_write_buffers(); ftape_state = writing; } /* if all buffers full we'll have to wait... */ wait_segment(writing); if (buffer[tail].status == error) { /* setup for a retry */ buffer[tail].status = waiting; bytes_written = -EAGAIN; /* force retry */ if (buffer[tail].hard_error_map != 0) { TRACEx1(1, "warning: %d hard error(s) in written segment", count_ones(buffer[tail].hard_error_map)); TRACEx1(4, "hard_error_map = 0x%08lx", buffer[tail].hard_error_map); /* Implement hard write error recovery here */ } } else if (buffer[tail].status == done) { history.defects += count_ones(buffer[tail].hard_error_map); } else { TRACE(1, "wait for empty segment failed"); result = -EIO; } /* If just passed last segment on tape: wait for BOT or EOT mark. */ if (result >= 0 && runner_status == logical_eot) { int status; result = ftape_ready_wait(timeout.seek, &status); if (result < 0 || (status & (QIC_STATUS_AT_BOT | QIC_STATUS_AT_EOT)) == 0) { TRACE(1, "eot/bot not reached"); } else { runner_status = end_of_tape; } } /* should runner stop ? */ if (result >= 0 && (runner_status == aborting || runner_status == buffer_underrun || runner_status == end_of_tape)) { if (runner_status != end_of_tape) { result = ftape_dumb_stop(); } if (result >= 0) { if (runner_status == aborting) { if (buffer[head].status == writing) { buffer[head].status = done; /* ????? */ } } runner_status = idle; /* aborted ? */ } } /* Don't start tape if runner idle and segment empty. */ if (result >= 0 && !(runner_status == idle && get_bad_sector_entry(segment_id) == EMPTY_SEGMENT)) { if (buffer[tail].status == done) { /* now at least one buffer is empty, fill it with our data. * skip bad sectors and generate ecc. * copy_and_gen_ecc return nr of bytes written, * range 0..29 Kb inclusive ! */ result = copy_and_gen_ecc(buffer[tail].address, address, get_bad_sector_entry(segment_id)); if (result >= 0) { bytes_written = result; buffer[tail].segment_id = segment_id; buffer[tail].status = waiting; next_buffer(&tail); } } /* Start tape only if all buffers full or flush mode. * This will give higher probability of streaming. */ if (result >= 0 && runner_status != running && ((head == tail && buffer[tail].status == waiting) || flushing)) { result = start_writing(WRITE_MULTI); } } TRACE_EXIT; return (result < 0) ? result : bytes_written; }