Re: [ILUG] How to copy some files

From: Paul Jakma (paul at domain clubi.ie)
Date: Sun 21 Jul 2002 - 01:41:44 IST


On Sat, 20 Jul 2002, kevin lyda wrote:

> let's call these super-soft-links. ln -ss
>
> % ln -ss foo bar
> % ls -i foo
> 111 foo
> % mv floyd foo
> % ls -i foo
> 222 foo

isnt this standard behaviour?? mv uses rename() which replaces the
new path name:

[paul at domain fogarty tmp]$ rm foo bar floyd ; echo foo > foo ; echo floyd >
floyd ; ln -s foo bar ; ls -i foo bar floyd ; strace -e
lstat,stat,stat64,lstat64,link,unlink,rename mv floyd foo ; ls -i foo
bar ; cat bar
rm: cannot remove `foo': No such file or directory
rm: cannot remove `bar': No such file or directory
rm: cannot remove `floyd': No such file or directory
52026333 bar 52026332 floyd 52026331 foo
stat64("foo", {st_mode=S_IFREG|0664, st_size=4, ...}) = 0
lstat64("floyd", {st_mode=S_IFREG|0664, st_size=6, ...}) = 0
lstat64("foo", {st_mode=S_IFREG|0664, st_size=4, ...}) = 0
rename("floyd", "foo") = 0
52026333 bar 52026332 foo
floyd

> and now bar no longer points to foo.

yes it does. :)

but your super-links dont is what you're saying i guess. but why? why
would you want a symlink, bar, linking to foo, to stop linking if foo
is changed?

> % ln -ss foo bar
> % ls -i foo
> 111 foo
> % rm foo
> % touch floyd
> % ls -i floyd
> 111 floyd

eh?

???

is this an example of inode reuse? :) or do you mean that somehow
floyd is the new foo, (foo is dead, all hail floyd) and that bar now
points to floyd?

how do i control this 'symlinks magically link to new files' feature?

> and this all fails to handle nfs mounted file systems or filesystems
> that have dynamic inodes (the fat fs's and reiser lacks inodes i think).

reiser's handles to files are hashes i believe. fat: dont think you
can make symlinks on it.

> kevin

anyway, links are directory entries that reference the same inode.
(and i'll bet the restriction on directories is an artificial these
days.. ELOOP exists anyway because of symlinks.)

and symlinks are inodes whose data is a reference in the namespace:

[root at domain fogarty tmp]# ls /var/tmp/foo
bin lib tmp
[root at domain fogarty tmp]# ls /var/tmp/foo/bin/
cat ls
[root at domain fogarty tmp]# pwd
/var/tmp/foo/tmp
[root at domain fogarty tmp]# echo "i am foo" > foo
[root at domain fogarty tmp]# ls
foo
[root at domain fogarty tmp]# ln foo fongle
[root at domain fogarty tmp]# chroot /var/tmp/foo cat /tmp/fongle /tmp/foo
i am foo
i am foo
[root at domain fogarty tmp]# rm fongle
rm: remove `fongle'? y
[root at domain fogarty tmp]# ln -s foo fongle
[root at domain fogarty tmp]# chroot /var/tmp/foo cat /tmp/fongle /tmp/foo
i am foo
i am foo
[root at domain fogarty tmp]# rm fongle
rm: remove `fongle'? y
[root at domain fogarty tmp]# ln -s /var/tmp/foo/tmp/foo fongle
[root at domain fogarty tmp]# cat foo fongle
i am foo
i am foo
[root at domain fogarty tmp]# chroot /var/tmp/foo cat /tmp/fongle /tmp/foo
cat: /tmp/fongle: No such file or directory
i am foo

in the last example, the symbolic link doesnt work in the chroot,
because the namespace is different.

aiui.

regards,

-- 
Paul Jakma	paul at domain clubi.ie	paul at domain jakma.org	Key ID: 64A2FF6A
Fortune:
Never try to teach a pig to sing.  It wastes your time and annoys the pig.
		-- Lazarus Long, "Time Enough for Love"


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:59 GMT