Unix Technical Forum

Howto calc header checksum of AIX backup file?

This is a discussion on Howto calc header checksum of AIX backup file? within the AIX Operating System forums, part of the Unix Operating Systems category; --> Appologies for previous post. I'm writing an open source application to provide multi-vendor software packaging, written entirely in Python. ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 11:53 AM
Graham Bevan
 
Posts: n/a
Default Howto calc header checksum of AIX backup file?

Appologies for previous post.

I'm writing an open source application to provide multi-vendor software
packaging, written entirely in Python.

I've managed to decode AIX BFF files ok, and extract contents etc, but the
problem I have is calculating the header checksums - I've tried all sorts of
methods.

The specific checksum field is in the header (from dumprestor.h):

struct hdr { /* common part of every header */
unsigned char len; /* hdr length in dwords */
unsigned char type; /* FS_* */
ushort magic; /* magic number (MAGIC above) */
ushort checksum; <<<<<< THIS FIELD
};

union fs_rec {

/* common fields */
struct hdr h;

/* FS_VOLUME -- begins each volume */
struct {
struct hdr h;
ushort volnum; /* volume number */
time_t date; /* current date */
time_t dumpdate; /* starting date */
daddr_t numwds; /* number of wds this volume */
char disk[SIZSTR]; /* name of disk */
char fsname[SIZSTR]; /* name of file system */
char user[SIZSTR]; /* name of user */
short incno; /* dump level (or BYNAME) */
} v;
....etc

Does anybody know how this is calculated?

Kind Regards...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 11:53 AM
Joachim Gann
 
Posts: n/a
Default Re: Howto calc header checksum of AIX backup file?

Graham Bevan wrote:

> The specific checksum field is in the header (from dumprestor.h):
> ...etc
> Does anybody know how this is calculated?



the backup(4) man page has more information:
http://publib.boulder.ibm.com/infoce...les/backup.htm

#define CHECKSUM (int)84446
seems you have to calculate checksum = CHECKSUM - (sum of whatever
payload data)

Regards
Joachim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 11:53 AM
Graham Bevan
 
Posts: n/a
Default Re: Howto calc header checksum of AIX backup file?

On Sat, 29 Sep 2007 14:34:18 +0200, Joachim Gann wrote:

> the backup(4) man page has more information:
> http://publib.boulder.ibm.com/infoce...les/backup.htm
>
> #define CHECKSUM (int)84446
> seems you have to calculate checksum = CHECKSUM - (sum of whatever
> payload data)
>
> Regards
> Joachim


Yes I've seen that man page. I've tried the code in
http://www.bitsavers.org/bits/Interd.../cmd/dumpdir.c
which has a similar use of CHECKSUM - I don't get a match. Here is the
code (in C) that i've tried:

checksum(b, BSIZE)
int *b;
{
register i, j;

j = BSIZE/sizeof(int);
i = 0;
do
i += *b++;
while (--j);
if (i != CHECKSUM) {
printf("Checksum error %u\n", i);
return(0);
}
return(1);
}

Which basically sums the data as integers, and then checks if the sum is
equal the CHECKSUM.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 11:53 AM
Joachim Gann
 
Posts: n/a
Default Re: Howto calc header checksum of AIX backup file?

Graham Bevan wrote:
> On Sat, 29 Sep 2007 14:34:18 +0200, Joachim Gann wrote:
>
>> the backup(4) man page has more information:
>> http://publib.boulder.ibm.com/infoce...les/backup.htm
>>
>> #define CHECKSUM (int)84446
>> seems you have to calculate checksum = CHECKSUM - (sum of whatever
>> payload data)
>>
>> Regards
>> Joachim

>
> Yes I've seen that man page. I've tried the code in
> http://www.bitsavers.org/bits/Interd.../cmd/dumpdir.c
> which has a similar use of CHECKSUM - I don't get a match. Here is the
> code (in C) that i've tried:
>
> checksum(b, BSIZE)
> int *b;
> {
> register i, j;
>
> j = BSIZE/sizeof(int);
> i = 0;
> do
> i += *b++;
> while (--j);
> if (i != CHECKSUM) {
> printf("Checksum error %u\n", i);
> return(0);
> }
> return(1);
> }
>
> Which basically sums the data as integers, and then checks if the sum is
> equal the CHECKSUM.
>



I haven't got a .bff here to verify, but that's what the manual says:

When reading the backup format, you want to check:

if ( i + yourheader.checksum != CHECKSUM )
report_error();

and when writing the backup format (as I wrote before):

yourheader.checksum = CHECKSUM - i;


Regards
Joachim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 11:53 AM
Graham Bevan
 
Posts: n/a
Default Re: Howto calc header checksum of AIX backup file?

On Sat, 29 Sep 2007 18:53:10 +0200, Joachim Gann wrote:

>
> I haven't got a .bff here to verify, but that's what the manual says:
>
> When reading the backup format, you want to check:
>
> if ( i + yourheader.checksum != CHECKSUM )
> report_error();
>
> and when writing the backup format (as I wrote before):
>
> yourheader.checksum = CHECKSUM - i;
>
>
> Regards
> Joachim


Thanks again for your response - its helpful to bounce this off someone else
when stuck...

I'm thinking now that the CHECKSUM calc is a red-herring. My reasoning is this:

The #define for CHECKSUM is (int)84446, but the hdr.checksum is a ushort. So
any calculation done as above would mostly overflow the ushort checksum,
leaving any later sum on the data to never add up to CHECKSUM. Looking again
at the header file and the examples on the net of dump.c (nearest equiv in code
I can find), I see that the CHECKSUM is being applied to the by_inode headers
(struct s_spcl), the field of which (c_checksum) is correctly an int type.

So, I'm guessing that the hdr.checksum should simply be a sum of ushorts of the
data. But I still havn't got it to add up...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:47 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com