Go to main content

Oracle® Solaris 11.3 Desktop Administrator's Guide

Exit Print View

Updated: March 2018
 
 

About the MIME Database

    The MIME database is a collection of files that include the following information:

  • The set of known MIME types

  • The method for determining the MIME type of a file

  • Meta information regarding a MIME type

The MIME database is created from the set of files located in the $XDG_DATA_HOME/mime and $XDG_DATA_DIRS/mime directories. If the environment variables are not set, then the default values are ~/.local/share and /usr/local/share:/usr/share respectively.

This guide uses <MIME> to refer collectively to these directories. If conflicting information for the same MIME type is found, the information in the file that is found first takes precedence.

    For example, assuming default paths for the environment variables , an instruction to load the <MIME>/text/plain.xml file, loads the following files:

  • ~/.local/share/mime/text/plain.xml

  • /usr/local/share/mime/text/plain.xml

  • /usr/share/mime/text/plain.xml


Note - The XDG shared mime info specification was drafted by the X Desktop Group, and the specification makes use of the XDG base directory specification.

MIME Database Contents

    The MIME database contains the following directories and files:

  • <MIME>/packages/

  • <MIME>//media/subtype.xml

  • <MIME>/globs

  • <MIME>/magic

  • <MIME>/XMLnamespaces

  • <MIME>/aliases

  • <MIME>/subclasses

    The following is a list of MIME directories and files in the MIME database with a brief description:

  • <MIME>/packages/– This directory can contain any number of XML files. Each XML file describes the collection of MIME types. The freedesktop.org.xml file located in the <MIME>/packages/ directory contains all the default MIME types that are widely used and recognized. By default, the freedesktop.org.xml file is installed in the /usr/share/mime/packages directory.

    Applications that provide information about new MIME types install a single new XML file in this directory. Depending on the prefix where the application is installed, the file is created in the /mime/package subdirectory. For example, an application installed in the /usr/bin directory should install a new source XML file in the /usr/share/mime/packages directory. For more information about the XML files in the packages directory, see Understanding MIME Type XML Files.

  • <MIME>/media/subtype.xml– These directories and files are automatically generated from the collection of source XML files in the <MIME>/packages/ subdirectory by the update-mime-database application. For example, for each mime-type element in the /usr/share/mime/packages/freedesktop.org.xml file, a directory is created in the /usr/share/mime/ directory with the media type of the MIME type. Along with the media type, an XML file is also created in that directory with the subtype identifier of that MIME type. The contents of the created XML file include comments and translations, subclasses designations, and aliases.

    The following example is an excerpt from the file generated by the update-mime-database application, using the freedesktop.org.xml default source XML file.

    <?xml version='1.0' encoding='utf-8'?>
    <mime-type 
    xmlns="https://www.freedesktop.org/standards/shared-mime-info"
    type="text/plain">
    <!--Created automatically by update-mime-database.
    DO NOT EDIT!-->
    	<comment>
    	plain text document
    	</comment>
    	<!-- possibly more translations-->
    	<comment xml:lang="es">
    	documento de texto sencillo
    	</comment>
    	<comment xml:lang="eu">
    	testu soileko dokumentua
    	</comment>
    	<comment xml:lang="fi">
    	perustekstiasiakirja
    	</comment>
    	<comment xml:lang="fr">
    	document plein texte
    	</comment>
    	<!-- possibly more translations --> 
    </mime-type> 
  • <MIME>/globs– Each line in this file contains a MIME type and a glob pattern, separated by a colon. The files that match the glob pattern are resolved to the MIME type specified before the colon. There are special rules about how filenames are matched by the glob pattern. For more information, see the XDG shared mime specification.

    This file is also generated by the update-mime-database application, using the freedesktop.org.xml default source XML file.

  • <MIME>/magic– This is a binary file that contains information about how to resolve MIME types by content sniffing (known as "magic rules"). A magic rule is a set of one or more rules that define a file's MIME type by specifying text or binary data to search for at the beginning of the file. For example, you can set a rule to check for the %PDF- string at byte offset 0 in the file. If the string is found, you can assign the file to the application/pdf MIME type.

    This file is also generated by the update-mime-database application.

  • <MIME>/XMLnamespaces– This file contains a mapping of XML namespaces to MIME types. Each line contains three fields:

    • namespace

    • localName

    • MIME type

    Each field is separated by a space. If the localName is empty, then there are two spaces between the namespace and the MIME type fields.

    This file is also generated by the update-mime-database application.

  • <MIME>/aliases– This file contains a list of aliases for each MIME type. An alias is another type of a MIME type. Each line in this file contains two fields:

    • alias name

    • MIME type

    The fields are separated by a space. This file is also generated by the update-mime-database application.

  • <MIME>/subclasses– This file contains a list of subclassed MIME types and their parent MIME type. According to the XDG shared mime specification, a type is a subclass of another type if a ny instance of the first type is also an instance of the second type. For example, all image/svg files are also text/xml, text/plain, and application/octet-stream files. Subclassing is about the format, rather than the category of the data. For example, all spreadsheets do not inherit from a generic spreadsheet class.

    The format of this file is similar to the aliases file. Each line contains two fields:

    • subclassed MIME type

    • parent MIME type

    Each field is separated by a space. This file is also generated by the update-mime-database application.

Refreshing the MIME Database

To add new MIME types to the system or to modify information about a MIME type, you need to understand how to refresh the MIME database. To refresh the MIME database, use the update-mime-database application. For example, if an application installs information about a new MIME type to the /usr/share/mime/packages/diff.xml file, the update-mime-database application must be invoked with the /usr/share/mime parameter.

# update-mime-database /usr/share/mime
***
* Updating MIME database in /usr/share/mime...
***

The MIME database is refreshed by scanning all the source XML files in the <MIME>/packages directory.