delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/09/26/01:09:38

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10109260503.AA12393@clio.rice.edu>
Subject: fixpath patch (fixes rm -rf disaster, retains deep directory usage)
To: eliz AT is DOT elta DOT co DOT il
Date: Wed, 26 Sep 2001 00:03:45 -0500 (CDT)
Cc: djgpp-workers AT delorie DOT com
In-Reply-To: <2110-Tue25Sep2001201613+0300-eliz@is.elta.co.il> from "Eli Zaretskii" at Sep 25, 2001 08:16:14 PM
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> > This seems to prevent the chdir problems in my quick testing (on Win2K only).
> > In a nutshell, if after the chdir, getcwd indicates root directory, and 
> > we didn't set a root directory, fail and put us back.  May want to save
> > the original getcwd return status and only _chdir back if OK.  May also
> > want to _chdir back on regular error.  Comments?
> 
> I can't say I like the idea of punishing Windows 9X under LFN, where
> this problem doesn't happen.  Can we condition these extra calls so
> that they only happen on non-LFN or W2K/XP platforms?

Here's an alternative patch which also seems to work on Win2K.  It allows
you to use long directories without any problems I've observed.  It's a
quick change to fixpath (which is called a bunch of places) to not call
getcwd and use truename instead.  I think it's a better fix than the
first one since it retains deep directory functionality.  No new 
interrupts, but I'm unsure on compatibility everywhere.  I built rm with it
and it works great (no new root dir problems).  This should also fix the
64 char limit on SFN systems if directory is deep.

*** fixpath.c_	Thu Jun  3 11:27:40 1999
--- fixpath.c	Tue Sep 25 22:58:30 2001
*************** __get_current_directory(char *out, int d
*** 25,37 ****
    char tmpbuf[FILENAME_MAX];
  
    memset(&r, 0, sizeof(r));
!   if(use_lfn)
!     r.x.ax = 0x7147;
!   else
!     r.h.ah = 0x47;
!   r.h.dl = drive_number + 1;
    r.x.si = __tb_offset;
!   r.x.ds = __tb_segment;
    __dpmi_int(0x21, &r);
  
    if (r.x.flags & 1)
--- 25,45 ----
    char tmpbuf[FILENAME_MAX];
  
    memset(&r, 0, sizeof(r));
!   if(use_lfn) {
!     r.x.ax = 0x7160;
!     r.x.cx = 2;		/* Get Long Path Name (if there is one) */
!   } else
!     r.x.ax = 0x6000;
!   r.x.ds = r.x.es = __tb_segment;
    r.x.si = __tb_offset;
!   r.x.di = __tb_offset + FILENAME_MAX;
!   
!   tmpbuf[0] = drive_number + 'A';
!   tmpbuf[1] = ':';
!   tmpbuf[2] = '.';
!   tmpbuf[3] = 0;
!   _put_path(tmpbuf);
! 
    __dpmi_int(0x21, &r);
  
    if (r.x.flags & 1)
*************** __get_current_directory(char *out, int d
*** 41,48 ****
    }
    else
    {
!     dosmemget(__tb, sizeof(tmpbuf), tmpbuf);
!     strcpy(out+1,tmpbuf);
  
      /* Root path, don't insert "/", it'll be added later */
      if (*(out + 1) != '\0')
--- 49,56 ----
    }
    else
    {
!     dosmemget(__tb + FILENAME_MAX, sizeof(tmpbuf), tmpbuf);
!     strcpy(out,tmpbuf+2);
  
      /* Root path, don't insert "/", it'll be added later */
      if (*(out + 1) != '\0')

- Raw text -


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