*** Makefile.ORIG Mon Nov 20 19:56:38 1995 --- Makefile Mon Nov 25 08:42:47 1996 *************** *** 1,13 **** PROGS= cdwrite isosize ! LINUX= /usr/src/linux ! CFLAGS= -Wall -O2 -fomit-frame-pointer -ansi -pedantic -I $(LINUX)/include -I $(LINUX)/drivers LDFLAGS= -s ! BINDIR= /usr/bin all: $(PROGS) install: $(PROGS) ! install $(PROGS) $(BINDIR) clean: -rm -f $(PROGS) *.o *~ --- 1,52 ---- PROGS= cdwrite isosize ! LINTFLAGS= -m -x ! LDLIBS= -lds ! CFLAGS= -O -DUSE_DSLIB -DUSE_AIO -DDEFAULT_DEV=\"/dev/scsi/sc1d3l0\" LDFLAGS= -s ! BINDIR= /usr/local/bin ! MANDIR= /usr/local/man ! MANSECT= 1 all: $(PROGS) install: $(PROGS) ! install -m 4755 -f $(BINDIR) $(PROGS) ! install -m 644 -f $(MANDIR)/man$(MANSECT) cdwrite.$(MANSECT) clean: -rm -f $(PROGS) *.o *~ + + lint: + lint $(LINTFLAGS) $(CFLAGS) cdwrite.c $(LDLIBS) + lint $(LINTFLAGS) $(CFLAGS) isosize.c $(LDLIBS) + + depend: + makedepend -- $(CFLAGS) -- *.c + + # DO NOT DELETE THIS LINE -- make depend depends on it. + + cdwrite.o: cdwrite.c /usr/include/stdio.h /usr/include/stdlib.h + cdwrite.o: /usr/include/sgidefs.h /usr/include/getopt.h /usr/include/stdarg.h + cdwrite.o: /usr/include/fcntl.h /usr/include/sys/types.h + cdwrite.o: /usr/include/sys/bsd_types.h /usr/include/sys/select.h + cdwrite.o: /usr/include/sys/fcntl.h /usr/include/errno.h + cdwrite.o: /usr/include/sys/errno.h /usr/include/sys/file.h + cdwrite.o: /usr/include/sys/time.h /usr/include/time.h + cdwrite.o: /usr/include/sys/resource.h /usr/include/sys/stat.h + cdwrite.o: /usr/include/sys/ioctl.h /usr/include/sys/ioccom.h + cdwrite.o: /usr/include/net/soioctl.h /usr/include/sys/termio.h + cdwrite.o: /usr/include/sys/termios.h /usr/include/sys/ttydev.h + cdwrite.o: /usr/include/unistd.h /usr/include/sys/unistd.h + cdwrite.o: /usr/include/utime.h /usr/include/sys/utime.h + cdwrite.o: /usr/include/limits.h /usr/include/dslib.h + cdwrite.o: /usr/include/sys/dsreq.h /usr/include/signal.h + cdwrite.o: /usr/include/sys/signal.h /usr/include/sys/siginfo.h + cdwrite.o: /usr/include/sys/procset.h /usr/include/sys/prctl.h + cdwrite.o: /usr/include/stddef.h /usr/include/sys/wait.h + cdwrite.o: /usr/include/string.h + isosize.o: isosize.c /usr/include/stdio.h /usr/include/termio.h + isosize.o: /usr/include/sys/termio.h /usr/include/sys/termios.h + isosize.o: /usr/include/sys/ttydev.h /usr/include/sys/types.h + isosize.o: /usr/include/sgidefs.h /usr/include/signal.h + isosize.o: /usr/include/sys/signal.h /usr/include/sys/siginfo.h + isosize.o: /usr/include/unistd.h /usr/include/sys/unistd.h *** cdwrite.c.ORIG Mon Nov 20 19:58:51 1995 --- cdwrite.c Sun Nov 24 10:44:33 1996 *************** *** 19,27 **** --- 19,34 ---- version 1.5: added multitrack and audio capabilities; further buffering improvements; SCSI generic handling improved. version 2.0: Yamaha and HP support added, command line changes. + version 2.1: Unofficial hack by forrest@lidar.ssec.wisc.edu + added support for SGI Irix 5.3 (-DUSE_DSLIB) + added support for IBM AIX 4.1.4 (-D_AIX) */ + #if defined(USE_DSLIB) || defined(_AIX) + const char *version = "2.1"; + #else /* defined(USE_DSLIB) || defined(_AIX) */ const char *version = "2.0"; + #endif /* defined(USE_DSLIB) || defined(_AIX) */ #ifndef DEFAULT_DEV #define DEFAULT_DEV "/dev/cdwriter" #endif *************** *** 42,47 **** --- 49,68 ---- #include #include + #ifdef _AIX + #include + #ifdef USE_AIO + #include + #endif /* def USE_AIO */ + #else /* def _AIX */ + #ifdef USE_DSLIB + #include + #include + #ifdef USE_AIO + #include + #include + #endif /* def USE_AIO */ + #else /* def USE_DSLIB */ #include #ifndef LINUX_VERSION_CODE /* Very old kernel? */ #define LINUX_VERSION_CODE 0 *************** *** 56,61 **** --- 77,84 ---- #include "scsi/scsi.h" #endif #include "scsi/sg.h" + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ #include *************** *** 66,71 **** --- 89,95 ---- #define STDOUT 1 #define STDERR 2 + #ifndef _AIX enum writer_t { type_unknown, /* Unknown type */ type_philips, /* Philips/IMS/Kodak */ *************** *** 80,85 **** --- 104,110 ---- "Yamaha", "HP" }; + #endif /* ndef _AIX */ struct track_info_t { *************** *** 90,110 **** --- 115,151 ---- int pad; /* Pad data track */ }; + #if !defined(USE_DSLIB) && !defined(_AIX) int pack_id = 5; + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ int verbose = 0; char *program; + #if !defined(USE_DSLIB) && !defined(_AIX) #define FUDGE 10 /* Number of bytes to reserve for request structure itself */ #define HDRSPC (sizeof(struct sg_header)+FUDGE) + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ #define DATA_CD_BLOCK_SIZE 2048 + #if defined(USE_DSLIB) || defined(_AIX) + #ifdef _AIX + #define DATA_BLOCKS_PER_WRITE (PIPE_BUF * 2 / DATA_CD_BLOCK_SIZE) + #else /* def _AIX */ + #define DATA_BLOCKS_PER_WRITE 32 + #endif /* def _AIX */ + #else /* defined(USE_DSLIB) || defined(_AIX) */ #define DATA_BLOCKS_PER_WRITE ((SG_BIG_BUFF-HDRSPC)/DATA_CD_BLOCK_SIZE) + #endif /* defined(USE_DSLIB) || defined(_AIX) */ #define DATA_WRITE_BLOCK_SIZE (DATA_CD_BLOCK_SIZE * DATA_BLOCKS_PER_WRITE) #define AUDIO_CD_BLOCK_SIZE 2352 + #if defined(USE_DSLIB) || defined(_AIX) + #define AUDIO_BLOCKS_PER_WRITE 32 + #else /* defined(USE_DSLIB) || defined(_AIX) */ #define AUDIO_BLOCKS_PER_WRITE ((SG_BIG_BUFF-HDRSPC)/AUDIO_CD_BLOCK_SIZE) + #endif /* defined(USE_DSLIB) || defined(_AIX) */ #define AUDIO_WRITE_BLOCK_SIZE (AUDIO_CD_BLOCK_SIZE * AUDIO_BLOCKS_PER_WRITE) #define WRITE_BLOCK_SIZE max(AUDIO_WRITE_BLOCK_SIZE,DATA_WRITE_BLOCK_SIZE) *************** *** 114,119 **** --- 155,162 ---- #define PAD_SIZE 15 /* Number of sectors for the -pad option Must be <= DATA_BLOCKS_PER_WRITE */ + #ifndef _AIX + #ifndef USE_DSLIB struct sg_request { struct sg_header header; unsigned char bytes[WRITE_BLOCK_SIZE+FUDGE]; *************** *** 123,128 **** --- 166,172 ---- struct sg_header header; unsigned char bytes[100]; }; + #endif /* ndef USE_DSLIB */ #define RESERVE_TRACK 0xE4 #define WRITE_TRACK 0xE6 *************** *** 130,143 **** --- 174,201 ---- #define MEDIUM_UNLOAD 0xE7 /* Yamaha */ #define FIXATION 0xE9 /* Write table of contents */ #define RECOVER 0xEC + #endif /* ndef _AIX */ /* Forward declarations */ int + #ifdef _AIX quiet_request_sense (int fd, int iteration, char *note, + struct cdr100_req_sense *rep); + #else /* def _AIX */ + #ifdef USE_DSLIB + quiet_request_sense (struct dsreq *dsp, int iteration, char *note); + #else /* def USE_DSLIB */ + quiet_request_sense (int fd, int iteration, char *note, int *reply_len, struct sg_reply *rep); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ + #if defined(USE_DSLIB) || defined(_AIX) + void die(char *message) + #else /* defined(USE_DSLIB) || defined(_AIX) */ int die(char *message) + #endif /* defined(USE_DSLIB) || defined(_AIX) */ { fprintf(stderr, "%s: %s\n", program, message); exit(1); *************** *** 144,150 **** --- 202,218 ---- } void + #ifdef _AIX + print_reply (const char *description, struct cdr100_req_sense *rep) { + int reply_len = rep->add_sense_length; + #else /* def _AIX */ + #ifdef USE_DSLIB + print_reply (const char *description, struct dsreq *dsp) { + int reply_len = SENSESENT(dsp) - 8; + #else /* def USE_DSLIB */ print_reply (const char *description, int reply_len, struct sg_reply *rep) { + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ int i; int bytes_to_show; *************** *** 161,184 **** --- 229,314 ---- rep->header.pack_id, rep->header.result); #endif + #ifdef _AIX + if ((rep->sense_key & 0xF) != 0) { + (void) fprintf (stderr, " %02X", rep->error_code); + (void) fprintf (stderr, " %02X", rep->segment_number); + (void) fprintf (stderr, " %02X", rep->sense_key); + (void) fprintf (stderr, " %02X", rep->info_byte[0]); + (void) fprintf (stderr, " %02X", rep->info_byte[1]); + (void) fprintf (stderr, " %02X", rep->info_byte[2]); + (void) fprintf (stderr, " %02X", rep->info_byte[3]); + (void) fprintf (stderr, " %02X", rep->add_sense_length); + #else /* def _AIX */ + #ifdef USE_DSLIB + if (RET(dsp) && RET(dsp) != DSRT_SHORT) { + (void) fprintf (stderr, "%s result %s, sense", + description, ds_vtostr(RET(dsp), dsrtnametab)); + for ( i = 0; i < 8; i++ ) { + (void) fprintf (stderr, " %02X", SENSEBUF(dsp)[i]); + #else /* def USE_DSLIB */ if ( rep->header.result != 0 || (rep->header.sense_buffer[2] & 0xF) != 0) { fprintf (stderr, "%s result %d, pack_id %d sense", description, rep->header.result, rep->header.pack_id); for ( i = 0; i < 16; i++ ) { fprintf (stderr, " %02X", rep->header.sense_buffer[i]); + #endif /* def USE_DSLIB */ } + #endif /* def _AIX */ fprintf (stderr, "\n"); } fprintf (stderr, "%d of %d %s reply bytes:", bytes_to_show, reply_len, description); for (i = 0; i < bytes_to_show; i++ ) + #ifdef _AIX + (void) fprintf (stderr, " %02X", rep->add_sense_bytes[i]); + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) fprintf (stderr, " %02X", SENSEBUF(dsp)[i + 8]); + #else /* def USE_DSLIB */ fprintf (stderr, " %02X", rep->bytes[i]); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ fprintf (stderr, "\n"); } + #ifndef _AIX static int auto_request_sense = 1; + #ifdef USE_DSLIB + #ifdef USE_AIO + static void sendrequest(arg) + void *arg; + { + struct dsreq *dsp = arg; + + (void) unblockproc(getppid()); + (void) doscsireq(getfd(dsp), dsp); + } + #endif /* def USE_AIO */ + void + fillbytes(unsigned char *bytes, int nbytes, ...) { + va_list args; + int i; + va_start(args, nbytes); + for (i = 0; i < nbytes; i++) { + bytes[i] = va_arg(args, unsigned int); + } + va_end (args); + } + #endif /* def USE_DSLIB */ + int + #ifdef USE_DSLIB + send_request(struct dsreq *dsp, char *note) { + int result = doscsireq(getfd(dsp), dsp); + if (auto_request_sense) { + auto_request_sense = 0; + (void) quiet_request_sense(dsp, 0, note); + auto_request_sense = 1; + } + return result; + #else /* def USE_DSLIB */ send_request(int fd, char *note, int *reply_len, struct sg_reply *rep, int nbytes, ...) { va_list args; *************** *** 217,228 **** --- 347,364 ---- } return 0; + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + write_data_track (struct dsreq *dsp) { + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ write_data_track (int fd, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof(struct sg_reply); return send_request (fd, "write_data_track", reply_len, rep, 10, + #endif /* def USE_DSLIB */ WRITE_TRACK, /* 0 */ 0, /* 1 */ 0,0,0, /* 2..4 */ *************** *** 229,240 **** --- 365,386 ---- 0, /* 5: track number (0=new) */ 1, /* 6: data track, mode 1 */ 0,0,0 /* 7..9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_WRITE | DSRQ_SENSE); + dsp->ds_time = 120 * 1000; + return send_request(dsp, "write_data_track"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + write_audio_track (struct dsreq *dsp, int preemp) { + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ write_audio_track (int fd, int *reply_len, struct sg_reply *rep, int preemp) { *reply_len = sizeof(struct sg_reply); return send_request (fd, "write_audio_track", reply_len, rep, 10, + #endif /* def USE_DSLIB */ WRITE_TRACK, /* 0 */ 0, /* 1 */ 0,0,0, /* 2..4 */ *************** *** 241,252 **** 0, /* 5: track number (0=new) */ preemp ? 5 : 4, /* 6: audio track */ 0,0,0 /* 7..9 */); ! } int pipe_to_cd (struct track_info_t *track_info, int out_fd, int *reply_len, struct sg_reply *rep) { unsigned char *start, *end; int bytes_written = 0; int last_bytes_written = 0; --- 387,429 ---- 0, /* 5: track number (0=new) */ preemp ? 5 : 4, /* 6: audio track */ 0,0,0 /* 7..9 */); ! #ifdef USE_DSLIB ! filldsreq(dsp, 0, 0, DSRQ_WRITE | DSRQ_SENSE); ! dsp->ds_time = 120 * 1000; ! return send_request(dsp, "write_audio_track"); ! #endif /* def USE_DSLIB */ ! } ! #endif /* ndef _AIX */ int + #ifdef _AIX + pipe_to_cd (struct track_info_t *track_info, int out_fd) + #else /* def _AIX */ + #ifdef USE_DSLIB + pipe_to_cd (struct track_info_t *track_info, struct dsreq *dsp) + #else /* def USE_DSLIB */ pipe_to_cd (struct track_info_t *track_info, int out_fd, int *reply_len, struct sg_reply *rep) + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ { + #ifdef _AIX + struct cdr100_req_sense rep; + #ifdef USE_AIO + struct aiocb aio; + struct aiocb *list[1] = { &aio }; + #endif /* def USE_AIO */ + #endif /* def _AIX */ + #if defined(USE_DSLIB) || defined(_AIX) + #if defined(USE_DSLIB) && defined(USE_AIO) + #define bbytes dbytes[buf] + unsigned char dbytes[2][WRITE_BLOCK_SIZE]; + int buf = 0; + pid_t pid; + #else /* defined(USE_DSLIB) && defined(USE_AIO) */ + unsigned char bbytes[WRITE_BLOCK_SIZE]; + #endif /* defined(USE_DSLIB) && defined(USE_AIO) */ + #endif /* defined(USE_DSLIB) || defined(_AIX) */ unsigned char *start, *end; int bytes_written = 0; int last_bytes_written = 0; *************** *** 253,260 **** --- 430,439 ---- int total_bytes_read = 0; int this_len = 0; /* Initialize to keep gcc happy */ int iteration = 1; + #if !defined(USE_DSLIB) && !defined(_AIX) int expected_len; unsigned char *write_ptr; + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ int write_block_size; int blocks_per_write; int block_size; *************** *** 264,270 **** --- 443,451 ---- int bytes_to_read; int this_read_len; int this_write_len; + #if !defined(USE_DSLIB) && !defined(_AIX) int short_read=0; + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ int slop; int pad; static int track_no = 0; *************** *** 278,283 **** --- 459,465 ---- pad = track_info->pad && !audio; /* Data track padding */ + #if !defined(USE_DSLIB) && !defined(_AIX) memset(&sg_request, 0, sizeof(sg_request)); sg_request.header.pack_len = sizeof(struct sg_header)+6+write_block_size; sg_request.header.reply_len = 20; *************** *** 286,291 **** --- 468,474 ---- sg_request.bytes[0] = WRITE_6; sg_request.bytes[4] = blocks_per_write; + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ if (verbose) { if ( max_bytes_to_copy != INT_MAX ) *************** *** 298,304 **** --- 481,491 ---- /* Read one block. */ + #if defined(USE_DSLIB) || defined(_AIX) + start = bbytes; + #else /* defined(USE_DSLIB) || defined(_AIX) */ start = &sg_request.bytes[6]; + #endif /* defined(USE_DSLIB) || defined(_AIX) */ end = start + write_block_size; this_read_len = 0; if (max_bytes_to_copy != INT_MAX) *************** *** 338,344 **** --- 525,533 ---- } if (start != end) { + #if !defined(USE_DSLIB) && !defined(_AIX) short_read = 1; + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ if ( (slop = this_read_len % block_size) != 0 ) { slop = block_size-slop; this_read_len += slop; *************** *** 347,356 **** --- 536,587 ---- } /* write the first block */ + #ifdef _AIX + #ifdef USE_AIO + (void) memset(&aio, 0, sizeof(aio)); + aio.aio_buf = bbytes; + aio.aio_nbytes = this_read_len; + if (aio_write(out_fd, &aio)) { + perror ("pipe_to_cd: aio_write"); + return -1; + } + this_write_len = this_read_len; + #else /* def USE_AIO */ + this_write_len = write(out_fd, bbytes, this_read_len); + #endif /* def USE_AIO */ + #else /* def _AIX */ + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), G0_WRIT, 0, + 0, 0, this_read_len / block_size, 0); + filldsreq(dsp, bbytes, this_read_len, DSRQ_WRITE | DSRQ_SENSE); + dsp->ds_time = 120 * 1000; + #ifdef USE_AIO + pid = sproc(sendrequest, PR_SADDR | PR_BLOCK, dsp); + buf ^= 1; + this_write_len = this_read_len; + #else /* def USE_AIO */ + (void) send_request(dsp, "pipe_to_cd_1"); + this_write_len = DATASENT(dsp); + #endif /* def USE_AIO */ + #else /* def USE_DSLIB */ if (short_read) { sg_request.header.pack_len = sizeof(struct sg_header)+6+this_read_len; sg_request.bytes[4] = this_read_len/block_size; } + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ + #if defined(USE_DSLIB) || defined(_AIX) + #ifndef USE_AIO + if (this_write_len != this_read_len) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* ndef USE_AIO */ + #else /* defined(USE_DSLIB) || defined(_AIX) */ expected_len = sizeof(struct sg_header) + 6 + this_read_len; write_ptr = (unsigned char*) &sg_request; do { *************** *** 368,379 **** --- 599,615 ---- write_ptr += this_write_len; bytes_written += this_write_len; } while (expected_len != 0); + #endif /* defined(USE_DSLIB) || defined(_AIX) */ while (this_read_len > 0 && total_bytes_read < max_bytes_to_copy) { /* Now we read the next block */ + #if defined(USE_DSLIB) || defined(_AIX) + start = bbytes; + #else /* defined(USE_DSLIB) || defined(_AIX) */ start = &sg_request.bytes[6]; + #endif /* defined(USE_DSLIB) || defined(_AIX) */ end = start + write_block_size; this_read_len = 0; if (max_bytes_to_copy != INT_MAX) *************** *** 413,419 **** --- 649,657 ---- } if (start != end) { + #if !defined(USE_DSLIB) && !defined(_AIX) short_read = 1; + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ if ( (slop = this_read_len % block_size) != 0 ) { slop = block_size - slop; this_read_len += slop; *************** *** 436,449 **** --- 674,773 ---- */ /* Get the response from the last block written */ + #ifdef _AIX + #ifdef USE_AIO + if (aio_suspend(1, list)) { + perror ("pipe_to_cd: aio_suspend"); + return -1; + } + if (aio_return(&aio) < 0) { + #else /* def USE_AIO */ + if (this_write_len < 0) { + #endif /* def USE_AIO */ + (void) ioctl(out_fd, CDR100_REQUEST_SENSE, &rep); + (void) quiet_request_sense (out_fd, iteration++, "pipe_to_cd", &rep); + } + #ifdef USE_AIO + if (this_write_len != aio_return(&aio)) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* def USE_AIO */ + #else /* def _AIX */ + #ifdef USE_DSLIB + #ifdef USE_AIO + if (pid != waitpid(pid, NULL, 0)) { + perror ("pipe_to_cd: waitpid"); + return -1; + } + #endif /* def USE_AIO */ + (void) quiet_request_sense (dsp, iteration++, "pipe_to_cd"); + #ifdef USE_AIO + if (this_write_len != DATASENT(dsp)) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* def USE_AIO */ + #else /* def USE_DSLIB */ *reply_len = read (out_fd, rep, sizeof(struct sg_reply)); quiet_request_sense (out_fd, iteration++, "pipe_to_cd", reply_len, rep); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ /* write the block */ + #ifdef _AIX + #ifdef USE_AIO + aio.aio_buf = bbytes; + aio.aio_nbytes = this_read_len; + if (aio_write(out_fd, &aio)) { + perror ("pipe_to_cd: aio_write"); + return -1; + } + this_write_len = this_read_len; + #else /* def USE_AIO */ + this_write_len = write(out_fd, bbytes, this_read_len); + #endif /* def USE_AIO */ + #else /* def _AIX */ + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), G0_WRIT, 0, + 0, 0, this_read_len / block_size, 0); + filldsreq(dsp, bbytes, this_read_len, DSRQ_WRITE | DSRQ_SENSE); + dsp->ds_time = 120 * 1000; + #ifdef USE_AIO + pid = sproc(sendrequest, PR_SADDR | PR_BLOCK, dsp); + buf ^= 1; + this_write_len = this_read_len; + #else /* def USE_AIO */ + (void) send_request(dsp, "pipe_to_cd_2"); + this_write_len = DATASENT(dsp); + #endif /* def USE_AIO */ + #else /* def USE_DSLIB */ if (short_read) { sg_request.header.pack_len = sizeof(struct sg_header)+6+this_read_len; sg_request.bytes[4] = this_read_len/block_size; } + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ + #if defined(USE_DSLIB) || defined(_AIX) + #ifndef USE_AIO + if (this_write_len != this_read_len) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* ndef USE_AIO */ + #else /* defined(USE_DSLIB) || defined(_AIX) */ expected_len = sizeof(struct sg_header) + 6 + this_read_len; write_ptr = (unsigned char*) &sg_request; *************** *** 471,476 **** --- 795,801 ---- write_ptr += this_write_len; bytes_written += this_write_len; } while (expected_len != 0); + #endif /* defined(USE_DSLIB) || defined(_AIX) */ } if ( pad ) *************** *** 477,491 **** --- 802,904 ---- { /* Note: we only pad data tracks, so we use the defined constants */ + #if defined(USE_DSLIB) || defined(_AIX) + (void) memset(bbytes, 0, PAD_SIZE * DATA_CD_BLOCK_SIZE); + #else /* defined(USE_DSLIB) || defined(_AIX) */ expected_len = sg_request.header.pack_len = sizeof(struct sg_header) + 6 + PAD_SIZE * DATA_CD_BLOCK_SIZE; sg_request.bytes[4] = PAD_SIZE; memset(&sg_request.bytes[6], 0, PAD_SIZE*DATA_CD_BLOCK_SIZE); + #endif /* defined(USE_DSLIB) || defined(_AIX) */ /* Wait for writer to ack the last data */ + #ifdef _AIX + #ifdef USE_AIO + if (aio_suspend(1, list)) { + perror ("pipe_to_cd: aio_suspend"); + return -1; + } + if (aio_return(&aio) < 0) { + #else /* def USE_AIO */ + if (this_write_len < 0) { + #endif /* def USE_AIO */ + (void) ioctl(out_fd, CDR100_REQUEST_SENSE, &rep); + (void) quiet_request_sense (out_fd, iteration++, "pipe_to_cd", &rep); + } + #ifdef USE_AIO + if (this_write_len != aio_return(&aio)) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* def USE_AIO */ + #else /* def _AIX */ + #ifdef USE_DSLIB + #ifdef USE_AIO + if (pid != waitpid(pid, NULL, 0)) { + perror ("pipe_to_cd: waitpid"); + return -1; + } + #endif /* def USE_AIO */ + (void) quiet_request_sense (dsp, iteration++, "pipe_to_cd"); + #ifdef USE_AIO + if (this_write_len != DATASENT(dsp)) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* def USE_AIO */ + #else /* def USE_DSLIB */ *reply_len = read (out_fd, rep, sizeof(struct sg_reply)); quiet_request_sense (out_fd, iteration++, "pipe_to_cd", reply_len, rep); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ + #if defined(USE_DSLIB) || defined(_AIX) + #ifdef _AIX + #ifdef USE_AIO + aio.aio_buf = bbytes; + aio.aio_nbytes = PAD_SIZE * DATA_CD_BLOCK_SIZE; + if (aio_write(out_fd, &aio)) { + perror ("pipe_to_cd: aio_write"); + return -1; + } + this_write_len = PAD_SIZE * DATA_CD_BLOCK_SIZE; + #else /* def USE_AIO */ + this_write_len = write(out_fd, bbytes, PAD_SIZE * DATA_CD_BLOCK_SIZE); + #endif /* def USE_AIO */ + #else /* def _AIX */ + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), G0_WRIT, 0, + 0, 0, PAD_SIZE, 0); + filldsreq(dsp, bbytes, PAD_SIZE * DATA_CD_BLOCK_SIZE, + DSRQ_WRITE | DSRQ_SENSE); + dsp->ds_time = 120 * 1000; + #ifdef USE_AIO + pid = sproc(sendrequest, PR_SADDR | PR_BLOCK, dsp); + buf ^= 1; + this_write_len = PAD_SIZE * DATA_CD_BLOCK_SIZE; + #else /* def USE_AIO */ + (void) send_request(dsp, "pipe_to_cd_3"); + this_write_len = DATASENT(dsp); + #endif /* def USE_AIO */ + #endif /* def _AIX */ + #ifndef USE_AIO + if (this_write_len != this_read_len) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* ndef USE_AIO */ + #else /* defined(USE_DSLIB) || defined(_AIX) */ write_ptr = (unsigned char*) &sg_request; do { this_write_len = write( out_fd, write_ptr, expected_len ); *************** *** 503,513 **** --- 916,972 ---- write_ptr += this_write_len; bytes_written += this_write_len; } while (expected_len != 0); + #endif /* defined(USE_DSLIB) || defined(_AIX) */ } /* wait for the Writer to ack the last block */ + #ifdef _AIX + #ifdef USE_AIO + if (aio_suspend(1, list)) { + perror ("pipe_to_cd: aio_suspend"); + return -1; + } + if (aio_return(&aio) < 0) { + #else /* def USE_AIO */ + if (this_write_len < 0) { + #endif /* def USE_AIO */ + (void) ioctl(out_fd, CDR100_REQUEST_SENSE, &rep); + (void) quiet_request_sense (out_fd, iteration++, "pipe_to_cd", &rep); + } + #ifdef USE_AIO + if (this_write_len != aio_return(&aio)) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* def USE_AIO */ + #else /* def _AIX */ + #ifdef USE_DSLIB + #ifdef USE_AIO + if (pid != waitpid(pid, NULL, 0)) { + perror ("pipe_to_cd: waitpid"); + return -1; + } + #endif /* def USE_AIO */ + (void) quiet_request_sense (dsp, iteration++, "pipe_to_cd"); + #ifdef USE_AIO + if (this_write_len != DATASENT(dsp)) { + (void) fprintf (stderr, "After writing %d bytes, only wrote %d " + "bytes to CD (should have written %d).\n", + bytes_written, this_write_len, this_read_len); + perror ("pipe_to_cd: write"); + return -1; + } + bytes_written += this_write_len; + #endif /* def USE_AIO */ + #else /* def USE_DSLIB */ *reply_len = read (out_fd, rep, sizeof(struct sg_reply)); quiet_request_sense (out_fd, iteration++, "pipe_to_cd", reply_len, rep); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ printf ("Track %02d: Total data bytes written: %d.\n", track_no, total_bytes_read); *************** *** 514,604 **** --- 973,1154 ---- return 0; } + #ifndef _AIX int + #ifdef USE_DSLIB + clear_unit_attention (struct dsreq *dsp) { + #else /* def USE_DSLIB */ clear_unit_attention (int fd, int *reply_len, struct sg_reply *rep) { + #endif /* def USE_DSLIB */ int saved_auto_request_sense = auto_request_sense, result; auto_request_sense = 0; + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_TEST, /* 0 */ + #else /* def USE_DSLIB */ *reply_len = sizeof(struct sg_reply); result = send_request (fd, "test_unit_ready", reply_len, rep, 6, TEST_UNIT_READY,/* 0 */ + #endif /* def USE_DSLIB */ 0, /* 1 */ 0,0,0,0 /* 2..5 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + result = send_request(dsp, "test_unit_ready"); + #endif /* def USE_DSLIB */ auto_request_sense = saved_auto_request_sense; return result; } int + #ifdef USE_DSLIB + test_unit_ready (struct dsreq *dsp) { + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_TEST, /* 0 */ + #else /* def USE_DSLIB */ test_unit_ready (int fd, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof(struct sg_reply); return send_request (fd, "test_unit_ready", reply_len, rep, 6, TEST_UNIT_READY,/* 0 */ + #endif /* def USE_DSLIB */ 0, /* 1 */ 0,0,0,0 /* 2..5 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + return send_request(dsp, "test_unit_ready"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + rezero_unit (struct dsreq *dsp) { + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_REZE, /* 0 */ + #else /* def USE_DSLIB */ rezero_unit (int fd, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof(struct sg_reply); return send_request (fd, "rezero_unit", reply_len, rep, 6, REZERO_UNIT, /* 0 */ + #endif /* def USE_DSLIB */ 0, /* 1 */ 0,0,0,0 /* 2..5 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 30 * 1000; + return send_request(dsp, "rezero_unit"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + start_stop (struct dsreq *dsp, int start) { + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_STOP, /* 0 */ + #else /* def USE_DSLIB */ start_stop (int fd, int start, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof( struct sg_reply ); return send_request (fd, "start_stop", reply_len, rep, 6, START_STOP, /* 0 */ + #endif /* def USE_DSLIB */ 0, /* 1 */ 0,0, /* 2..3 */ start, /* 4 */ 0 /* 5 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + return send_request(dsp, "start_stop"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + synchronize_cache (struct dsreq *dsp) { + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + G1_FCAC, /* 0 */ + #else /* def USE_DSLIB */ synchronize_cache (int fd, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof( struct sg_reply ); return send_request (fd, "synchronize_cache", reply_len, rep, 10, SYNCHRONIZE_CACHE, /* 0 */ + #endif /* def USE_DSLIB */ 0,0,0,0,0, /* 1..5 */ 0, /* 6 */ 0,0,0 /* 7..9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + return send_request(dsp, "synchronize_cache"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + set_removable (struct dsreq *dsp, int removable) { + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_PREV,/* 0 */ + #else /* def USE_DSLIB */ set_removable (int fd, int removable, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof( struct sg_reply ); return send_request (fd, "set_removable", reply_len, rep, 6, ALLOW_MEDIUM_REMOVAL, /* 0 */ + #endif /* def USE_DSLIB */ 0,0,0, /* 1..3 */ !removable, /* 4 */ 0 /* 5 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + return send_request(dsp, "set_removable"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + fixation (struct dsreq *dsp, int cdrom) { + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ fixation (int fd, int *reply_len, struct sg_reply *rep, int cdrom) { *reply_len = sizeof( struct sg_reply ); return send_request (fd, "fixation", reply_len, rep, 10, + #endif /* def USE_DSLIB */ FIXATION, /* 0 */ 0,0,0,0,0,0,0, /* 1..7 */ cdrom ? 1 : 0, /* 8: TOC type */ 0 /* 9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 5 * 60 * 1000; + return send_request(dsp, "fixation"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + recover (struct dsreq *dsp) { + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ recover (int fd, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof( struct sg_reply ); return send_request (fd, "recover", reply_len, rep, 10, + #endif /* def USE_DSLIB */ RECOVER, /* 0 */ 0,0,0,0,0,0,0, /* 1..7 */ 0, /* 8 */ 0 /* 9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + return send_request(dsp, "recover"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + medium_load_unload (struct dsreq *dsp, int load) { + #else /* def USE_DSLIB */ medium_load_unload (int fd, int load, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof( struct sg_reply ); + #endif /* def USE_DSLIB */ /** ALPHA NOTES: Turned off IMMEDIATE bit; do this only once **/ *************** *** 607,617 **** --- 1157,1178 ---- #if 0 case type_philips: /* Philips drivers seem to have this told twice */ + #ifdef USE_DSLIB + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ if ( send_request (fd, "load_unload", reply_len, rep, 10, + #endif /* def USE_DSLIB */ LOAD_UNLOAD, /* 0 */ 1,0,0,0,0,0,0, /* 1..7 */ !load, /* 8 */ + #ifdef USE_DSLIB + 0 /* 9 */); + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + if (send_request(dsp, "load_unload")) + #else /* def USE_DSLIB */ 0 /* 9 */) ) + #endif /* def USE_DSLIB */ return 1; /* Fall though */ *************** *** 618,646 **** --- 1179,1234 ---- case type_hp: + #ifdef USE_DSLIB + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ return send_request (fd, "load_unload", reply_len, rep, 10, + #endif /* def USE_DSLIB */ LOAD_UNLOAD, /* 0 */ 1,0,0,0,0,0,0, /* 1..7 */ !load, /* 8 */ 0 /* 9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + return send_request(dsp, "load_unload"); + #endif /* def USE_DSLIB */ #endif case type_philips: case type_hp: + #ifdef USE_DSLIB + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ return send_request (fd, "load_unload", reply_len, rep, 10, + #endif /* def USE_DSLIB */ LOAD_UNLOAD, /* 0 */ 0,0,0,0,0,0,0, /* 1..7 */ !load, /* 8 */ 0 /* 9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + return send_request(dsp, "load_unload"); + #endif /* def USE_DSLIB */ case type_yamaha: if ( load ) return 1; /* There is no LOAD command for Yamaha */ + #ifdef USE_DSLIB + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ return send_request (fd, "medium_unload", reply_len, rep, 10, + #endif /* def USE_DSLIB */ MEDIUM_UNLOAD, /* 0 */ 0,0,0,0,0,0,0, /* 1..7 */ 0, /* 8 */ 0 /* 9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + dsp->ds_time = 10 * 1000; + return send_request(dsp, "medium_unload"); + #endif /* def USE_DSLIB */ default: die("default in medium_load_unload"); *************** *** 650,683 **** --- 1238,1322 ---- } int + #ifdef USE_DSLIB + request_sense (struct dsreq *dsp) { + unsigned char bytes[18]; + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_REQU, /* 0 */ + #else /* def USE_DSLIB */ request_sense (int fd, int *reply_len, struct sg_reply *rep) { *reply_len = 18; return send_request (fd, "request_sense", reply_len, rep, 6, REQUEST_SENSE, /* 0 */ + #endif /* def USE_DSLIB */ 0,0,0,18,0 /* 1..5 */); + #ifdef USE_DSLIB + filldsreq(dsp, bytes, 18, DSRQ_READ | DSRQ_SENSE); + return send_request(dsp, "request_sense"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + quiet_active_request_sense (struct dsreq *dsp) { + unsigned char bytes[18]; + #else /* def USE_DSLIB */ quiet_active_request_sense (int fd, int iteration, char *note, int *reply_len, struct sg_reply *rep) { *reply_len = 18; + #endif /* def USE_DSLIB */ if (!auto_request_sense) return 0; auto_request_sense = 0; + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_REQU, /* 0 */ + #else /* def USE_DSLIB */ return send_request (fd, NULL, reply_len, rep, 6, REQUEST_SENSE, /* 0 */ + #endif /* def USE_DSLIB */ 1,0,0,18,0 /* 1..5 */); + #ifdef USE_DSLIB + filldsreq(dsp, bytes, 18, DSRQ_READ | DSRQ_SENSE); + return send_request(dsp, NULL); + #endif /* def USE_DSLIB */ } + #endif /* ndef _AIX */ int + #ifdef _AIX + /*ARGSUSED*/ + quiet_request_sense (int fd, int iteration, char *note, + struct cdr100_req_sense *rep) { + if ((rep->sense_key & 0xF) != 0) { + #else /* def _AIX */ + #ifdef USE_DSLIB + quiet_request_sense (struct dsreq *dsp, int iteration, char *note) { + #define DEBUG 0 + #if DEBUG + (void) fprintf(stderr, "%s %d %d %d %d %x %d\n", note, STATUS(dsp), RET(dsp), + SENSESENT(dsp), DATASENT(dsp), SENSEBUF(dsp), SENSELEN(dsp)); + #endif /* DEBUG */ + if (RET(dsp) && RET(dsp) != DSRT_SHORT) { + #else /* def USE_DSLIB */ quiet_request_sense (int fd, int iteration, char *note, int *reply_len, struct sg_reply *rep) { *reply_len = 18; if (rep->header.sense_buffer[2] & 0xF || rep->header.result != 0) { + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ if (iteration != 0) { fprintf (stderr, "SENSE_ERROR iter %d: ", iteration); } + #ifdef _AIX + print_reply( note, rep); + #else /* def _AIX */ + #ifdef USE_DSLIB + print_reply( note, dsp); + #else /* def USE_DSLIB */ print_reply( note, *reply_len, rep); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ #if 0 quiet_active_request_sense (fd, iteration, "request_sense", reply_len, rep); #endif *************** *** 685,691 **** --- 1324,1342 ---- return 0; } + #ifndef _AIX int + #ifdef USE_DSLIB + read_capacity (struct dsreq *dsp) { + struct foo { + unsigned char bytes[8]; + }; + struct foo bar; + struct foo *rep = &bar; + int result; + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + G1_RCAP, /* 0 */ + #else /* def USE_DSLIB */ read_capacity (int fd, int *reply_len, struct sg_reply *rep) { int result; *reply_len = sizeof( struct sg_reply ); *************** *** 692,698 **** --- 1343,1354 ---- result= send_request (fd, "read_capacity", reply_len, rep, 10, READ_CAPACITY, /* 0 */ + #endif /* def USE_DSLIB */ 0,0,0,0,0,0,0,0,0 /* 1..9 */); + #ifdef USE_DSLIB + filldsreq(dsp, rep->bytes, sizeof(rep->bytes), DSRQ_READ | DSRQ_SENSE); + result= send_request (dsp, "read_capacity"); + #endif /* def USE_DSLIB */ printf ("Capacity = %d blocks, block length = %d (0x%x).\n", (rep->bytes[0] << 24) + (rep->bytes[1] << 16) + (rep->bytes[2] << 8) + rep->bytes[3], *************** *** 705,714 **** --- 1361,1375 ---- } int + #ifdef USE_DSLIB + reserve_track (struct dsreq *dsp, unsigned long len) { + fillg1cmd(dsp, (uchar_t *) CMDBUF(dsp), + #else /* def USE_DSLIB */ reserve_track (int fd, unsigned long len, int *reply_len, struct sg_reply *rep) { *reply_len = sizeof( struct sg_reply ); return send_request (fd, "reserve_track", reply_len, rep, 10, + #endif /* def USE_DSLIB */ RESERVE_TRACK, /* 0 */ 0,0,0,0, /* 1..4 */ (len >> 24) & 0xFF, /* 5 */ *************** *** 716,733 **** --- 1377,1416 ---- (len >> 8) & 0xFF, /* 7 */ len & 0xFF, /* 8 */ 0 /* 9 */); + #ifdef USE_DSLIB + filldsreq(dsp, 0, 0, DSRQ_READ | DSRQ_SENSE); + return send_request(dsp, "reserve_track"); + #endif /* def USE_DSLIB */ } int + #ifdef USE_DSLIB + inquiry (struct dsreq *dsp, char *manufacturer, char *model, char *revision) { + struct foo { + unsigned char bytes[255]; + }; + struct foo bar; + struct foo *rep = &bar; + #else /* def USE_DSLIB */ inquiry (int fd, int *reply_len, struct sg_reply *rep, char *manufacturer, char *model, char *revision) { + #endif /* def USE_DSLIB */ int result; int i; char *reply; + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_INQU, /* 0 */ + #else /* def USE_DSLIB */ *reply_len = sizeof( struct sg_reply ); result = send_request (fd, "inquiry", reply_len, rep, 6, INQUIRY, /* 0 */ + #endif /* def USE_DSLIB */ 0,0,0,255,0); + #ifdef USE_DSLIB + filldsreq(dsp, rep->bytes, sizeof(rep->bytes), DSRQ_READ | DSRQ_SENSE); + result = send_request(dsp, "inquiry"); + #endif /* def USE_DSLIB */ for(i=15; i>8; i--) if(rep->bytes[i] != ' ') break; reply = (char *) &rep->bytes[8]; *************** *** 750,769 **** --- 1433,1467 ---- } int + #ifdef USE_DSLIB + mode_select1(struct dsreq *dsp, int audio, int preemp) { + unsigned char bytes[20]; + #else /* def USE_DSLIB */ mode_select1(int fd, int *reply_len, int audio, int preemp, struct sg_reply *rep) { /* Per-track mode select */ *reply_len = sizeof( struct sg_reply ); + #endif /* def USE_DSLIB */ switch (cdwriter_type) { case type_yamaha: + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_MSEL, /* 0 */ + #else /* def USE_DSLIB */ return send_request (fd, "mode_select6#1", reply_len, rep, 18, MODE_SELECT, /* 0 */ + #endif /* def USE_DSLIB */ 0x00, /* 1 : Page Format Bit */ 0, 0, /* 2..3 */ 12, /* 4 : Parameter List Length */ + #ifdef USE_DSLIB + 0 /* 5 */); + fillbytes(bytes, 12, + #else /* def USE_DSLIB */ 0, /* 5 */ + #endif /* def USE_DSLIB */ /* Mode Select Header */ 0, /* 6+0 reserved */ *************** *** 780,793 **** --- 1478,1505 ---- (audio ? 0x09 : 0x08), /* 6+4+6 Block Size */ (audio ? 0x30 : 0x00) /* 6+4+7 LSB Block Size */ ); + #ifdef USE_DSLIB + filldsreq(dsp, bytes, 12, DSRQ_WRITE | DSRQ_SENSE); + return send_request(dsp, "mode_select6#1"); + #endif /* def USE_DSLIB */ case type_philips: case type_hp: + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_MSEL, /* 0 */ + #else /* def USE_DSLIB */ return send_request (fd, "mode_select6#1", reply_len, rep, 26, MODE_SELECT, /* 0 */ + #endif /* def USE_DSLIB */ 0x10, /* 1 : page format bit */ 0, 0, /* 2..3 */ 20, /* 4 : parameter list length? */ + #ifdef USE_DSLIB + 0 /* 5 */); + fillbytes(bytes, 20, + #else /* def USE_DSLIB */ 0, /* 5 */ + #endif /* def USE_DSLIB */ /* Mode select header: */ 0, /* 6+0 reserved */ *************** *** 806,811 **** --- 1518,1527 ---- 0,0,0,0,0, /* reserved */ 0 /* 6+4+15, total byte count = 26 */ ); + #ifdef USE_DSLIB + filldsreq(dsp, bytes, 20, DSRQ_WRITE | DSRQ_SENSE); + return send_request(dsp, "mode_select6#1"); + #endif /* def USE_DSLIB */ default: die("default in mode_select1"); } *************** *** 813,832 **** --- 1529,1563 ---- } int + #ifdef USE_DSLIB + mode_select2(struct dsreq *dsp, unsigned char dummy, unsigned char speed) { + unsigned char bytes[12]; + #else /* def USE_DSLIB */ mode_select2(int fd, int *reply_len, int dummy, int speed, struct sg_reply *rep) { /* Per-disc mode select */ *reply_len = sizeof( struct sg_reply ); + #endif /* def USE_DSLIB */ switch (cdwriter_type) { case type_yamaha: + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_MSEL, /* 0 */ + #else /* def USE_DSLIB */ return send_request (fd, "mode_select6#2", reply_len, rep, 14, MODE_SELECT, /* 0 */ + #endif /* def USE_DSLIB */ 0x10, /* 1 : Page Format Bit */ 0, 0, /* 2..3 */ 8, /* 4 : Parameter List Length */ + #ifdef USE_DSLIB + 0 /* 5 */); + fillbytes(bytes, 8, + #else /* def USE_DSLIB */ 0, /* 5 */ + #endif /* def USE_DSLIB */ /* Mode Select Header */ 0, /* 6+0 reserved */ *************** *** 842,855 **** --- 1573,1600 ---- ((speed == 4 ? 0x20 : speed == 1 ? 0x00 : 0x10) | (dummy ? 0x01 : 0x00)) ); + #ifdef USE_DSLIB + filldsreq(dsp, bytes, 8, DSRQ_WRITE | DSRQ_SENSE); + return send_request(dsp, "mode_select6#2"); + #endif /* def USE_DSLIB */ case type_philips: case type_hp: + #ifdef USE_DSLIB + fillg0cmd(dsp, (uchar_t *) CMDBUF(dsp), + G0_MSEL, /* 0 */ + #else /* def USE_DSLIB */ return send_request (fd, "mode_select6#2", reply_len, rep, 18, MODE_SELECT, /* 0 */ + #endif /* def USE_DSLIB */ 0x10, /* 1 : page format bit */ 0, 0, /* 2..3 */ 12, /* 4 : parameter list length? */ + #ifdef USE_DSLIB + 0 /* 5 */); + fillbytes(bytes, 12, + #else /* def USE_DSLIB */ 0, /* 5 */ + #endif /* def USE_DSLIB */ /* Mode select header: */ 0, /* 6+0 reserved */ *************** *** 864,869 **** --- 1609,1618 ---- dummy, /* 6+4+3 1 = dummy write, 0 = real */ 0,0,0,0 /* ...6+4+7 reserved, total byte count = 18 */ ); + #ifdef USE_DSLIB + filldsreq(dsp, bytes, 12, DSRQ_WRITE | DSRQ_SENSE); + return send_request(dsp, "mode_select6#2"); + #endif /* def USE_DSLIB */ default: die("default in mode_select2"); *************** *** 870,875 **** --- 1619,1625 ---- } return -1; } + #endif /* ndef _AIX */ void usage(int exit_code) { *************** *** 911,921 **** --- 1661,1673 ---- {"--dummy", 'y'}, {"--eject", 'e'}, {"--device", 'D'}, + #ifndef _AIX {"--philips", 1001}, {"--ims", 1001}, {"--kodak", 1001}, {"--yamaha", 1002}, {"--hp", 1003}, + #endif /* ndef _AIX */ {"--bytes", 'b'}, {"--audio", 'a'}, {"--data", 'd'}, *************** *** 929,939 **** --- 1681,1700 ---- int main( int argc, char **argv ) { + #ifdef _AIX + int fd; + #else /* def _AIX */ + #ifdef USE_DSLIB + struct dsreq *dsp; + #else /* def USE_DSLIB */ int fd; struct sg_reply reply; int reply_len; + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ int speed_factor = 0; int dummy_write = 0; + #if !defined(USE_DSLIB) && !defined(_AIX) unsigned long timeout = 10 * 60 * 100; /* default timeout = 1 minute, but it */ /* takes slightly longer than that to */ *************** *** 940,945 **** --- 1701,1707 ---- /* write the leadin and leadout. (The */ /* fixation command.) So, we set it */ /* to 10 minutes, just to be safe. */ + #endif /* !defined(USE_DSLIB) && !defined(_AIX) */ int tracks = 0; int do_eject = 0; int cdrom = 0; *************** *** 946,956 **** --- 1708,1722 ---- struct track_info_t track_info[MAX_TRACKS]; struct track_info_t trackopt; const char *cd_writer = default_dev; + #ifndef _AIX char Manufacturer[8+1]; char Model[16+1]; char Revision[4+1]; + #endif /* ndef _AIX */ struct stat st; + #ifndef _AIX struct rlimit rlim; + #endif /* ndef _AIX */ int optchar; char *optarg; int i, j; *************** *** 964,969 **** --- 1730,1736 ---- trackopt.pad = 0; /* no padding */ trackopt.bytes = INT_MAX; /* no -bytes option given */ + #ifndef _AIX /* Set max # of file descriptors to no less than MAX_TRACKS + 16 */ getrlimit(RLIMIT_NOFILE, &rlim); *************** *** 974,979 **** --- 1741,1747 ---- program, rlim.rlim_max); } setrlimit(RLIMIT_NOFILE, &rlim); + #endif /* ndef _AIX */ /* Parse command line */ *************** *** 1071,1077 **** --- 1839,1849 ---- case 'h': /* -h, --help */ usage(0); + #if defined(USE_DSLIB) || defined(_AIX) + break; + #endif /* defined(USE_DSLIB) || defined(_AIX) */ + #ifndef _AIX case 1001: /* --philips, --kodak, --ims */ cdwriter_type = type_philips; break; *************** *** 1083,1088 **** --- 1855,1861 ---- case 1003: /* --hp */ cdwriter_type = type_hp; break; + #endif /* ndef _AIX */ case 0: /* End of option string */ break; *************** *** 1181,1191 **** --- 1954,1979 ---- /* Open SCSI device */ + #ifdef USE_DSLIB + (void) signal(SIGHUP, SIG_IGN); + (void) signal(SIGINT, SIG_IGN); + (void) signal(SIGQUIT, SIG_IGN); + (void) signal(SIGTERM, SIG_IGN); + if ((dsp = dsopen(cd_writer, O_RDWR)) == NULL) { + #else /* def USE_DSLIB */ if ( (fd = open (cd_writer, O_RDWR)) < 0 ) { + #endif /* def USE_DSLIB */ perror ("opening scsi device"); exit (4); } + #ifdef _AIX + if (speed_factor == 0) + speed_factor = 4; + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) inquiry (dsp, Manufacturer, Model, Revision); + #else /* def USE_DSLIB */ /* Eat any unwanted garbage from prior use of this device */ i = fcntl(fd, F_GETFL); /* Be very proper about this */ *************** *** 1204,1209 **** --- 1992,1998 ---- } inquiry (fd, &reply_len, &reply, Manufacturer, Model, Revision); + #endif /* def USE_DSLIB */ if ( cdwriter_type == type_unknown ) { *************** *** 1245,1250 **** --- 2034,2040 ---- /* On HP, speed_factor == 0 can be passed to the drive. */ speed_factor = 2; } + #endif /* def _AIX */ if ( verbose ) { *************** *** 1256,1265 **** --- 2046,2105 ---- /* Do it! */ + #ifdef _AIX + if (ioctl(fd, CDR100_TUR) < 0) { + perror("ioctl(CDR100_TUR)"); + exit(1); + } + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) clear_unit_attention (dsp); + #else /* def USE_DSLIB */ clear_unit_attention (fd, &reply_len, &reply); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ if ( tracks ) { + #ifdef _AIX + if (ioctl(fd, CDR100_LOAD) < 0) { + perror("ioctl(CDR100_LOAD)"); + exit(1); + } + if (ioctl(fd, CDR100_PREVENT) < 0) { + perror("ioctl(CDR100_PREVENT)"); + exit(1); + } + if (ioctl(fd, CDR100_START) < 0) { + perror("ioctl(CDR100_START)"); + exit(1); + } + if (ioctl(fd, CDR100_REZERO_UNIT) < 0) { + perror("ioctl(CDR100_REZERO_UNIT)"); + exit(1); + } + if (ioctl(fd, CDR100_TUR) < 0) { + perror("ioctl(CDR100_TUR)"); + exit(1); + } + if (ioctl(fd, CDR100_START) < 0) { + perror("ioctl(CDR100_START)"); + exit(1); + } + if (ioctl(fd, CDR100_MODE_SELECT2, (speed_factor & 6) | dummy_write) < 0) { + perror("ioctl(CDR100_MODE_SELECT2)"); + exit(1); + } + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) medium_load_unload (dsp, 1); + (void) set_removable (dsp, 0); + (void) start_stop (dsp, 1); + (void) rezero_unit (dsp); + (void) test_unit_ready (dsp); + (void) start_stop (dsp, 1); + (void) mode_select2 (dsp, dummy_write, speed_factor); + #else /* def USE_DSLIB */ medium_load_unload (fd, 1, &reply_len, &reply); set_removable (fd, 0, &reply_len, &reply); start_stop (fd, 1, &reply_len, &reply); *************** *** 1267,1275 **** --- 2107,2137 ---- test_unit_ready (fd, &reply_len, &reply); start_stop (fd, 1, &reply_len, &reply); mode_select2 (fd, &reply_len, dummy_write, speed_factor, &reply); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ for ( i = 0 ; i < tracks ; i++ ) { + #ifdef _AIX + (void) ioctl(fd, CDR100_MODE_SELECT1, track_info[i].audio); + if ( track_info[i].audio ) + (void) ioctl(fd, CDR100_WRITE_AUDIO, track_info[i].preemp); + else + (void) ioctl(fd, CDR100_WRITE_DATA); + + (void) pipe_to_cd (&track_info[i], fd); + (void) ioctl(fd, CDR100_SYNC_CACHE); + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) mode_select1 (dsp, track_info[i].audio, track_info[i].preemp); + if ( track_info[i].audio ) + (void) write_audio_track (dsp, track_info[i].preemp); + else + (void) write_data_track (dsp); + + (void) pipe_to_cd (&track_info[i], dsp); + (void) synchronize_cache (dsp); + #else /* def USE_DSLIB */ mode_select1 (fd, &reply_len, track_info[i].audio, track_info[i].preemp, &reply); if ( track_info[i].audio ) *************** *** 1279,1303 **** --- 2141,2201 ---- pipe_to_cd (&track_info[i], fd, &reply_len, &reply); synchronize_cache (fd, &reply_len, &reply); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ } if ( verbose ) printf("Fixating...\n"); + #ifdef _AIX + (void) ioctl(fd, CDR100_FIXATION, cdrom); + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) fixation(dsp, cdrom); + #else /* def USE_DSLIB */ fixation(fd, &reply_len, &reply, cdrom); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ + #ifndef _AIX if (cdwriter_type != type_yamaha) { /* Possibly unneeded, but doesn't hurt */ + #ifdef USE_DSLIB + (void) synchronize_cache (dsp); + #else /* def USE_DSLIB */ synchronize_cache (fd, &reply_len, &reply); + #endif /* def USE_DSLIB */ } + #endif /* ndef _AIX */ } + #ifdef _AIX + (void) ioctl(fd, CDR100_STOP); + (void) ioctl(fd, CDR100_ALLOW); + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) start_stop (dsp, 0); + (void) set_removable (dsp, 1); + #else /* def USE_DSLIB */ start_stop (fd, 0, &reply_len, &reply); set_removable (fd, 1, &reply_len, &reply); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ if ( do_eject ) + #ifdef _AIX + (void) ioctl(fd, CDR100_UNLOAD); + (void) close(fd); + #else /* def _AIX */ + #ifdef USE_DSLIB + (void) medium_load_unload (dsp, 0); + dsclose(dsp); + #else /* def USE_DSLIB */ medium_load_unload (fd, 0, &reply_len, &reply); close(fd); + #endif /* def USE_DSLIB */ + #endif /* def _AIX */ return 0; } *** isosize.c.ORIG Mon Nov 20 20:03:41 1995 --- isosize.c Thu Oct 3 13:50:13 1996 *************** *** 1,4 **** --- 1,6 ---- + #ifndef _AIX #define _POSIX_SOURCE 1 /* fileno is POSIX, not ANSI */ + #endif /* ndef _AIX */ #include #include #include *************** *** 63,69 **** --- 65,73 ---- int main(int argc, char * argv[]){ struct iso_primary_descriptor ipd; + #if 0 struct iso_directory_record * idr; + #endif /* 0 */ if(argc < 2) return 0; infile = fopen(argv[1],"rb"); *************** *** 72,78 **** --- 76,84 ---- lseek(fileno(infile), file_addr, 0); read(fileno(infile), &ipd, sizeof(ipd)); + #if 0 idr = (struct iso_directory_record *) &ipd.root_directory_record; + #endif /* 0 */ #if 1 printf ("%d\n", isonum_733(ipd.volume_space_size) * 2048); #else