Bug 163014 - incorrect working directory after removing USB flash disk without umounting it
incorrect working directory after removing USB flash disk without umounting it
Product: Fedora
Classification: Fedora
Component: kernel (Show other bugs)
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Kernel Maintainer List
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2005-07-12 05:26 EDT by Vlado Potisk
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-07-12 18:06:41 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Vlado Potisk 2005-07-12 05:26:28 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Fedora/1.0.4-1.3.1 Firefox/1.0.4

Description of problem:
Removing a USB flash disk without unmounting it first is a user error, but the kernel seems to have some recovery procedure for this case, but it changes the working directory in a wrong way.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. plug in the USB flash disk
2. mount /media/usbdisk
3. cd /media/usbdisk/some/directory
4. unplug the USB flash disk (this is not normal, but can happen by mistake)
5. pwd

Actual Results:  pwd shows that the current working directory is /some/directory, but such directory does not exist and never existed before.

Expected Results:  I'm not sure, but in my opinion the CWD should stay unchanged, i.e. /media/usbdisk/some/directory and all access to it should result in an I/O error.
If the kernel is permitted to change the cwd of a process, then /media as a new CWD makes more sense - it is an existing parent directory of the original working directory.

Additional info:

Getting the same results with a memory card and a USB card reader.
Comment 1 Dave Jones 2005-07-12 18:06:41 EDT
This is expected behaviour.  Trying to do anything like reading/writing files in
that dir will fail, but as you have a current reference count on the dir, it's
still a valid part of the tree until you cd out of it.

Comment 2 Vlado Potisk 2005-07-13 07:58:50 EDT
The situation is little bit different, but worse when the directory structure on
the flash disk are similar to the root disk, here is an example:

# mount /media/usbdisk1
# cd /media/usbdisk1/bin
-- unplug the usb disk hardware now --
# pwd
# sh
# pwd
# ls . | wc
     77      77     419
# ls /bin | wc
     96      96     593

The new shell says its working directory is /bin with 77 entries (on the flash
disk) but it also recognizes another /bin with 96 entries (on the root hard
disk). Two directories with the same name !

Be sure to always correctly unmount external disks, otherwise strange things
might happen !

Note You need to log in before you can comment on or make changes to this bug.