[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interview



Am Sam, 04 Sep 1999 hast Du wahrscheinlich geschrieben:
>Steve Baker wrote:
>
>> A more elegant thing is to store a 'magic number' at the top of the
>> file.
>> ALL Binary files should start with a 4 byte magic number anyway so that
>> you can check that you aren't being fed a file of the wrong kind - and
>> also so that the Linux/UNIX 'file' command can be set to recognise your
>> file type using /etc/magic.

Ok, that sounds good. But there is something else we have to do too:
Detecting the alignment holes.
What if the write platform has a 4 Byte Alignment, and the Target has
a 2 Byte alignment? (64 Bit Risc processors often have 4 Byte
aligning)
Let´s think about that too, then we can implement both techniques.
I suggest the following thing:

The first 5 Bytes are the Magic code. We should not use 1234, because
someone else will have the same idea. We should use something that
means Penguin-File-API. "PFAPI" would be an idea..
Why 5 bytes? Because then there will be a hole for the next integer.
We should use a short:

typedef struct
{
   char magic[5];
   short aligndetector;
   any data ...
} File_Structure;

memset(FileStructure,0,sizeof(FileStructure));
memcpy(Filestructure.magic,"PFAPI");
File_Structure.aligndetector=0x1234;
fwrite()...

With this combination, we should be able to detect everything.
The file will look like this:
1 Byte alignment, Little Endian:
0000: 50 46 41 50 49 12 34 ..
1 Byte alignment, Big Endian:
0000: 50 46 41 50 49 34 12 ...
2 Byte alignment, Little Endian:
0000: 50 46 41 50 49 00 12 34 ...
4 Byte alignment, Little Endian:
0000: 50 46 41 50 49 00 00 00 12 34 ...
8 Byte alignment, Little Endian:
0000: 50 46 41 50 49 00 00 00 12 34 ...
Oops, the Idea wasn´t that good.

We would need only one byte at the beginning, that we can detect
every possible alignment. (Except nibble-alignment :)))
But then, we have no Magic-Code.

"The magic code of our new file-type is 50 12 34. Or 50 00 12 34. Or
50 00 00 00.12 34 Or ..." Doesn´t soud like a magic code. :)

Many greetings,
--
~ Philipp Gühring              p.guehring@poboxes.com
~ http://www.poboxes.com/p.guehring  ICQ UIN: 6588261
~ Please change p.guehring@xpoint.at to p.guehring@poboxes.com