[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Removable USB device contents cached after removal? [Part 2]


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 _at_ matt mnt]# mount floppy
[root _at_ 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 _at_ matt mnt]# dd if=/dev/fd0 of=/dev/null count=10 bs=1024
dd: opening `/dev/fd0': No such device or address
[root _at_ matt mnt]# umount floppy/
[root _at_ matt mnt]# cat /dev/fd0
cat: /dev/fd0: No such device or address

And the memory device as a comparison:

[root _at_ matt mnt]# mount /dev/sdd1
[root _at_ 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 _at_ matt mnt]# dd if=/dev/sdd1 of=/dev/null count=10 bs=1024
10+0 records in
10+0 records out
[root _at_ matt mnt]# umount /dev/sdd1
[root _at_ 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 _at_ matt mnt]# mount atech2
mount: No medium found
[root _at_ matt mnt]# mount atech2
[root _at_ 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 _at_ matt mnt]# dd if=/dev/sdd of=/dev/null count=10 bs=1024
dd: opening `/dev/sdd': No medium found
[root _at_ matt mnt]# umount atech2
[root _at_ 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 _at_ matt mnt]# mount floppy
[root _at_ 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 _at_ 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 _at_ matt mnt]# cat /dev/fd0
cat: /dev/fd0: No such device or address
[root _at_ matt mnt]# ls -l floppy
total 0

Matt.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo _at_ vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


この情報があなたの探していたものかどうか選択してください。
yes/まさにこれだ!   no/違うなぁ   part/一部見つかった   try/これで試してみる

あなたが探していた情報はどのようなことか、ご自由に記入下さい。特に「まさにこれだ!」と言う場合は記入をお願いします。
例:「複数のマシンからCATV経由でipmasqueradeを利用してWebを参照したい場合の設定について」