In writeToFile(), the function returns 0 after getting a "No more data blocks available" error. This doesn't seem right because it doesn't update the size for the data already written to this file. Therefore, those data won't really belong to this file, creating ghost blocks (allocated but not really used).
This is mainly due to the fact that Read and Delete are based on the file size.
Possible fix is to keep track of number of bytes (size) already written to the file. So when the error occurs, I will break the loop instead of returning 0. This way I won't skip the file size update.