home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / sys / vfs / statfs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-11  |  1.1 KB  |  49 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <dpmi.h>
  3. #include <errno.h>
  4. #include <sys/vfs.h>
  5. #include <ctype.h>
  6.  
  7. int
  8. statfs(const char *path, struct statfs *buf)
  9. {
  10.   __dpmi_regs regs;
  11.   int drive_number;
  12.  
  13.   /* Get the drive number */
  14.   if (isalpha(path[0]) && path[1] == ':')
  15.     drive_number = (path[0] & 0x1f) - 1;
  16.   else
  17.   {
  18.     regs.h.ah = 0x19;
  19.     __dpmi_int(0x21, ®s);
  20.     drive_number = regs.h.al;
  21.   }
  22.  
  23.   /* Get free space info */
  24.   regs.h.ah = 0x36;        /* DOS Get Free Disk Space call */
  25.   regs.h.dl = drive_number + 1;
  26.   __dpmi_int(0x21, ®s);
  27.  
  28.   /* Check for errors */
  29.   if ((regs.x.ax & 0xffff) == 0xffff)
  30.   {
  31.     errno = ENODEV;
  32.     return -1;
  33.   }
  34.  
  35.   /* Fill in the structure */
  36.   buf->f_bavail = regs.x.bx;
  37.   buf->f_bfree = regs.x.bx;
  38.   buf->f_blocks = regs.x.dx;
  39.   buf->f_bsize = regs.x.cx * regs.x.ax;
  40.   buf->f_ffree = regs.x.bx;
  41.   buf->f_files = regs.x.dx;
  42.   buf->f_type = 0;
  43.   buf->f_fsid[0] = drive_number;
  44.   buf->f_fsid[1] = MOUNT_UFS;
  45.   buf->f_magic = FS_MAGIC;
  46.  
  47.   return 0;
  48. }
  49.