version 1.14, 2006/06/27 02:43:18 |
version 1.15, 2006/08/26 03:48:50 |
|
|
int |
int |
writetao(struct track_head *thp) |
writetao(struct track_head *thp) |
{ |
{ |
u_char modebuf[70]; |
u_char modebuf[70], bdlen; |
struct track_info *tr; |
struct track_info *tr; |
u_char bdlen; |
int r, track = 0; |
int r; |
|
|
|
if ((r = mode_sense_write(modebuf)) != SCCMD_OK) { |
if ((r = mode_sense_write(modebuf)) != SCCMD_OK) { |
warnx("mode sense failed: %d", r); |
warnx("mode sense failed: %d", r); |
|
|
modebuf[2+8+bdlen] |= 0x01; /* change write type to TAO */ |
modebuf[2+8+bdlen] |= 0x01; /* change write type to TAO */ |
|
|
SLIST_FOREACH(tr, thp, track_list) { |
SLIST_FOREACH(tr, thp, track_list) { |
|
track++; |
switch (tr->type) { |
switch (tr->type) { |
case 'd': |
case 'd': |
modebuf[3+8+bdlen] = 0x04; /* track mode = data */ |
modebuf[3+8+bdlen] = 0x04; /* track mode = data */ |
|
|
while (unit_ready() != SCCMD_OK) |
while (unit_ready() != SCCMD_OK) |
continue; |
continue; |
if ((r = mode_select_write(modebuf)) != SCCMD_OK) { |
if ((r = mode_select_write(modebuf)) != SCCMD_OK) { |
warnx("mode select failed: %d",r); |
warnx("mode select failed: %d", r); |
return (r); |
return (r); |
} |
} |
writetrack(tr); |
writetrack(tr, track); |
synchronize_cache(); |
synchronize_cache(); |
} |
} |
fprintf(stderr,"Closing session.\n"); |
fprintf(stderr, "Closing session.\n"); |
close_session(); |
close_session(); |
return (0); |
return (0); |
} |
} |
|
|
int |
int |
writetrack(struct track_info *tr) |
writetrack(struct track_info *tr, int track) |
{ |
{ |
u_char databuf[65536]; |
struct timeval tv, otv, atv; |
|
u_char databuf[65536], nblk; |
|
u_int end_lba, lba, tmp; |
scsireq_t scr; |
scsireq_t scr; |
u_int end_lba, lba; |
|
u_int tmp; |
|
int r; |
int r; |
u_char nblk; |
|
|
|
nblk = 65535/tr->blklen; |
nblk = 65535/tr->blklen; |
bzero(&scr, sizeof(scr)); |
bzero(&scr, sizeof(scr)); |
|
|
scr.senselen = SENSEBUFLEN; |
scr.senselen = SENSEBUFLEN; |
scr.flags = SCCMD_ESCAPE|SCCMD_WRITE; |
scr.flags = SCCMD_ESCAPE|SCCMD_WRITE; |
|
|
|
timerclear(&otv); |
|
atv.tv_sec = 1; |
|
atv.tv_usec = 0; |
|
|
if (get_nwa(&lba) != SCCMD_OK) { |
if (get_nwa(&lba) != SCCMD_OK) { |
warnx("cannot get next writable address"); |
warnx("cannot get next writable address"); |
return (-1); |
return (-1); |
|
|
memcpy(&scr.cmd[2], &tmp, sizeof(tmp)); |
memcpy(&scr.cmd[2], &tmp, sizeof(tmp)); |
|
|
if (tr->sz / tr->blklen + 1 > UINT_MAX || tr->sz < tr->blklen) { |
if (tr->sz / tr->blklen + 1 > UINT_MAX || tr->sz < tr->blklen) { |
warnx("file %s has invalid size",tr->file); |
warnx("file %s has invalid size", tr->file); |
return (-1); |
return (-1); |
} |
} |
if (tr->sz % tr->blklen) { |
if (tr->sz % tr->blklen) { |
|
|
again: |
again: |
r = ioctl(fd, SCIOCCOMMAND, &scr); |
r = ioctl(fd, SCIOCCOMMAND, &scr); |
if (r != 0) { |
if (r != 0) { |
printf("\r"); |
printf("%60s\r", ""); |
warn("ioctl failed while attempting to write"); |
warn("ioctl failed while attempting to write"); |
return (-1); |
return (-1); |
} |
} |
|
|
goto again; |
goto again; |
} |
} |
if (scr.retsts != SCCMD_OK) { |
if (scr.retsts != SCCMD_OK) { |
printf("\r"); |
printf("%60s\r", ""); |
warnx("ioctl returned bad status while " |
warnx("ioctl returned bad status while " |
"attempting to write: %d", |
"attempting to write: %d", |
scr.retsts); |
scr.retsts); |
return (r); |
return (r); |
} |
} |
lba += nblk; |
lba += nblk; |
fprintf(stderr,"\rLBA: %08u/%08u", |
|
lba, end_lba); |
gettimeofday(&tv, NULL); |
|
if (lba == end_lba || timercmp(&tv, &otv, >)) { |
|
fprintf(stderr, |
|
"track %02d '%c' %08u/%08u %3d%%\r", |
|
track, tr->type, |
|
lba, end_lba, 100 * lba / end_lba); |
|
timeradd(&tv, &atv, &otv); |
|
} |
tmp = htobe32(lba); /* update lba in cdb */ |
tmp = htobe32(lba); /* update lba in cdb */ |
memcpy(&scr.cmd[2], &tmp, sizeof(tmp)); |
memcpy(&scr.cmd[2], &tmp, sizeof(tmp)); |
} |
} |
|
|
u_char databuf[28]; |
u_char databuf[28]; |
struct scsi_read_track_info *scb; |
struct scsi_read_track_info *scb; |
scsireq_t scr; |
scsireq_t scr; |
int r,tmp; |
int r, tmp; |
|
|
bzero(&scr, sizeof(scr)); |
bzero(&scr, sizeof(scr)); |
scb = (struct scsi_read_track_info *)scr.cmd; |
scb = (struct scsi_read_track_info *)scr.cmd; |
|
|
{ |
{ |
u_char databuf[28]; |
u_char databuf[28]; |
scsireq_t scr; |
scsireq_t scr; |
int r,tmp; |
int r, tmp; |
|
|
bzero(&scr, sizeof(scr)); |
bzero(&scr, sizeof(scr)); |
scr.timeout = 4000; |
scr.timeout = 4000; |