www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/03/15/09:39:01

Date: Sun, 15 Mar 1998 16:36:49 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: DJ Delorie <dj AT delorie DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: __FSEXT_alloc_fd freed from FILES= limits
Message-ID: <Pine.SUN.3.91.980315163342.10360A-100000@is>
MIME-Version: 1.0

The following patches will lift the limitation of handles available for 
the filesystem extensions by the FILES= parameter.  Also, it seems that 
the previous version didn't expand the default 20-handle table in the 
PSP, and so could fail even before the FILES= limit was reached; this is 
now fixed as well.

*** src/libc/fsext/fsext.c~0	Fri Jan  2 05:29:06 1998
--- src/libc/fsext/fsext.c	Sat Mar 14 19:14:56 1998
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdio.h>
  #include <stdlib.h>
***************
*** 8,13 ****
--- 9,15 ----
  #include <libc/bss.h>
  #include <libc/dosio.h>
  #include <unistd.h>
+ #include <fcntl.h>
  
  typedef struct __FSEXT_entry {
    __FSEXT_Function *function;
*************** static __FSEXT_entry *fsext_list;
*** 20,52 ****
  extern void (*__FSEXT_exit_hook)(void);
  static void __FSEXT_close_all(void);
  
! static void
  init(void)
  {
    static int init_count = -1;
    if (init_count == __bss_count)
!     return;
    init_count = __bss_count;
    num_fds = 0;
    fsext_list = 0;
  
    /* Attach our hook to close all of the remaining open extensions. */
    __FSEXT_exit_hook = __FSEXT_close_all;
  }
  
  int
  __FSEXT_alloc_fd(__FSEXT_Function *_function)
  {
    int fd;
    __dpmi_regs r;
  
!   init();
! 
!   _put_path("nul");
!   r.x.ax = 0x3d82;	/* open, no inherit, read/write */
!   r.x.dx = __tb_offset;
!   r.x.ds = __tb_segment;
!   __dpmi_int(0x21, &r);
  
    if (r.x.flags & 1)
    {
--- 22,67 ----
  extern void (*__FSEXT_exit_hook)(void);
  static void __FSEXT_close_all(void);
  
! static int
  init(void)
  {
    static int init_count = -1;
    if (init_count == __bss_count)
!     return 0;
    init_count = __bss_count;
    num_fds = 0;
    fsext_list = 0;
  
    /* Attach our hook to close all of the remaining open extensions. */
    __FSEXT_exit_hook = __FSEXT_close_all;
+   return 1;
  }
  
  int
  __FSEXT_alloc_fd(__FSEXT_Function *_function)
  {
+   static int null_dev_fd = -1;
    int fd;
    __dpmi_regs r;
  
!   if (init() || null_dev_fd == -1)
!   {
!     /*  This is our first time.  Open the NUL device, just this once.  */
!     _put_path("nul");
!     r.x.ax = 0x3d82;	/* open, no inherit, read/write */
!     r.x.dx = __tb_offset;
!     r.x.ds = __tb_segment;
!     __dpmi_int(0x21, &r);
!     null_dev_fd = (r.x.flags & 1) == 0 ? r.x.ax : -1;
!   }
!   else
!   {
!     /* On subsequent calls, just dup the handle we got the first time.  This
!        has the advantage of being independent of what their FILES= says.  */
!     r.h.ah = 0x45;
!     r.x.bx = null_dev_fd;
!     __dpmi_int(0x21, &r);
!   }
  
    if (r.x.flags & 1)
    {
*************** __FSEXT_alloc_fd(__FSEXT_Function *_func
*** 55,60 ****
--- 70,76 ----
    }
  
    fd = r.x.ax;
+   __file_handle_set(fd, O_BINARY); /* so the JFT is expanded as needed */
    __FSEXT_set_function(fd, _function);
    return fd;
  }
*** src/libc/fsext/fsext.t~0	Fri Jan  2 05:28:02 1998
--- src/libc/fsext/fsext.txh	Sat Mar 14 20:31:24 1998
***************
*** 161,169 ****
  
  This function is part of the @ref{File System Extensions}.  It is used
  by extensions that fully emulate the I/O functions, and thus don't
! have a corresponding DOS file handle.  This function opens DOS's
! @samp{NUL} device, so as to allocate a handle that DOS won't then reuse.
! It also assigns the handler function for that descriptor.
  
  The module is responsible for calling @code{_close} on the descriptor
  after setting the handler function to zero in the extended close
--- 161,174 ----
  
  This function is part of the @ref{File System Extensions}.  It is used
  by extensions that fully emulate the I/O functions, and thus don't
! have a corresponding DOS file handle.  Upon the first call, this
! function opens DOS's @samp{NUL} device, so as to allocate a handle that
! DOS won't then reuse.  Upon subsequent calls, that handle is duplicated
! by calling the DOS @code{dup} function; this makes all of the handles
! use a single entry in the System File Table, and thus be independent of
! what the @samp{FILES=} parameter of @file{CONFIG.SYS} says.
! @code{__FSEXT_alloc_fd} also assigns the handler function for the handle
! it returns.
  
  The module is responsible for calling @code{_close} on the descriptor
  after setting the handler function to zero in the extended close
*** src/docs/kb/wc202.t~6	Fri Mar  6 20:07:06 1998
--- src/docs/kb/wc202.txi	Sat Mar 14 19:29:10 1998
***************
*** 351,353 ****
--- 351,360 ----
  other processes can create files in the same directory, and opens the
  file in DENY_ALL mode.
  @findex mkstemp
+ 
+ @code{__FSEXT_alloc_fd} now duplicates the initial file handle instead
+ of reopening the NUL device on each call.  Thus, it is no longer limited
+ by the value of the @samp{FILES=} parameter on your @file{CONFIG.SYS},
+ but can allocate up to 254 handles (which is the maximum number allowed
+ by DOS).
+ @findex __FSEXT_alloc_fd

- Raw text -


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