1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <sys/types.h>
46 #define BUFSIZE (4096)
48 #define min(a,b) ((a) < (b) ? (a) : (b))
50 int main(int argc, char *argv[])
56 int line, delta, next;
59 const char ok_chars[] = "MonTueWedThuFriSatSun"
60 "JanFebMarAprMayJunJulAugSepOctNovDec"
61 "Line 0123456789 of file, written at:\n";
65 char pathname[256] = "/mnt/lustre/linetest_";
69 strncpy(pathname, argv[1], 255);
73 host = getenv("HOSTNAME");
75 strcat(pathname, host);
78 sleeptime = strtoul(argv[2], NULL, 0);
83 printf("Test file used is: %s at %ds intervals\n", pathname, sleeptime);
85 w_str = fopen(pathname, "wb");
90 read_fd = open(pathname, O_RDONLY);
104 now = time((time_t *)NULL);
106 now_time = asctime(t);
108 printf("iter: %d\n", iter);
110 for (line=next; line<(next+delta); line++) {
111 rc = fprintf(w_str, "Line %8d of file, written at: %s",
113 /* \n comes from ctime() result */
126 /* Check for corruption */
127 offset = ftell(w_str);
128 rc = lseek(read_fd, offset & ~4095, SEEK_SET);
129 if (rc != (offset & ~4095)) {
134 rc = read(read_fd, buf_r, min(100, offset & 4095));
135 if (rc != min(100, offset & 4095)) {
136 printf("rc: %d, off %lu buf: '%s'\n", rc,offset,buf_r);
140 /* Chars from "C" days/months, and above Line */
141 if (strspn(buf_r, ok_chars) != rc) {
142 printf("Corruption detected at %lu on %s",
143 offset & ~4095, now_time);