From: Matthew Mastracci <mmastrac@canada.com>
To: linux-kernel@vger.kernel.org
Subject: Removable USB device contents cached after removal? [Part 2]
Date: Wed, 31 Dec 2003 18:36:50 -0700 [thread overview]
Message-ID: <3FF379B2.3010301@canada.com> (raw)
Just as a note in regards to my previous post: I'm mostly looking for a
way to determine that the device was improperly mounted and use this
information to display an error. I know it's not a good idea to be
removing mounted devices without a umount first. :)
To investigate further, as an experiment, I tried the same thing with
fd0. It turns out that the floppy driver is able to detect the media
change and doesn't return any cached data when accessing the raw device.
Accessing the memory device's raw device rather than the partition
device (ie: sdd vs. sdd1) also detected the change.
Here's an example:
[root@matt mnt]# mount floppy
[root@matt mnt]# dd if=/dev/fd0 of=/dev/null count=10 bs=1024
10+0 records in
10+0 records out
(manually ejecting floppy while still mounted)
[root@matt mnt]# dd if=/dev/fd0 of=/dev/null count=10 bs=1024
dd: opening `/dev/fd0': No such device or address
[root@matt mnt]# umount floppy/
[root@matt mnt]# cat /dev/fd0
cat: /dev/fd0: No such device or address
And the memory device as a comparison:
[root@matt mnt]# mount /dev/sdd1
[root@matt mnt]# dd if=/dev/sdd1 of=/dev/null count=10 bs=1024
10+0 records in
10+0 records out
(manually removing memory card)
[root@matt mnt]# dd if=/dev/sdd1 of=/dev/null count=10 bs=1024
10+0 records in
10+0 records out
[root@matt mnt]# umount /dev/sdd1
[root@matt mnt]# dd if=/dev/sdd1 of=/dev/null count=10 bs=1024
dd: opening `/dev/sdd1': No medium found
And interestingly, accessing the root of the memory device works like
the floppy does (note that atech2 = /dev/sdd1):
[root@matt mnt]# mount atech2
mount: No medium found
[root@matt mnt]# mount atech2
[root@matt mnt]# dd if=/dev/sdd of=/dev/null count=10 bs=1024
10+0 records in
10+0 records out
(manually removing memory card)
[root@matt mnt]# dd if=/dev/sdd of=/dev/null count=10 bs=1024
dd: opening `/dev/sdd': No medium found
[root@matt mnt]# umount atech2
[root@matt mnt]# dd if=/dev/sdd of=/dev/null count=10 bs=1024
dd: opening `/dev/sdd': No medium found
An interesting observation is that the floppy will also cache the
directory contents, even when the floppy is removed. As soon as an
error occurs, the cached contents are tossed. I'm not certain of the
correct behaviour in this situation, however, but it's here for comparison:
[root@matt mnt]# mount floppy
[root@matt mnt]# ls -l floppy
total 388
-rwxr-xr-x 1 root root 14 Mar 20 2002 autoexec.bat
-rwxr-xr-x 1 root root 66785 Sep 21 1999 command.com
-rwxr-xr-x 1 root root 18 Feb 13 2002 config.sys
-rwxr-xr-x 1 root root 2563 Nov 13 20:30 drvinf.txt
-rwxr-xr-x 1 root root 14766 Jan 7 1999 himem.sys
-rwxr-xr-x 1 root root 24810 Sep 21 1999 ibmbio.com
-rwxr-xr-x 1 root root 30880 Sep 21 1999 ibmdos.com
-rwxr-xr-x 1 root root 244264 May 20 2003 powermax.exe
-rwxr-xr-x 1 root root 10041 May 8 2003 PWMXReadme.txt
(manually ejecting floppy)
[root@matt mnt]# ls -l floppy
total 388
-rwxr-xr-x 1 root root 14 Mar 20 2002 autoexec.bat
-rwxr-xr-x 1 root root 66785 Sep 21 1999 command.com
-rwxr-xr-x 1 root root 18 Feb 13 2002 config.sys
-rwxr-xr-x 1 root root 2563 Nov 13 20:30 drvinf.txt
-rwxr-xr-x 1 root root 14766 Jan 7 1999 himem.sys
-rwxr-xr-x 1 root root 24810 Sep 21 1999 ibmbio.com
-rwxr-xr-x 1 root root 30880 Sep 21 1999 ibmdos.com
-rwxr-xr-x 1 root root 244264 May 20 2003 powermax.exe
-rwxr-xr-x 1 root root 10041 May 8 2003 PWMXReadme.txt
[root@matt mnt]# cat /dev/fd0
cat: /dev/fd0: No such device or address
[root@matt mnt]# ls -l floppy
total 0
Matt.
reply other threads:[~2004-01-01 1:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=3FF379B2.3010301@canada.com \
--to=mmastrac@canada.com \
--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