home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / private / mpc93mar.zip / CHKDSK.DAT < prev    next >
Text File  |  1993-02-15  |  18KB  |  341 lines

  1.                            Understanding CHKDSK
  2.  
  3.      By: Ellen Siever, Boston Computer Society
  4.  
  5.      Have you ever issued the CHKDSK command expecting to find out that
  6.      everything is fine, only to discover instead that something is wrong?
  7.      Before I switched to DOS 5.0, I used CHKDSK as an easy way to see how
  8.      much free space was available on my hard drive, expecting to get the
  9.      warm fuzzy feeling that all's well with the world. Or at least with
  10.      the hard disk. Except that occasionally what I got instead was
  11.      something like this:
  12.  
  13.             Errors found, F parameter not specified.
  14.             Corrections will not be written to disk.
  15.  
  16.             16 lost clusters found in 2 chains.
  17.             Convert lost chains to files (Y/N)?
  18.  
  19.  
  20.      I'll discuss what this message means and what to do about it
  21.      later--for now, it's sufficient to say that it means there is a
  22.      problem that needs to be dealt with. Note that this was pre-DOS 5.0;
  23.      these days the message refers to lost allocation units instead --an
  24.      allocation unit is the DOS 5.0 term for what had been known as a
  25.      cluster. I'll use both terms interchangeably in this article.
  26.  
  27.      So I learned to take care of lost cluster problems. Then one day
  28.      CHKDSK came up with the following message:
  29.  
  30.             C:\PCT\PCSECURE.CFG is cross linked on allocation unit 1709
  31.             C:\NAV\INSTALL.EXE is cross linked on allocation unit 1709
  32.  
  33.      Since I hadn't known that CHKDSK ever gave anything other than "all's
  34.      well" or "lost cluster/allocation unit" messages, that was a surprise
  35.      to me, and it led me on a search for more information about CHKDSK,
  36.      which in turn resulted in this article.
  37.  
  38.                              Hard Disk Organization
  39.  
  40.      At the lowest level, your hard disk is organized into units known as
  41.      sectors. Each sector can contain 512 bytes. Files are stored on the
  42.      disk in groups of sectors that were called clusters prior to the
  43.      release of DOS 5.0, when they became known as allocation units. The
  44.      number of sectors per allocation unit is fixed and depends on the size
  45.      of the disk.
  46.  
  47.      DOS maintains two structures for the purpose of locating files on the
  48.      disk: the file allocation table (FAT) and the file directory. (There
  49.      are actually two copies of the FAT, but DOS only uses one of them.)
  50.  
  51.      The FAT is used to keep track of the disk sectors. Every FAT entry
  52.      represents one cluster and contains a code that indicates the status
  53.      of the cluster. For a cluster that is in use by a file, the FAT entry
  54.      either contains the number of the next cluster used by the file, or it
  55.      contains an end-of-file marker if it is the last cluster. If the
  56.      cluster is not in use, the entry indicates either that it is free and
  57.      available for use, or that it is a bad cluster and cannot be used. DOS
  58.      uses the next-cluster information in the FAT to chain its way through
  59.      the sectors of a file when you issue a command that accesses the file.
  60.      DOS needs to have this information because files are not necessarily
  61.      written on contiguous clusters, and it has to be able to move from one
  62.      cluster to the next.
  63.  
  64.      The directory contains the starting cluster number for each file, in
  65.      addition to the name, attributes, size, and creation date and time for
  66.      the file. When you issue the DIR command, you are accessing the
  67.      information in the file directory. DOS uses the starting cluster
  68.      number from the directory to locate the entry in the FAT that will
  69.      tell it where on the drive the file begins. It can then follow the
  70.      chain of cluster numbers through the FAT.
  71.  
  72.                                  The Command
  73.  
  74.      The CHKDSK command verifies the logical structure of the disk not the
  75.      physical structure, and it reports back to you. In checking that the
  76.      interrelationships among the directory, the FAT and the disk itself
  77.      are undamaged, it deals with the logical disk partitions. That is, if
  78.      your hard drive is petitioned into multiple disks (C: and D:, for
  79.      example), you have two disks as far as CHKDSK is concerned.
  80.  
  81.      In addition to checking the disk if you specify the /F switch, CHKDSK
  82.      can also attempt to repair any damage that it finds. However, as you
  83.      will see in more detail later, CHKDSK repairs can be of the brute
  84.      force variety, and you should get in the habit of always issuing the
  85.      command first without /F to identify any problems and then re-issuing
  86.      it with /F if and when you are sure that is the best way to proceed.
  87.      In some cases, it may be better to use other techniques or another
  88.      program, such as the Norton Utilities or pc Tools, to correct disk
  89.      problems found by CHKDSK.
  90.  
  91.      In general, for any problem other than lost clusters, try to use one
  92.      of the major disk repair programs before running CHKDSK/F. Chances are
  93.      good that will fix the problem.
  94.  
  95.      The syntax of CHKDSK is:
  96.  
  97.             chkdsk [d:] [filespec] [/f] [/v]
  98.  
  99.      The D: indicates the drive to be checked; the default is the current
  100.      drive. In the normal case where there are no problems for CHKDSK to
  101.      report, after you issue the command CHKDSK C:, you will see something
  102.      like this:
  103.  
  104.             Volume MY_DISK created 05-28-1990 4:07p
  105.  
  106.                    81264640    bytes total disk space
  107.                       98304    bytes in 4 hidden files
  108.                      327680    bytes in 40 directories
  109.                    34086912    bytes in 1053 user files
  110.                    46751744    bytes available on disk
  111.  
  112.                        8192    bytes in each allocation unit
  113.                        9920    total allocation units on disk
  114.                        5707    available allocation units on disk
  115.  
  116.                      655360    total bytes memory
  117.                      512944    bytes free
  118.  
  119.      This shows you how the space on your disk is allocated, how much is
  120.      used, and how much is available. It also indicates the amount of
  121.      memory available for running programs. If you include a filespec in
  122.      the command, CHKDSK tells you whether the file is stored on contiguous
  123.      blocks, and if not, how many it uses. For example, if you entered
  124.  
  125.             chkdsk c:\wp51\letters\*.*
  126.  
  127.      you might see the output shown above, followed by:
  128.  
  129.             C:\wp51\letters\xyzcorp.let Contains 2 non-contiguous blocks
  130.             C:\wp51\letters\dbprog.let Contains 2 non-contiguous blocks
  131.  
  132.      This gives you information on how fragmented your disk is. You don't
  133.      want your files to become too fragmented, because accessing files that
  134.      are scattered across a disk takes longer and slows down overall system
  135.      performance. If you start to see files with many non-contiguous
  136.      blocks, you should consider running a utility to unfragment the disk.
  137.  
  138.      The /F switch is used with CHKDSK to repair disk errors. Every time
  139.      you issue the CHKDSK command, CHKDSK goes through the motions of
  140.      fixing the disk. But it won't actually make any changes unless you
  141.      have specified /F in the command. The steps it takes to correct a
  142.      problem depend on what it finds and are described in the following
  143.      sections. Once CHKDSK has "fixed" the problem, you may still have work
  144.      to do to finish restoring your files.
  145.  
  146.      The /v switch causes CHKDSK to display the name of every file in every
  147.      subdirectory (and its complete path) as it checks the disk. If you are
  148.      running a version of DOS earlier than 5.0, this can be a convenient
  149.      way to get a full listing of all files on your disk. With the "new,
  150.      improved" DIR command in DOS 5.0, /v seems to have lost much of its
  151.      usefulness.
  152.  
  153.      Lost Clusters
  154.  
  155.      Lost clusters are the most common problem detected by CHKDSK. A lost
  156.      cluster is one which is marked in the FAT as being in use, but which
  157.      is not part of any file in the directory. A contiguous group of lost
  158.      clusters is a lost chain. CHKDSK/F will convert each lost chain to a
  159.      file if you answer Y, or will free the disk space if you answer N, to
  160.      the "convert to file?" message.
  161.  
  162.      If you run CHKDSK (without /F), and you get a lost clusters message
  163.      like the one shown in the example at the beginning of this article,
  164.      CHKDSK has followed all the chains from the directory through the FAT
  165.      and in doing so, it has noted that some number of entries in the table
  166.      (16 in the example) are not part of any chain from the directory; in
  167.      this case there are 2 chains involved.
  168.  
  169.      You can now re-run CHKDSK with /F, and it will ask you:
  170.  
  171.             16 lost clusters found in 2 chains.
  172.             Convert lost chains to files (Y/N)?
  173.  
  174.      When you ran initially without /F, it didn't matter whether you
  175.      answered Y or N to the prompt--CHKDSK wouldn't make any changes either
  176.      way. But now that you've specified /F, if you answer Y, CHKDSK creates
  177.      two files in your root directory, one for each chain, called
  178.      FILE0000.CHK and FILE0001.CHK. It always adds one file per chain and
  179.      numbers them sequentially starting with 0000.
  180.  
  181.      You can then examine each .CHK file with the TYPE command, with a
  182.      utility program like Vern Buerg's List program, or with the text
  183.      editor of your choice, to see if it contains any useful information.
  184.      If so, you can rename the file to save it, or copy the data to another
  185.      file. Otherwise, you can safely delete the .CHK files.
  186.  
  187.      Why do lost cluster problems occur? Usually it is because a program
  188.      has ended before all files were properly closed. Maybe a program hung
  189.      and you had to reboot or maybe there was a power failure. When I first
  190.      used Ventura Publisher, I had problems getting it to work with my
  191.      printer and used to use [Ctrl]+ [Alt]+[Delete] to reboot the system so
  192.      I could try again. Not too surprisingly, I got a lot of lost clusters
  193.      when rebooting killed Ventura with my text file open. I always allowed
  194.      CHKDSK to convert the lost chains to files, I always checked the
  195.      files, I always ended up deleting them, and my original files were
  196.      always fine. But I'll continue to check each time I get a lost
  197.      cluster, to make sure. What if you answer N to the "convert lost
  198.      chains to files?" message? In that case, CHKDSK marks the sectors in
  199.      those chains as free in the FAT, and they become available for reuse.
  200.      Whether you answer yes or no, CHKDSK /F corrects the problem so that
  201.      your system is once more internally consistent.
  202.  
  203.      The difference lies in whether or not you want to try to recover data
  204.      from the lost chains. It's possible that recovering those lost
  205.      clusters will lead to further lost clusters being uncovered, and that
  206.      you will have to run CHKDSK several times before you get a clean
  207.      report. At that point, you know you have uncovered and repaired them
  208.      all.
  209.  
  210.      If you never run CHKDSK (or another disk analysis program), the lost
  211.      allocation units remain unavailable, and you will essentially have
  212.      lost the use of some of your disk space. If your system locks up
  213.      during program execution and you have to reboot, or there is a power
  214.      failure while you are in the middle of modifying a data or text file,
  215.      it's a good idea to run CHKDSK when the system comes up next, to make
  216.      sure everything is okay.
  217.  
  218.      Cross Linked Files
  219.  
  220.      Cross linked files occur when more than one chain is linked to the
  221.      same entry in the FAT--that is, one cluster is assigned to more than
  222.      one file. If that happens, you need to fix the problem before you can
  223.      safely use either file. CHKDSK /F won't help, but it won't do any
  224.      harm. The best solution (assuming that you have backups), and the only
  225.      really safe one if the files are executables (as they were when it
  226.      happened to me), is to delete both files and restore from the
  227.      originals or from backups. I did that and everything was fine after
  228.      that.
  229.  
  230.      If you don't have backups, try copying both files to a diskette or a
  231.      new directory and erasing the original cross linked files. Then
  232.      examine both files with an editor or file viewer--at least one and
  233.      possibly both of them will have problems--and take whatever steps seem
  234.      to be appropriate to fix them, depending on what you find.
  235.  
  236.      If you start to get cross linked files often, there may be a hardware
  237.      problem that you should investigate.
  238.  
  239.      Size Allocation Errors
  240.    
  241.      If CHKDSK reports something like:
  242.  
  243.                Errors found, F parameter not specified
  244.                Corrections will not be written to disk
  245.                C:\DBPROG.LET
  246.                Allocation error, size adjusted.
  247.  
  248.      that means that the size of the file as indicated in the directory
  249.      does not agree with the number of entries in the FAT for the file. If
  250.      you proceed to run CHKDSK /F, CHKDSK will assume that the FAT is
  251.      correct and the directory is wrong, and it will force the file's
  252.      directory entry to match the FAT entry. But this might not be the
  253.      right solution, since it could be that the directory is correct and
  254.      the FAT incorrect. In this case, it would be better to try one of the
  255.      disk repair utilities first. Otherwise, run the DIR command to see if
  256.      the file size it shows seems reasonable--if it does, try first copying
  257.      the file somewhere else, then try deleting the original file and using
  258.      an undelete utility to recover it.
  259.  
  260.      Invalid Allocation Unit
  261.      
  262.      If you get an "invalid allocation unit, file truncated" message,
  263.      CHKDSK found a zero or an otherwise invalid "next cluster" pointer
  264.      while following a chain through the FAT--one that doesn't point to
  265.      another cluster and isn't an end-of-chain entry. As in the previous
  266.      case, the best thing to do is run a utility disk repair program.
  267.  
  268.      If instead you run CHKDSK /F (run DIR first and see if the file length
  269.      seems reasonable), it will "solve" the problem by writing an
  270.      end-of-chain entry in place of the invalid entry (i.e., it will
  271.      truncate the entry), or if the problem was with the first cluster (an
  272.      invalid starting-cluster number), it will set the length to zero. You
  273.      may then find the missing data in a .CHK file.
  274.  
  275.      Another alterative is to try deleting and then undeleting the file.
  276.  
  277.                      Invalid Subdirectory Entry
  278.  
  279.      This is another case where it the best solution is to try running a
  280.      utility repair program first. The message
  281.  
  282.             C:\MYDIR
  283.             Invalid sub-directory entry
  284.             Convert directory to file (Y/N)?
  285.  
  286.      means that there is something wrong with the entry for the specified
  287.      directory so that CHKDSK was unable to follow the directory tree.
  288.  
  289.      If you run CHKDSK /F, it turns the directory into a file. That may be
  290.      the right solution if you know that the so-called directory is really
  291.      a file and somehow the directory attribute mistakenly got set.
  292.  
  293.      If it really is a directory, first run a utility if you have one.
  294.      Otherwise try to copy all the files in the directory and any of its
  295.      subdirectories elsewhere, then delete the directory and subdirectories
  296.      and recreate them from the files you moved.
  297.  
  298.      In the worst case, run CHKDSK /F, answer Y to the "convert to file?"
  299.      prompt and try to recover as much as you can from the lost sectors
  300.      that will be put into .CHK files.
  301.  
  302.      If CHKDSK discovers that the first byte of the FAT is not valid, it
  303.      gives you the message "probable non-DOS disk." If it really is a DOS
  304.      disk something has overwritten that initial byte. Once again, the
  305.      utility programs can be used to correct the invalid byte.
  306.  
  307.                            CHKDSK and Windows
  308.  
  309.      What if you're running Windows? Does that affect your use of CHKDSK?
  310.      Yes, it does. You should always exit from Windows before running
  311.      CHKDSK with the /F switch. The Microsoft Windows User's Guide says to
  312.      "always quit Windows before running the CHKDSK command with the /F
  313.      option; never run CHKDSK /F from Windows. Loss of data might result."
  314.      According to the DOS manual, this can happen if there are open files
  315.      that haven't yet been recorded in the FAT--in that case, CHKDSK might
  316.      report them as lost allocation units.
  317.  
  318.                                Conclusion
  319.  
  320.      Use CHKDSK first without /F; if you find a problem other than a lost
  321.      cluster, try moving the affected file(s) and running one of the
  322.      utility programs; as a last resort run CHKDSK /F and recover what you
  323.      can from the files it creates. If the problem is a lost cluster, run
  324.      CHKDSK /F, let it make the .CHK files, and examine them.
  325.  
  326.      If you don't already own one of the major utility packages, and if
  327.      it's at all possible to do so, buy one--they have many useful features
  328.      besides the disk fixing capabilities.
  329.  
  330.      Run CHKDSK periodically to make sure all is well. Even if all you ever
  331.      see is lost cluster messages (and most likely that is what you'll see,
  332.      if anything), it's worth doing, just to recover the disk space and
  333.      make it available again for new files.
  334.  
  335.      And finally, make regular backups.
  336.  
  337.      **********************************************************************
  338.  
  339.      Ellen Siever is a freelance writer with over 20 years of technical
  340.      computer industry experience.
  341.