From: bqt@softjar.se (Johnny Billquist)
Subject: [pups] extract old archive format?
Date: Fri, 09 Apr 2010 12:15:03 +0200 [thread overview]
Message-ID: <4BBEFE27.1080104@softjar.se> (raw)
In-Reply-To: <alpine.NEB.2.01.1004082057300.13963@t1.m.reedmedia.net>
Jeremy C. Reed wrote:
> Well I found the ar specification (in ar.5 not ar.1).
>
> struct ar_hdr {
> char ar_name[14];
> long ar_date;
> char ar_uid;
> char ar_gid;
> int ar_mode;
> long ar_size;
> };
Simple enough... :-)
> This is same as the old ar.c source.
>
> (plus more in the manual page.)
>
> Now my problem is I don't know what "long" or "int" is on the old PDP-11
> / system 5 this was made on.
An int on the pdp11 is 16 bits, and a long is 32.
Remember? int is whatever size is most convenient for the architecture? :-)
> And I read about PDP-11 "middle endianess" (first time I heard of
> "middle").
A mess, but we have to live with it.
In short, the bytes of a long on a PDP11 is likely laid out like this:
3412
So, the 16-bit values are each little-endian, but the 16 bit values as
such, in the 32-bit view, is laid out as big-endian.
Thus middle-endian... :-)
> So I had (wrong but gets ar_name and ar_size correct for my few tests
> for the first header but chops two characters into the data section).
>
> struct {
> char ar_name[14];
> int32_t ar_date;
> char ar_uid;
> char ar_gid;
> uint16_t ar_mode;
> uint16_t ar_size;
> } ar_buf;
>
> Well I know above is wrong because ar_size and ar_date should be the
> same. But I get ar_size correct each time. But it also loses the next
> two bytes from the data. So I am guessing I have some endian issue where
> I am getting some things reversed.
>
> Any ideas?
As others already said, it's your compiler trying to optimize the
alignments.
One solution (already presented) is to just play with 16-bit values.
You could also explain to the compiler that it shouldn't try to optimize
the alignments, but since you have to deal with the middle-endianess
anyway, you are probably better off just looking at 16-bit values and
combine them into 32-bit values as needed yourself.
Johnny
next prev parent reply other threads:[~2010-04-09 10:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-09 1:13 Norman Wilson
2010-04-09 2:11 ` Jeremy C. Reed
2010-04-09 10:15 ` Johnny Billquist [this message]
2010-04-09 5:49 ` Bob Eager
[not found] <337550.74945.qm@web82407.mail.mud.yahoo.com>
2010-04-09 5:35 ` Jeremy C. Reed
-- strict thread matches above, loose matches on Subject: below --
2010-04-09 2:40 John Holden
[not found] ` <n2m5904d5731004082137u5b054823wd4a9ce55113b1dee@mail.gmail.com>
2010-04-09 4:39 ` Carl Lowenstein
2010-04-09 10:23 ` Johnny Billquist
2010-04-09 10:21 ` Johnny Billquist
2010-04-08 13:25 Jeremy C. Reed
2010-04-08 14:49 ` Tim Bradshaw
2010-04-08 15:16 ` Brantley Coile
2010-04-08 17:09 ` Bob Eager
2010-04-09 5:11 ` Warren Toomey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BBEFE27.1080104@softjar.se \
--to=bqt@softjar.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).