🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.programmer
Article #566

Re: Problem with disk full in programs compiled with Turbo-C

#566
From: 2fjomummer
Date: Sat, 02 Jun 1990 01:21
43 lines
2300 bytes
Article-I.D.: kuhub.22661.2612e98b
References: <5705@ncsugn.ncsu.edu>
Organization: University of Kansas Academic Computing Services
Lines: 38

In article <5705@ncsugn.ncsu.edu>, emigh@ncsugn.ncsu.edu (Ted H. Emigh) writes:
> I am using Turbo-C (Version 2.0), and am having trouble determining if the
> disk is full.  I have tried the obvious (at least to me obvious):
> 1)	Code fragment:
> 	result=fprintf(...)
> 	if(result==EOF) { do something}
> 
> 	result always returns the number of characters -- even if the disk
> 	is full.  There is disk activity, but nothing is written (obviously).
> 
> 2)	Code fragment:
> 	harderr(hardware_handler);
> 	...
> 	int hardware_handler() { do something }
> 
> 	This routine is never called for disk full.  It functions OK for write-
> 	protect and disk not ready, but not for disk full.
> 
> Do you have any suggestions to help detect disk full?  Thanks.

Although I've never actually tried it, there is an MS-DOS function that reports
the free space on a drive.  I'm basically a Turbo Pascal programmer, so I don't
know the exact commands for C, but the function you want to call is 36h.  You
put 36h in AH and the drive code in the DL register (use 0 for the default
drive, 1 for drive A:, 2 for drive B:, etc.).  If the drive code that
was given is bad, AX will be set to FFFFh, otherwise Dos will return the
following:
	AX = sectors per cluster
	BX = available cluster count
	CX = bytes per sector
	DX = total clusters on the disk
So, the total number of free bytes is simply AX * BX * CX.

If you call this before you perform the write, you should be able to tell if
you have enough free space on the disk.

By the way, I must give credit where it is due.  I got most of the above from
Peter Norton's  _Programmer's Guide to the IBM PC_.  Good book.
Technical Details
Message-ID: <22661.2612e98b@kuhub.cc.ukans.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ns-mx!iowasp!deimos.cis.ksu.edu!unmvax!sci.ccny.cuny.edu!cucard!dasys1!cooper!phri!sci.ccny.cuny.edu!rpi!zaphod.mps.ohio-state.edu!usc!wuarchive!kuhub.cc.ukans.edu!2fjomummer

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ns-mx!iowasp!deimos.cis.ksu.edu!unmvax!sci.ccny.cuny.edu!cucard!dasys1!cooper!phri!sci.ccny.cuny.edu!rpi!zaphod.mps.ohio-state.edu!usc!wuarchive!kuhub.cc.ukans.edu!2fjomummer
From: 2fjomummer@kuhub.cc.ukans.edu
Newsgroups: comp.sys.ibm.pc.programmer,alt.msdos.programmer
Subject: Re: Problem with disk full in programs compiled with Turbo-C
Message-ID: <22661.2612e98b@kuhub.cc.ukans.edu>
Date: 2 Jun 90 01:21:25 GMT
Lines: 43