ihom@sdcsvax.ARPA (07/24/85)
Does anyone know of a correct algorithm for finding the amount of free space on a drive in Turbo Pascal? My quick and dirty algorithm below outputs the corect results on my 128k floppies and 96k RAM disk, but errors on a hard drive. When a drive is activated in CP/M, an allocation vector is set up to determine the amount of free space remaining on the drive. This vector is composed of bits with a 0 indicating a free block and a 1 indicating an allocated block. Calling BDOSHL(alloc_vect) puts the address of the allocation vector (for the current selected drive) in the HL register pair. "temp" points to the address in memory where the allocation vector is stored. "quotient" incre- ments to the next consecutive 8-bit byte in the vector. "freek" tallies up all the 0 bits and is the value for the space remaining. Would someone compile and execute this, and mail me the results? (Be sure to change the constant "total_k" to match your drive size.) Or better yet, supply me with a correct algorithm... --Irwin Hom ...crash!ihom@ucsd ---------cut here---------cut here---------cut here---------cut here--------- program free_space; const alloc_vect = $1B; { Allocation vector address } total_k = 128; { since the total kilobytes is easy to find in the } { DPB, set to a constant here for this example } type alvec = byte; var cnt,freek,i : integer; quotient : byte; temp : ^alvec; begin writeln('Total k = ',total_k); { address of space allocation bit vector } temp := ptr(BDOSHL(alloc_vect)); freek := 0; { counter for free blocks } for i := 0 to (total_k div 8) - 1 do { 8 bits per byte } begin cnt := 0; { bit counter } quotient := mem[addr(temp^) + i]; writeln(quotient); while quotient > 0 do { kludge to convert from dec to bin } { 0 = free, 1 = allocated } begin { start from LSB to MSB } if not odd(quotient) then { even = free block } freek := freek + 1; cnt := cnt + 1; quotient := quotient div 2 end; freek := freek + (8 - cnt) { add remaining (0 bits) free blocks } end; writeln('Free k = ',freek) end. -----------------------------
ihom@sdcsvax.ARPA (07/25/85)
Yesterday, I left a message and algorithm about the problem I was having in finding the free space on a drive. Well, in less than twenty-four hours, I discovered my error -- I forgot to take the block size into consideration. Nevertheless, the algorithm works now. Disregard the previous sample program. I'll post the results if anyone is interested. --Irwin Hom ...crash!ihom@ucsd