[Vm-dev] magic decode for image files

K K Subbu kksubbu.ml at gmail.com
Tue Apr 11 07:17:57 UTC 2017


On Tuesday 11 April 2017 05:03 AM, David T. Lewis wrote:
> On Mon, Apr 10, 2017 at 07:31:47PM +0530, K K Subbu wrote:
>>
>> I saw the ckformat program and couldn't see why it was needed. Perhaps I
>> am missing something here.
>
> It answers the image format number on standard output, for use in shell scripts.
>
> The attached "run" file is the script that I use on my own PC to select Spur 64,
> Spur 32 bit, Cog 32 bit, interpreter VM 64 bit, or interpreter VM 32 bit.
>
> The start script for interpreter VM uses this approach also:
> http://squeakvm.org/cgi-bin/viewvc.cgi/squeak/trunk/platforms/unix/cmake/squeak.in?revision=3609&view=markup

I use the commonly available od(1) to extract magic numbers:

$ alias sqmagic='od -An -N4 -t x1'
$ sqmagic SpurVMMaker.image
  79 19 00 00
$

The case statement duplicates binfmt_misc registrations. Each image 
format requires a just a single line to register with binfmt_misc. E.g.

# :name:type:offset:pattern:mask:interpreter:flags

$ echo ':spur32le:M::\x79\x19\x00\x00::/opt/squeak/spur32:' | sudo tee 
/proc/sys/fs/binfmt_misc/register

and removed with
$ echo -1 | sudo tee /proc/sys/fs/binfmt_misc/spur32le

The run script is fragile (e.g. it will break if $0 is symlink). If the 
disambiguation can be done outside, then it can be simplified without 
losing flexibility.

Other interpreters/emulators like python, lua, qemu work this way.

>>
>> If we generate magic and binfmt_misc registrations, then
>> package-managers can launch the right vm for any image file. It also
>> integrates well with other utilities like update-binfmts.
>>
>> Regards .. Subbu
>
> That approach would work also.
>
> Your magic decode logic is nice, do you mind if I steal it and add it to ImageFormat?

Please do. It is very nice of you to offer me to help merge the code. 
Thanks. I am still in the catchup mode :-(. The magic file has to be 
generated just like any other .c file. It can be compiled into a binary 
file with "file -C ..." into magic.mgc bin file but that would be an 
overkill for such a small file.

Regards .. Subbu


More information about the Vm-dev mailing list