home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / io / flushdc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-19  |  1.2 KB  |  37 lines

  1. #include <libc/stubs.h>
  2. #include <fcntl.h>    /* for _USE_LFN */
  3. #include <io.h>        /* for the prototype of `_flush_disk_cache' */
  4. #include <dir.h>    /* for `getdisk' */
  5. #include <dpmi.h>    /* for `__dpmi_int' and friends */
  6.  
  7. /* Try to cause the disk cache to write the cached data to disk(s).  */
  8. void
  9. _flush_disk_cache (void)
  10. {
  11.   __dpmi_regs r;
  12.   int drv = getdisk ();
  13.  
  14.   if (_USE_LFN)
  15.     {
  16.       /* Windows 95 have special function to do what we want.  */
  17.       /* FIXME: What if LFN is supported by a platform other than W95?  */
  18.       r.x.ax = 0x710d;
  19.       r.x.cx = 1;    /* flush buffers and cache, reset drive */
  20.       r.x.dx = drv + 1;
  21.       __dpmi_int (0x21, &r);
  22.       /* According to docs (Interrupt list), this doesn't return
  23.      any error codes (??).  */
  24.     }
  25.   else
  26.     {
  27.       /* The BIOS Disk Reset function causes most DOS caches to flush.  */
  28.       r.x.ax = 0;
  29.       /* Hard disks should have 7th bit set.  */
  30.       /* FIXME: The mapping between DOS drive numbers and BIOS
  31.      drives is ignored.  The assumption is that Reset function
  32.      on ANY hard disk causes the cache to flush its buffers.  */
  33.       r.x.dx = drv > 2 ? ((drv - 2) | 0x80) : drv;
  34.       __dpmi_int (0x13, &r);
  35.     }
  36. }
  37.