Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

file(1)



MAGIC(4-SysV)       RISC/os Reference Manual        MAGIC(4-SysV)



NAME
     magic - configuration for file command

SYNOPSIS
     /etc/magic

DESCRIPTION
     When file(1) is executed, it reads the file /etc/magic (or
     an alternate file if requested).  This file, also called the
     ``magic number file'', contains information to help file
     decide what type of file it is looking at.

     The name ``magic'' comes from the term ``magic number'',
     which refers to a (usually) unique combination of bytes that
     is used by either the operating system or system programs to
     recognize the file.

     For example, the octal representation of the first two bytes
     of an old style archive file is 0177545.  Thus, any program
     that needed to work with these files (such as a compiler,
     linker, or archiver) would check to make sure that this data
     was present.  If it isn't. then the file isn't an old style
     archive.

     The magic number file contains four types of lines: com-
     ments, specifications, and continuations.  Blank lines are
     also allowed, and are ignored.

     A comment is any line that has a `#' in the first column.
     All comment lines are ignored.

     A specification line is used to describe a magic number.  It
     consists of four fields, separated by tabs:

     offset    This is the byte offset in the file where the data
               to be looked at is found.  The number may be in
               decimal, octal (begins with a 0), or hexadecimal
               (begins with 0x).

     type      This is the type of the data to be looked at.  The
               type can be byte (single byte of data), short
               (short integer, usually 2 bytes, of data), long
               (long integer, usually 4 bytes, of data), or
               string (null-terminated string of bytes).

     match     This field contains the value to be matched
               against the value in the file.  If the type field
               is string, that value is compared literally.  Oth-
               erwise, the value consists of an optional rela-
               tional operator (! or ^ for not equal, < for less
               than, > for greater than, or = for equal, which is
               the default) and a numeric value (in decimal,



                         Printed 1/15/91                   Page 1





MAGIC(4-SysV)       RISC/os Reference Manual        MAGIC(4-SysV)



               octal, or hexadecimal, as with the offset field).
               In addition, if the field is a single `x', any
               value is allowed (useful for printing version
               numbers or strings).

     output    This field, which consists of the rest of the
               line, is the string to be printed if the value in
               the file matches the match field value.  This may
               contain a printf(3S)-style `%' specifier to print
               the value.  This should be a string or integer
               specifier (depending on the type field).

     Normally, the first field printed for a file is preceded by
     a tab, and all subsequent fields are preceded by a space.
     If the first character of the field is a backspace or the
     characters \b, leading spaces are supressed.  This is useful
     for printing data in which the value is split across fields,
     such as multi-word version numbers.

     A specification line is used by file as meaning ``read the
     required number of bytes from the file, and if the value
     matches the required value, print the specified output''.

     Continuation lines are used for printing other information
     about a file of a certain type.  A continuation line has the
     same format as a specification line, except that the offset
     is preceded by the character `>'.  This type of line is used
     just like a specification line, but only if the specifica-
     tion preceding it matches.  The output is printed preceded
     by a space (to separate it from previously printed output).
     Multiple continuation lines are allowed for a specification
     line, in which case all continuation lines are checked, in
     the order they appear in the magic file.

     Once a matching specification is found and processed
     (including checking continuations), no other searches are
     made for that file.

     The following magic file lines show how a specification and
     related continuations might work:


          0       short    0173737     Joe's file type
          >8      long     >0          - version %d
          >8      long     0           - prerelease
          >12     long     >0          (checksum 0%lo)

     If a file begins with a short integer whose octal value is
     0173737, file will print the text ``Joe's file type''.
     Then, the long integer found at location 8 in the file is
     checked to see if it is a positive integer, in which case
     the text ``- version'' followed by the number found is



 Page 2                  Printed 1/15/91





MAGIC(4-SysV)       RISC/os Reference Manual        MAGIC(4-SysV)



     printed.  Next, the long integer found at location 8 in the
     file is checked to see if it is a 0, in which case the text
     ``-prerelease'' is printed.  Finally, the long integer found
     at location 12 in the file is checked to see if it is a
     positive integer, in which case the text ``(checksum'' is
     printed followed by the number found, which is printed in
     octal, followed by ``)''.

     So, a file named joefile with a short 0173737 at location 0,
     a long 7 at location 8, and a long 04088 at location 12
     would cause file to print the text:


          joefile:   Joe's file type - version 7 (checksum 04088)

SEE ALSO
     file(1) in the User's Reference Manual.






































                         Printed 1/15/91                   Page 3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026