All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/. The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop.org.xml. Applications can add new MIME types to the MIME database.
Applications use the MIME database to detect the MIME type of a file, in the following ways:
The application checks the contents of the file, then uses the MIME database to identify the appropriate MIME type. The MIME database contains file content sniffer information. The file content sniffer information provides details of a specific pattern in the file. The MIME database associates this pattern with a MIME type. The application checks the file for the pattern. If the application finds a match for the pattern in the file content, the MIME type associated with the pattern is the MIME type of the file.
The magic elements in the MIME database specify the file content sniffer information.
The application checks the filename, then uses the MIME database to identify the appropriate MIME type. The MIME database associates particular file extensions and filename patterns, with particular MIME types. The application checks the filename to search for a particular pattern in the filename. If a match for the filename is found, the MIME type associated with the extension or pattern is the MIME type of the file.
The glob elements in the MIME database specify the filename pattern and file extension pattern information.
The MIME database also contains a text description of each MIME type. The MIME database can also contain a list of applications that you can use to view or edit a MIME type.
The following is a sample from the MIME type database:
<mime-type type="image/png"> <comment>PNG image</comment> <comment xml:lang="de">PNG-Grafik</comment> : : : <magic priority="50"> <match offset="0" type="string" value="\x89PNG" /> </magic> <glob pattern="*.png" /> </mime-type>
Table 5–1 describes the elements in the MIME type database.
Table 5–1 MIME Type Database Elements
Element |
Description |
---|---|
mime-info |
This is the document element, or highest level element in the MIME database. This element contains the required information for all MIME types. The namespace URI of this element is as follows: http://www.freedesktop.org/standards/shared-mime-info |
mime-type |
Describes one MIME type. This element has a type attribute, which specifies the MIME type. |
comment |
Provides a description of the MIME type that is used in the user interface. The description can be displayed in the file manager and other applications. The database might contain comment elements with xml:lang attributes. These elements can provide the descriptive text in other languages. |
magic |
Contains match elements. The match elements specify a particular pattern to search for in the contents of a file. This associates a specific pattern in a file with the MIME type specified in the mime-type element. If an application finds a match for the pattern, the MIME type associated with the pattern is the MIME type of the file. The magic element includes a priority attribute. You can specify a priority value for the pattern. If there are identical patterns in the magic elements in the MIME database, the element with the highest priority value takes precedence. For more information about the attributes of a match element, see Attributes in Match Elements. |
glob |
Specifies a filename pattern to match with the MIME type. Any file that matches this filename pattern takes this MIME type. |
root-XML |
If a file is identified as an XML file, you can associate a more specific MIME type than text/xml with the file. To do this, you assign values to the following attributes of the root-XML element:
This element is optional. This element is not present in the example. |
Table 5–2 describes the attributes in a match element.
Table 5–2 Attributes in match Elements
When a new MIME type is installed, the update-mime-database command is executed to update the MIME database. Table 5–3 describes the files that the update-mime-database command generates:
Table 5–3 Files Generated by update-mime-database
File |
Description |
---|---|
globs |
The globs file is generated from the glob elements in the MIME database, and from the glob elements in any MIME type description files in the packages directory. The globs file contains a simple list of MIME types and the filename patterns that are associated with that file type. The following are examples of entries in the globs file: application/x-bzip-compressed-tar:*.tar.bz2 text/html:*.html image/png:*.png If there are two identical filename patterns in the glob elements in the MIME database, only the entry from the MIME type description file which comes later alphabetically is added to the globs file. For example, if the MIME type description files abc.xml and def.xml contain identical filename patterns in the glob elements, only the glob element from def.xml is added to the globs file. That is, filename patterns in alphabetically later MIME type description files take precedence. If you want a MIME type description to take precedence over other MIME type descriptions, no matter what the alphabetical order is, put the MIME type description in a file called Override.xml in the packages directory. |
magic |
The magic file is generated from the magic elements in the MIME database, and from the magic elements in any MIME type description files in the packages directory. The magic file is stored in binary format. |
XMLnamespaces |
The magic file is generated from the root-XML elements in the MIME database. This file lists all of the XML namespaces that the XML file types use. |
content-type/content-subtype.xml |
These files are generated from the comment elements in the MIME database. |