Use be16toh(), be32toh(), le16toh() and le32toh() rather than

ntohs(), ntohl() or homegrown bswap() functions.

XXX Does anyone use drives with PQUIRK_LITTLETOC on big endian machines?
This commit is contained in:
tsutsui 2001-09-02 13:11:53 +00:00
parent 8d327e93bf
commit 354cce66e5
2 changed files with 20 additions and 46 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd.c,v 1.156 2001/08/20 15:45:10 ad Exp $ */
/* $NetBSD: cd.c,v 1.157 2001/09/02 13:11:53 tsutsui Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@ -1225,12 +1225,10 @@ cdioctl(dev, cmd, addr, flag, p)
if ((error = cd_read_toc(cd, 0, 0, &th, sizeof(th),
XS_CTL_DATA_ONSTACK, 0)) != 0)
return (error);
if (cd->sc_periph->periph_quirks & PQUIRK_LITTLETOC) {
#if BYTE_ORDER == BIG_ENDIAN
bswap((u_int8_t *)&th.len, sizeof(th.len));
#endif
} else
th.len = ntohs(th.len);
if (cd->sc_periph->periph_quirks & PQUIRK_LITTLETOC)
th.len = le16toh(th.len);
else
th.len = be16toh(th.len);
memcpy(addr, &th, sizeof(th));
return (0);
}
@ -1259,20 +1257,15 @@ cdioctl(dev, cmd, addr, flag, p)
ntracks >= 0; ntracks--) {
cte = &toc.entries[ntracks];
cte->addr_type = CD_LBA_FORMAT;
if (periph->periph_quirks & PQUIRK_LITTLETOC) {
#if BYTE_ORDER == BIG_ENDIAN
bswap((u_int8_t*)&cte->addr,
sizeof(cte->addr));
#endif
} else
cte->addr.lba = ntohl(cte->addr.lba);
if (periph->periph_quirks & PQUIRK_LITTLETOC)
cte->addr.lba = le32toh(cte->addr.lba);
else
cte->addr.lba = be32toh(cte->addr.lba);
}
if (periph->periph_quirks & PQUIRK_LITTLETOC) {
#if BYTE_ORDER == BIG_ENDIAN
bswap((u_int8_t*)&th->len, sizeof(th->len));
#endif
} else
th->len = ntohs(th->len);
if (periph->periph_quirks & PQUIRK_LITTLETOC)
th->len = le16toh(th->len);
else
th->len = be16toh(th->len);
len = min(len, th->len - (sizeof(th->starting_track) +
sizeof(th->ending_track)));
return (copyout(toc.entries, te->data, len));
@ -1295,18 +1288,12 @@ cdioctl(dev, cmd, addr, flag, p)
cte = &toc.entries[0];
if (periph->periph_quirks & PQUIRK_LITTLETOC) {
#if BYTE_ORDER == BIG_ENDIAN
bswap((u_int8_t*)&cte->addr, sizeof(cte->addr));
#endif
} else
cte->addr.lba = ntohl(cte->addr.lba);
if (periph->periph_quirks & PQUIRK_LITTLETOC) {
#if BYTE_ORDER == BIG_ENDIAN
bswap((u_int8_t*)&toc.header.len,
sizeof(toc.header.len));
#endif
} else
toc.header.len = ntohs(toc.header.len);
cte->addr.lba = le32toh(cte->addr.lba);
toc.header.len = le16toh(toc.header.len);
} else {
cte->addr.lba = be32toh(cte->addr.lba);
toc.header.len = be16toh(toc.header.len);
}
*(int*)addr = (toc.header.len >= 10 && cte->track > 1) ?
cte->addr.lba : 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: scsipiconf.h,v 1.56 2001/08/31 07:09:42 augustss Exp $ */
/* $NetBSD: scsipiconf.h,v 1.57 2001/09/02 13:11:53 tsutsui Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@ -714,8 +714,6 @@ static __inline u_int32_t _3ltol __P((const u_int8_t *bytes))
__attribute__ ((unused));
static __inline u_int32_t _4ltol __P((const u_int8_t *bytes))
__attribute__ ((unused));
static __inline void bswap __P((char *, int))
__attribute__ ((unused));
static __inline void
_lto2b(val, bytes)
@ -855,15 +853,4 @@ _4ltol(bytes)
return (rv);
}
static __inline void
bswap (buf, len)
char *buf;
int len;
{
u_int16_t *p = (u_int16_t *)(buf + len);
while (--p >= (u_int16_t *)buf)
*p = (*p & 0xff) << 8 | (*p >> 8 & 0xff);
}
#endif /* _DEV_SCSIPI_SCSIPICONF_H_ */