diff options
author | Michael Coulter <mjc@cvs.openbsd.org> | 2006-06-01 07:12:19 +0000 |
---|---|---|
committer | Michael Coulter <mjc@cvs.openbsd.org> | 2006-06-01 07:12:19 +0000 |
commit | 2aeabb9b1249e14bb5c85026fb3715d1e1a1356f (patch) | |
tree | 04183f3bb10aba9953b7abe9763fd5f71f5e15e4 /usr.bin | |
parent | fe5653519d4299584ef926c50e50d5899d6e4e12 (diff) |
add checks for disc size before we set out trying to burn 4gb
onto an unsuspecting cdr
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cdio/cdio.c | 20 | ||||
-rw-r--r-- | usr.bin/cdio/extern.h | 2 | ||||
-rw-r--r-- | usr.bin/cdio/mmc.c | 33 |
3 files changed, 48 insertions, 7 deletions
diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index a7b6dd553c4..42fd279ef6a 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.49 2006/06/01 06:32:17 mjc Exp $ */ +/* $OpenBSD: cdio.c,v 1.50 2006/06/01 07:12:18 mjc Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -226,6 +226,9 @@ main(int argc, char **argv) struct stat sb; struct track_info *cur_track; struct track_info *tr; + off_t availblk,needblk = 0; + u_int blklen; + u_int ntracks = 0; char type; cdname = getenv("DISC"); @@ -271,6 +274,7 @@ main(int argc, char **argv) usage(); SLIST_INIT(&tracks); type = 'd'; + blklen = 2048; while (argc > 1) { tr = malloc(sizeof(struct track_info)); tr->type = type; @@ -280,15 +284,18 @@ main(int argc, char **argv) switch (ch) { case 'a': type = 'a'; + blklen = 2352; break; case 'd': type = 'd'; + blklen = 2048; break; default: usage(); } } tr->type = type; + tr->blklen = blklen; argc -= optind; argv += optind; if (argv[0] == NULL) @@ -299,6 +306,8 @@ main(int argc, char **argv) return (-1); } tr->sz = sb.st_size; + if (tr->type == 'a') + tr->sz -= WAVHDRLEN; if (SLIST_EMPTY(&tracks)) SLIST_INSERT_HEAD(&tracks,tr,track_list); else @@ -307,6 +316,15 @@ main(int argc, char **argv) } if (! open_cd(cdname, 1)) exit(1); + get_disc_size(&availblk); + SLIST_FOREACH(tr, &tracks, track_list) { + needblk += tr->sz/tr->blklen; + ntracks++; + } + needblk += (ntracks - 1) * 150; /* transition area between tracks */ + if (needblk > availblk) + errx(1,"Only %llu of the required %llu blocks available", + availblk,needblk); if (writetao(&tracks) != 0) exit(1); else diff --git a/usr.bin/cdio/extern.h b/usr.bin/cdio/extern.h index c9078c01ea6..3096ffb7f3a 100644 --- a/usr.bin/cdio/extern.h +++ b/usr.bin/cdio/extern.h @@ -46,6 +46,7 @@ extern int blank(void); extern int unit_ready(void); extern int synchronize_cache(void); extern int close_session(void); +extern int get_disc_size(off_t *); extern int get_nwa(int *); extern int writetao(struct track_head *); extern int writetrack(struct track_info *); @@ -53,3 +54,4 @@ extern int mode_sense_write(unsigned char []); extern int mode_select_write(unsigned char []); #define VERSION "2.1" +#define WAVHDRLEN 44 diff --git a/usr.bin/cdio/mmc.c b/usr.bin/cdio/mmc.c index 4414aec2512..7ff773230aa 100644 --- a/usr.bin/cdio/mmc.c +++ b/usr.bin/cdio/mmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmc.c,v 1.5 2006/06/01 06:32:17 mjc Exp $ */ +/* $OpenBSD: mmc.c,v 1.6 2006/06/01 07:12:18 mjc Exp $ */ /* * Copyright (c) 2006 Michael Coulter <mjc@openbsd.org> * @@ -26,7 +26,6 @@ #include <unistd.h> #include "extern.h" -#define WAVHDRLEN 44 extern int errno; extern int fd; extern char *cdname; @@ -136,13 +135,11 @@ writetao(struct track_head *thp) 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 */ - 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 */ - tr->blklen = 2352; break; default: warn("impossible tracktype detected"); @@ -195,8 +192,6 @@ writetrack(struct track_info *tr) warnx("file %s has invalid size",tr->file); return (-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; @@ -280,6 +275,32 @@ mode_select_write(unsigned char buf[]) } int +get_disc_size(off_t *availblk) +{ + u_char databuf[28]; + scsireq_t scr; + int r,tmp; + + bzero(&scr, sizeof(scr)); + scr.timeout = 4000; + scr.senselen = SENSEBUFLEN; + scr.cmd[0] = 0x52; /* READ TRACK INFO */ + scr.cmd[1] = 0x01; + scr.cmd[5] = 0x01; /* Track 01 */ + scr.cmd[7] = 0x00; + scr.cmd[8] = 0x1c; + scr.cmdlen = 10; + scr.datalen= 0x1c; + scr.flags = SCCMD_ESCAPE|SCCMD_READ; + scr.databuf = (caddr_t)databuf; + + r = ioctl(fd, SCIOCCOMMAND, &scr); + memcpy(&tmp, &databuf[16], sizeof(tmp)); + *availblk = betoh32(tmp); + return (r == 0 ? scr.retsts : -1); +} + +int get_nwa(int *nwa) { u_char databuf[28]; |