Solved Best way to verify disk is zeroed?

I made a few modifications to his code to report where the error lies if it finds one, but otherwise this does appear to read at the maximum disk speed. Thanks!

Edit: If anyone is interested here's the code after the changes I made. It's also a bit more verbose.
C:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>

#define BLOCKSIZE (128 * 1024)
uint64_t data[(BLOCKSIZE + 7) / 8];

int main(void) {
    int inbytes;
    uint64_t intotal = 0;

    while((inbytes = read(STDIN_FILENO, data, BLOCKSIZE)) > 0) {
        inbytes = (inbytes + 7) >> 3;

        for(int i = 0; i < inbytes; i++) {
            if(data[i]) {
                intotal = (intotal + i) << 3;    // Convert back to byte offset
                printf("Non-zero byte detected at offset range: %lu to %lu\n", intotal, intotal + 7);
                exit(1);
            }
        }

        intotal += inbytes;
    }

    if(inbytes < 0) {
        perror(NULL);
        exit(2);
    }

    printf("Disk is fully zeroed.\n");
    return 0;
}
 
Back
Top