| 501 | } |
| 502 | |
| 503 | static int fill_pattern(const char *fname) |
| 504 | { |
| 505 | size_t left = FSIZE; |
| 506 | unsigned int val, *ptr; |
| 507 | void *buf; |
| 508 | int fd, i; |
| 509 | |
| 510 | fd = open(fname, O_WRONLY); |
| 511 | if (fd < 0) { |
| 512 | if (errno == EPERM || errno == EACCES) |
| 513 | return T_EXIT_SKIP; |
| 514 | perror("open"); |
| 515 | return 1; |
| 516 | } |
| 517 | |
| 518 | val = 0; |
| 519 | buf = t_malloc(4096); |
| 520 | while (left) { |
| 521 | int u_in_buf = 4096 / sizeof(val); |
| 522 | size_t this = left; |
| 523 | |
| 524 | if (this > 4096) |
| 525 | this = 4096; |
| 526 | ptr = buf; |
| 527 | for (i = 0; i < u_in_buf; i++) { |
| 528 | *ptr = val; |
| 529 | val++; |
| 530 | ptr++; |
| 531 | } |
| 532 | if (write(fd, buf, 4096) != 4096) |
| 533 | return 1; |
| 534 | left -= 4096; |
| 535 | } |
| 536 | |
| 537 | fsync(fd); |
| 538 | close(fd); |
| 539 | free(buf); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | int main(int argc, char *argv[]) |
| 544 | { |