public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Miquel van Smoorenburg <miquels@cistron.nl>
To: linux-kernel@vger.kernel.org
Subject: Re: rm-ing files with open file descriptors
Date: Sat, 19 Jan 2002 11:10:06 +0000 (UTC)	[thread overview]
Message-ID: <a2bk6e$t2u$1@ncc1701.cistron.net> (raw)
In-Reply-To: <87lmevjrep.fsf@localhost.localdomain> <Pine.LNX.3.95.1020118163838.3008B-100000@chaos.analogic.com> <a2afsg$73g$2@ncc1701.cistron.net> <a2almg$vtl$1@cesium.transmeta.com>

In article <a2almg$vtl$1@cesium.transmeta.com>,
H. Peter Anvin <hpa@zytor.com> wrote:
>Followup to:  <a2afsg$73g$2@ncc1701.cistron.net>
>By author:    Miquel van Smoorenburg <miquels@cistron.nl>
>In newsgroup: linux.dev.kernel
>> 
>> There is no way to recreate a file with a nlink count of 0,
>> well that is until someone adds flink(fd, newpath) to the kernel.
>
>This *might* work:
>
>link("/proc/self/fd/40", newpath);

I used the following perl script to test this, and alas this
doesn't work (yet):

open(FD, ">flink-test.txt") || die;
print FD "flink-test\n";
unlink "flink-test.txt"|| die;
link("/proc/self/fd/" . fileno(FD), "flink-test2.txt") || die;
print "Success.\n";

It results in:

link("/proc/self/fd/3", "flink-test2.txt") = -1 EXDEV (Invalid cross-device link)

This is probably because link() doesn't look up the target of the
symlink, it links the symlink itself. Linux allows symlinks with
a nlink count of 2:

% ln -s a b
% ln b c
ln: `b': warning: making a hard link to a symbolic link is not portable
% ls -l
lrwxrwxrwx    2 miquels  staff           1 Jan 19 11:34 b -> a
lrwxrwxrwx    2 miquels  staff           1 Jan 19 11:34 c -> a

This could be hacked around ofcourse in fs/namei.c, so I tried
it for fun. And indeed, with a minor correction it works:

% perl flink.pl 
Success.

I now have a flink-test2.txt file. That is pretty cool ;)

Here's the patch:

--- linux-2.4.15-pre4/fs/namei.c.orig	Wed Oct 17 23:46:29 2001
+++ linux-2.4.15-pre4/fs/namei.c	Sat Jan 19 12:08:13 2002
@@ -22,6 +22,7 @@
 #include <linux/dnotify.h>
 #include <linux/smp_lock.h>
 #include <linux/personality.h>
+#include <linux/proc_fs.h>
 
 #include <asm/namei.h>
 #include <asm/uaccess.h>
@@ -1640,6 +1641,16 @@
 			error = path_walk(from, &old_nd);
 		if (error)
 			goto exit;
+#if 1 /* flink()-like support */
+		if (old_nd.mnt->mnt_sb->s_magic == PROC_SUPER_MAGIC) {
+			path_release(&old_nd);
+			if (path_init(from, LOOKUP_POSITIVE|LOOKUP_FOLLOW,
+			    &old_nd))
+				error = path_walk(from, &old_nd);
+			if (error)
+				goto exit;
+		}
+#endif
 		if (path_init(to, LOOKUP_PARENT, &nd))
 			error = path_walk(to, &nd);
 		if (error)



Mike.


  parent reply	other threads:[~2002-01-19 11:10 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-18 21:11 rm-ing files with open file descriptors Doug Alcorn
2002-01-18 21:27 ` Xavier Bestel
2002-01-18 21:28 ` Ken Brownfield
2002-01-19 20:23   ` Rob Landley
2002-01-18 21:49 ` Richard B. Johnson
2002-01-19  0:50   ` Miquel van Smoorenburg
2002-01-19  2:29     ` H. Peter Anvin
2002-01-19 10:57       ` Xavier Bestel
2002-01-19 11:10       ` Miquel van Smoorenburg [this message]
2002-01-19 11:28         ` Alexander Viro
2002-01-19 12:01           ` Miquel van Smoorenburg
2002-01-23 12:18             ` Pavel Machek
2002-01-24  9:46               ` Herbert Xu
2002-01-19 17:44           ` Kai Henningsen
2002-01-20 15:30             ` Richard Kettlewell
2002-01-20 18:21               ` Doug McNaught
2002-01-20 23:10               ` Miquel van Smoorenburg
2002-01-20  3:55           ` Chris Wedgwood
2002-01-19 15:21         ` Horst von Brand
2002-01-19 15:32           ` Mr. James W. Laferriere
2002-01-19 20:26             ` Rob Landley
2002-01-19 17:53           ` Miquel van Smoorenburg
2002-01-20 15:48             ` Horst von Brand
2002-01-19 20:24           ` Rob Landley
2002-01-19 11:15       ` Ville Herva
2002-01-19 12:16       ` Matthias Schniedermeyer
2002-01-19 12:22         ` Xavier Bestel
2002-01-19 12:29           ` Alexander Viro
2002-01-19 12:46             ` Xavier Bestel
2002-01-19 13:18               ` Rogier Wolff
2002-01-19 15:24             ` Horst von Brand
2002-01-19 14:50     ` Horst von Brand
2002-01-20 14:23     ` Remi Turk
2002-01-20 20:02       ` Ville Herva
2002-01-20 20:44         ` Andreas Ferber
2002-01-20 21:08           ` Ville Herva
2002-01-21  9:06             ` Horst von Brand
2002-01-21  9:21               ` Ville Herva
2002-01-18 21:59 ` J Sloan
2002-01-19  4:18 ` Andreas Bombe
2002-01-19 14:51   ` christophe barbé
2002-01-19 18:01     ` Kai Henningsen
2002-01-20  3:43       ` christophe barbé
  -- strict thread matches above, loose matches on Subject: below --
2002-01-18 22:11 Hank Leininger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='a2bk6e$t2u$1@ncc1701.cistron.net' \
    --to=miquels@cistron.nl \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox