I haven't tried this, but since the iPhone is a UNIX based OS you should be able to get the free space on the flash file system using the statfs system call (see link for documentation).
Just use as parameter the path to the app directory that you plan to write to.