1. Naive Method
for (ii=0; ii<filesize; ii += stridelength)
{
char string[stridelength];
randomise(string);
write(fd,string,stridelength);
lseek(fd,stridelength,CUR_POS);
}2. Sparse files method
write(fd,"\0",1);
lseek(fd,filesize-1,CUR_SET);
write(fd,"\0",1);This is insanely quick compared to the method 1! The man page for lseek() explains this nicely:
"The lseek() function allows the file offset to be set beyond the end of the file (but this does not change the size of the file). If data is later written at this point, subsequent reads of the data in the gap (a "hole") return null bytes ('\0') until data is actually written into the gap.".Does this work on OSes other than Linux?
No comments:
Post a Comment