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. ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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... |
| |||
| 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 |
| |||
| 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. |
| |||
| 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 |
| ||||
| 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... |