/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <thread.h>
#include <synch.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include "device.h"
#include "bstream.h"
#include "trackio.h"
#include "util.h"
#include "mmc.h"
#include "transport.h"
#include "misc_scsi.h"
#include "main.h"
/*
* tio data
*/
static int tio_errno;
static int tio_got_ctrl_c;
/*
* Progress call back data.
*/
static void
fini_tio_data(void)
{
int i;
for (i = 0; i < NIOBS; i++) {
}
}
if (tio_synch_initialized == 1) {
(void) mutex_destroy(&tio_mutex);
(void) cond_destroy(&tio_cond);
}
}
static void
{
int i;
for (i = 0; i < NIOBS; i++) {
}
tio_got_ctrl_c = 0;
}
static void
init_pcb_data(void)
{
pcb_user_abort = pcb_done = 0;
}
static void
fini_pcb_data(void)
{
if (pcb_synch_initialized == 1) {
(void) mutex_destroy(&pcb_mutex);
(void) cond_destroy(&pcb_cond);
}
pcb_user_abort = pcb_done = 0;
}
/* ARGSUSED */
static void *
{
int i;
i = 0;
#ifndef lint
while (1) {
#endif
(void) mutex_lock(&tio_mutex);
(tio_abort == 0)) {
/* Wait for buffer to become ready */
}
if (tio_abort == 1) {
/* Do a flush cache before aborting */
(void) flush_cache(tio_fd);
(void) mutex_unlock(&tio_mutex);
thr_exit((void *)1);
}
/* If no more data, then close the track */
if (tio_iobs[i].iob_data_size == 0) {
/* Some drives misbehave if flush_cache is not done */
(void) flush_cache(tio_fd);
if (write_mode == TAO_MODE) {
/* Its important to try hard to close track */
if (simulation)
retry = 5;
/* OK to hold mutex when close_track */
if (close_track(tio_fd,
tio_trackno, 0, 0))
break;
(void) sleep(1);
}
}
/* Some drives don't allow close track in test write */
if ((retry == 0) && (simulation == 0)) {
if (errno)
else
tio_errno = -1;
}
tio_done = 1;
(void) cond_broadcast(&tio_cond);
(void) mutex_unlock(&tio_mutex);
thr_exit((void *)0);
}
(void) mutex_unlock(&tio_mutex);
tio_iobs[i].iob_data_size)) {
(void) mutex_lock(&tio_mutex);
if (err)
else
tio_errno = -1;
(void) cond_broadcast(&tio_cond);
(void) mutex_unlock(&tio_mutex);
thr_exit((void *)2);
}
(void) mutex_lock(&tio_mutex);
(void) cond_broadcast(&tio_cond);
(void) mutex_unlock(&tio_mutex);
i++;
if (i == NIOBS)
i = 0;
#ifndef lint
}
#endif
return (NULL);
}
/* ARGSUSED */
static void *
{
int ret;
(void) mutex_lock(&pcb_mutex);
if (!pcb_done) {
}
if (pcb_done) {
(void) mutex_unlock(&pcb_mutex);
if (tio_got_ctrl_c) {
}
thr_exit((void *)0);
}
(void) mutex_unlock(&pcb_mutex);
if (ret != 0) {
(void) mutex_lock(&pcb_mutex);
(void) mutex_unlock(&pcb_mutex);
thr_exit((void *)0);
}
#ifdef lint
return (NULL);
#else
goto pc_again;
#endif
}
/* ARGSUSED */
static void
trackio_sig_handler(int i)
{
/* Dont need mutex as it is only modified here */
tio_got_ctrl_c = 1;
}
int
{
int write_cd_thr_created;
int retval;
void (*ohandler)(int);
signal_handler_installed = retval = 0;
else
/* Initialize buffers */
/* Fill in all buffers before starting */
/*
* Start filling initial buffer to ensure that there is plenty of
* data when writing begins.
*/
for (i = 0; i < NIOBS; i++) {
tio_iobs[i].iob_total_size);
/*
* We need to read the source file into the buffer and make
* sure that the data in the buffer is a multiple of the
* blocksize (data or audio blocksize). iob_total_size is a
* multiple of the blocksize so this case should only be
* encountered at EOF or from piped input.
*/
int ret;
/*
* rem contains the amount of data past the previous
* block boundry. we need to subtract it from the
* blocksize to get the amount needed to reach the
* next block boundry.
*/
tio_iobs[i].iob_total_size) {
/*
* This should not occur, but we are trying to
* write past the end of the buffer. return
* with an error.
*/
sz_read = -1;
break;
}
/*
* Try to continue reading in case the data is being
* piped in.
*/
if (ret < 0) {
break;
}
/*
* No more data. We need to make sure that we are
* aligned with the blocksize. so pad the rest of
* the buffer with 0s
*/
if (ret == 0) {
0, ret);
}
}
if (sz_read < 0) {
/* reading the source failed, clean up and return */
goto write_track_failed;
}
if (sz_read == 0)
break;
}
/* Install signal handler for CTRL-C */
if (ohandler) {
}
/* Create thread which will issue commands to write to device */
goto write_track_failed;
}
write_cd_thr_created = 1;
/* If caller specified a callback, create a thread to do callbacks */
goto write_track_failed;
}
}
i = 0;
while (sz_read != 0) {
(void) mutex_lock(&tio_mutex);
(tio_errno == 0) && (pcb_user_abort == 0)) {
/* Do callbacks only if there is nothing else to do */
(void) mutex_lock(&pcb_mutex);
(void) cond_broadcast(&pcb_cond);
(void) mutex_unlock(&pcb_mutex);
}
/* If user requested abort, bail out */
if (pcb_user_abort || tio_got_ctrl_c) {
break;
}
}
if (pcb_user_abort || tio_got_ctrl_c) {
(void) mutex_unlock(&tio_mutex);
goto write_track_failed;
}
/*
* We've got a transport error, stop writing, save all
* of the error information and clean up the threads.
*/
if (tio_errno != 0) {
(void) mutex_unlock(&tio_mutex);
if (uscsi_status == 2) {
}
goto write_track_failed;
}
(void) mutex_unlock(&tio_mutex);
tio_iobs[i].iob_total_size);
/*
* We need to read the source file into the buffer and make
* sure that the data in the buffer is a multiple of the
* blocksize (data or audio blocksize). this case should only
* be encountered at EOF or from piped input.
*/
int ret;
/*
* This should not occur, we are trying to write
* past the end of the buffer, return error.
*/
tio_iobs[i].iob_total_size) {
sz_read = -1;
break;
}
/*
* Try to continue reading in case the data is being
* piped in.
*/
if (ret < 0) {
break;
}
/*
* No more data. We need to make sure that we are
* aligned with the blocksize. so pad the rest of
* the buffer with 0s
*/
if (ret == 0) {
/*
* rem contains the amount of data past the
* previous block boundry. we need to subtract
* it from the blocksize to get the amount
* needed to reach the next block boundry.
*/
0, ret);
}
}
if (sz_read < 0) {
goto write_track_failed;
}
(void) mutex_lock(&tio_mutex);
(void) cond_broadcast(&tio_cond);
(void) mutex_unlock(&tio_mutex);
i++;
if (i == NIOBS)
i = 0;
}
(void) mutex_lock(&tio_mutex);
/* Wait for track IO to complete */
if (tio_errno != 0) {
if (uscsi_status == 2) {
}
(void) mutex_unlock(&tio_mutex);
goto write_track_failed;
}
(void) mutex_lock(&pcb_mutex);
(void) cond_broadcast(&pcb_cond);
(void) mutex_unlock(&pcb_mutex);
i++;
if (i == NIOBS)
i = 0;
}
}
}
(void) mutex_unlock(&tio_mutex);
retval = 1;
(void) mutex_lock(&pcb_mutex);
pcb_done = 1;
(void) cond_broadcast(&pcb_cond);
(void) mutex_unlock(&pcb_mutex);
}
}
if (write_cd_thr_created) {
if (thr_kill(tio_thread, 0) == 0) {
(void) mutex_lock(&tio_mutex);
tio_abort = 1;
(void) cond_broadcast(&tio_cond);
(void) mutex_unlock(&tio_mutex);
}
}
if (signal_handler_installed) {
}
return (retval);
}