Are the extra 4 bytes padding at the end of the structure?  You can have C
print the offset of each element and then use unsafe.Offsetof to find the
same for the Go structure.  I am sure you will quickly discover where the
extra 4 bytes are (the C structure is probably padding to a word boundary
or one of the fields got word aligned.

On Tue, Dec 6, 2016 at 3:04 PM, Steven Logan <ste.l...@gmail.com> wrote:

> I am trying to interact with devices using the V4L2 API.  The API defines
> the following struct
>
> typedef __u64 v4l2_std_id
>
> struct v4l2_input {
>   __u32      index;
>   __u8       name[32];
>   __u32      type;
>   __u32      audioset;
>   __u32        tuner;
>   v4l2_std_id  std;
>   __u32      status;
>   __u32      capabilities;
>   __u32      reserved[3];
> };
>
> In Go I have replicated this struct with the following
>
> type StandardId uint64
>
> type Input struct {
> Index        uint32
> Name         [32]uint8
> Type         uint32
> Audioset     uint32
> Tuner        uint32
> Standard     StandardId
> Status       uint32
> Capabilities uint32
> reserved     [3]uint32
> }
>
> When I attempt to use the Go struct in an Ioctl call I get the following
> error
>
> EnumerateVideoInput:   inappropriate ioctl for device
>>
>
> I have managed to track this down to what appears to be a slight
> difference in the size of the structs.
> The Go struct has sizeof 76 bytes and the C struct has sizeof 80 bytes.
> This means the creation of my ioctl request value is incorrect as I
> generate a value of 3,226,228,250 and the actual C #define from
> linux/videodev2.h has value 3,226,490,394.
>
> Up to this point I have not had a problem replicating the C structs in Go
> and using them to call Ioctl, with calls succeeding and all fields being
> populated with the expected values so far.  It seems that the system calls
> in Go do not come with much documentation and I have seen a similar method
> to this used elsewhere online hence my adoption of this approach.
> My main goal was to avoid having to use CGO as this obviously comes with
> overhead on compilation time, etc.
>
> Assuming I haven't missed something glaringly obvious, is it possible to
> replicate the C structs in Go and use them in this way?
> What would be the recommended approach for using Ioctl?
> Does anyone know of some good resources for using the /x/sys/unix package
> (specifically Syscall related)?
>
> Thanks
>
> --
> 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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to