Anyways, so there was this utility very similar to the UNIX cat utility that read in a file, and wrote it to some other location. However, this utility also performs a check to determine if:
- There is sufficient space on the destination disk.
- The destination file is on a special file system
Only if both the conditions are met does the utility go ahead with the task of creating the destination file. A special feature of this utility is that it will create sparse files if the source file contains many holes in it. So, it is not strictly required that the destination file system contain as much space as the source file size. Also, the second check is made to make sure that the destination file system supports sparse files. However, if we know that there is another file system which supports sparse files, we can do away with that check as well.
All said and done, I did not have the source code to the utility that I am talking about, so I decided to do something else. I used the LD_PRELOAD environment variable available on all Linux machines to load in a custom compiled shared object file which overrides system calls such as statfs(), statvfs() and ioctl() that are the typical calls used to get this sort of information from the underlying OS, and viola! there it was. My hooks worked, and I was able to see what was being returned for each request. The only thing I had to do was fool the program into thinking it was getting the information it needed to go ahead with the file conversion. That again was just a matter of inspecting and inserting the correct values for each over-ridden system call. the whole process took about 4hrs, but it was time well spent. It felt good to get back to doing this sort of hacking-programming after a while....
No comments:
Post a Comment