Hunk is the executable file format of tools and programs of the Amiga Operating System based on Motorola 68000 CPU and other processors of the same family. The file format was originally defined by MetaComCo. as part of TRIPOS, which formed the basis for AmigaDOS. This kind of executable got its name from the fact that the software programmed on Amiga is divided in its internal structure into many pieces called hunks, in which every portion could contain either code or data.
Hunk structure
The hunks in an Amiga executable file could exist in various types. There are 32-bit hunks, 16-bit hunks, and even some 8-bit hunks.
Types of hunks were standardized in AmigaOS, and well documented in The AmigaDOS Manual edited by Commodore to explain to programmers how to code on the Amiga, during the years in which Commodore manufactured Amiga computers. Their structure was officially codified and could be changed only by a Commodore committee, which then communicated the modifications to the developers for new releases of the Amiga operating system.
The structure of an Amiga hunk is very simple: There is a header at the beginning of the hunk indicating that that kind of "portion of code" is a known and valid Amiga hunk type, then follows an ID which indicates the length of the hunk itself, and at the bottom is the segment of the hunk which contains the real code or data.
Features of Amiga executable files
Amiga executable files can be launched either from the graphical shell of the Amiga, the Workbench or from the Amiga's command line interpreter (called CLI, later AmigaShell).
No particular filename extension is required for Amiga executable files. For example, the calculator applet "Calculator" can be renamed to "Calculator.com", "Calculator.exe", "Calculator.bin", or even "Calculator.jpeg". These are all valid names for programs or tools, because AmigaOS does not differentiate between filename extensions.
AmigaOS adopted another method to recognize it is dealing with a valid executable. There is a particular sequence of bytes in the file header, yielding the hexadecimal value $000003f3. This sequence, which signifies an executable file and lets it be self-running, is called a magic cookie (from the magic cookies in Alice's Adventures in Wonderland by Lewis Carroll).
This kind of solution to identify executables on the Amiga was taken from similar solutions which were adopted by UNIX/Unix-like operating systems, where magic cookies are called magic numbers.
Structure of an Amiga executable file
The internal structure of an Amiga executable file is very simple. In the beginning of the file there is the magic cookie, then is declared the total number of hunks in the executable, and just after this is the progressive numbers of hunks starting from "0" (zero).
The first hunk is always numbered zero, so if the executable is (for example) subdivided into three hunks, they will be numbered "0" for the first one, "1" the second and "2" the third hunk, and so on.
Just before the real hunks start is a table containing information about the length of any hunks present in the executable, and in the last part of the file are positioned the real hunks, each one described by its type name: HUNK_CODE, HUNK_DATA, et cetera.
Representation of the structure:
Hunk Types
Known hunk types for the Amiga are:
* Extended Hunk Format
Metadata
The Amiga could save metadata into hunks, as the hunk structure could be easily adapted to support this feature, but the hunk format of executables was abandoned in favour of ELF and there is no central authority (as the dismissed Commodore) which could implement this feature as one of the Amiga standards.
The Amiga saves some metadata into sidecar files known as ".info" (so called from the name of their extension suffix).
".info" files may be created any time a project (datafile) is saved on disk. Example: When user saves a file called "MyProject" two files may be created on disk called "MyProject" and MyProject.info".
The "MyProject" file contains the real data of the project file, while the "MyProject.info" file contains the icon, and the information regarding the software which originated the file, so any time the project icon is invoked by clicking on it with mouse, the parent software will be opened (users can change this information at any time, allowing other programs to believe they created the project file rather than the original software which physically created it).
Application Binding does not exist in AmigaOS as in other systems like MacOS.