Skip to content

Commit

Permalink
switch usage of unaligned.h to sg_unaligned.h
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools@4727 4ea69e1a-61f1-4043-bf83-b5c94c648137
  • Loading branch information
dpgilbert committed Apr 16, 2018
1 parent 2cacd3d commit a134603
Show file tree
Hide file tree
Showing 10 changed files with 646 additions and 415 deletions.
18 changes: 18 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
$Id$

2018-04-16 Douglas Franke <[email protected]>

switch usage of unaligned.h to sg_unaligned.h which are functionally
the same. sg_unaligned.h is the same header used by libsgutils which
is the basis of the sg3_utils, sdparm and ddpt packages available on
many of the same architectures as smartmontools is. This change
introduces a "sg_" prefix on the inline functions defined
sg_unaligned.h . The new header has specializations for big and little
endian machines that depends on the non-standard bswap_16(), bswap_32()
and bswap_64() calls that are defined in the byteswap.h header which is
a GNU extension. According to the 'net both gcc and clang use intrinsics
{assembler ?} to implement these calls. If the byteswap.h header is not
present on the build machine, the generic implementations will be
used for the "unaligned" family of functions. Additionally the generic
implementations can be imposed with './configure --disable-fast-lebe'.
Developers may need to use './autogen.sh' prior to their normal build
sequence. Please report any problems to the author.

2018-03-28 Christian Franke <[email protected]>

ataprint.cpp, nvmeprint.cpp, scsiprint.cpp:
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ smartctl_SOURCES = \
scsiprint.h \
utility.cpp \
utility.h \
unaligned.h
sg_unaligned.h

smartctl_LDADD = $(os_deps) $(os_libs)
smartctl_DEPENDENCIES = $(os_deps)
Expand Down Expand Up @@ -152,7 +152,7 @@ smartd_SOURCES = \
scsiata.cpp \
utility.cpp \
utility.h \
unaligned.h
sg_unaligned.h

smartd_LDADD = $(os_deps) $(os_libs) $(CAPNG_LDADD)
smartd_DEPENDENCIES = $(os_deps)
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ AC_MSG_RESULT([$is_svn_build])

dnl Checks for header files.
AC_CHECK_HEADERS([locale.h])
AC_CHECK_HEADERS([byteswap.h], [], [], [])

case "$host" in
*-*-freebsd*|*-*-dragonfly*|*-*-kfreebsd*-gnu*)
Expand Down Expand Up @@ -319,6 +320,10 @@ AC_ARG_ENABLE([scsi-cdb-check],
AC_DEFINE_UNQUOTED(SCSI_CDB_CHECK, 1, [enable check on SCSI cdbs], )
)

AC_ARG_ENABLE([fast-lebe],
AC_HELP_STRING([--disable-fast-lebe], [use generic little-endian/big-endian code instead]),
[AC_DEFINE_UNQUOTED(IGNORE_FAST_LEBE, 1, [use generic little-endian/big-endian instead], )], [])

AC_ARG_WITH(os-deps,
[AS_HELP_STRING([--with-os-deps='os_module.o ...'], [Specify OS dependent module(s) [guessed]])],
[ for x in $with_os_deps; do
Expand Down
6 changes: 3 additions & 3 deletions json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
const char * json_cvsid = "$Id$"
JSON_H_CVSID;

#include "unaligned.h"
#include "sg_unaligned.h"

#include <stdexcept>

Expand Down Expand Up @@ -162,8 +162,8 @@ void json::ref::set_unsafe_uint128(uint64_t value_hi, uint64_t value_lo)

void json::ref::set_unsafe_le128(const void * pvalue)
{
set_unsafe_uint128(get_unaligned_le64((const uint8_t *)pvalue + 8),
get_unaligned_le64( pvalue ));
set_unsafe_uint128(sg_get_unaligned_le64((const uint8_t *)pvalue + 8),
sg_get_unaligned_le64( pvalue ));
}

json::node::node()
Expand Down
10 changes: 5 additions & 5 deletions nvmeprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const char * nvmeprint_cvsid = "$Id$"
#include "atacmds.h" // dont_print_serial_number
#include "scsicmds.h" // dStrHex()
#include "smartctl.h"
#include "unaligned.h"
#include "sg_unaligned.h"

using namespace smartmontools;

Expand Down Expand Up @@ -133,7 +133,7 @@ static void print_drive_info(const nvme_id_ctrl & id_ctrl, const nvme_id_ns & id

jout("IEEE OUI Identifier: 0x%02x%02x%02x\n",
id_ctrl.ieee[2], id_ctrl.ieee[1], id_ctrl.ieee[0]);
jglb["nvme_ieee_oui_identifier"] = get_unaligned_le(3, id_ctrl.ieee);
jglb["nvme_ieee_oui_identifier"] = sg_get_unaligned_le(3, id_ctrl.ieee);

// Capacity info is optional for devices without namespace management
if (show_all || le128_is_non_zero(id_ctrl.tnvmcap) || le128_is_non_zero(id_ctrl.unvmcap)) {
Expand Down Expand Up @@ -186,8 +186,8 @@ static void print_drive_info(const nvme_id_ctrl & id_ctrl, const nvme_id_ns & id
jout("Namespace %u IEEE EUI-64: %s%02x%02x%02x %02x%02x%02x%02x%02x\n",
nsid, align, id_ns.eui64[0], id_ns.eui64[1], id_ns.eui64[2], id_ns.eui64[3],
id_ns.eui64[4], id_ns.eui64[5], id_ns.eui64[6], id_ns.eui64[7]);
jrns["eui64"]["oui"] = get_unaligned_be(3, id_ns.eui64);
jrns["eui64"]["ext_id"] = get_unaligned_be(5, id_ns.eui64 + 3);
jrns["eui64"]["oui"] = sg_get_unaligned_be(3, id_ns.eui64);
jrns["eui64"]["ext_id"] = sg_get_unaligned_be(5, id_ns.eui64 + 3);
}
}

Expand Down Expand Up @@ -341,7 +341,7 @@ static void print_smart_log(const nvme_smart_log & smart_log, unsigned nsid,
jout("Critical Warning: 0x%02x\n", smart_log.critical_warning);
jref["critical_warning"] = smart_log.critical_warning;

int k = get_unaligned_le16(smart_log.temperature);
int k = sg_get_unaligned_le16(smart_log.temperature);
jout("Temperature: %s\n", kelvin_to_str(buf, k));
if (k) {
jref["temperature"] = k - 273;
Expand Down
10 changes: 5 additions & 5 deletions scsiata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include "dev_interface.h"
#include "dev_ata_cmd_set.h" // ata_device_with_command_set
#include "dev_tunnelled.h" // tunnelled_device<>
#include "unaligned.h"
#include "sg_unaligned.h"

const char * scsiata_cpp_cvsid = "$Id$";

Expand Down Expand Up @@ -1080,7 +1080,7 @@ bool usbjmicron_device::ata_pass_through(const ata_cmd_in & in, ata_cmd_out & ou
cdb[ 0] = 0xdf;
cdb[ 1] = (rwbit ? 0x10 : 0x00);
cdb[ 2] = 0x00;
put_unaligned_be16(io_hdr.dxfer_len, cdb + 3);
sg_put_unaligned_be16(io_hdr.dxfer_len, cdb + 3);
cdb[ 5] = in.in_regs.features;
cdb[ 6] = in.in_regs.sector_count;
cdb[ 7] = in.in_regs.lba_low;
Expand Down Expand Up @@ -1151,9 +1151,9 @@ bool usbjmicron_device::get_registers(unsigned short addr,
cdb[ 0] = 0xdf;
cdb[ 1] = 0x10;
cdb[ 2] = 0x00;
put_unaligned_be16(size, cdb + 3);
sg_put_unaligned_be16(size, cdb + 3);
cdb[ 5] = 0x00;
put_unaligned_be16(addr, cdb + 6);
sg_put_unaligned_be16(addr, cdb + 6);
cdb[ 8] = 0x00;
cdb[ 9] = 0x00;
cdb[10] = 0x00;
Expand Down Expand Up @@ -1265,7 +1265,7 @@ bool usbprolific_device::ata_pass_through(const ata_cmd_in & in, ata_cmd_out & o
cdb[ 3] = in.in_regs.features; // Feature register (SMART command)
cdb[ 4] = 0x06; // Check Word (VendorID magic, Prolific: 0x067B)
cdb[ 5] = 0x7B; // Check Word (VendorID magic, Prolific: 0x067B)
put_unaligned_be32(io_hdr.dxfer_len, cdb + 6);
sg_put_unaligned_be32(io_hdr.dxfer_len, cdb + 6);
cdb[10] = in.in_regs.sector_count; // Sector Count
cdb[11] = in.in_regs.lba_low; // LBA Low (7:0)
cdb[12] = in.in_regs.lba_mid; // LBA Mid (15:8)
Expand Down
Loading

0 comments on commit a134603

Please sign in to comment.