FSRESIZE HACKING INFO
=====================

I'll attempt to explain how this thing works, and how you can use it, help, etc.

A good place to refer to is fsresize.c.  The basic resize operation is performed
like this:

-------------------------------------
#include "libresize.h"

msdos_filesystem   fs;

int main() {
    trimlib_init_filesystem (&fs,           /* filesystem structure */
                             device_name,   /* physical device, eg: /dev/sda */
                             partition_no); /* partition number, eg: 3 */

    trimlib_resize_filesystem (&fs,         /* filesystem structure */
                               new_size);   /* new size in bytes */

    trimlib_close_filesystem (&fs);
}
-------------------------------------



THE ALGORITHM
=============

The trimlib_resize_filesystem () does the following:  (in order)

 * plans the cluster remap (fs::fat_remap).  This is an array that maps the
old clusters to the new ones.  fs::fats[0][cluster] == fs::fat_remap[cluster] if
a cluster is not to be moved.  Clusters that are beyond the new size of the
filesystem, or part of the directory tree are moved.  The latter is done to
make it simple to revert to the old filesystem.

 * copies the clusters that were marked to be moved.  i.e. if
fs::fats[0][cluster] != fs::fat_remap[cluster], copy the old to the new.  This
is NOT done for clusters that are part of the directory tree.

 * constructs the new directory tree.  This is necessary because the start
cluster for each directory entry (file/sub directory) may have been changed.

 * constructs the new FAT, to match the rest of the filesystem.

 * constructs the new boot sector

 * modifies the partition table



IMPORTANT INTERNAL FUNCTIONS
============================

* fatio.h provides the basic low-level stuff.  Things like
trimlib_write_cluster (filesystem, buffer, cluster_no)

* traverse.h provides routines to traverse the directory structure.  Traversal
is done in three steps:
   (1)  beginning with either trimlib_traversal_begin (fs, start_cluster, name)
        or trimlib_traverse_directory (fs, directory_entry)
        these functions return an iterator structure (trimlib_traversal_info).
   (2)  trimlib_get_next (iterator) returns the current directory entry, and
        advances to the next one.
   (3)  trimlib_traversal_complete (iterator) should be called to free memory.
   
* trimlib_prepare_filesystem (filesytem) the following:
   (1)  loads and analyses the boot sector and info sector, filling in relevant
        fields in the filesystem struct.
   (2)  allocates buffers for reading / writing.
   (3)  reads the FATs and checks for errors.
   (4)  traverses the directory structure, and classifies each cluster into
        one of:
          * available
          * bad
          * file
          * directory


