Date: Mon, 17 Nov 1997 19:22:59 +0200 (IST) From: Eli Zaretskii To: DJ Delorie cc: djgpp-workers AT delorie DOT com Subject: Re: djgpp 2.02 alpha 971114 In-Reply-To: <199711150256.VAA01339@delorie.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk Here's a patch that fixes the problem whereby several files are reported with the same (and bogus) inode number on Windows 95. It also reports the file attributes better when running on Windows 95. (DJ, this is relative to the last version of `fstat' whose patches I sent to you the other day.) *** src/libc/posix/sys/stat/fstat.c~1 Sun Apr 6 16:34:30 1997 --- src/libc/posix/sys/stat/fstat.c Sun Nov 9 16:42:28 1997 *************** *** 1,3 **** --- 1,4 ---- + /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* This is file FSTAT.C */ *************** fstat_assist(int fhandle, struct stat *s *** 537,542 **** --- 538,545 ---- */ else if (have_trusted_values) { + unsigned char *pname = sft_buf + name_ofs; + /* This is a regular, existing file. It cannot be a * directory, because DOS won't let us open() a directory. * Each file under MS-DOS is always readable by everyone. *************** fstat_assist(int fhandle, struct stat *s *** 550,556 **** sft_fdate = *((unsigned short *)(sft_buf + fdate_ofs)); sft_ftime = *((unsigned short *)(sft_buf + ftime_ofs)); sft_fsize = *((long *)(sft_buf + fsize_ofs)); ! if (sft_ftime == trusted_ftime && sft_fdate == trusted_fdate && sft_fsize == trusted_fsize) { /* Now we are ready to get the SFT info. */ --- 553,572 ---- sft_fdate = *((unsigned short *)(sft_buf + fdate_ofs)); sft_ftime = *((unsigned short *)(sft_buf + ftime_ofs)); sft_fsize = *((long *)(sft_buf + fsize_ofs)); ! ! /* In addition, it seems that 32-bit File Access, at least ! * in Windows 95, creates fake SFT entries for some files, ! * which have bogus cluster numbers and all-blank file name ! * and extension. (It is unclear to me when exactly are ! * these fake SFT entries created.) ! * So, in addition, we check the file's name in the SFT to ! * be non-blank, since file names in the FCB format cannot ! * be all-blank, even on Windows 95. */ ! while (pname < sft_buf + name_ofs + 8 + 3 && *pname == ' ') ! pname++; ! ! if (pname < sft_buf + name_ofs + 8 + 3 && ! sft_ftime == trusted_ftime && sft_fdate == trusted_fdate && sft_fsize == trusted_fsize) { /* Now we are ready to get the SFT info. */ *************** fstat_assist(int fhandle, struct stat *s *** 762,769 **** if (_djstat_flags & _STAT_ACCESS) _djstat_fail_bits |= _STFAIL_WRITEBIT; /* Executables are detected if they have magic numbers. */ ! if ( (_djstat_flags & _STAT_EXECBIT) && _is_executable((const char *)0, fhandle, (const char *)0)) stat_buf->st_mode |= EXEC_ACCESS; --- 778,804 ---- if (_djstat_flags & _STAT_ACCESS) _djstat_fail_bits |= _STFAIL_WRITEBIT; + /* 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 >= 7 && _USE_LFN) + { + __dpmi_regs r; + + r.x.ax = 0x71a6; /* file info by handle */ + r.x.bx = fhandle; + r.x.ds = __tb >> 4; + r.x.dx = 0; + __dpmi_int(0x21, &r); + if ((r.x.flags & 1) == 0 + && (_farpeekl(dos_mem_base, __tb) & 0x07) == 0) + stat_buf->st_mode |= WRITE_ACCESS; /* no R, S or H bits set */ + } + /* Executables are detected if they have magic numbers. */ ! if ( (_djstat_flags & _STAT_EXEC_MAGIC) == 0 && _is_executable((const char *)0, fhandle, (const char *)0)) stat_buf->st_mode |= EXEC_ACCESS;