tags:

views:

98

answers:

4

how can i create a corrupt file with specified size ?

corrupt as in make a empty file or take an actual file and corrupting it so it becomes unreadable.

+6  A: 

Burn the file onto a cd/dvd then lightly scratch the disk

gnibbler
+1 , fine grit sandpaper or smoker's toothpaste works well.
Tim Post
+5  A: 
dd if=/dev/urandom of=somefile bs=somesize count=1

See the man page for details on the size.

Ignacio Vazquez-Abrams
Huh? This just creates a file filled with random bytes, that's not "corrupt" in any way?
unwind
@unwind: It most certainly *is* a corrupt XML file. Or a corrupt C source file. Or...
Ignacio Vazquez-Abrams
@Ignacio: sure, but he didn't mention a type. I thought he wanted read() to fail, i.e. the file should be unreadable at the lowest level. I guess it's just another vague question, then. :)
unwind
+5  A: 

Files can contain any arbitrary pattern of bytes, so there is no (digital) way to create a file that is "corrupted". You can certainly modify a file in an existing format (for example, an XML file) so that it no longer is valid in whatever format it's supposed to be, but it's still just a file on disk and is perfectly readable.

You generally need to physically alter the storage medium on which the file is stored, in order to make the file actually unreadable.

Greg Hewgill
+2  A: 

My guess is that your best way is to mount a FUSE filesystem which is modified to return errors for specific files. as FUSE really is a filesystem driver (albeit in userspace) it can throw back whatever error code you want.

MarkR
I think there is a FUSE implementation that injects random rubbish on client read()'s .. I just can't think of the name off hand. It simulates all kinds of errors.
Tim Post