delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1996/09/18/13:09:51

Date: Wed, 18 Sep 1996 18:56:43 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: djgpp-workers AT delorie DOT com
Subject: `_flush_disk_cache'
Message-Id: <Pine.SUN.3.91.960918185500.1945G-100000@is>
Mime-Version: 1.0

This was written for the port of GNU `sync'.  I suggest to put it into 
the library.

*** src/libc/dos/io/flushdc.c~0	Wed Sep 18 17:13:56 1996
--- src/libc/dos/io/flushdc.c	Wed Sep 18 17:29:10 1996
***************
*** 0 ****
--- 1,36 ----
+ #include <libc/stubs.h>
+ #include <fcntl.h>	/* for _USE_LFN */
+ #include <io.h>		/* for the prototype of `_flush_disk_cache' */
+ #include <dir.h>	/* for `getdisk' */
+ #include <dpmi.h>	/* for `__dpmi_int' and friends */
+ 
+ /* Try to cause the disk cache to write the cached data to disk(s).  */
+ void
+ _flush_disk_cache (void)
+ {
+   __dpmi_regs r;
+   int drv = getdisk ();
+ 
+   if (_USE_LFN)
+     {
+       /* Windows 95 have special function to do what we want.  */
+       /* FIXME: What if LFN is supported by a platform other than W95?  */
+       r.x.ax = 0x710d;
+       r.x.cx = 1;	/* flush buffers and cache, reset drive */
+       r.x.dx = drv + 1;
+       __dpmi_int (0x21, &r);
+       /* According to docs (Interrupt list), this doesn't return
+ 	 any error codes (??).  */
+     }
+   else
+     {
+       /* The BIOS Disk Reset function causes most DOS caches to flush.  */
+       r.x.ax = 0;
+       /* Hard disks should have 7th bit set.  */
+       /* FIXME: The mapping between DOS drive numbers and BIOS
+ 	 drives is ignored.  The assumption is that Reset function
+ 	 on ANY hard disk causes the cache to flush its buffers.  */
+       r.x.dx = drv > 2 ? ((drv - 2) | 0x80) : drv;
+       __dpmi_int (0x13, &r);
+     }
+ }
*** src/libc/dos/io/flushdc.t~0	Wed Sep 18 17:13:56 1996
--- src/libc/dos/io/flushdc.txh	Wed Sep 18 17:31:38 1996
***************
*** 0 ****
--- 1,17 ----
+ @node _flush_disk_cache, dos
+ @subheading Syntax
+ 
+ @example
+ #include <io.h>
+ 
+ void _flush_disk_cache (void);
+ @end example
+ 
+ @subheading Description
+ 
+ Attempts to update the disk with the data cached in the write-behind
+ disk cache.
+ 
+ @subheading Return Value
+ 
+ None.
*** src/libc/dos/io/makefile.~0~	Mon Aug 28 00:29:10 1995
--- src/libc/dos/io/makefile	Wed Sep 18 17:33:28 1996
***************
*** 17,21 ****
--- 17,22 ----
  SRC += setmode.c
  SRC += tell.c
  SRC += unlock.c
+ SRC += flushdc.c
  
  include $(TOP)/../makefile.inc
*** include/io.h~0	Wed Jan 31 04:49:58 1996
--- include/io.h	Wed Sep 18 17:22:46 1996
***************
*** 30,35 ****
--- 30,36 ----
  int		unlock(int _fd, long _offset, long _length);
  ssize_t		_write(int _fd, const void *_buf, size_t _nbyte);
  int	        _chmod(const char *_path, int _func, ...);
+ void		_flush_disk_cache(void);
  
  #define sopen(path, access, shflag, mode) \
  	open((path), (access)|(shflag), (mode))

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019