[comp.sys.amiga.tech] Calculating blocks used by file

utoddl@uncecs.edu (Todd M. Lewis) (10/27/89)

Hello, net:

     A friend and I are working on a program which will end up
copying lots of files to lots of floppies.  We need to know how to
calculate how many blocks a group of files will use on a floppy,
including the overhead for directory entries, etc.  We would like
the user to be able to select a bunch of files and have the program
be able to tell
    1) if the files will fit on a given floppy,
    2) how many blocks will be used, and
    3) how many blocks will be left.

(Ok, so 3 should be easy if you know 1 and two.)  So how
does one (or in our case, two) go about calculating such things.
Your help is greatly appreciated.
_____        
  |      Todd M. Lewis            Disclaimer: If you want my employer's
  ||\/|  utoddl@ecsvax.uncecs.edu             ideas, you'll have to
  ||  || utoddl@ecsvax.bitnet                 _buy_ them. 
       |___   ("Prgrms wtht cmmnts r lk sntncs wtht vwls." --TML)

ccplumb@rose.waterloo.edu (Colin Plumb) (10/27/89)

In article <1989Oct26.190532.3479@uncecs.edu> utoddl@uncecs.edu (Todd M. Lewis) writes:
>    1) if the files will fit on a given floppy,
>    2) how many blocks will be used, and
>    3) how many blocks will be left.
>
>(Ok, so 3 should be easy if you know 1 and two.)  So how
>does one (or in our case, two) go about calculating such things.
>Your help is greatly appreciated.

This is easily drived from the information in the AmigaDOS Technical Reference
Manual, which you probably have.

To compute the number of blocks a file will take up, divide its size in
bytes by 488 (for OFS) or 512 (for FFS).  Then add 1/72 of this number
(round up, and there is always at least 1) blocks of overhead.  Files
from 0 to 72 blocks long have 1 block of overhead; files from 73 to 144
blocks long have two blocks of overhead, etc.

A directory is 1 block, period.

A floppy also usually contains two boot blocks and one block of bitmap.
On top of that, just count the root directory as a normal directory and
that should be all you need.  A blank floppy has 880*2 = 1760 blocks free.
1756 after allocating the boot blocks, bitmap block, and root directory.
-- 
	-Colin