[comp.sys.ibm.pc] Finding free space on a joined drive

pfales@ttrde.UUCP (Peter Fales) (01/09/89)

Someone was asking how to find out how much space is available on
a drive, when that drive has been JOINed to another directory.  At least
one solution has been posted, but I think the following method is much 
simpler, even though it also depends on an undocumented DOS function.
(This is function is documented in Ralf Brown's interrupt list, an
excellent reference, which has been posted to the net).

------------------------------ cut here -------------------------------------

/****************************************************************************

    FUNCTION: DiskFreeSpace

    PURPOSE: Returns number of free bytes on selected disk.  Argument
	is a path to a file or directory on the selected disk.  If the
	file is actually on a JOINed drive, the amount of free space
	on the joined drive will be returned.

****************************************************************************/

#include <dos.h>

long
DiskFreeSpace(char *path)
{
	union	REGS r;
	struct 	SREGS s;
	char 	buffer[80];

/* Use the undocumented DOS function 0x60 to map a relative path to a fully
qualified path name.  Then use the first character of that pathname to
determine the drive to which that path belongs.  The key thing here is
that it works even if the path is on another drive that has been JOINed */
	r.x.ax = 0x6000;
	r.x.si = (unsigned)path;	/* ds:si is input path */
	segread(&s);
	r.x.di = (unsigned)buffer;	/* es:di is output path */
	s.es = s.ds;
	intdosx(&r,&r,&s);

/* The first character of the returned path is the drive name, so we
use function 0x36 to read the free space */

	r.x.ax = 0x3600;
	r.x.dx = buffer[0]-'A'+1;
	intdos(&r,&r);
			/* Returns: Sectors/cluster in ax 
				    Bytes/sector in cx
				    Available clusters in bx 
			*/
	return((long)r.x.bx * r.x.cx * r.x.ax);
}
-- 
Peter Fales			AT&T, Room 2F-217
				200 Park Plaza
UUCP:	...att!ttrde!pfales	Naperville, IL 60566
Domain: pfales@ttrde.att.com	work:	(312) 416-5357		

Ralf.Brown@B.GP.CS.CMU.EDU (01/10/89)

In article <812@ttrde.UUCP>, pfales@ttrde.UUCP (Peter Fales) writes:
}/* Use the undocumented DOS function 0x60 to map a relative path to a fully
}qualified path name.  Then use the first character of that pathname to
}determine the drive to which that path belongs.  The key thing here is
}that it works even if the path is on another drive that has been JOINed */

I also tried it on a SUBSTed path, and that worked the same way.  Just a drive
letter did strange things, though (looks like the DOS function doesn't put
anything into the result buffer).


INT 21 - DOS 3+ internal - RESOLVE PATH STRING TO FULLY QUALIFIED PATH STRING
        AH = 60h
        DS:SI -> ASCIZ relative path string
        ES:DI -> 67???-byte buffer for ASCIZ fully qualified name
Return: buffer filled with qualified name of form D:\PATH
        may return error code, unknown.
Note:   if path string is on a JOINed drive, the returned name is the one that
        would be needed if the drive were not JOINed; similarly for a SUBSTed
        drive letter.  Because of this, it is possible to get a qualified name
        that is not legal with the current combination of SUBSTs and JOINs


--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=-=-=- Voice: (412) 268-3053 (school)
ARPA: ralf@cs.cmu.edu  BIT: ralf%cs.cmu.edu@CMUCCVMA  FIDO: Ralf Brown 1:129/31
			Disclaimer? I claimed something?
	You cannot achieve the impossible without attempting the absurd.