We have finished testing fs_disk. We are able to confirm that there was no problem by reading the randomly written information and comparing. This is code below.
for(index_t test=0; test < 64; ++test) {
const sector_t begin = rand() % 10000000;
const counter_t num = rand() % 94581920;
if(num==0) continue;
const fsize_t bsize = num * SECTOR_SIZE;
byte_t *wbuf = fs_malloc(bsize);
assert(wbuf);
{
FSDISK *fdp;
assert(fs_disk_open(&fdp));
for(index_t i = 0; i < bsize; ++i)
wbuf[i] = (byte_t)rand();
assert(fs_disk_write(fdp, begin, num, wbuf));
fs_disk_close(fdp, true_t);
}
{
FSDISK *fdp;
assert(fs_disk_open(&fdp));
byte_t *rbuf = fs_malloc(bsize);
assert(rbuf);
assert(fs_disk_read(fdp, begin, num, rbuf));
assert(memcmp(wbuf, rbuf, bsize) == 0);
fs_free(rbuf, fs_disk_close(fdp, true_t));
}
fs_free(wbuf, true_t);
}