Receive bytes from UART camera
Well, code looks almost ok. But, while storing the buffer to SD card, if new byte arrived, you will have a problem. To be on a safe side, you could create a ring buffer of larger size of needed buffer and flush it every xy values.

int head = 0, tail = 0, cnt = 0;
bool overflow = false;
#define BUFFSIZE 1024
char buff [BUFFSIZE];
#define MEMBUFSIZE 512
char memoryBuff[MEMBUFSIZE];

void appendToBuff(char a_byte)
{
   buff[head++] = a_byte;
   if (head &gt;= BUFFSIZE) {
       head = 0;
       }
   if (head == tail) {
       overflow = true;
       flushBuffer();
       }
}
void flushBuffer ()
{
    while (tail != head || overflow){
        overflow = false;
        memoryBuff[cnt++] = buff[tail++];
        if (tail &gt;= BUFFSIZE) tail = 0;
        if (cnt &gt;= MEMBUFSIZE) {
             Write_Sector(SectorNumber,Buff);
             cnt = 0;
             }
        }
}
void main() 
{
    while (1) {
       flushBuffer();
       }
}


i havent try this code, so it might have bug or two, but it will help with an overview what you should handle ...