Back to Table of Contentsgentoo - A Click-Ass Filemanager Go to Obsession Developments Homepage
  LICENSE   GUIDE   INTRO   USAGE CONFIG HISTORY CONTRIBUTING ACKS  

File Types

Introduction

Almost all of the files we use every day can be said to have a specific "type", something that categorizes the file, be it by its name, its contents, or some other property. This chapter is about how you can teach gentoo about the file types you work most with, so it can (for example) tell a Perl source code file from a HTML text file.

By itself, this typing doesn't achieve much. Sure, you can turn on the "Type" pane content column so you can learn about file types in a directory at a glance. You can even sort on that column, thus grouping files of equal types together in the listing. While all of this is useful, the actual purpose for the file typing mechanism is more subtle: each type is associated with exactly one style, and styles are real neat things, as we will see later on.

File Types in gentoo

A file type in gentoo has a pretty simple structure. It is basically a set of rules of various types which are applied to files in order to determine if they "belong" to the type in question. The type also has a name, to make it easier to work with, and a link to something called a style. That's really all there is to it.

Type Rules

When you define a new type, you must specify the type's rule set. The rules are applied to each row to be displayed by gentoo, and as soon as all rules of some type match, the file is said to have (be of, belong to) that type. You must try to be as exclusive as possible when you design type rules, so that the type doesn't "eat up" all files, thus causing incorrect typing.

There are five different kinds of rule you can use. Of these five, one is obligatory and must always be used. The other four are optional; you choose freely among them, using none, a few, or all. The rules are:

  1. Intrinsic Type (obligatory)
  2. Protection
  3. File Name Suffix
  4. File Name Regular Expression
  5. 'file' Command Regular Expression

Let's investigate each of these in turn:

Intrinsic Type

All objects in the file system have an intrinsic type. For example, a directory just isn't a regular file; it's intrinsic type is directory and that cannot be changed. If you create a type and specify e.g. "character device" as the type's intrinsic type requirement, only character device files will ever be considered as beloning to your new type.

There are seven intrinsic types: file, directory, soft link, block device, character device, FIFO and socket. You must specify exactly one.

Protection

A file's protection (or mode) is a file system level intrinsic property. All files always have protection information available. The protection information can be seen in gentoo by using the various "mode" column content types. You can change a file's protection with the built-in ChMod command (named after a standard shell command which does the same thing). Checking a file's protection is a fast operation. A protection rule is specified as a set of six flags; each flag requires something from the file's protection. The rule matches when all flags succeed. These are the flags:

SetUID
Set this to require files to have the SetUID protection bit set.
SetGID
When set, this requires files to have the SetGID bit set.
Sticky
This requires files to be "sticky". Not often used.
Readable, Writeable, Executable
These three flags allow you to require that a file shall be readable, writaable, or executable, respectively. They are interesting because they are not just direct flag comparisons against files. Rather, these three are a little intelligent. They each require that you, i.e. the user currently running gentoo, have the permission in question. When evaluating these rules, gentoo compares your (UID,GID) values against those of files, and apply logic to determine which of the three sets of RWX flags available in the file applies.

File Name Suffix

This is a simple file name rule. It allows you to specify a string, and then requires candidate files to have names ending in that very string for a match to be considered. If you always use the same suffix (sometimes called extension) for your file names, this rule will maybe be all you need. Typically, a file type suffix is separated from the actual name of the file by a dot; this rule pretends it doesn't know that, so you must always include the dot as the first character in the suffix. The suffix comparison is case-insensitive, so .jpg, .JPG and .JPg all mean the same thing, and all will match each other.

A "problem" with this rule is that it only allows you to specify one suffix. Many file types have several popular suffices, one of which is generally a dot followed by three letters for compatibility with the broken nightmare known as FAT. For example, HTML hypertext files are often given a suffix of ".html" or just ".htm". You cannot specify such alternatives with this rule; it has been optimized to check for just one suffix.

File Name Regular Expression

For those cases when a simple suffix isn't enough, but the type is anyway deductable from just the name of a file, you can use the regular expression matching rule. This rule lets you enter a full regular expression against which the names of files are checked. A match is required for the rule to succeed.

When entering regular expressions for file name matching, remember that the dot (.) is in fact a RE meta-character and need to be escaped (by a backslash; \.) if you really want to match against a dot. Also note that your regular expression is used as a "search RE"; if a match is produced between your RE and any part of a file name, that is enough. So try to be restrictive when you write regular expressions; for example by using the ^ and $ metasymbols appropriately.

As an example of when RE matching comes in handy, consider attempting to define a file type for JPEG image files. Such files are generally given the extension ".jpeg" on real filesystems, or just ".jpg