1 /* Simple test to check that device nodes are correctly created and visible */
10 #define TEST_MINOR 120
13 void usage(char *prog)
15 fprintf(stderr, "usage: %s <filename>\n", prog);
19 int main( int argc, char **argv)
22 char *filename = argv[1];
25 dev_t device = makedev(TEST_MAJOR, TEST_MINOR);
31 /* First try block devices */
32 rc = mknod(filename, 0700 | S_IFBLK, device);
34 fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n",
35 prog, filename, errno, strerror(errno));
39 rc = stat(filename, &st);
41 fprintf(stderr, "%s: stat(%s) failed: rc %d: %s\n",
42 prog, filename, errno, strerror(errno));
45 if ( st.st_rdev != device) {
46 fprintf(stderr, "%s: created device other than requested: (%d,%d) instead of (%d,%d)\n", prog, major(st.st_rdev),minor(st.st_rdev),major(device),minor(device));
49 if (!S_ISBLK(st.st_mode)) {
50 fprintf(stderr, "%s: created device of different type. Requested block device, got mode %o\n", prog, st.st_mode);
54 rc = unlink(filename);
56 fprintf(stderr, "%s: Cannot unlink created device %s, rc %d: %s\n",
57 prog, filename, errno, strerror(errno));
61 /* Second try char devices */
62 rc = mknod(filename, 0700 | S_IFCHR, device);
64 fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n",
65 prog, filename, errno, strerror(errno));
69 rc = stat(filename, &st);
71 fprintf(stderr, "%s: stat(%s) failed: rc %d: %s\n",
72 prog, filename, errno, strerror(errno));
75 if ( st.st_rdev != device) {
76 fprintf(stderr, "%s: created device other than requested: (%d,%d) instead of (%d,%d)\n", prog, major(st.st_rdev),minor(st.st_rdev),major(device),minor(device));
79 if (!S_ISCHR(st.st_mode)) {
80 fprintf(stderr, "%s: created device of different type. Requested char device, got mode %o\n", prog, st.st_mode);
84 rc = unlink(filename);
86 fprintf(stderr, "%s: Cannot unlink created device %s, rc %d: %s\n",
87 prog, filename, errno, strerror(errno));
91 printf("%s: device nodes created correctly\n", prog);