diff options
-rw-r--r-- | sys/scsi/cd.c | 21 | ||||
-rw-r--r-- | sys/sys/endian.h | 13 |
2 files changed, 20 insertions, 14 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index 2deb29ec3c3..44419601619 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.38 1999/07/20 09:41:41 csapuntz Exp $ */ +/* $OpenBSD: cd.c,v 1.39 1999/07/21 05:58:25 csapuntz Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -875,9 +875,7 @@ cdioctl(dev, cmd, addr, flag, p) if ((error = cd_read_toc(cd, 0, 0, &th, sizeof(th), 0)) != 0) return (error); if (cd->sc_link->quirks & ADEV_LITTLETOC) { -#if BYTE_ORDER == BIG_ENDIAN - bswap((u_int8_t *)&th.len, sizeof(th.len)); -#endif + th.len = letoh16(th.len); } else th.len = ntohs(th.len); bcopy(&th, addr, sizeof(th)); @@ -917,16 +915,14 @@ cdioctl(dev, cmd, addr, flag, p) cte->addr_type = CD_LBA_FORMAT; if (cd->sc_link->quirks & ADEV_LITTLETOC) { #if BYTE_ORDER == BIG_ENDIAN - bswap((u_int8_t*)&cte->addr, - sizeof(cte->addr)); + swap16_multi((u_int16_t *)&cte->addr, + sizeof(cte->addr) / 2); #endif } else cte->addr.lba = ntohl(cte->addr.lba); } if (cd->sc_link->quirks & ADEV_LITTLETOC) { -#if BYTE_ORDER == BIG_ENDIAN - bswap((u_int8_t*)&th->len, sizeof(th->len)); -#endif + th->len = letoh16(th->len); } else th->len = ntohs(th->len); len = min(len, th->len - (sizeof(th->starting_track) + @@ -960,14 +956,13 @@ cdioctl(dev, cmd, addr, flag, p) cte = &toc->entries[0]; if (cd->sc_link->quirks & ADEV_LITTLETOC) { #if BYTE_ORDER == BIG_ENDIAN - bswap((u_int8_t*)&cte->addr, sizeof(cte->addr)); + swap16_multi((u_int16_t *)&cte->addr, + sizeof(cte->addr) / 2); #endif } else cte->addr.lba = ntohl(cte->addr.lba); if (cd->sc_link->quirks & ADEV_LITTLETOC) { -#if BYTE_ORDER == BIG_ENDIAN - bswap((u_int8_t*)&toc->header.len, sizeof(toc->header.len)); -#endif + toc->header.len = letoh16(toc->header.len); } else toc->header.len = ntohs(toc->header.len); diff --git a/sys/sys/endian.h b/sys/sys/endian.h index 5e9bee14be4..1cd9f4b0919 100644 --- a/sys/sys/endian.h +++ b/sys/sys/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.3 1997/11/30 18:50:17 millert Exp $ */ +/* $OpenBSD: endian.h,v 1.4 1999/07/21 05:58:25 csapuntz Exp $ */ /*- * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. @@ -112,6 +112,17 @@ #define swap32 __swap32gen #endif /* MD_SWAP */ +#define swap16_multi(v, n) do { \ + size_t __swap16_multi_n = (n); \ + u_int16_t *__swap16_multi_v = (v); \ + \ + while (__swap16_multi_n) { \ + *__swap16_multi_v = swap16(*__swap16_multi_v); \ + __swap16_multi_v++; \ + __swap16_multi_n--; \ + } \ +} while (0) + __BEGIN_DECLS u_int32_t htobe32 __P((u_int32_t)); u_int16_t htobe16 __P((u_int16_t)); |