Date: Sun, 16 Mar 1997 18:58:39 +0300 (IDT) From: Eli Zaretskii To: Douglas Rupp , djgpp-workers AT delorie DOT com Subject: Re: fstat returns garbage In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Here's a patch I want to put into `fstat', so that random bits on DOS clones doesn't fail it. Can people who have access to NT, Windows 95 and other DOS clones please see if this works for them? Thanks. *** src/libc/posix/sys/stat/fstat.c~0 Sat Mar 15 11:42:38 1997 --- src/libc/posix/sys/stat/fstat.c Sat Mar 15 12:50:36 1997 *************** fstat_assist(int fhandle, struct stat *s *** 366,371 **** --- 366,372 ---- short have_trusted_values = 1; unsigned int dos_ftime; char drv_no; + short dev_info; unsigned char is_dev; unsigned char is_remote; short sft_idx = -1; *************** fstat_assist(int fhandle, struct stat *s *** 374,379 **** --- 375,383 ---- unsigned short trusted_ftime = 0, trusted_fdate = 0; long trusted_fsize = 0; + if ((dev_info = _get_dev_info(fhandle)) == -1) + return -1; /* errno set by _get_dev_info() */ + _djstat_fail_bits = 0; /* Get pointer to an SFT entry which holds data for our handle. */ *************** fstat_assist(int fhandle, struct stat *s *** 401,406 **** --- 405,424 ---- else have_trusted_values = 0; + if (dev_info & 0x0080) + { + is_dev = 1; + is_remote = 0; /* device can't be remote */ + } + else + { + is_dev = 0; + if (dev_info & 0x8000) + is_remote = 1; + else + is_remote = 0; + } + /* First, fill the fields which are constant under DOS. */ stat_buf->st_uid = getuid(); stat_buf->st_gid = getgid(); *************** fstat_assist(int fhandle, struct stat *s *** 421,427 **** case 2: fattr_ofs = 2; drv_no = sft_buf[3] - 1; /* 1 = 'A' etc. */ - is_dev = drv_no < 0; /* sft_buf[3] = 0 */ name_ofs = 4; ext_ofs = 0x0b; fsize_ofs = 0x13; --- 439,444 ---- *************** fstat_assist(int fhandle, struct stat *s *** 434,441 **** case 3: fattr_ofs = 4; drv_no = sft_buf[5] & 0x3f; - is_dev = sft_buf[5] & 0x80; - is_remote = sft_buf[6] & 0x80; if (dos_minor == 0) { name_ofs = 0x21; --- 451,456 ---- *************** fstat_assist(int fhandle, struct stat *s *** 455,462 **** default: /* DOS 4 and up */ fattr_ofs = 4; drv_no = sft_buf[5] & 0x3f; - is_dev = sft_buf[5] & 0x80; - is_remote = sft_buf[6] & 0x80; clust_ofs = 0x0b; ftime_ofs = 0x0d; fdate_ofs = 0x0f; --- 470,475 ---- *************** fstat_assist(int fhandle, struct stat *s *** 684,694 **** */ if (have_trusted_values) { ! short dev_info = _get_dev_info(fhandle); /* IOCTL Function 0 */ ! if (dev_info == -1) ! return -1; /* errno set by get_dev_info() */ ! ! if (dev_info & 0x80) /* it's a device */ { if (_djstat_flags & _STAT_INODE) { --- 697,703 ---- */ if (have_trusted_values) { ! if (is_dev) { if (_djstat_flags & _STAT_INODE) {