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

Magic Numbers to identify datatypes



I came across the text below in my net travels lately.  Is it possible to use
"magic" numbers with MiNT?  If we will have the ability to access different
file systems, then it would seem to be rather useful.   


Peter
----------
>I would _really love to see a super-smart program that can use any of
>these formats, and allow you to unarchive _anything_.  Then the choice
>of archive format would become less of a problem in the present and
>the future.
>

It's possible to write such program. However, it's pretty hard to write
a program to handle multiple format by itself with comfortable speed.

It's much easier to write a program to identify the compression format 
and call appropriate compression program to handle the data file. Under UNIX,
this is trival as each of these four compression schemes has an unique 'magic' 
number. The UNIX command `file' can be used for such application. If you add 
following lines in the 'magic' file (/etc/magic), the command should be able 
to identify the format of an compressed file:

0       short           0x1f9d          compress(l) output
0       byte            0x1a            arc(l) archive output
2       string          -l                      lharc(l) archive output
20      long            0xdca7c4fd      zoo(l) archive output

Note that the magic number for zoo is for Motorola 680x0 chips, the Intell
chips and VAX family (?) store the long integer in normal order. So the
number should 0xfdc4a7dc instead.

I'm not 100% sure the lharc magic string covers every format of lharc. Inside
lharc.c, there are four of them listed:

#define LZHUFF0_METHOD          "-lh0-"
#define LZHUFF1_METHOD          "-lh1-"
#define LARC4_METHOD            "-lz4-"
#define LARC5_METHOD            "-lz5-"

Alternatively, one can add these information to the magic file so `file' command
can even tell you which archive method lharc uses.