From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ota, Takaaki" Newsgroups: gmane.emacs.bugs Subject: bug#10733: 24.0.93; w32 file truncation Date: Mon, 6 Feb 2012 15:43:27 -0800 Message-ID: <20120206.154327.522668003.Takaaki.Ota@am.sony.com> References: <87r4y74zew.fsf@wanadoo.es> <83sjinbyez.fsf@gnu.org> <87fwen4k6s.fsf@wanadoo.es> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1328571861 24131 80.91.229.3 (6 Feb 2012 23:44:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Feb 2012 23:44:21 +0000 (UTC) Cc: lekktu@gmail.com, 10733@debbugs.gnu.org To: Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 07 00:44:20 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RuYEI-0008Mz-JU for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Feb 2012 00:44:14 +0100 Original-Received: from localhost ([::1]:48246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuYEI-0005WS-8W for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Feb 2012 18:44:14 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:56400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuYEF-0005WK-AY for bug-gnu-emacs@gnu.org; Mon, 06 Feb 2012 18:44:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RuYEE-0005JH-1G for bug-gnu-emacs@gnu.org; Mon, 06 Feb 2012 18:44:11 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuYED-0005JD-Ui for bug-gnu-emacs@gnu.org; Mon, 06 Feb 2012 18:44:10 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1RuYF3-0005Jo-WF for bug-gnu-emacs@gnu.org; Mon, 06 Feb 2012 18:45:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Ota, Takaaki" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Feb 2012 23:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10733-submit@debbugs.gnu.org id=B10733.132857187520396 (code B ref 10733); Mon, 06 Feb 2012 23:45:01 +0000 Original-Received: (at 10733) by debbugs.gnu.org; 6 Feb 2012 23:44:35 +0000 Original-Received: from localhost ([127.0.0.1]:57784 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RuYEc-0005Iv-GA for submit@debbugs.gnu.org; Mon, 06 Feb 2012 18:44:34 -0500 Original-Received: from am1ehsobe003.messaging.microsoft.com ([213.199.154.206]:8745 helo=AM1EHSOBE002.bigfish.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RuYEY-0005Ie-V9 for 10733@debbugs.gnu.org; Mon, 06 Feb 2012 18:44:32 -0500 Original-Received: from mail118-am1-R.bigfish.com (10.3.201.227) by AM1EHSOBE002.bigfish.com (10.3.204.22) with Microsoft SMTP Server id 14.1.225.23; Mon, 6 Feb 2012 23:43:32 +0000 Original-Received: from mail118-am1 (localhost [127.0.0.1]) by mail118-am1-R.bigfish.com (Postfix) with ESMTP id 1E4A21605DB; Mon, 6 Feb 2012 23:43:32 +0000 (UTC) X-SpamScore: -15 X-BigFish: VPS-15(z21eNzc89bh1432N98dKzz1202hzz8275dhz2fh668h839h) X-Forefront-Antispam-Report: CIP:160.33.98.74; KIP:(null); UIP:(null); IPV:NLI; H:mail7.fw-bc.sony.com; RD:mail7.fw-bc.sony.com; EFVD:NLI Received-SPF: pass (mail118-am1: domain of am.sony.com designates 160.33.98.74 as permitted sender) client-ip=160.33.98.74; envelope-from=Takaaki.Ota@am.sony.com; helo=mail7.fw-bc.sony.com ; -bc.sony.com ; Original-Received: from mail118-am1 (localhost.localdomain [127.0.0.1]) by mail118-am1 (MessageSwitch) id 1328571809812433_15809; Mon, 6 Feb 2012 23:43:29 +0000 (UTC) Original-Received: from AM1EHSMHS004.bigfish.com (unknown [10.3.201.247]) by mail118-am1.bigfish.com (Postfix) with ESMTP id B77BEE0045; Mon, 6 Feb 2012 23:43:29 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by AM1EHSMHS004.bigfish.com (10.3.207.104) with Microsoft SMTP Server id 14.1.225.23; Mon, 6 Feb 2012 23:43:29 +0000 Original-Received: from mail2x.bc.in.sel.sony.com (mail3.bc.in.sel.sony.com [43.144.100.56]) by mail7.fw-bc.sony.com (Switch-3.4.2/Switch-3.3.2mp) with ESMTP id q16NhShC015770; Mon, 6 Feb 2012 23:43:28 GMT Original-Received: from localhost (fantawin8.am.sony.com [43.191.14.206] (may be forged)) by mail2x.bc.in.sel.sony.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id q16NhQp1032175; Mon, 6 Feb 2012 23:43:27 GMT In-Reply-To: <87fwen4k6s.fsf@wanadoo.es> X-Mailer: Mew-6.3.50 on Emacs-24.0.93.1 (i386-mingw-nt6.1.7601 built on 2012-01-29) X-OriginatorOrg: am.sony.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:56606 Archived-At: Don't you need to dispose fh properly? -Tak Mon, 6 Feb 2012 15:27:07 -0800: =D3scar Fuentes wrote:= > Eli Zaretskii writes: > = > [snip] > = > > No. The `stat' Emacs uses is in w32.c. What you see on > > lib-src/ntlib.c is just a minimal subset of what we have in w32.c. > = > That's important. Thanks. > = > >> Symlinks are detected and handled specially on MSVCRT's stat. In > >> aessence, for symlinks it uses fstat. > > > > But fstat probably calls GetFileInformationByHandle under the hood,= > > and we already call that function in w32.c:stat. So maybe the fix = is > > not as ugly and inelegant as you thought. > = > Yup. This patch fixes the problem: > = > diff --git a/src/w32.c b/src/w32.c > index f610a36..035e1f2 100644 > --- a/src/w32.c > +++ b/src/w32.c > @@ -3444,6 +3444,29 @@ stat (const char * path, struct stat * buf) > } > } > = > + buf->st_size =3D 0; > + > + if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && > + (wfd.dwReserved0 =3D=3D IO_REPARSE_TAG_SYMLINK)) > + { > + HANDLE fh; > + BY_HANDLE_FILE_INFORMATION info; > + > + if ((fh =3D CreateFile (name, 0, 0, NULL, OPEN_EXISTING, > + FILE_FLAG_BACKUP_SEMANTICS, NULL)) > + && GetFileInformationByHandle (fh, &info)) > + { > + buf->st_size =3D info.nFileSizeHigh; > + buf->st_size <<=3D 32; > + buf->st_size +=3D info.nFileSizeLow; > + } > + else > + { > + errno =3D ENOENT; > + return -1; > + } > + } > + > if (!(NILP (Vw32_get_true_file_attributes) > || (EQ (Vw32_get_true_file_attributes, Qlocal) && is_slow_fs (name)= )) > /* No access rights required to get info. */ > @@ -3532,9 +3555,12 @@ stat (const char * path, struct stat * buf) > buf->st_dev =3D volume_info.serialnum; > buf->st_rdev =3D volume_info.serialnum; > = > - buf->st_size =3D wfd.nFileSizeHigh; > - buf->st_size <<=3D 32; > - buf->st_size +=3D wfd.nFileSizeLow; > + if (! buf->st_size) > + { > + buf->st_size =3D wfd.nFileSizeHigh; > + buf->st_size <<=3D 32; > + buf->st_size +=3D wfd.nFileSizeLow; > + } > = > /* Convert timestamps to Unix format. */ > buf->st_mtime =3D convert_time (wfd.ftLastWriteTime); > = > = > Maybe it can be integrated in the > = > if (!(NILP(Vw32_get_true_file_attributes) ... > = > hence reusing the calls to CreateFile and GetFileInformationByHandle = and > shortening the patch, but as I don't know what > Vw32_get_true_file_attributes does, preferread to follow the safe way= .= > = > However, we still have another implementation on ntlib.c. > = > And the fix is just for the size. Don't know if there are other > attributes suffer from the same problem. Possibly the right thing is = to > do what MSVCRT does: > = > if is-symlink? > use fstat > fi > =