/* 'pnum' is set to the number of sectors (including and immediately following the first one) that are known to be in the same allocated/unallocated state.  */
static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum)
/* 'pnum' is set to the number of sectors (including and immediately following the first one) that are known to be in the same allocated/unallocated state.  */
static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum)
{
    bool is_zero;
    int i;
    if (n <= 0) {
        *pnum = 0;
        return 0;
    }
    is_zero = buffer_is_zero(buf, 512);
    for(i = 1; i < n; i++) {
        buf += 512;
        if (is_zero != buffer_is_zero(buf, 512)) {
            break;
        }
    }
    *pnum = i;
    return !is_zero;
}