1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
17 const char usage_fmt[] = "Usage: %s <file> <mountpoint>\n";
18 #define INAME_LEN (PATH_MAX + 1)
20 #define CHECK_IT(exp, pstr) \
22 fprintf(stderr, "%s: at %s:%d: ", progname, __FILE__, __LINE__); \
27 #define CHECK_SNPRINTF(rc, len) \
28 CHECK_IT((rc) > 0 && (rc) <= (len), "snprintf() failed")
30 static char *get_iname(char *fname, const char *mtpt)
36 iname = malloc(INAME_LEN);
37 CHECK_IT(iname, "malloc() failed");
39 fd = open(fname, O_CREAT, 0644);
40 if (fd < 0 && errno != EISDIR) {
41 fprintf(stderr, "%s:%d: open(%s) failed: %s\n", __FILE__,
42 __LINE__, fname, strerror(errno));
49 rc = stat(fname, &buf);
51 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n", __FILE__,
52 __LINE__, fname, strerror(errno));
56 rc = snprintf(iname, INAME_LEN,
57 "%s/__iopen__/%lu", mtpt, (unsigned long)buf.st_ino);
58 CHECK_SNPRINTF(rc, INAME_LEN);
63 int main(int argc, char *argv[])
65 char *fname, *mtpt, *iname, *pname;
70 pname = strdup(argv[0]);
71 progname = basename(pname);
74 fprintf(stderr, usage_fmt, progname);
81 iname = get_iname(fname, mtpt);
82 printf("%s:started...\n", argv[0]);
83 for (i = 0; i < 10000; i++) {
84 rc = stat(fname, &buf);
86 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n",
87 __FILE__, __LINE__, fname, strerror(errno));
91 rc = stat(iname, &buf);
93 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n",
94 __FILE__, __LINE__, iname, strerror(errno));
98 printf("%s:finished...\n", argv[0]);