File Attributes
Each file is stored in a directory, and uses a directory entry that describes its characteristics such as its name and size. The directory entry 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 the operating system and application software more information about the file and how it is intended to be used.
 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

The attribute bits are summed to form the attribute byte. So, the attribute byte for a hidden, read-only directory would be 00010011, which is simply the code 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 applies 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 the user 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 the user to 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 the user 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 most part 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. Of course in practice, trying to do this would result in a mess--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. Still, you should not rely on this mechanism absolutely to ensure that your critical files are backed up.

File Operations

  • General file operations are: open, close, read, write (bytes or records).
  • Random access is sometimes provided, and prevented on files where is doesn't name any sense, e.g I/O pseudo-devices.
  • Record oriented files often have special operations to insert and delete records.

open
            open creates a stream for the file designated in File, and binds Stream to a structure representing that stream. Mode can be one of either read to create an input stream or write or append to create an output stream. If the mode is write, the contents of File are removed and File becomes a record of the output stream. If the mode is append the output stream is appended to the contents of File.
Close
            After finishing the input and output operations on a file we shall close it so that its resources become available again. In order to do that we have to call the stream's member function close (). This member function takes no parameters, and what it does is to flush the associated buffers and close the file.