4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
28 * Lustre is a trademark of Sun Microsystems, Inc.
30 * lustre/tests/ll_sparseness_verify.c
32 * The companion to ll_sparseness_write; walk all the bytes in the file.
33 * the bytes at the offsets specified on the command line must be '+', as
34 * previously written by ll_sparseness_write. All other bytes must be 0.
42 #include <sys/types.h>
48 #define BUFSIZE (1024 * 1024)
50 void error(char *fmt, ...)
55 vfprintf(stderr, fmt, ap);
60 int compare_offsets(const void *a, const void *b)
62 off_t *A = (off_t *)a;
63 off_t *B = (off_t *)b;
68 int main(int argc, char **argv)
70 unsigned int num_offsets, cur_off = 0, i;
71 off_t *offsets, pos = 0, end_of_buf = 0;
78 error("Usage: %s <filename> <offset> [ offset ... ]\n",
81 fd = open(argv[1], O_RDONLY);
83 error("couldn't open %s: %s\n", argv[1], strerror(errno));
85 buf = malloc(BUFSIZE);
87 error("can't allocate buffer\n");
89 num_offsets = argc - 2;
90 offsets = calloc(sizeof(offsets[0]), num_offsets);
91 for (i = 0; i < num_offsets; i++) {
92 offsets[i] = strtoul(argv[i + 2], &end, 10);
94 error("couldn't parse offset '%s'\n", argv[i + 2]);
96 qsort(offsets, num_offsets, sizeof(offsets[0]), compare_offsets);
98 if (fstat(fd, &st) < 0)
99 error("stat: %s\n", strerror(errno));
101 for (i = 0; pos < st.st_size; i++, pos++) {
102 if (pos == end_of_buf) {
103 ret = read(fd, buf, BUFSIZE);
105 error("read(): %s\n", strerror(errno));
106 end_of_buf = pos + ret;
107 if (end_of_buf > st.st_size)
108 error("read %d bytes past file size?\n",
109 end_of_buf - st.st_size);
113 /* check for 0 when we aren't at a given offset */
114 if (cur_off >= num_offsets || pos != offsets[cur_off]) {
116 error("found char 0x%x at pos %lu instead of 0x0\n",
121 /* the command line asks us to check for + at this offset */
123 error("found char 0x%x at pos %lu instead of '.'\n",
126 /* skip over duplicate offset arguments */
127 while (cur_off < num_offsets && offsets[cur_off] == pos)
130 /* don't bother freeing or closing.. */