diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-08-03 23:37:08 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-08-03 23:37:08 +0000 |
commit | 55d29e030a46029d6fee23a3b3305333eb73cb50 (patch) | |
tree | 873c7420a80c38d7342e64304d423a2fe083074a | |
parent | d3e82ec52862cbf0dc9aaa9b40b852d0cc74a721 (diff) |
Move a couple of 2048+4 byte structures from the stack to the heap.
Create structures to eliminate 2048+4 magic number everywhere. Mostly
adapted from NetBSD.
tested by sturm@, beck@. ok beck@
-rw-r--r-- | sys/scsi/cd.c | 72 | ||||
-rw-r--r-- | sys/scsi/cd.h | 19 |
2 files changed, 61 insertions, 30 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index b3f8b4b8247..1b36e21938f 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.85 2005/06/11 14:49:54 krw Exp $ */ +/* $OpenBSD: cd.c,v 1.86 2005/08/03 23:37:07 krw Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -1936,23 +1936,29 @@ dvd_read_disckey(cd, s) struct cd_softc *cd; union dvd_struct *s; { - struct scsi_generic cmd; - u_int8_t buf[4 + 2048]; + struct scsi_read_dvd_structure cmd; + struct scsi_read_dvd_structure_data *buf; int error; + + buf = malloc(sizeof(*buf), M_TEMP, M_WAITOK); + if (buf == NULL) + return (ENOMEM); + bzero(buf, sizeof(*buf)); - bzero(cmd.bytes, sizeof(cmd.bytes)); - bzero(buf, sizeof(buf)); + bzero(&cmd, sizeof(cmd)); cmd.opcode = GPCMD_READ_DVD_STRUCTURE; - cmd.bytes[6] = s->type; - _lto2b(sizeof(buf), &cmd.bytes[7]); + cmd.format = s->type; + cmd.agid = s->disckey.agid << 6; + _lto2b(sizeof(*buf), cmd.length); - cmd.bytes[9] = s->disckey.agid << 6; - error = scsi_scsi_cmd(cd->sc_link, &cmd, sizeof(cmd), buf, sizeof(buf), - CDRETRIES, 30000, NULL, SCSI_DATA_IN); - if (error) - return (error); - bcopy(&buf[4], s->disckey.value, 2048); - return (0); + error = scsi_scsi_cmd(cd->sc_link, (struct scsi_generic *)&cmd, + sizeof(cmd), (u_char *)buf, sizeof(*buf), CDRETRIES, 30000, NULL, + SCSI_DATA_IN); + if (error == 0) + bcopy(buf->data, s->disckey.value, sizeof(s->disckey.value)); + + free(buf, M_TEMP); + return (error); } int @@ -1986,25 +1992,33 @@ dvd_read_manufact(cd, s) struct cd_softc *cd; union dvd_struct *s; { - struct scsi_generic cmd; - u_int8_t buf[4 + 2048]; + struct scsi_read_dvd_structure cmd; + struct scsi_read_dvd_structure_data *buf; int error; + + buf = malloc(sizeof(*buf), M_TEMP, M_WAITOK); + if (buf == NULL) + return (ENOMEM); + bzero(buf, sizeof(*buf)); - bzero(cmd.bytes, sizeof(cmd.bytes)); - bzero(buf, sizeof(buf)); + bzero(&cmd, sizeof(cmd)); cmd.opcode = GPCMD_READ_DVD_STRUCTURE; - cmd.bytes[6] = s->type; - _lto2b(sizeof(buf), &cmd.bytes[7]); + cmd.format = s->type; + _lto2b(sizeof(*buf), cmd.length); + + error = scsi_scsi_cmd(cd->sc_link, (struct scsi_generic *)&cmd, + sizeof(cmd), (u_char *)buf, sizeof(*buf), CDRETRIES, 30000, NULL, + SCSI_DATA_IN); + if (error == 0) { + s->manufact.len = _2btol(buf->len); + if (s->manufact.len >= 0 && s->manufact.len <= 2048) + bcopy(buf->data, s->manufact.value, s->manufact.len); + else + error = EIO; + } - error = scsi_scsi_cmd(cd->sc_link, &cmd, sizeof(cmd), buf, sizeof(buf), - CDRETRIES, 30000, NULL, SCSI_DATA_IN); - if (error) - return (error); - s->manufact.len = _2btol(&buf[0]); - if (s->manufact.len < 0 || s->manufact.len > 2048) - return (EIO); - bcopy(&buf[4], s->manufact.value, s->manufact.len); - return (0); + free(buf, M_TEMP); + return (error); } int diff --git a/sys/scsi/cd.h b/sys/scsi/cd.h index b3ff7050a68..9ac006fda6c 100644 --- a/sys/scsi/cd.h +++ b/sys/scsi/cd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.h,v 1.8 2005/07/02 15:39:55 krw Exp $ */ +/* $OpenBSD: cd.h,v 1.9 2005/08/03 23:37:07 krw Exp $ */ /* $NetBSD: scsi_cd.h,v 1.6 1996/03/19 03:06:39 mycroft Exp $ */ /* @@ -211,6 +211,23 @@ struct cd_audio_page { #define CDRETRIES 4 +struct scsi_read_dvd_structure { + u_int8_t opcode; /* GPCMD_READ_DVD_STRUCTURE */ + u_int8_t reserved; + u_int8_t address[4]; + u_int8_t layer; + u_int8_t format; + u_int8_t length[2]; + u_int8_t agid; /* bottom 6 bits reserved */ + u_int8_t control; +}; + +struct scsi_read_dvd_structure_data { + u_int8_t len[2]; /* Big-endian length of valid data. */ + u_int8_t reserved[2]; + u_int8_t data[2048]; +}; + #ifdef _KERNEL struct cd_softc { |