Whamcloud - gitweb
b=17661
[fs/lustre-release.git] / lustre / tests / cmknod.c
index 0efdc00..49e7ecc 100644 (file)
@@ -1,4 +1,43 @@
-/* Simple test to check that device nodes are correctly created and visible */
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/tests/cmknod.c
+ *
+ * Simple test to check that device nodes are correctly created and visible
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -17,12 +56,11 @@ void usage(char *prog)
        exit(1);
 }
 
-/* 
- * this stuff inlined here instead of using appropriate header 
- * to avoid linking to symbols which is not present in newer libc.
- * Currently this is the case, as UML image contains RedHat 9 and 
- * developers use something newer (Fedora, etc.) --umka
- */
+/* UMKA: This stuff inlined here instead of using appropriate header 
+   to avoid linking to symbols which is not present in newer libc.
+   
+   Currently this is the case, as UML image contains RedHat 9 and 
+   developers use something newer (Fedora, etc.). */
 inline unsigned int
 __gnu_dev_major (unsigned long long int __dev)
 {
@@ -51,35 +89,33 @@ int main( int argc, char **argv)
 {
        char *prog = argv[0];
        char *filename = argv[1];
-
-       struct stat st;
-       int rq_rdev;
        int rc;
+       struct stat st;
+       dev_t device = __makedev(TEST_MAJOR, TEST_MINOR);
 
        if (argc != 2) 
                usage(prog);
 
        unlink(filename);
        
-       /* first try block devices */
-       rq_rdev = __makedev(TEST_MAJOR, TEST_MINOR);
-       rc = mknod(filename, 0700 | S_IFBLK, rq_rdev);
-       if (rc < 0) {
+       /* First try block devices */
+       rc = mknod(filename, 0700 | S_IFBLK, device);
+       if ( rc < 0 ) {
                fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n",
                        prog, filename, errno, strerror(errno));
                return 2;
        }
 
        rc = stat(filename, &st);
-       if (rc < 0) {
+       if ( rc < 0 ) {
                fprintf(stderr, "%s: stat(%s) failed: rc %d: %s\n",
                        prog, filename, errno, strerror(errno));
                return 3;
        }
-
-       if (st.st_rdev != rq_rdev) {
+       
+       if ( st.st_rdev != device) {
                fprintf(stderr, "%s: created device other than requested: (%u,%u) instead of (%u,%u)\n", 
-                       prog, __major(st.st_rdev),__minor(st.st_rdev),__major(rq_rdev),__minor(rq_rdev));
+                       prog, __major(st.st_rdev),__minor(st.st_rdev),__major(device),__minor(device));
                return 4;
        }
        if (!S_ISBLK(st.st_mode)) {
@@ -95,7 +131,7 @@ int main( int argc, char **argv)
        }
 
        /* Second try char devices */
-       rc = mknod(filename, 0700 | S_IFCHR, rq_rdev);
+       rc = mknod(filename, 0700 | S_IFCHR, device);
        if ( rc < 0 ) {
                fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n",
                        prog, filename, errno, strerror(errno));
@@ -108,9 +144,9 @@ int main( int argc, char **argv)
                        prog, filename, errno, strerror(errno));
                return 8;
        }
-       if (st.st_rdev != rq_rdev) {
+       if ( st.st_rdev != device) {
                fprintf(stderr, "%s: created device other than requested: (%u,%u) instead of (%u,%u)\n", 
-                       prog, __major(st.st_rdev),__minor(st.st_rdev),__major(rq_rdev),__minor(rq_rdev));
+                       prog, __major(st.st_rdev),__minor(st.st_rdev),__major(device),__minor(device));
                return 9;
        }
        if (!S_ISCHR(st.st_mode)) {