1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
10 main(int argc, char **argv)
14 long long maxblks = -1; /* no limit */
21 int oflags = O_WRONLY;
25 if (strrchr(argv[0],'/'))
26 progname = strrchr(argv[0],'/')+1;
30 while ((fd = getopt(argc, argv, "b:n:o:v:ct")) != EOF) {
33 blksize = atoi(optarg) * 512;
36 maxblks = atoll(optarg);
39 offset = atoll(optarg);
54 if (sts || argc - optind != 1) {
56 "Usage: %s [-b N*512] [-n N] [-o off] [-v val] "
57 " [-c] [-t] <dev/file>\n",
59 fprintf(stderr," -c: create -t: truncate\n");
65 if ((fd = open(path, oflags, 0600)) < 0) {
67 "error opening \"%s\": %s\n",
68 path, strerror(errno));
71 if ((lseek64(fd, offset, SEEK_SET)) < 0) {
72 fprintf(stderr, "%s: error seeking to offset %llu "
74 progname, (unsigned long long)offset, path, strerror(errno));
78 if ((z = memalign(getpagesize(), blksize)) == NULL) {
79 fprintf(stderr, "%s: can't memalign %u bytes: %s\n",
80 progname, blksize, strerror(errno));
83 memset(z, value, blksize);
86 if (nblks++ == maxblks)
88 if ((sts = write(fd, z, blksize)) < blksize) {
89 if (errno == ENOSPC || sts >= 0)
91 fprintf(stderr, "%s: write failed: %s\n",
92 progname, strerror(errno));
96 printf("Wrote %.2fKb (value 0x%x)\n",
97 (double) ((--nblks) * blksize) / 1024, value);