Avoid overflowing of counter
It will wrap around though 0.

0xFFFFFFFF + 1 = 0


You can add a higher order word to track more data:

if (byteWritten &gt; 0) {
    uint32_t newUsed = usedBytes + byteWritten;
    if (newUsed &lt; usedBytes) {
        fourGigsUsed ++;
    }
    usedBytes = newUsed;
}


Or you could use uint64_t to automate it - however none of the Arduino print routines cope with the uint64_t variable type.