Path: utzoo!utgpu!watmath!clyde!att!ttrdc!ttrde!pfales From: pfales@ttrde.UUCP (Peter Fales) Newsgroups: comp.sys.ibm.pc Subject: Finding free space on a joined drive Message-ID: <812@ttrde.UUCP> Date: 9 Jan 89 15:19:32 GMT Organization: AT&T, Skokie, IL Lines: 58 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 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