FAQ
In C language:

#include <stdio.h>

#include <stdlib.h>


typedef struct sg_io_hdr

{

     int interface_id; /* [i] 'S' (required) */

     int dxfer_direction; /* [i] */

     unsigned char cmd_len; /* [i] */

     unsigned char mx_sb_len; /* [i] */

     unsigned short iovec_count; /* [i] */

     unsigned int dxfer_len; /* [i] */

     void * dxferp; /* [i], [*io] */

     unsigned char * cmdp; /* [i], [*i] */

     unsigned char * sbp; /* [i], [*o] */

     unsigned int timeout; /* [i] unit: millisecs */

     unsigned int flags; /* [i] */

     int pack_id; /* [i->o] */

     void * usr_ptr; /* [i->o] */

     unsigned char status; /* [o] */

     unsigned char masked_status;/* [o] */

     unsigned char msg_status; /* [o] */

     unsigned char sb_len_wr; /* [o] */

     unsigned short host_status; /* [o] */

     unsigned short driver_status;/* [o] */

     int resid; /* [o] */

     unsigned int duration; /* [o] */

     unsigned int info; /* [o] */

} sg_io_hdr_t; /* 64 bytes long (on i386) */


In Go:


// Data that is passed to/from ioctl calls

type SgIoHeader struct {

     interface_id int

     dxfer_direction int

     cmd_len uint8

     mx_sb_len uint8

     iovect_count uint16

     dxfer_len uint32

     dxferp uint64

     cmdp uint64

     sbp uint64

     timeout uint32

     flags uint32

     pack_id int

     usr_ptr uint64

     status uint8

     masked_status uint8

     msg_status uint8

     sb_len_wr uint16

     host_status uint16

     driver_status uint16

     resid int

     duration uint32

     info uint32

}

On 64-bit machine, using C, the size is 88 bytes; while using go, the size
is 96 bytes.


Looks the alignment mechanism is different. Anybody can shed some light on
this?


I want to port this to Go and access disk info using Go.


Thanks,


