/* * Initialize device for track-at-once mode of writing. All of the data will * need to be written to the track without interruption. * This initialized TAO by setting page code 5 and speed. */ void write_init(int mode) { (void) printf(gettext("Initializing device")); if (simulation) (void) printf(gettext("(Simulation mode)")); print_n_flush("..."); get_media_type(target->d_fd); /* DVD- requires DAO mode */ if (device_type == DVD_MINUS) { write_mode = DAO_MODE; } /* DVD+ and DVD- have no support for AUDIO, bail out */ if ((mode == TRACK_MODE_AUDIO) && (device_type != CD_RW)) { err_msg(gettext("Audio mode is only supported for CD media\n")); exit(1); } if (simulation && check_device(target, CHECK_MEDIA_IS_NOT_BLANK) && !check_device(target, CHECK_MEDIA_IS_NOT_ERASABLE) && device_type != DVD_PLUS_W) { /* * If we were in simulation mode, and media wasn't blank, * but medium was erasable, then cdrw goes to erase the * contents of the media after the simulation writing in order * to cleanup the ghost TOC (see write_fini() calls blank()). * This is bad because it removes existing data if media was * multi-session. Therefore, we no longer allow simulation * writing if such condition is met. we don't blank the DVD+RW * media, so DVD+RWs are fine. */ err_msg(gettext( "Cannot perform simulation for non-blank media\n")); exit(1); } if (!prepare_for_write(target, mode, simulation, keep_disc_open)) { /* l10n_NOTE : 'failed' as in Initializing device...failed */ (void) printf(gettext("failed.\n")); err_msg(gettext("Cannot initialize device for write\n")); exit(1); } /* l10n_NOTE : 'done' as in "Initializing device...done" */ (void) printf(gettext("done.\n")); /* if speed change option was used (-p) then try to set the speed */ if (requested_speed != 0) { if (verbose) (void) printf(gettext("Trying to set speed to %dX.\n"), requested_speed); if (target->d_speed_ctrl(target, SET_WRITE_SPEED, requested_speed) == 0) { err_msg(gettext("Unable to set speed.\n")); exit(1); } if (verbose) { int speed; speed = target->d_speed_ctrl(target, GET_WRITE_SPEED, 0); if (speed == requested_speed) { (void) printf(gettext("Speed set to %dX.\n"), speed); } else if (speed == 0) { (void) printf(gettext("Could not obtain " "current Write Speed.\n")); } else { (void) printf( gettext("Speed set to closest approximation " "of %dX allowed by device (%dX).\n"), requested_speed, speed); } } } }
static int process_data(server *srv, connection *con, plugin_data *p, buffer *filename, chunkqueue *cq, off_t range_start) { int err; size_t len; //off_t *abs_off; vhd_state_t *state; vhd_context_t *vhd; err = 0; state = &p->state; vhd = &state->vhd; //abs_off = range_start + con->range_offset; //abs_off = state->abs_off; DEBUGLOG("so", "Absolute Offset", state->abs_off); DEBUGLOG("sd", "Current Virtual Block = ", state->curr_virt_blk); if (state->curr_virt_blk != -1) { DEBUGLOG("s", "Process Block"); err = process_block(srv, cq, state, &(state->abs_off)); goto done; } if (state->abs_off < 0 + sizeof(vhd_footer_t)) { err = get_footer(srv, cq, state, &(state->abs_off)); goto done; } if (((off_t)state->abs_off) < vhd->footer.data_offset + sizeof(vhd_header_t)) { err = get_header(srv, cq, state, &(state->abs_off)); goto done; } if (((off_t)state->abs_off) < vhd->header.table_offset + state->bat_buf_size) { err = get_bat(srv, cq, state, &(state->abs_off)); if (err) goto done; if (state->vhd_ready) err = prepare_for_write(srv, state, filename, state->abs_off); goto done; } if (state->blocks_written < state->blocks_allocated) { LOG("sdd", "BUG!", state->blocks_written, state->blocks_allocated); err = -EINVAL; goto done; } // TODO: we could actually validate the primary footer at the end len = chunkqueue_avail(cq); DEBUGLOG("sd", "Discarding the remainder", len); discard_bytes(srv, cq, len); state->abs_off += len; if (state->zero_unalloc) { err = zero_unallocated(srv, state); state->zero_unalloc = 0; } done: con->range_offset = state->abs_off - range_start; return err; }