2 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 main(int argc, char **argv)
26 long long maxblks = -1; /* no limit */
33 int oflags = O_WRONLY;
37 if (strrchr(argv[0],'/'))
38 progname = strrchr(argv[0],'/')+1;
42 while ((fd = getopt(argc, argv, "b:n:o:v:ct")) != EOF) {
45 blksize = atoi(optarg) * 512;
48 maxblks = atoll(optarg);
51 offset = atoll(optarg);
66 if (sts || argc - optind != 1) {
68 "Usage: %s [-b N*512] [-n N] [-o off] [-v val] "
69 " [-c] [-t] <dev/file>\n",
71 fprintf(stderr," -c: create -t: truncate\n");
77 if ((fd = open(path, oflags, 0600)) < 0) {
79 "error opening \"%s\": %s\n",
80 path, strerror(errno));
83 if ((lseek64(fd, offset, SEEK_SET)) < 0) {
84 fprintf(stderr, "%s: error seeking to offset %llu "
86 progname, (unsigned long long)offset, path, strerror(errno));
90 if ((z = memalign(getpagesize(), blksize)) == NULL) {
91 fprintf(stderr, "%s: can't memalign %u bytes: %s\n",
92 progname, blksize, strerror(errno));
95 memset(z, value, blksize);
98 if (nblks++ == maxblks)
100 if ((sts = write(fd, z, blksize)) < blksize) {
101 if (errno == ENOSPC || sts >= 0)
103 fprintf(stderr, "%s: write failed: %s\n",
104 progname, strerror(errno));
108 printf("Wrote %.2fKb (value 0x%x)\n",
109 (double) ((--nblks) * blksize) / 1024, value);