Roy

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Paul Borman at Aug 19, 2015 at 4:02 pm
    A quick way to find out for yourself is to find the offset of each field
    from each language and then compare them. I bet you will find that
    alignment is different.
    On Tue, Aug 18, 2015 at 11:24 PM, Roy Yang wrote:

    In C language:

    #include <stdio.h>

    #include <stdlib.h>


    typedef struct sg_io_hdr

    {

    int interface_id; /* [i] 'S' (required) */

    int dxfer_direction; /* [i] */

    unsigned char cmd_len; /* [i] */

    unsigned char mx_sb_len; /* [i] */

    unsigned short iovec_count; /* [i] */

    unsigned int dxfer_len; /* [i] */

    void * dxferp; /* [i], [*io] */

    unsigned char * cmdp; /* [i], [*i] */

    unsigned char * sbp; /* [i], [*o] */

    unsigned int timeout; /* [i] unit: millisecs */

    unsigned int flags; /* [i] */

    int pack_id; /* [i->o] */

    void * usr_ptr; /* [i->o] */

    unsigned char status; /* [o] */

    unsigned char masked_status;/* [o] */

    unsigned char msg_status; /* [o] */

    unsigned char sb_len_wr; /* [o] */

    unsigned short host_status; /* [o] */

    unsigned short driver_status;/* [o] */

    int resid; /* [o] */

    unsigned int duration; /* [o] */

    unsigned int info; /* [o] */

    } sg_io_hdr_t; /* 64 bytes long (on i386) */


    In Go:


    // Data that is passed to/from ioctl calls

    type SgIoHeader struct {

    interface_id int

    dxfer_direction int

    cmd_len uint8

    mx_sb_len uint8

    iovect_count uint16

    dxfer_len uint32

    dxferp uint64

    cmdp uint64

    sbp uint64

    timeout uint32

    flags uint32

    pack_id int

    usr_ptr uint64

    status uint8

    masked_status uint8

    msg_status uint8

    sb_len_wr uint16

    host_status uint16

    driver_status uint16

    resid int

    duration uint32

    info uint32

    }

    On 64-bit machine, using C, the size is 88 bytes; while using go, the size
    is 96 bytes.


    Looks the alignment mechanism is different. Anybody can shed some light on
    this?


    I want to port this to Go and access disk info using Go.


    Thanks,


    Roy

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrey mirtchovski at Aug 19, 2015 at 4:02 pm
    on a 64-bit machine Go's ints are 64 bit. it's very likely that your C
    ints are 32 bit.
    On Wed, Aug 19, 2015 at 12:24 AM, Roy Yang wrote:
    In C language:

    #include <stdio.h>

    #include <stdlib.h>


    typedef struct sg_io_hdr

    {

    int interface_id; /* [i] 'S' (required) */

    int dxfer_direction; /* [i] */

    unsigned char cmd_len; /* [i] */

    unsigned char mx_sb_len; /* [i] */

    unsigned short iovec_count; /* [i] */

    unsigned int dxfer_len; /* [i] */

    void * dxferp; /* [i], [*io] */

    unsigned char * cmdp; /* [i], [*i] */

    unsigned char * sbp; /* [i], [*o] */

    unsigned int timeout; /* [i] unit: millisecs */

    unsigned int flags; /* [i] */

    int pack_id; /* [i->o] */

    void * usr_ptr; /* [i->o] */

    unsigned char status; /* [o] */

    unsigned char masked_status;/* [o] */

    unsigned char msg_status; /* [o] */

    unsigned char sb_len_wr; /* [o] */

    unsigned short host_status; /* [o] */

    unsigned short driver_status;/* [o] */

    int resid; /* [o] */

    unsigned int duration; /* [o] */

    unsigned int info; /* [o] */

    } sg_io_hdr_t; /* 64 bytes long (on i386) */


    In Go:


    // Data that is passed to/from ioctl calls

    type SgIoHeader struct {

    interface_id int

    dxfer_direction int

    cmd_len uint8

    mx_sb_len uint8

    iovect_count uint16

    dxfer_len uint32

    dxferp uint64

    cmdp uint64

    sbp uint64

    timeout uint32

    flags uint32

    pack_id int

    usr_ptr uint64

    status uint8

    masked_status uint8

    msg_status uint8

    sb_len_wr uint16

    host_status uint16

    driver_status uint16

    resid int

    duration uint32

    info uint32

    }

    On 64-bit machine, using C, the size is 88 bytes; while using go, the size
    is 96 bytes.


    Looks the alignment mechanism is different. Anybody can shed some light on
    this?


    I want to port this to Go and access disk info using Go.


    Thanks,


    Roy

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Roy Yang at Aug 19, 2015 at 4:06 pm
    Thanks, I figure out this already.

    The root cause is that Go's ints are 64 bit.

    Making the int as int32 solving the issue.

    Roy
    On Wed, Aug 19, 2015 at 9:02 AM, andrey mirtchovski wrote:

    on a 64-bit machine Go's ints are 64 bit. it's very likely that your C
    ints are 32 bit.
    On Wed, Aug 19, 2015 at 12:24 AM, Roy Yang wrote:
    In C language:

    #include <stdio.h>

    #include <stdlib.h>


    typedef struct sg_io_hdr

    {

    int interface_id; /* [i] 'S' (required) */

    int dxfer_direction; /* [i] */

    unsigned char cmd_len; /* [i] */

    unsigned char mx_sb_len; /* [i] */

    unsigned short iovec_count; /* [i] */

    unsigned int dxfer_len; /* [i] */

    void * dxferp; /* [i], [*io] */

    unsigned char * cmdp; /* [i], [*i] */

    unsigned char * sbp; /* [i], [*o] */

    unsigned int timeout; /* [i] unit: millisecs */

    unsigned int flags; /* [i] */

    int pack_id; /* [i->o] */

    void * usr_ptr; /* [i->o] */

    unsigned char status; /* [o] */

    unsigned char masked_status;/* [o] */

    unsigned char msg_status; /* [o] */

    unsigned char sb_len_wr; /* [o] */

    unsigned short host_status; /* [o] */

    unsigned short driver_status;/* [o] */

    int resid; /* [o] */

    unsigned int duration; /* [o] */

    unsigned int info; /* [o] */

    } sg_io_hdr_t; /* 64 bytes long (on i386) */


    In Go:


    // Data that is passed to/from ioctl calls

    type SgIoHeader struct {

    interface_id int

    dxfer_direction int

    cmd_len uint8

    mx_sb_len uint8

    iovect_count uint16

    dxfer_len uint32

    dxferp uint64

    cmdp uint64

    sbp uint64

    timeout uint32

    flags uint32

    pack_id int

    usr_ptr uint64

    status uint8

    masked_status uint8

    msg_status uint8

    sb_len_wr uint16

    host_status uint16

    driver_status uint16

    resid int

    duration uint32

    info uint32

    }

    On 64-bit machine, using C, the size is 88 bytes; while using go, the size
    is 96 bytes.


    Looks the alignment mechanism is different. Anybody can shed some light on
    this?


    I want to port this to Go and access disk info using Go.


    Thanks,


    Roy

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Brad Fitzpatrick at Aug 21, 2015 at 2:51 am

    On Thu, Aug 20, 2015 at 1:06 AM, Roy Yang wrote:

    Thanks, I figure out this already.

    The root cause is that Go's ints are 64 bit.
    No, Go's ints depends on the architecture. (either 32- or 64-bit)

    Don't use "int" when size matters.

    Making the int as int32 solving the issue.

    Roy

    On Wed, Aug 19, 2015 at 9:02 AM, andrey mirtchovski <mirtchovski@gmail.com
    wrote:
    on a 64-bit machine Go's ints are 64 bit. it's very likely that your C
    ints are 32 bit.
    On Wed, Aug 19, 2015 at 12:24 AM, Roy Yang wrote:
    In C language:

    #include <stdio.h>

    #include <stdlib.h>


    typedef struct sg_io_hdr

    {

    int interface_id; /* [i] 'S' (required) */

    int dxfer_direction; /* [i] */

    unsigned char cmd_len; /* [i] */

    unsigned char mx_sb_len; /* [i] */

    unsigned short iovec_count; /* [i] */

    unsigned int dxfer_len; /* [i] */

    void * dxferp; /* [i], [*io] */

    unsigned char * cmdp; /* [i], [*i] */

    unsigned char * sbp; /* [i], [*o] */

    unsigned int timeout; /* [i] unit: millisecs */

    unsigned int flags; /* [i] */

    int pack_id; /* [i->o] */

    void * usr_ptr; /* [i->o] */

    unsigned char status; /* [o] */

    unsigned char masked_status;/* [o] */

    unsigned char msg_status; /* [o] */

    unsigned char sb_len_wr; /* [o] */

    unsigned short host_status; /* [o] */

    unsigned short driver_status;/* [o] */

    int resid; /* [o] */

    unsigned int duration; /* [o] */

    unsigned int info; /* [o] */

    } sg_io_hdr_t; /* 64 bytes long (on i386) */


    In Go:


    // Data that is passed to/from ioctl calls

    type SgIoHeader struct {

    interface_id int

    dxfer_direction int

    cmd_len uint8

    mx_sb_len uint8

    iovect_count uint16

    dxfer_len uint32

    dxferp uint64

    cmdp uint64

    sbp uint64

    timeout uint32

    flags uint32

    pack_id int

    usr_ptr uint64

    status uint8

    masked_status uint8

    msg_status uint8

    sb_len_wr uint16

    host_status uint16

    driver_status uint16

    resid int

    duration uint32

    info uint32

    }

    On 64-bit machine, using C, the size is 88 bytes; while using go, the size
    is 96 bytes.


    Looks the alignment mechanism is different. Anybody can shed some light on
    this?


    I want to port this to Go and access disk info using Go.


    Thanks,


    Roy

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Roy Yang at Aug 21, 2015 at 4:16 am
    Thanks,
    This clarifies my understanding.

    Roy
    On Thu, Aug 20, 2015 at 7:51 PM, Brad Fitzpatrick wrote:


    On Thu, Aug 20, 2015 at 1:06 AM, Roy Yang wrote:

    Thanks, I figure out this already.

    The root cause is that Go's ints are 64 bit.
    No, Go's ints depends on the architecture. (either 32- or 64-bit)

    Don't use "int" when size matters.

    Making the int as int32 solving the issue.

    Roy

    On Wed, Aug 19, 2015 at 9:02 AM, andrey mirtchovski <
    mirtchovski@gmail.com> wrote:
    on a 64-bit machine Go's ints are 64 bit. it's very likely that your C
    ints are 32 bit.
    On Wed, Aug 19, 2015 at 12:24 AM, Roy Yang wrote:
    In C language:

    #include <stdio.h>

    #include <stdlib.h>


    typedef struct sg_io_hdr

    {

    int interface_id; /* [i] 'S' (required) */

    int dxfer_direction; /* [i] */

    unsigned char cmd_len; /* [i] */

    unsigned char mx_sb_len; /* [i] */

    unsigned short iovec_count; /* [i] */

    unsigned int dxfer_len; /* [i] */

    void * dxferp; /* [i], [*io] */

    unsigned char * cmdp; /* [i], [*i] */

    unsigned char * sbp; /* [i], [*o] */

    unsigned int timeout; /* [i] unit: millisecs */

    unsigned int flags; /* [i] */

    int pack_id; /* [i->o] */

    void * usr_ptr; /* [i->o] */

    unsigned char status; /* [o] */

    unsigned char masked_status;/* [o] */

    unsigned char msg_status; /* [o] */

    unsigned char sb_len_wr; /* [o] */

    unsigned short host_status; /* [o] */

    unsigned short driver_status;/* [o] */

    int resid; /* [o] */

    unsigned int duration; /* [o] */

    unsigned int info; /* [o] */

    } sg_io_hdr_t; /* 64 bytes long (on i386) */


    In Go:


    // Data that is passed to/from ioctl calls

    type SgIoHeader struct {

    interface_id int

    dxfer_direction int

    cmd_len uint8

    mx_sb_len uint8

    iovect_count uint16

    dxfer_len uint32

    dxferp uint64

    cmdp uint64

    sbp uint64

    timeout uint32

    flags uint32

    pack_id int

    usr_ptr uint64

    status uint8

    masked_status uint8

    msg_status uint8

    sb_len_wr uint16

    host_status uint16

    driver_status uint16

    resid int

    duration uint32

    info uint32

    }

    On 64-bit machine, using C, the size is 88 bytes; while using go, the size
    is 96 bytes.


    Looks the alignment mechanism is different. Anybody can shed some light on
    this?


    I want to port this to Go and access disk info using Go.


    Thanks,


    Roy

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 19, '15 at 3:40p
activeAug 21, '15 at 4:16a
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase