Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
First, you seem to not understand how to handle these lines:

__u8 cdte_adr :4; __u8 cdte_ctrl :4;

You are trying to unpack this with C4 which represents 4 one-byte values. The C code says that each of those represents one 4-bit value, thus both those values are probably packed with one-byte. (You'll need to seperate them later, with the various bitshifting operators, therefore. You can probably explore and see what part of the byte each value is stored in.). As for the integer that comes later, you'll probably need to add some bytes of padding (x in the format for unpack) so that it will be aligned propperly. On a 32-bit machine this would probably imply one byte of padding to align on a 32-bit boundry.

I would strongly advise that you avoid trying to unpack structures yourself. How they are packed is not always easy to fiquire out and is often dependent on the architecture being used. In some cases, it may even vary from compiler to compiler on that architecture. Writing a little bit of C to do it is likely to be more portable most of the time.

update: Oops. Forgot to talk about that union. The union can hold either the structure cdrom_addr or an int. Usually this means that it's packed such that storage is only allocated for one. This means you'll probably need to have to two formats one which does CCCx (for the struct, padding to match the size of the integer. You'll need more if your platform has ints larger then 32 bits.) and one with does i (for the integer) depending on which is there. This doesn't really seem ideal, however, given you have to look at the info in the struct to see which to use. One solution would be to have a format where you first unpack that field with the format a4 (update: where 4 may be another number if ints are larger then 32 bits), and then further unpack the results with the aforementioned formats. Or you could unpack it as an integer and use bit operations to extract the __u8 values, too.


In reply to Re: ioctl into or from perl structs by wog
in thread ioctl into or from perl structs by Rhandom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-18 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found