How to delete unreadable files from NTFS

I have a new Linux-based toy – a media player. For some strange reason, the developers decided that it’s a good idea to keep all the important files (like the porn collection!) on a NTFS partition. Since the device can be accessed via a USB host port, I guess they wanted to make sure the disk is accesible from Windows.

It didn’t take me too long to mess up the filesystem. I just had to copy a file with a “:” in the filename (04 – 40:1.mp3). The filename is valid on any ext* partition and most likely also on all the other decent filesystems. Not on NTFS.

The funny thing is that the filesystem code had no problem creating and writing the file. But when you tried to do a simple directory listing:

# ls -l
ls: ./04 - 40:1.mp3: No such file or directory

and sometimes also:

# ls -l
ls: ./04 - 40:1.mp3: Input/output error

After a few minutes of considering whether I want to just reformat the partition, I found out this question where I got the solution.

Aparently writing something to the file makes it visible (?), and you also get two directory entries, one the complete file name, the other just the part until the “:” (?!). Yes, it’s strange, but it works. This is what I had to do to remove the file:

# echo "blah" > "04 - 40:1.mp3"
# ls
04 - 40 04 - 40:1.mp3
# mv "04 - 40:1.mp3" file1
# ls
04 - 40 file1
# mv "04 - 40" file2
# ls
file1 file2
# rm -f *

Of course, the next step was to make sure my data doesn’t touch the player’s NTFS partition again. And this, kids, is why open source is the better alternative!

Image credit: Andres Rueda.

TwitterFacebookLinkedInGoogle ReaderYahoo MessengerEmailGoogle GmailYahoo MailPrintShare

Related posts:

  1. How to change files in a initrd image

2 comments

  1. Alin says:

    Actually, you’ve created an alternate data stream (ADS) – basically, a mechanism that allows stuff like having two files in an entry such as C:tesztharmless_text.txt:virus_gotcha.exe, that can be accessed via a command line.

    The ADS are typically used for describing “potentially unsafe” files downloaded from an untrusted zone (see :Zone.Identifier:$DATA). Since XP SP2, Windows Explorer uses this data to ask for confirmation when a downloaded file (like an .exe) is opened; if the “Always ask before opening this file” checkbox is unticked, the ADS for that file is removed.

  2. Ovidiu says:

    @Alin, oh, what a great idea! I could have all my files with a single file name? Why didn’t I think of that? :)

    As I said… “And this, kids, is why open source is the better alternative!” :D

Leave a Reply

Your email address will not be published. Required fields are marked *

*


six + 2 =

CommentLuv badge