From: sandmann AT clio DOT rice DOT edu (Charles Sandmann) Message-Id: <10108180453.AA14191@clio.rice.edu> Subject: Re: Win2K : what about _creat* ? To: djgpp-workers AT delorie DOT com Date: Fri, 17 Aug 2001 23:53:28 -0500 (CDT) Cc: wojciech DOT galazka AT polkomtel DOT com DOT pl, eliz AT is DOT elta DOT co DOT il (Eli Zaretskii) In-Reply-To: <6137-Fri17Aug2001142611+0300-eliz@is.elta.co.il> from "Eli Zaretskii" at Aug 17, 2001 02:26:11 PM X-Mailer: ELM [version 2.5 PL2] Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Precedence: bulk > > > I suggest the other way around: open first, then close the LFN > > > handle. This way, you minimize the risk of something removing the > > > file in between. (You might need to fsync the handle before the call > > > to _open, though.) At this point the file should be empty either way, so why would fsync be needed? I think the odds of the file disappearing in the millisecond between close and reopen to be pretty small (especially since this insanity only is foisted upon Win2K/XP). But I'll play with it. > > Shouldn't we worry about sharing permission on the file being > > oopened twice? > > I don't know; is there some problem? As written the patch seems to work. I created several long names and was able to fstat() the handles and get correct information. Case seems to be preserved. Swapping to do an open first, then close also consumes (temporarily) an additional file handle. The _open also works fine with case. Opening an existing file by short name doesn't seem to change anything. *** _creat.bak Wed Jul 25 02:54:00 2001 --- _creat.c Fri Aug 17 23:00:12 2001 *************** _creat(const char* filename, int attrib) *** 61,66 **** --- 61,74 ---- errno = __doserr_to_errno(r.x.ax); return -1; } + if(use_lfn && _osmajor == 5 && _get_dos_version(1) == 0x532) { + /* Windows 2000 or XP; or NT with LFN TSR. Windows 2000 behaves + badly when using IOCTL and write-truncate calls on LFN handles. + We close the long name file and re-open it with _open.c (short) + to work around the bugs. */ + _close(r.x.ax); + return _open(filename,2); + } __file_handle_set(r.x.ax, O_BINARY); return r.x.ax; } *** _creat_n.bak Tue Jan 30 13:53:26 2001 --- _creat_n.c Fri Aug 17 23:01:30 2001 *************** _creatnew(const char* filename, int attr *** 67,72 **** --- 67,80 ---- errno = __doserr_to_errno(r.x.ax); return -1; } + if(use_lfn && _osmajor == 5 && _get_dos_version(1) == 0x532) { + /* Windows 2000 or XP; or NT with LFN TSR. Windows 2000 behaves + badly when using IOCTL and write-truncate calls on LFN handles. + We close the long name file and re-open it with _open.c (short) + to work around the bugs. */ + _close(r.x.ax); + return _open(filename, flags | 2); + } __file_handle_set(r.x.ax, O_BINARY); return r.x.ax; }