How to make SD card read/write faster?

Obviously, this code is a fail

That is NOT at all obvious.

Not closing the file on the write pass is NOT good. That can lead to corrupt, unrecoverable files.

Why are you using a struct to wrap one int? What is the advantage in that?