home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / libsrc / c / sys / statfs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-24  |  1.4 KB  |  56 lines

  1. /*
  2.   (c) Copyright 1992 Eric Backus
  3.  
  4.   This software may be used freely so long as this copyright notice is
  5.   left intact.  There is no warrantee on this software.
  6. */
  7.  
  8. #include <dos.h>        /* For REGS and intdos() */
  9. #include <errno.h>        /* For errno */
  10. #include <sys/vfs.h>        /* For statfs() */
  11.  
  12. /* From fixpath.c */
  13. extern int    _get_default_drive(void);
  14.  
  15. /* An implementation of statfs() for DJGPP. */
  16. int
  17. statfs(const char *path, struct statfs *buf)
  18. {
  19.     union REGS        regs;
  20.     int            drive_number;
  21.  
  22.     /* Get the drive number */
  23.     if (path[0] >= 'a' && path[0] <= 'z' && path[1] == ':')
  24.     drive_number = path[0] - 'a';
  25.     else if (path[0] >= 'A' && path[0] <= 'Z' && path[1] == ':')
  26.     drive_number = path[0] - 'A';
  27.     else
  28.     drive_number = _get_default_drive();
  29.  
  30.     /* Get free space info */
  31.     regs.h.ah = 0x36;        /* DOS Get Free Disk Space call */
  32.     regs.h.dl = drive_number + 1;
  33.     (void) intdos(®s, ®s);
  34.  
  35.     /* Check for errors */
  36.     if ((regs.x.ax & 0xffff) == 0xffff)
  37.     {
  38.     errno = ENODEV;
  39.     return -1;
  40.     }
  41.  
  42.     /* Fill in the structure */
  43.     buf->f_bavail = regs.x.bx;
  44.     buf->f_bfree = regs.x.bx;
  45.     buf->f_blocks = regs.x.dx;
  46.     buf->f_bsize = regs.x.cx * regs.x.ax;
  47.     buf->f_ffree = regs.x.bx;
  48.     buf->f_files = regs.x.dx;
  49.     buf->f_type = 0;
  50.     buf->f_fsid[0] = drive_number;
  51.     buf->f_fsid[1] = MOUNT_UFS;
  52.     buf->f_magic = FS_MAGIC;
  53.  
  54.     return 0;
  55. }
  56.