X-Authentication-Warning: smtp3.ihug.com.au: Host p513-apx1.syd.ihug.com.au [203.173.142.5] claimed to be acceleron Message-ID: <00aa01c12584$34acb890$0a02a8c0@acceleron> From: "Andrew Cottrell" To: "Eli Zaretskii" Cc: References: <00fe01c12311$92957890$0a02a8c0 AT acceleron> <4331-Mon13Aug2001125532+0300-eliz AT is DOT elta DOT co DOT il> <019701c123f9$6febae70$0a02a8c0 AT acceleron> <557-Mon13Aug2001165656+0300-eliz AT is DOT elta DOT co DOT il> <028c01c12405$d1b326e0$0a02a8c0 AT acceleron> <013d01c124bc$b4b1fe60$0a02a8c0 AT acceleron> <6480-Tue14Aug2001182649+0300-eliz AT is DOT elta DOT co DOT il> Subject: Re: Fw: Fstat.c patch Date: Wed, 15 Aug 2001 22:17:07 +1000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00A7_01C125D8.0565DD10" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Reply-To: djgpp-workers AT delorie DOT com This is a multi-part message in MIME format. ------=_NextPart_000_00A7_01C125D8.0565DD10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I have attached a preliminary patch for fstat.c that calls the fstat_init() to setup the required info. I hope I covered the emacs issue correctly. I started to use the osmajor function, but then I checked and osmajor is is not always the true osmajor version as it calles _get_dos_version(0) not get_dos_version(1), which means that osmajor can be changed by setver. I wonder what can of worms using setver would cause!! I don't want to go there, but someone should. I have used this version of fstat.c in building cp.exe from filutils and the fstat_init() is called and the relevant variables are setup. On Win 98 dos_major is 7 and on Win 2K it is 5. The one cp.exe worked on both Win 98 and Win 2K. Any comments? Hopefully another issue is on it's way to the grave. Note that this change is fix the underlying problem with stat_buf->st_mode not being set correctly as the original code did not work as expected under all conditions and especially Win 2k. > > If I recompile CP from fileutils using only the relevant files and step > > through the code then the code does NOT set up the dos_major variable, it's > > set to zero. I have traced this to the djstart.c program which sets the > > _djstat_flags to 0x34 in the static init_stat_bits() function. The > > definition for _STAT_NEEDS_SFT is 0x23 and as such if I and these together I > > do NOT get 0 and as such the GNUC compiler does not call the get_sft_entry() > > which in turn initalises the dos_version function. > > Right, I forgot about that djstart gork. It got me confused for a while. I still am not 100% sure what it all means, but eventually I will get there. The more I get exposed to the code the more I will gradually understand it. > > > /* Get pointer to an SFT entry which holds data for our handle. */ > > > if ( (_djstat_flags & _STAT_NEEDS_SFT) == 0 && > > > (sft_idx = get_sft_entry(fhandle)) == -1) > > > { > > > errno = EBADF; > > > return -1; > > > } > > > > Now for the queries to help me try to find a correct solution: > > 1) Is it expected that the get_sft_entry() is not called in the scenario > > above? > > Yes, it is expected: if _STAT_NEEDS_SFT is set, it means `fstat' > doesn't need any of the info it gets from the SFT. > > > 2) Is it expected that the dos_major is setup even if the get_sft_entry() is > > not called? (I think the answer is yes) > > Yes, expected. > > > 3) Any suggestions as to where to head with this issue? > > It's a bug: the if clause that checks whether to call function 71A6 > should have used _osmajor, which is always set. There's no reason to > condition it on the true DOS version. > > Thanks for hunting this down. > ------=_NextPart_000_00A7_01C125D8.0565DD10 Content-Type: application/octet-stream; name="fstat_v1.dif" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fstat_v1.dif" *** fstatold.c Wed Aug 15 21:34:42 2001 --- fstat.c Wed Aug 15 21:41:08 2001 *************** *** 1,3 **** --- 1,4 ---- + /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */ *************** *** 176,181 **** --- 177,186 ---- /* The address of the PSP of the caller. */ static unsigned long psp_addr; =20 + /* The fstat initialization code has been called. */ + static char fstat_init_called =3D 0; + static int fstat_init_result =3D 0; +=20 /* Initialization routine, called once per program run. * Finds DOS version, SFT entry size and addresses of * program handle table and first SFT sub-table. *************** *** 187,192 **** --- 192,199 ---- int sft_ptr_addr; unsigned short true_dos_version; =20 + fstat_init_called =3D -1; +=20 /* Selectors for _farXXX() functions. */ dos_mem_base =3D _dos_ds; our_mem_base =3D _my_ds(); *************** *** 258,277 **** =20 _djstat_fail_bits =3D fstat_init_bits; =20 /* Force initialization if we were restarted (emacs). */ if (fstat_count !=3D __bss_count) { fstat_count =3D __bss_count; dos_major =3D 0; } !=20 ! /* Find the PSP address of the current process. */ ! regs.h.ah =3D 0x62; /* Get PSP address */ ! __dpmi_int(0x21, ®s); ! psp_addr =3D (unsigned long)regs.x.bx << 4; !=20 ! /* If first time called, initialize. */ ! if (!dos_major && !fstat_init()) { fstat_init_bits =3D _djstat_fail_bits; return -2; --- 265,284 ---- =20 _djstat_fail_bits =3D fstat_init_bits; =20 + /* Find the PSP address of the current process. */ + regs.h.ah =3D 0x62; /* Get PSP address */ + __dpmi_int(0x21, ®s); + psp_addr =3D (unsigned long)regs.x.bx << 4; +=20 /* Force initialization if we were restarted (emacs). */ if (fstat_count !=3D __bss_count) { fstat_count =3D __bss_count; dos_major =3D 0; + fstat_init_result =3D fstat_init(); } ! /* If not initialized exit. */ ! if (!fstat_init_result) { fstat_init_bits =3D _djstat_fail_bits; return -2; *************** *** 391,396 **** --- 398,408 ---- =20 _djstat_fail_bits =3D 0; =20 + /* If first time called, initialize. */ + if (!fstat_init_called) + { + fstat_init_result =3D fstat_init(); + } /* Get pointer to an SFT entry which holds data for our handle. */ if ( (_djstat_flags & _STAT_NEEDS_SFT) =3D=3D 0 && (sft_idx =3D get_sft_entry(fhandle)) =3D=3D -1) *************** *** 815,827 **** stat_buf->st_mode |=3D (S_IFREG | READ_ACCESS); if (_djstat_flags & _STAT_ACCESS) _djstat_fail_bits |=3D _STFAIL_WRITEBIT; ! =20 ! /* If we run on Windows 9X, and LFN is enabled, try = harder. Note that we deliberately do NOT use this call when = LFN is ! disabled, even if we are on Windows 9X, because then = we open the file with function 3Ch, and such handles = aren't supported by 71A6h call we use here. */ ! if (dos_major >=3D 7 && _USE_LFN) { __dpmi_regs r; =20 --- 827,842 ---- stat_buf->st_mode |=3D (S_IFREG | READ_ACCESS); if (_djstat_flags & _STAT_ACCESS) _djstat_fail_bits |=3D _STFAIL_WRITEBIT; ! /* Only call this is LFN is set. Note that we deliberately do NOT use this call when LFN is ! disabled, even if we are on Windows 9X or NT/2000/XP, because then = we open the file with function 3Ch, and such handles aren't supported by 71A6h call we use here. */ ! #ifdef DEBUG ! printf("%s %d dosmajor =3D %d, uselfn =3D %s\n", __FILE__, __LINE__, = dos_major, ! _USE_LFN ? "True" : "False"); ! #endif ! if (_USE_LFN) { __dpmi_regs r; =20 ------=_NextPart_000_00A7_01C125D8.0565DD10--