Re: Resizing FAT partitions



David, thank you for your quick response.

I was not entirely clear in my original post about the purpose of this
project so let me explain now. This is actually additional functionality
that a client is requesting for their USB duplicator software which I have
created. The software is used to copy from a source USB drive to many drives
at once (up to 60).

Currently, there are options for file copy and also a drive copy which
performs a byte-for-byte copy of the raw disk device (PhysicalDriveX), from
start to finish, including any unused portions. The new features being
requested are to allow "short imaging" of a disk by skipping unused portions
of the drive and also to allow for very basic partition resizing on-the-fly,
especially for copying larger drives (32GB+).

As you mentioned, the current code works fine when copying to a larger drive
and just leaves extra unpartitioned space at the end of the drive. This is
one of the inconveniences they wish to eliminate.

As for your suggestion of formatting the target drive and using xcopy to get
the files over, I have already designed this USB duplication software with
that capability, however the problem that users are encountering is that file
copies can take a VERY large amount of time when working with large numbers
of small files and writing to slower USB thumb drives. In cases like this,
it would be way more efficient to perform a copy of the entire device,
skipping unused portions, and resize the partition (if necessary).

Since copy speed is a major concern here, it wouldn't make a lot of sense
for this application to do anything to modify the content of the disk in a
major way, such as rearranging the file system based on a new cluster size
(thank you for bringing this to my attention however!). In light of this, I
will likely just allow them to keep the current cluster size and resize the
partition. For disks larger than 32GB formatted with FAT32, the cluster size
is 32k already so if they were trying to copy a 150GB partition to a 40GB
drive there would be no problem. If on the other hand they were trying to
copy to a 20GB hard drive they would end up with a partition of ~20GB with a
cluster size of 32k (even though the default for a 20GB FAT32 partition would
be 16k if it was reformatted). This will be a limitation they can live with.
If they really need to change the cluster size, they have many options such
as formatting the target drive(s) and performing a file copy or using a
partition tool on the source drive to resize the partition and then dupe the
drive.

I hope this has provided a little bit more background as to what I need to
accomplish and why I need to do it the way I am. I have studied the
fatgen103.docx over multiple times and am using it as my main source of
information here.

So, after all that explanation, my question I think is somewhat
straightforward. Can resizing a partition really be as simple as just
changing the appropriate values in the partition table and the BS/BPB
provided I am not modifying the cluster size?

Thanks again!!

David

"David Craig" wrote:

1. Have you considered using Partition Magic or several other utilities?
2. If you are copying from a smaller drive to a larger drive, your current
utility should work. You will have some sectors not included in any
partition, but that won't hurt you and they can be used to create another
partition.
3. If you must, then consider just formatting the target and using xcopy to
get the files over there. Depending upon the cluster size differences you
will not be able to just copy data sectors (defragmented or not) without
knowing what file is located in which sector(s).
4. You said you read the Microsoft technical article on FAT. Is that
fatgen103.docx? If not, find it.


"David K." <DavidK@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F3F2023D-473D-41F0-8F28-76400CDFD6B0@xxxxxxxxxxxxxxxx
I'm not sure if this is the correct place to post this question, however I
couldn't find anywhere that was really more appropriate. If it should be
moved, please let me know.

I currently have some code that copies data byte-for-byte from one disk
directly to another (most likely from one source drive out to multiple
drives) using Windows API functions such as CreateFile, ReadFile,
WriteFile,
etc. My code works great and is fairly well optimized speed-wise when
copying to disks that are the exact size of the source disk.
Unfortunately,
a lot of the target disks that are being written to will not be the same
size
as the source disk. As it stands, my code cannot handle this case, and it
ends gracefully with an error.

At this point I need to add the ability to resize a single partition while
copying to each of the disks. For example, say the source drive is 120GB
with a single 120GB partition on it that contains only 20GB of data.
Provided that the source drive has been defragmented, I should be able to
copy the 120GB drive to 40GB drives and dynamically resize the partition
as I
am copying by modifying the partition table in the MBR and the FAT boot
sector (only FAT16/FAT32 will be supported for now).

I've done a considerable amount of research on this, and read the
Microsoft
technical article documenting the FAT boot sector, BPB, etc. I've also
read
up on the MBR and familiarized myself with how it is layed out. Having
done
all this, I feel like I have a good grasp of what values need to be
changed
in the partition table and FAT boot sector to be done to accomplish the
task
of resizing a partition. However, before digging in and attempting to
modify
a drive's MBR and FAT boot sector to practice resizing a partition, I
wanted
to double check and make sure I'm not missing something here.

First thing that needs to be changed is the partition table in the MBR. I
shouldn't need to modify the Beginning of Partition CHS value since I will
only be doing this for the first partition and not supporting drives with
multiple partitions. I will need to modify the End of Partition CHS value
as
well as the value containing the number of sectors in the partition.

As for the boot sector, I should only need to modify the value specifying
the number of sectors in the partition (stored in one of two places
depending
on the size of the partition being described). According to Microsoft
documentation, the size of the FAT can be larger than required, so I would
only need to extend the size of the FAT (and move everything else on the
disk
further forward in turn) if I was increasing the size of the partition.
When
resizing to make it smaller, it can stay the same size and part of it will
just be unused.

If I'm missing something or misunderstanding what I need to do, I would
appreciate some correction on the matter. Any advice or useful
tips/comments
are greatly appreciated.

Thanks,

David



.



Relevant Pages

  • Re: Dual Boot Instructions
    ... the PHYSICAL DISK number, ... Partition and Boot Volume as well as other things. ... You should, at any one time, see ONE System Partition and ONE Boot Volume - ... for the typical two floppy drives and assigning Drive C: ...
    (microsoft.public.windows.vista.hardware_devices)
  • Re: Boot Problem
    ... Right mouse click the dest disk> Advanced> Edit ... but it should eventually boot to Windows. ... I see a lot of posts in here about the ability of Acronis to clone drives. ... I have managed to successfully copy by DELETING partition, ...
    (microsoft.public.windowsxp.hardware)
  • Re: A Dual-boot question; I thought C was always the partition with the running OS
    ... The Server 2003 will then call its partion "C:" Local Disk. ... When Server 2003 starts up, it will call itself "C:" and it will call the WinXP partition "E:", but again, who cares? ... The OS then assigns drive letters to the first primary partition recognized on each successive hard disk. ... Because they're on separate hard drives, ...
    (microsoft.public.windowsxp.setup_deployment)
  • vinum limits disk size to 255MB
    ... I'm trying to set up vinum on a freshly installed FreeBSD 5.3-BETA7 ... drives to create a vinum volume. ... BIOS sector numbering starts with sector 1 ... The data for partition 1 is: ...
    (freebsd-questions)
  • RE: Change Tracks Per Sector on system Partition
    ... mirroring system partitions of a cluster to an offsite SAN due to differing ... We cannot physically read the file system boot sector usually at ... If your software mirror a Windows NT/2000/2003 operating system partition ... another disk that is translated as 32spt, ...
    (microsoft.public.windows.server.setup)