<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 20 Dec 1983 08:34:00 EST
From   : Eric Stork <STORK@mit-mc>
Subject: Computing Free Space on a disk

Re your question:
    Date: 16 Dec 83 7:47:02-PST (Fri)
    To: info-cpmbrl
    From:
    hplabs!hao!seismo!rlgvax!cvl!umcp-cs!aplvax!deducb-vax
    Subject: Computing free space on a disk
    There  comes  a  time  when I would like to know how much
    free space remains on a  disk  in  a  CP/M  system.   The
    question  is:  how do I find out?  One way is to scan the
    file directory, keeping a running count of sectors  used,
    and subtract that sum from the total available.  Is there
    an easier way?


If I understand correctly (i.e., you want to include a routine in
a  file  that  checks  remaining  disk space), what you need is a
combination of data from BDOS Functions 27 and 31.  #27 points to
the  disk  map, where there is a string of bits (not bytes,   tho
of course grouped into bytes) that say if a block on a disk is in
use or not.  Function 31 tells you other data you need about your
disk, e.g., density, sectors per track, etc.

Then you need to combine these into a program segment that counts
the empty blocks, multiplies  by  their  size,  and  reports  the
result.   There  is  a  fine  example by M. Karas in November '82
LIFELINES.

Using that example, plus the superb description of BDOS functions
in Johnson-Laird's THE PROGRAMMERS CP/M HANDBOOK, I was  able  to
write  a  routine  for my favorite editor that pretty well solves
the problem of a full disk when  saving  a  file.     My  routine
checks  remaining  disk space,  checks the size of the file being
loaded into the editor, the size of the BAK file  (if  any),  and
then  calculates how much space will remain after deletion of the
old BAK file, creating of the new BAK file,  and  saving  of  the
edited file.  If that value is less than 20k, the editor warns me
and allows me to abort right then.  If the value is less than 4k,
the editor will not let me load the file at all.  (I mention this
just to show that the Karas routine works and is very useful.)

Good luck.  If I can help more, let me know.

Eric
SUBJECT: Computing Free Space on a disk

Re your question:
    Date: 16 Dec 83 7:47:02-PST (Fri)
    To: info-cpmbrl
    From:
    hplabs!hao!seismo!rlgvax!cvl!umcp-cs!aplvax!deducb-vax
    Subject: Computing free space on a disk
    There  comes  a  time  when I would like to know how much
    free space remains on a  disk  in  a  CP/M  system.   The
    question  is:  how do I find out?  One way is to scan the
    file directory, keeping a running count of sectors  used,
    and subtract that sum from the total available.  Is there
    an easier way?


If I understand correctly (i.e., you want to include a routine in
a  file  that  checks  remaining  disk space), what you need is a
combination of data from BDOS Functions 27 and 31.  #27 points to
the  disk  map, where there is a string of bits (not bytes,   tho
of course grouped into bytes) that say if a block on a disk is in
use or not.  Function 31 tells you other data you need about your
disk, e.g., density, sectors per track, etc.

Then you need to combine these into a program segment that counts
the empty blocks, multiplies  by  their  size,  and  reports  the
result.   There  is  a  fine  example by M. Karas in November '82
LIFELINES.

Using that example, plus the superb description of BDOS functions
in Johnson-Laird's THE PROGRAMMERS CP/M HANDBOOK, I was  able  to
write  a  routine  for my favorite editor that pretty well solves
the problem of a full disk when  saving  a  file.     My  routine
checks  remaining  disk space,  checks the size of the file being
loaded into the editor, the size of the BAK file  (if  any),  and
then  calculates how much space will remain after deletion of the
old BAK file, creating of the new BAK file,  and  saving  of  the
edited file.  If that value is less than 20k, the editor warns me
and allows me to abort right then.  If the value is less than 4k,
the editor will not let me load the file at all.  (I mention this
just to show that the Karas routine works and is very useful.)

Good luck.  If I can help more, let me know.

Eric
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>