diff options
author | av <av@cvs.openbsd.org> | 2008-08-13 12:21:20 +0000 |
---|---|---|
committer | av <av@cvs.openbsd.org> | 2008-08-13 12:21:20 +0000 |
commit | 94345a96b6867ba746f48e4f629784c0e9764290 (patch) | |
tree | 5163ea34b2d3e57422b011dfc129fb25edf22676 /usr.bin/cdio | |
parent | 2a6b706b53fb10c22090dfe938393927ba883962 (diff) |
Old drives (reported Giovanni Bechis <bigionews@snb.it>) don't report CD-RW
write feature. Add additional check for media type before blanking.
The patch fixes problem for Giovanni.
ok fgsch
Diffstat (limited to 'usr.bin/cdio')
-rw-r--r-- | usr.bin/cdio/cdio.c | 5 | ||||
-rw-r--r-- | usr.bin/cdio/extern.h | 10 | ||||
-rw-r--r-- | usr.bin/cdio/mmc.c | 38 |
3 files changed, 49 insertions, 4 deletions
diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index cbf194afe42..a5d2a8900e9 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.65 2008/08/08 07:26:40 fgsch Exp $ */ +/* $OpenBSD: cdio.c,v 1.66 2008/08/13 12:21:19 av Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -517,7 +517,8 @@ run(int cmd, char *arg) warnx("Can't determine media type"); return (0); } - if ((mediacap & MEDIACAP_CDRW_WRITE) == 0) { + if ((mediacap & MEDIACAP_CDRW_WRITE) == 0 && + get_media_type() != MEDIATYPE_CDRW) { warnx("The media doesn't support blanking"); return (0); } diff --git a/usr.bin/cdio/extern.h b/usr.bin/cdio/extern.h index 6a6a45b716b..fd26816c000 100644 --- a/usr.bin/cdio/extern.h +++ b/usr.bin/cdio/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.12 2008/06/30 23:35:39 av Exp $ */ +/* $OpenBSD: extern.h,v 1.13 2008/08/13 12:21:19 av Exp $ */ /* * Copyright (c) 2002 Marc Espie. * @@ -60,12 +60,20 @@ SLIST_HEAD(track_head, track_info) tracks; */ #define CD_MAX_SPEED 380 +/* + * Media types + */ +#define MEDIATYPE_UNKNOWN 0 +#define MEDIATYPE_CDR 1 +#define MEDIATYPE_CDRW 2 + 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 **); +extern int get_media_type(void); extern int get_media_capabilities(int *cap); extern int blank(void); extern int unit_ready(void); diff --git a/usr.bin/cdio/mmc.c b/usr.bin/cdio/mmc.c index 4b76e8e747a..df9b898970a 100644 --- a/usr.bin/cdio/mmc.c +++ b/usr.bin/cdio/mmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmc.c,v 1.24 2008/08/08 07:26:40 fgsch Exp $ */ +/* $OpenBSD: mmc.c,v 1.25 2008/08/13 12:21:19 av Exp $ */ /* * Copyright (c) 2006 Michael Coulter <mjc@openbsd.org> * @@ -40,6 +40,42 @@ extern char *cdname; #define MMC_FEATURE_CDRW_WRITE 0x37 int +get_media_type(void) +{ + scsireq_t scr; + char buf[32]; + u_char disctype; + int rv, error; + + rv = MEDIATYPE_UNKNOWN; + memset(buf, 0, sizeof(buf)); + memset(&scr, 0, sizeof(scr)); + + scr.cmd[0] = READ_TOC; + scr.cmd[1] = 0x2; /* MSF */ + scr.cmd[2] = 0x4; /* ATIP */ + scr.cmd[8] = 0x20; + + scr.flags = SCCMD_ESCAPE | SCCMD_READ; + scr.databuf = buf; + scr.datalen = sizeof(buf); + scr.cmdlen = 10; + scr.timeout = 120000; + scr.senselen = SENSEBUFLEN; + + error = ioctl(fd, SCIOCCOMMAND, &scr); + if (error != -1 && scr.retsts == 0 && scr.datalen_used > 7) { + disctype = (buf[6] >> 6) & 0x1; + if (disctype == 0) + rv = MEDIATYPE_CDR; + else if (disctype == 1) + rv = MEDIATYPE_CDRW; + } + + return (rv); +} + +int get_media_capabilities(int *cap) { scsireq_t scr; |