From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: w32.c/link() Date: Mon, 16 Jun 2014 17:55:23 +0300 Message-ID: <83k38gvr8k.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1402930569 11078 80.91.229.3 (16 Jun 2014 14:56:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Jun 2014 14:56:09 +0000 (UTC) Cc: emacs-devel@gnu.org To: Fabrice Popineau Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 16 16:56:01 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WwYKG-0007aW-NJ for ged-emacs-devel@m.gmane.org; Mon, 16 Jun 2014 16:56:00 +0200 Original-Received: from localhost ([::1]:44473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwYKG-0004SH-AK for ged-emacs-devel@m.gmane.org; Mon, 16 Jun 2014 10:56:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwYK0-0004Of-B4 for emacs-devel@gnu.org; Mon, 16 Jun 2014 10:55:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwYJl-00028l-Be for emacs-devel@gnu.org; Mon, 16 Jun 2014 10:55:43 -0400 Original-Received: from mtaout27.012.net.il ([80.179.55.183]:54436) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwYJl-000281-2n for emacs-devel@gnu.org; Mon, 16 Jun 2014 10:55:29 -0400 Original-Received: from conversion-daemon.mtaout27.012.net.il by mtaout27.012.net.il (HyperSendmail v2007.08) id <0N7900I00NXZFU00@mtaout27.012.net.il> for emacs-devel@gnu.org; Mon, 16 Jun 2014 17:52:28 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout27.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0N7900HQRNZF0Y10@mtaout27.012.net.il>; Mon, 16 Jun 2014 17:52:28 +0300 (IDT) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.179.55.183 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:172477 Archived-At: > From: Fabrice Popineau > Date: Mon, 16 Jun 2014 07:30:50 +0000 (UTC) > > I tried to use add-name-to-file from elisp, > which calls w32.c/link(). It seems to end up in doing > a copy of the file. No, it doesn't copy. It creates a hard link, as you'd expect. You can verify this yourself, with the following simple procedure: . start Dired on some directory . go to any file in the listing (not a directory: Windows doesn't support hard links to directories) . notice that the second column from the left says "1", i.e. this file has only 1 link to its data . press H, type the name of a link in the minibuffer and press RET . press g to refresh the directory listing, and notice that both the original file and the link now have their link count at 2 . visit the original file, set backup-by-copying-when-linked to a non-nil value, then modify the file and save it . visit the link and observe that the same modifications are "miraculously" present there as well . still not convinced? type "C-u C-x d", change the switches to say "-ali", hit RET, and observe that both the file and the link have the same filesystem index (a.k.a. "inode"), which means they share the same file data If you have a decent port of GNU 'ls', you will see the link counts change there as well. If you see something different from the above, please describe what you see. > I'm fine with that, but that wasn't clear before trying it. > OTOH if hard links were possible, why not using them? Permissions? We do use them (on NTFS; on other Windows filesystems you'll likely get an error). > Could someone (Eli ?) care to explain why link() is implemented this way? > Why BackupWrite() is used? I would have expected either CopyFile() or > CreateHardLink(). CreateHardLink was introduced with Windows 2000, while this code tries to support older NT systems which lacked that API. Back then this was the only way to create a hard link. I don't think we still support NT4 etc., but the code works very well, so I see no reason to rewrite it using newer APIs.