Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/scsipi Use be16toh(), be32toh(), le16toh() and le32t...
details: https://anonhg.NetBSD.org/src/rev/cdbe051ba558
branches: trunk
changeset: 514424:cdbe051ba558
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Sun Sep 02 13:11:53 2001 +0000
description:
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?
diffstat:
sys/dev/scsipi/cd.c | 51 ++++++++++++++++----------------------------
sys/dev/scsipi/scsipiconf.h | 15 +------------
2 files changed, 20 insertions(+), 46 deletions(-)
diffs (114 lines):
diff -r 975ccef44f60 -r cdbe051ba558 sys/dev/scsipi/cd.c
--- a/sys/dev/scsipi/cd.c Sun Sep 02 08:45:22 2001 +0000
+++ b/sys/dev/scsipi/cd.c Sun Sep 02 13:11:53 2001 +0000
@@ -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 @@
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 @@
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 @@
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;
diff -r 975ccef44f60 -r cdbe051ba558 sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h Sun Sep 02 08:45:22 2001 +0000
+++ b/sys/dev/scsipi/scsipiconf.h Sun Sep 02 13:11:53 2001 +0000
@@ -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 @@
__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 @@
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_ */
Home |
Main Index |
Thread Index |
Old Index