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
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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 (c) 2003, 2010, Oracle and/or its affiliates. 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>
49 const char usage_fmt[] = "Usage: %s <file> <mountpoint>\n";
50 #define INAME_LEN (PATH_MAX + 1)
52 #define CHECK_IT(exp, pstr) \
54 fprintf(stderr, "%s: at %s:%d: ", progname, __FILE__, __LINE__); \
59 #define CHECK_SNPRINTF(rc, len) \
60 CHECK_IT((rc) > 0 && (rc) <= (len), "snprintf() failed")
62 static char *get_iname(char *fname, const char *mtpt)
68 iname = malloc(INAME_LEN);
69 CHECK_IT(iname, "malloc() failed");
71 fd = open(fname, O_CREAT, 0644);
72 if (fd < 0 && errno != EISDIR) {
73 fprintf(stderr, "%s:%d: open(%s) failed: %s\n", __FILE__,
74 __LINE__, fname, strerror(errno));
81 rc = stat(fname, &buf);
83 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n", __FILE__,
84 __LINE__, fname, strerror(errno));
88 rc = snprintf(iname, INAME_LEN,
89 "%s/__iopen__/%lu", mtpt, (unsigned long)buf.st_ino);
90 CHECK_SNPRINTF(rc, INAME_LEN);
95 int main(int argc, char *argv[])
97 char *fname, *mtpt, *iname, *pname;
102 pname = strdup(argv[0]);
103 progname = basename(pname);
106 fprintf(stderr, usage_fmt, progname);
113 iname = get_iname(fname, mtpt);
114 printf("%s:started...\n", argv[0]);
115 for (i = 0; i < 10000; i++) {
116 rc = stat(fname, &buf);
118 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n",
119 __FILE__, __LINE__, fname, strerror(errno));
123 rc = stat(iname, &buf);
125 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n",
126 __FILE__, __LINE__, iname, strerror(errno));
130 printf("%s:finished...\n", argv[0]);