Each file is stored in a directory, and uses a directory entry that describes its
characteristics such as its name and size, and also contains a pointer to where the file
is stored on disk. One of the characteristics stored for each file is a set of file
attributes that give DOS and application software more information about the file and
how it is intended to be used.
The use of attributes is "voluntary". What this means is that any software
program can look in the directory entry to discern the attributes of a file, and based on
them, make intelligent decisions about how to treat the file. For example, a file
management program's delete utility, seeing a file marked as a read-only system file,
would be well-advised to at least warn the user before deleting it. However, it doesn't
have to. Any program that knows what it is doing can override the attributes of a file,
and certainly, viruses will do this routinely.
That said, DOS and most other operating systems assign definite meanings to the
attributes stored for files, and will alter their behavior according to what they see. If
at a DOS prompt you type "DIR" to list the files in the directory, by default
you will not see any files that have the "hidden" attribute set. You have to
type "DIR /AH" to see the hidden files.
A file can have more than one attribute attached to it, although only certain
combinations really make any sense. The attributes are stored in a single byte, with each
bit of the byte representing a specific attribute (actually, only six bits are used of the
eight in the byte). Each bit that is set to a one means that the file has that attribute
turned on. (These are sometimes called attribute bits or attribute flags).
This method is a common way that a bunch of "yes/no" parameters are stored in
computers to save space. The following are the attributes and the bits they use in the
attribute byte:
Attribute |
Bit Code |
Read-Only |
00000001 |
Hidden |
00000010 |
System |
00000100 |
Volume Label |
00001000 |
Directory |
00010000 |
Archive |
00100000 |
So, the attribute byte for a hidden, read-only directory would be 00010011, which is
simply the codes for those three attributes from the table above, added together. Here is
a more detailed description of what these attributes mean (or more accurately, how they
are normally used). Note that each of the attributes below apply equally to files and
directories (except for the directory attribute of course!):
- Read-Only: Most software, when seeing a file marked read-only, will refuse to
delete or modify it. This is pretty straight-forward. For example, DOS will say
"Access denied" if you try to delete a read-only file. On the other hand,
Windows Explorer will happily munch it. Some will choose the middle ground: they will let
you modify or delete the file, but only after asking for confirmation.
- Hidden: This one is pretty self-explanatory as well; if the file is marked hidden
then under normal circumstances it is hidden from view. DOS will not display the file when
you type "DIR" unless a special flag is used, as shown in the earlier example.
- System: This flag is used to tag important files that are used by the system and
should not be altered or removed from the disk. In essence, this is like a "more
serious" read-only flag and is for the mostpart treated in this manner.
- Volume Label: Every disk volume can be assigned an identifying label, either when
it is formatted, or later through various tools such as the DOS command "LABEL".
The volume label is stored in the root directory as a file entry with the label attribute
set.
- Directory: This is the bit that differentiates between entries that describe
files and those that describe subdirectories within the current directory. In theory you
can convert a file to a directory by changing this bit, but of course in practice trying
to do this would result in a mess because the entry for a directory has to be in a
specific format.
- Archive: This is a special bit that is used as a "communications link"
between software applications that modify files, and those that are used for backup. Most
backup software allows the user to do an incremental
backup, which only selects for backup any files that have changed since the last
backup. This bit is used for this purpose. When the backup software backs up
("archives") the file, it clears the archive bit (makes it zero). Any software
that modifies the file subsequently, is supposed to set the archive bit. Then, the next
time that the backup software is run, it knows by looking at the archive bits which files
have been modified, and therefore which need to be backed up. Again, this use of the bit
is "voluntary"; the backup software relies on other software to use the archive
bit properly; some programs could modify the file without setting the archive attribute,
but fortunately most software is "well-behaved" and uses the bit properly.
Most of the attributes for files can be modified using the DOS ATTRIB command, or by
looking at the file's properties through the Windows 95 Windows Explorer or other similar
file navigation tools.
Next: Clusters and
File Allocation