Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Strange behaviour with . directory
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
SableEA
n00b
n00b


Joined: 23 Aug 2024
Posts: 4
Location: Belarus

PostPosted: Sun Aug 25, 2024 8:39 am    Post subject: Strange behaviour with . directory Reply with quote

I turned off computer with gentoo installation on the stage Installing the Gentoo installation files (I unpacked archive.). After turning on I mounted needed partitions of disk
Code:
cd /mnt/gentoo; mnt /dev/sda3 .

Then there where strange behaviour: output of
Code:
ls /mnt/gentoo
showed me all files, but output of just
Code:
ls
was nothing
I understood that this is problem with . directory, because working with direct path /mnt/gentoo was normal, but with . directory not (I retried ls, find and file commands).
I decided to make something with . directory, so I just wrote
Code:
od .

And there is surprise: after that ls command and another commands with . worked normal
Why did it happened?
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 31280
Location: here

PostPosted: Sun Aug 25, 2024 10:35 am    Post subject: Reply with quote

Moved from Other Things Gentoo to Installing Gentoo.
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
kimchi_sg
Advocate
Advocate


Joined: 26 Nov 2004
Posts: 3038

PostPosted: Mon Aug 26, 2024 1:08 am    Post subject: Re: Strange behaviour with . directory Reply with quote

SableEA wrote:
output of
Code:
ls /mnt/gentoo
showed me all files, but output of just
Code:
ls
was nothing

This is expected, the latter command shows current directory just after you booted the Gentoo live USB; this is empty by default.
Back to top
View user's profile Send private message
Banana
Moderator
Moderator


Joined: 21 May 2004
Posts: 1747
Location: Germany

PostPosted: Mon Aug 26, 2024 8:03 am    Post subject: Reply with quote

I do think the ls was executed after the cd /mnt/gentoo.

I never use the mount command like that. I do always provide the full target path.
_________________
Forum Guidelines

PFL - Portage file list - find which package a file or command belongs to.
My delta-labs.org snippets do expire
Back to top
View user's profile Send private message
Chiitoo
Administrator
Administrator


Joined: 28 Feb 2010
Posts: 2733
Location: Here and Away Again

PostPosted: Mon Aug 26, 2024 1:42 pm    Post subject: Reply with quote

I'm not entirely sure how to explain it at this time, but the current work directory doesn't seem to get "updated" for the mount.

I see the same behaviour if I 'cd /to/some/dir' and 'bind' mount anything to it: the 'ls' command will not show anything until I 'cd' to that directory again.
_________________
Kindest of regardses.
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 272
Location: Pennsylvania, USA

PostPosted: Mon Aug 26, 2024 10:49 pm    Post subject: Reply with quote

Interesting. Mounting to the current working directory is different. Here's a test: (/dev/sda2 is my boot partition.)
Code:
# ls -a toto
.  ..
# cd toto
# touch HI_THERE
# ls -a
.  ..  HI_THERE
# mount -o ro /dev/sda2 .
# ls -a
.  ..  HI_THERE
# cd ..
# cd toto
# ls -a
.                                grub
..                               initramfs-5.15.19
.keep                            initramfs-generic
System.map-6.6.38-gentoo-x86_64  intel-uc.img
System.map-6.6.47-gentoo-x86_64  lost+found
amd-uc.img                       vmlinuz-6.6.38-gentoo-x86_64
config-6.6.38-gentoo-x86_64       vmlinuz-6.6.47-gentoo-x86_64
config-6.6.47-gentoo-x86_64
#

Mounting a filesystem hides whatever was under the mount point. BUT if a process had the mount point as its working directory, the old content remains visible to that process. (In the above test, changing out of toto lost the pointer to the old content.)

Might be interesting to follow this in the kernel sources.
Question: can the process can give the old content to another process by open(".") and passing the descriptor through an AF_UNIX socket ?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum