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/
32 #include <sys/types.h>
43 static int usage(char *prog)
45 fprintf(stderr, "usage: %s <basename>\n", prog);
49 int main(int argc, char *argv[])
58 for (i = 0; i <= S_IFMT; i += (1 << S_SHIFT)) {
63 snprintf(name, sizeof(name), "%s-mknod%07o", argv[1], mode);
64 rc = mknod(name, mode, 0x1234);
69 case S_IFCHR: case S_IFBLK:
70 if (rc < 0 && getuid() != 0)
72 case S_IFSOCK: case S_IFIFO:
74 fprintf(stderr, "%s: ERROR mknod %s: %s\n",
75 argv[0], name, strerror(errno));
80 fprintf(stderr, "%s: ERROR stat %s: %s",
81 argv[0], name, strerror(errno));
84 if (st.st_mode != mode) {
85 fprintf(stderr, "%s: ERROR mode %s: %o != %o",
86 argv[0], name, st.st_mode, mode);
89 if (i == S_IFCHR || i == S_IFBLK) {
90 if (st.st_rdev != 0x1234) {
91 fprintf(stderr, "%s: ERROR rdev %s: "
94 (unsigned long long)st.st_rdev);
100 fprintf(stderr, "%s: ERROR unlink %s: %s",
101 argv[0], name, strerror(errno));
107 fprintf(stderr, "%s: ERROR: %s created\n",
114 for (i = 0; i <= S_IFMT; i += (1 << S_SHIFT)) {
121 snprintf(name, sizeof(name), "%s-creat%07o", argv[1], mode);
122 fd = open(name, O_CREAT|O_RDONLY, mode);
124 fprintf(stderr, "%s: ERROR creat %s: %s\n",
125 argv[0], name, strerror(errno));
129 rc = stat(name, &st);
131 fprintf(stderr, "%s: ERROR stat %s: %s",
132 argv[0], name, strerror(errno));
135 if (!S_ISREG(st.st_mode & S_IFMT)) {
136 fprintf(stderr, "%s: ERROR mode %s: %o != %o",
137 argv[0], name, st.st_mode & S_IFMT, S_IFREG);
142 fprintf(stderr, "%s: ERROR unlink %s: %s\n",
143 argv[0], name, strerror(errno));
148 for (i = 0; i <= S_IFMT; i += (1 << S_SHIFT)) {
152 snprintf(name, sizeof(name), "%s-mkdir%06o", argv[1], i | 0644);
153 rc = mkdir(name, i | 0664);
155 fprintf(stderr, "%s: ERROR mkdir %s: %s\n",
156 argv[0], name, strerror(errno));
159 rc = stat(name, &st);
161 fprintf(stderr, "%s: ERROR stat %s: %s",
162 argv[0], name, strerror(errno));
165 if (!S_ISDIR(st.st_mode)) {
166 fprintf(stderr, "%s: ERROR mode %s: %o != %o",
167 argv[0], name, st.st_mode & S_IFMT, S_IFDIR);
172 fprintf(stderr, "%s: ERROR rmdir %s: %s\n",
173 argv[0], name, strerror(errno));
178 printf("%s: SUCCESS\n", argv[0]);