If I may I'd like to offer a couple of comments on the writer.
Having the write function which is used by the print() calls go through a general-purpose write function is less efficient than making things work the other way viz:
void SDWriter::write(uint8_t theByte)
{
sector_buffer[buffer_pos]= theByte;
++buffer_pos;
if(buffer_pos==512)
{
flush();
}
}
void SDWriter::write(unsigned long val,int bytes)
{
for(int b=bytes-1;b>=0;--b)
{
write((val>>(8*b)) & 0xff);
}
}
This way the print calls all go through the minimal version.