MPE/iX Shell and Utilities Reference Manual, Vol 2

magic(2) MPE/iX Shell and Utilities magic(2)
NAME
magic — format of the /etc/magic file
DESCRIPTION
The file command uses /etc/magic in its attempt to identify the type of a binary file.
Essentially, /etc/magic contains templates showing what different types of files look like.
The magic file contains lines describing magic numbers which identify particular types of
files. Lines beginning with a > character represent continuation lines to the main entry. If
file finds a match on the main entry line, these additional patterns are checked and addi-
tional output may be generated for matching lines, separated by a single blank. Each line con-
sists of four fields, separated by one or more tabs.
(a) The first field is a byte offset in the file.
(b) The next field is a type: byte, short, long,orstring. byte, short, and
long can be followed by an optional mask which is bitwise ANDed to the value pri-
or to comparison, for example, byte &0x80 looks at the high bit.
(c) The next field is a value, preceded by an optional operator. Operators only apply to
non-string types: byte, short, and long. The default operator is = (exact match).
The other operators are:
= equal
! not equal
> greater than
< less than
& all bits in pattern must match
ˆ any bits in pattern may match
x or ? any value matches (must be the only
character in the field) (? is an extension
to traditional implementations of magic.)
string values to be matched may contain any valid
ANSI C backslash sequence.
Thus, to match a single backslash, \\ must be entered in the magic file.
Note: Due to its format, the magic file must use a \t to match a tab character.
(d) The rest of the line is a string to be printed if the particular file matches the template.
The fourth field may contain a printf()-type format indicator to output the magic
number (See printf(1) for more details on format indicators).
2-4 File Formats