diff options
author | Michael Coulter <mjc@cvs.openbsd.org> | 2006-06-01 06:32:18 +0000 |
---|---|---|
committer | Michael Coulter <mjc@cvs.openbsd.org> | 2006-06-01 06:32:18 +0000 |
commit | e020b6e3f45a5db33223baddbbd4efc54ae0617f (patch) | |
tree | 3375b2df0991f22a45c0aed46b500adab6da92ff | |
parent | efb658d3e0b4fde40e7287c91612f83538b05ce4 (diff) |
better command line usage as suggested by deraadt@
ok @deraadt
-rw-r--r-- | usr.bin/cdio/cdio.1 | 27 | ||||
-rw-r--r-- | usr.bin/cdio/cdio.c | 63 | ||||
-rw-r--r-- | usr.bin/cdio/extern.h | 15 | ||||
-rw-r--r-- | usr.bin/cdio/mmc.c | 74 |
4 files changed, 99 insertions, 80 deletions
diff --git a/usr.bin/cdio/cdio.1 b/usr.bin/cdio/cdio.1 index 4413bd4f44e..22012e64c44 100644 --- a/usr.bin/cdio/cdio.1 +++ b/usr.bin/cdio/cdio.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cdio.1,v 1.34 2006/05/31 20:59:32 jmc Exp $ +.\" $OpenBSD: cdio.1,v 1.35 2006/06/01 06:32:17 mjc Exp $ .\" .\" Copyright (c) 1995 Serge V. Vakulenko .\" All rights reserved. @@ -201,29 +201,22 @@ and the current values of the volume for left and right channels. .It Ic stop Stop the disc. .It Xo Ic tao -.Op Fl t Ar tracktypes +.Op Fl a +.Op Fl d .Ar trackfile ... .Xc Write a track-at-once CD containing each .Ar trackfile specified. -The string -.Ar tracktypes -is used to assign types to each corresponding -.Ar trackfile . -Valid characters for the -.Ar tracktypes -string are -.Sq a -for audio, -.Sq d -for data. +The tracktype is specified by using the +.Fl a +flag for audio and +.Fl d +for data tracks. If there are more tracks specified than corresponding types, the last type will be used for the remainder. -If -.Ar tracktypes -is completely unspecified, a track type of data is used. -This option is only available from the command line. +If no tracktypes are specified a track type of data is used. +This command is only available from the command line. .It Ic volume Ar left_channel Ar right_channel Set the volume of the left channel to .Ar left_channel diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index 6d1f7b53aaa..a7b6dd553c4 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.48 2006/05/31 01:14:41 mjc Exp $ */ +/* $OpenBSD: cdio.c,v 1.49 2006/06/01 06:32:17 mjc Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -56,7 +56,9 @@ #include <sys/file.h> #include <sys/cdio.h> #include <sys/ioctl.h> +#include <sys/queue.h> #include <sys/scsiio.h> +#include <sys/stat.h> #include <ctype.h> #include <err.h> @@ -145,8 +147,7 @@ int fd = -1; int verbose = 1; int msf = 1; const char *cddb_host; -char **track_names; -char *track_types; +char **track_names; EditLine *el = NULL; /* line-editing structure */ History *hist = NULL; /* line-editing history */ @@ -160,7 +161,6 @@ int play_msf(int, int, int, int, int, int); int play_track(int, int, int, int); int get_vol(int *, int *); int status(int *, int *, int *, int *); -int open_cd(char *, int); int play(char *arg); int info(char *arg); int cddbinfo(char *arg); @@ -223,6 +223,10 @@ main(int argc, char **argv) { int ch, cmd; char *arg; + struct stat sb; + struct track_info *cur_track; + struct track_info *tr; + char type; cdname = getenv("DISC"); if (! cdname) @@ -263,30 +267,51 @@ main(int argc, char **argv) } if (argc > 0 && ! strcasecmp(*argv, "tao")) { - optreset = 1; - optind = 0; - while ((ch = getopt(argc, argv, "t:")) != -1) { - switch (ch) { - case 't': - track_types = optarg; - break; - default: + if (argc == 1) + usage(); + SLIST_INIT(&tracks); + type = 'd'; + while (argc > 1) { + tr = malloc(sizeof(struct track_info)); + tr->type = type; + optreset = 1; + optind = 1; + while ((ch = getopt(argc, argv, "ad")) != -1) { + switch (ch) { + case 'a': + type = 'a'; + break; + case 'd': + type = 'd'; + break; + default: + usage(); + } + } + tr->type = type; + argc -= optind; + argv += optind; + if (argv[0] == NULL) usage(); + tr->file = argv[0]; + if (stat(tr->file, &sb) != 0) { + warn("cannot stat file %s",tr->file); + return (-1); } - + tr->sz = sb.st_size; + if (SLIST_EMPTY(&tracks)) + SLIST_INSERT_HEAD(&tracks,tr,track_list); + else + SLIST_INSERT_AFTER(cur_track,tr,track_list); + cur_track = tr; } - argc -= optind; - argv += optind; - if (argc == 0) - usage(); if (! open_cd(cdname, 1)) exit(1); - if (writetao(argc,argv) != 0) + if (writetao(&tracks) != 0) exit(1); else exit(0); } - if (argc > 0) { char buf[80], *p; int len; diff --git a/usr.bin/cdio/extern.h b/usr.bin/cdio/extern.h index b766ba3cac3..c9078c01ea6 100644 --- a/usr.bin/cdio/extern.h +++ b/usr.bin/cdio/extern.h @@ -24,10 +24,21 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <sys/queue.h> + struct cd_toc_entry; +struct track_info { + off_t sz; + u_int blklen; + char *file; + SLIST_ENTRY(track_info) track_list; + char type; +}; +SLIST_HEAD(track_head, track_info) tracks; extern unsigned long entry2time(struct cd_toc_entry *); extern unsigned long entry2frames(struct cd_toc_entry *); +extern int open_cd(char *, int); extern char ** cddb(const char *, int, struct cd_toc_entry *, char *); extern unsigned long cddb_discid(int, struct cd_toc_entry *); extern void free_names(char **); @@ -36,8 +47,8 @@ extern int unit_ready(void); extern int synchronize_cache(void); extern int close_session(void); extern int get_nwa(int *); -extern int writetao(int, char *[]); -extern int writetrack(char *, u_int, u_int, char); +extern int writetao(struct track_head *); +extern int writetrack(struct track_info *); extern int mode_sense_write(unsigned char []); extern int mode_select_write(unsigned char []); diff --git a/usr.bin/cdio/mmc.c b/usr.bin/cdio/mmc.c index 7c167fd174d..4414aec2512 100644 --- a/usr.bin/cdio/mmc.c +++ b/usr.bin/cdio/mmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmc.c,v 1.4 2006/05/31 23:01:15 mjc Exp $ */ +/* $OpenBSD: mmc.c,v 1.5 2006/06/01 06:32:17 mjc Exp $ */ /* * Copyright (c) 2006 Michael Coulter <mjc@openbsd.org> * @@ -17,7 +17,6 @@ #include <sys/limits.h> #include <sys/types.h> -#include <sys/stat.h> #include <sys/scsiio.h> #include <err.h> #include <errno.h> @@ -31,7 +30,6 @@ extern int errno; extern int fd; extern char *cdname; -extern char *track_types; int blank(void) @@ -117,16 +115,13 @@ close_session(void) } int -writetao(int ntracks, char *track_files[]) +writetao(struct track_head *thp) { u_char modebuf[70]; - u_int blklen; - u_int t; - int i,r; + struct track_info *tr; + int r; u_char bdlen; - - if (track_types == NULL) - track_types = strdup("d"); + if ((r = mode_sense_write(modebuf)) != SCCMD_OK) { warnx("mode sense failed: %d", r); return (r); @@ -135,20 +130,23 @@ writetao(int ntracks, char *track_files[]) modebuf[2+8+bdlen] |= 0x40; /* Buffer Underrun Free Enable */ modebuf[2+8+bdlen] |= 0x01; /* change write type to TAO */ - for (i = 0, t = 0; t < ntracks; t++) { - if (track_types[i] == 'd') { + SLIST_FOREACH(tr, thp, track_list) { + switch(tr->type) { + case 'd': modebuf[3+8+bdlen] = 0x04; /* track mode = data */ modebuf[4+8+bdlen] = 0x08; /* 2048 block track mode */ modebuf[8+8+bdlen] = 0x00; /* turn off XA */ - blklen = 2048; - } else if (track_types[i] == 'a') { + tr->blklen = 2048; + break; + case 'a': modebuf[3+8+bdlen] = 0x00; /* track mode = audio */ modebuf[4+8+bdlen] = 0x00; /* 2352 block track mode */ modebuf[8+8+bdlen] = 0x00; /* turn off XA */ - blklen = 2352; - } else { - warnx("invalid track type specified"); - return (1); + tr->blklen = 2352; + break; + default: + warn("impossible tracktype detected"); + break; } while (unit_ready() != SCCMD_OK) continue; @@ -156,29 +154,25 @@ writetao(int ntracks, char *track_files[]) warnx("mode select failed: %d",r); return (r); } - writetrack(track_files[t], blklen, t, track_types[i]); + writetrack(tr); synchronize_cache(); - if (track_types[i+1] != '\0') - i++; } fprintf(stderr,"\n"); - synchronize_cache(); close_session(); return (0); } int -writetrack(char *file, u_int blklen, u_int trackno, char type) +writetrack(struct track_info *tr) { u_char databuf[65536]; - struct stat sb; scsireq_t scr; u_int end_lba, lba; u_int tmp; int r,rfd; u_char nblk; - nblk = 65535/blklen; + nblk = 65535/tr->blklen; bzero(&scr, sizeof(scr)); scr.timeout = 300000; scr.cmd[0] = 0x2a; @@ -186,7 +180,7 @@ writetrack(char *file, u_int blklen, u_int trackno, char type) scr.cmd[8] = nblk; /* Transfer length in blocks (LSB) */ scr.cmdlen = 10; scr.databuf = (caddr_t)databuf; - scr.datalen = nblk * blklen; + scr.datalen = nblk * tr->blklen; scr.senselen = SENSEBUFLEN; scr.flags = SCCMD_ESCAPE|SCCMD_WRITE; @@ -197,32 +191,28 @@ writetrack(char *file, u_int blklen, u_int trackno, char type) tmp = htobe32(lba); /* update lba in cdb */ memcpy(&scr.cmd[2], &tmp, sizeof(tmp)); - if (stat(file, &sb) != 0) { - warn("cannot stat file %s",file); - return (-1); - } - if (sb.st_size / blklen + 1 > UINT_MAX || sb.st_size < blklen) { - warnx("file %s has invalid size",file); + if (tr->sz / tr->blklen + 1 > UINT_MAX || tr->sz < tr->blklen) { + warnx("file %s has invalid size",tr->file); return (-1); } - if (type == 'a') - sb.st_size -= WAVHDRLEN; - if (sb.st_size % blklen) { - warnx("file %s is not multiple of block length %d",file,blklen); - end_lba = sb.st_size / blklen + lba + 1; + if (tr->type == 'a') + tr->sz -= WAVHDRLEN; + if (tr->sz % tr->blklen) { + warnx("file %s is not multiple of block length %d", tr->file, tr->blklen); + end_lba = tr->sz / tr->blklen + lba + 1; } else { - end_lba = sb.st_size / blklen + lba; + end_lba = tr->sz / tr->blklen + lba; } - rfd = open(file, O_RDONLY, 0640); - if (type == 'a') { + rfd = open(tr->file, O_RDONLY, 0640); + if (tr->type == 'a') { if (lseek(rfd, WAVHDRLEN, SEEK_SET) == -1) err(1, "seek failed"); } while ((lba < end_lba) && (nblk != 0)) { while (lba + nblk <= end_lba) { - read(rfd, databuf, nblk * blklen); + read(rfd, databuf, nblk * tr->blklen); scr.cmd[8] = nblk; - scr.datalen = nblk * blklen; + scr.datalen = nblk * tr->blklen; r = ioctl(fd, SCIOCCOMMAND, &scr); if (r != 0) { warn("ioctl failed while attempting to write"); |