Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  The root directory on a diskette or in a fixed-disk partition is created
  by the DOS FORMAT program. The root directory's size is determined by
  FORMAT, so the number of root directory entries is limited. (See Figure
  5-10.)

  Disk                          Capacity      Size           Number of
                                                             Entries
  --------------------------------------------------------------------------
  51/4-inch diskette            180 KB         4 sectors      64
                                360 KB         7             112
                                1.2 MB        14             224
  31/2-inch diskette            720 KB         7             112
                                1.44 MB       14             224
  Typical PC/XT fixed disk      10 MB         32             512
  PC/AT fixed disk, type 20     30 MB         32             512
  PS/2 Model 30, fixed disk,    20 MB         32             512
  type 26
  PS/2 Model 60, fixed disk,    44 MB         32             512
  type 31
  --------------------------------------------------------------------------

  Figure 5-10.  Root directory sizes for some common DOS disk formats.

  In DOS versions 1.0 and later, which did not support subdirectories, the
  size of the root directory limited the number of files that could be
  stored on a diskette. This restriction disappeared in DOS versions 2.0 and
  later, where file names could be placed in subdirectories as well as in
  the root directory.

  The root directory contains a series of 32-byte directory entries. Each
  directory entry contains the name of a file, a subdirectory, or a disk
  volume label. The directory entry for a file contains such basic
  information as the file's size, its location on the disk, and the time and
  date it was most recently modified. This information is contained in the
  eight fields listed in Figure 5-11.

                                       Size
  Offset      Description              (bytes)     Format
  --------------------------------------------------------------------------
  00H         Filename                  8          ASCII characters
  08H         Filename extension        3          ASCII characters
  0BH         Attribute                 1          Bit coded
  0CH         Reserved                 10          Unused; zeros
  16H         Time                      2          Word, coded
  18H         Date                      2          Word, coded
  1AH         Starting cluster number   2          Word
  1CH         File size                 4          Integer
  --------------------------------------------------------------------------

  Figure 5-11.  The eight parts of a directory entry.

  Offset 00H: The filename

  The first 8 bytes in a directory entry contain the filename, stored in
  ASCII format. If the filename is less than eight characters, it is filled
  out to the right with blanks (CHR$(32)). Letters should be uppercase,
  because lowercase letters will not be properly recognized. Normally,
  blanks should not be embedded in the filename, as in AA BB. Most DOS
  command programs, such as DEL and COPY, will not recognize filenames with
  embedded blanks. BASIC works successfully with these filenames, however,
  and DOS services usually can too. (See Chapters 16 and 17.) This
  capability suggests some useful tricks, such as creating files that cannot
  easily be erased.

  Two codes, used to indicate special situations, may appear in the first
  byte of the filename field. When a file is deleted, DOS sets the first
  byte of the filename field in its directory entry to E5H to indicate that
  the directory entry can be reused for another filename. In DOS versions
  2.0 and later, the first byte of a directory entry can also be set to 00H
  to indicate the end of the list of directory entries.

  When a file is erased, only two things on the disk are affected: The first
  byte of the directory entry is set to E5H, and the file's space-allocation
  chain in the FAT is wiped out (we'll cover this in the section on the
  FAT). All other directory information about the file is retained,
  including the rest of its name, its size, and even its starting cluster
  number. The lost information can be recovered, with suitably sophisticated
  methods, provided that the directory entry has not been reused for another
  file. Be forewarned, though, that whenever a new directory entry is
  needed, DOS uses the first available entry, quickly recycling an erased
  file's entries and making recovery more problematic.

  Offset 08H: The filename extension

  Directly following the filename is the standard filename extension, stored
  in ASCII format. It is 3 bytes long and, like the filename, is padded with
  blanks if it is less than the full three-character length. While a
  filename must have at least one ordinary character in it, the extension
  can be all blanks. Generally, the rules that apply to the filename also
  apply to the filename extension.

  --------------------------------------------------------------------------
  NOTE:
    When the directory contains a volume ID label entry, the filename and
    extension fields are treated as one combined field of 11 bytes. In this
    case, embedded blanks are permitted.
  --------------------------------------------------------------------------

  Offset 0BH: The file attribute

  The third field of the directory entry is 1 byte long. The bits of the
  attribute byte are individually coded as bits 0 through 7, as shown in
  Figure 5-12, and each bit is used to categorize the directory entry.

        Bit
  7 6 5 4 3 2 1 0          Meaning
  --------------------------------------------------------------------------
  . . . . . . . 1          Read-only
  . . . . . . 1 .          Hidden
  . . . . . 1 . .          System
  . . . . 1 . . .          Volume label
  . . . 1 . . . .          Subdirectory
  . . 1 . . . . .          Archive
  . 1 . . . . . .          Unused
  1 . . . . . . .          Unused
  --------------------------------------------------------------------------

  Figure 5-12.  The 8 file-attribute bits.

  Bit 0, the low-order bit, is set to mark a file as read-only. In this
  state, the file is protected from being changed or deleted by any DOS
  operation. We should point out that many DOS services ignore this
  attribute, so even though bit 0 can provide worthwhile protection for
  data, it is not foolproof.

  Bit 1 marks a file as hidden and bit 2 marks a file as a system file.
  Files marked as hidden, system, or both, cannot be seen by ordinary DOS
  operations, such as the DIR command. Programs can gain access to such
  files only by using DOS services to search explicitly for hidden or system
  files. There is no particular significance to the system attribute; it
  exists to perpetuate a feature of CP/M and has absolutely nothing to do
  with DOS.

  --------------------------------------------------------------------------
  Subdirectories
    There are two types of directories: root directories and subdirectories.
    The contents and use of each type are essentially the same (both store
    the names and locations of files on the disk) but their characteristics
    are different. The root directory has a fixed size and is stored in a
    fixed location on the disk. A subdirectory has no fixed size and can be
    stored anywhere on the disk. Any version of DOS numbered 2.0 or later
    can use subdirectories.

                    Root Directory
                           |
         +-----------------+--------------------------------+
         |                 |                                |
      Programs    Word-processing data                Accounting data
    subdirectory     subdirectory                      subdirectory
                           |                                |
                   +----------------+               +----------------+
                   |                |               |                |
                Letters          Reports      Current year      Prior year
              subdirectory     subdirectory   subdirectory     subdirectory

    A subdirectory is stored in a disk's files area, just like any other
    file. The format of directory entries in a subdirectory is identical to
    the format of entries in a root directory, but a subdirectory is not
    limited in size. Like an ordinary file, a subdirectory can grow without
    bounds as long as disk space is available to hold it.

    A subdirectory is always attached to a parent directory, which can be
    either the root directory or another subdirectory. When you nest
    subdirectories, one within another, they are related in the form of a
    tree structure.

    A parent directory has one entry for each of its subdirectories. A
    subdirectory entry is just like a filename entry, except that the
    attribute byte marks the entry as a subdirectory and the file-size field
    is set to 0. The actual size of the subdirectory can be found by tracing
    its allocation chain through the FAT.

    When DOS creates a subdirectory, it places two special entries in it,
    with . and . . as filenames. These act like entries for further
    subdirectories, but . actually refers to the present subdirectory and .
    . refers to its parent directory. The starting cluster number in each of
    these directory entries gives the location of the subdirectory itself or
    of its parent. When the starting cluster number is 0, the parent of the
    subdirectory is the root directory.

    If the size of a "normal" file is reduced, you can generally count on
    DOS to release any unused space. In the case of subdirectories, however,
    clusters of space that are no longer used (because the directory entries
    that occupied that space are erased) are not released until the entire
    subdirectory is deleted.
  --------------------------------------------------------------------------

  Bit 3 marks a directory entry as a volume label. A volume label entry is
  properly recognized only in the root directory, and uses only a few of the
  eight fields available in the directory entry: The label itself is stored
  in the filename and extension fields, which are treated as one unified
  field for this purpose; the size and starting cluster fields are not used,
  but the date and time fields are.

  Bit 4, the subdirectory attribute, identifies a directory entry as a
  subdirectory. Because subdirectories are stored like ordinary data files,
  they need a supporting directory entry. All the directory fields are used
  for these entries, except the file-size field, which is zero. The actual
  size of a subdirectory can be found simply by following its space
  allocation chain in the FAT.

  Bit 5, the archive attribute, was created to assist in making backup
  copies of the many files that can be stored on a fixed disk. This bit is 0
  on all files that haven't changed since they were last backed up; DOS sets
  this bit to 1 whenever a file is created or modified.

  Offset 0CH: Reserved

  This 10-byte area is set aside for possible future uses. All 10 bytes are
  normally set to 0.

  Offset 16H: The time

  This field contains a 2-byte value that marks the time that the file was
  created or last changed. It is used in conjunction with the date field,
  and the two together can be treated as a single 4-byte unsigned integer.
  This 4-byte integer can be compared with those in other directory entries
  for greater-than, less-than, or equal values. The time, by itself, is
  treated as an unsigned word integer. It is based on a 24-hour clock and is
  built out of the hour, minutes, and seconds with this formula:

  Time=(Hourx2048)+(Minutesx32)+(Seconds.2)

  The 2-byte word used to store the time is one bit too short to store all
  the seconds, so seconds are stored in units of 2 seconds from 0 through
  29; a value of 5, for example, would represent 10 seconds. The time
  11:32:10 would be stored as the value 5C05H (decimal 23557).

  Offset 18H: The date

  This field contains a 2-byte value that marks the date the file was
  created or last changed. It is used in conjunction with the time field,
  and the two together can be treated as a single 4-byte unsigned integer
  that can be compared with those in other directory entries for
  greater-than, less-than, or equal values. The date, by itself, is treated
  as an unsigned word integer that is built out of the year, month, and day
  with this formula:

  Date=((Year-1980)x512)+(Monthx32)+Day

  This formula compresses the year by subtracting 1980 from it. Thus, the
  year 1988 is calculated as a value of 8. Using this formula, a date such
  as December 12, 1988 is stored by the formula as 118CH (decimal 4492):

  (1988-1980)x512+12x32+12=4492

  Although this scheme allows for years up through 2107, the highest year
  supported by DOS is 2099.

  Offset 1AH: The starting cluster number

  The seventh field of a directory entry is a 2-byte value that gives the
  starting cluster number for the file's data space. This cluster number
  acts as the entry point into the file's space allocation chain in the FAT.
  For files with no space allocated and for volume-label entries, the
  starting cluster number is 0.

  Offset 1CH: The file size

  The last field of a directory entry gives the size of the file in bytes.
  It is coded as a 4-byte unsigned integer, which allows file sizes to grow
  very large--4,294,967,295 bytes, to be exact--large enough for all
  practical purposes.

  DOS uses the file size in a file's directory entry to determine the exact
  size of the file. Because a file's disk space is allocated in clusters of
  512 bytes or more, the actual disk space occupied by a file is usually
  greater than the value in the directory entry. On disk, the space between
  the end of the file and the end of the last cluster in the file is wasted.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson