Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

why does the current folder stop being usable?

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
MagicPoulp
Posts: 431
Joined: 2018-11-05 21:30

why does the current folder stop being usable?

#1 Post by MagicPoulp »

why the current folder stops being usable?
Sometimes in my git repo, I get this error, and I have to do "cd; cd -"
sh: 0: getcwd() failed: No such file or directory

I am using a webpack watch and the folder is on a mounted file with cifs
here is the fstab entry for the mounting.
//REPLACED_SECRET_PATH cifs user=externo,password=REPLACED,uid=1000,gid=1000,mfsymlinks

note:
this thead gives a hint:
https://askubuntu.com/questions/286467/ ... -directory

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 68 times

Re: why does the current folder stop being usable?

#2 Post by LE_746F6D617A7A69 »

Probably You have already discovered, that in Linux-based OS it's possible to delete and re-create a directory or file which is currently used by some other program. Whether this is a feature or bug, depends on a point of view, but there are practical reasons to have such functionality.
Anyway, in such case the fstat structure is changed (see fstat(2) )

The applications which have already obtained a file descriptor for that deleted/re-created file or directory will obviously return faults, because their file descriptors are no longer valid -> this also affects the shells -> that's why it's required to execute the "cd" command again.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

MagicPoulp
Posts: 431
Joined: 2018-11-05 21:30

Re: why does the current folder stop being usable?

#3 Post by MagicPoulp »

It seems dangerous that anything would delete recreate my folders. I don't think so.

IT seems to me more related to how mounting cifs works. And also related to a windows VM running a nodejs process on that same cifs.

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 68 times

Re: why does the current folder stop being usable?

#4 Post by LE_746F6D617A7A69 »

MagicPoulp wrote:It seems dangerous that anything would delete recreate my folders. I don't think so.
IT seems to me more related to how mounting cifs works. And also related to a windows VM running a nodejs process on that same cifs.
I was referring to the article from the askubuntu.com which You've referenced. Unmounting a filesystem also invalidates all the currently used file/directory descriptors.

But I think that We need more details to explain what is actually happening. I'm guesing that the directory in question is just re-created during project synchronization (what invalidates the file/directory descriptors).
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: why does the current folder stop being usable?

#5 Post by p.H »

LE_746F6D617A7A69 wrote:in Linux-based OS it's possible to delete and re-create a directory or file which is currently used by some other program.
No, it is not possible to delete a file or directory in use. You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 68 times

Re: why does the current folder stop being usable?

#6 Post by LE_746F6D617A7A69 »

p.H wrote:
LE_746F6D617A7A69 wrote:in Linux-based OS it's possible to delete and re-create a directory or file which is currently used by some other program.
No, it is not possible to delete a file or directory in use. You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.
Nope.
Proof:
Open 2 terminal instances
terminal 1:

Code: Select all

mkdir testdir; cd testdir; touch testfile; ls
terminal 2:

Code: Select all

rm -r testdir; mkdir testdir; cd testdir; touch testfile2; ls
terminal 1:

Code: Select all

ls
Result: no files found, invalid descriptor for re-created directory 'testdir'
Now, in terminal 1:

Code: Select all

cd ..; cd testdir; ls
Now, the file 'testfile2' will be listed
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

Islander
Posts: 42
Joined: 2020-10-20 08:29
Has thanked: 16 times
Been thanked: 1 time

Re: why does the current folder stop being usable?

#7 Post by Islander »

p.H wrote:You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.
That's true, but does "standing" in a directory (having it as current directory) count as the directory being in use?

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 68 times

Re: why does the current folder stop being usable?

#8 Post by LE_746F6D617A7A69 »

Islander wrote:
p.H wrote:You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.
That's true, but does "standing" in a directory (having it as current directory) count as the directory being in use?
Nope, Test2:

terminal 1:

Code: Select all

mkdir testdir; cd testdir; touch testfile; less testfile
The file 'testfile' is now opened for read in terminal 1 (so it is opened for read, while the commands in terminal 2 are executed)
terminal 2:

Code: Select all

rm -r testdir; mkdir testdir; cd testdir; touch testfile2; less testfile2
The 'testdir' has been re-created (opened file 'testfile' has been deleted, and the file 'testfile2' is now opened for read in terminal 2)
terminal 1: type 'q' to quit less, then type 'ls'

Code: Select all

ls
The same result: no files found, invalid descriptor for re-created directory 'testdir'

Re-creation or deletion of a directory or file currently opened in some other program is possible in UNIX/BSD/Linux.
This also works on a very low level (descriptors) and if the above examples are not sufficient, I can spend another 5 minutes to demonstrate this behaviour on a C-code level.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

Post Reply