2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
24 static char message[256]; /* keep it off the stack */
25 static DEFINE_SPINLOCK(xfs_err_lock);
27 /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
28 #define XFS_MAX_ERR_LEVEL 7
29 #define XFS_ERR_MASK ((1 << 3) - 1)
30 static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
31 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
32 KERN_ERR, KERN_WARNING, KERN_NOTICE,
33 KERN_INFO, KERN_DEBUG};
36 cmn_err(register int level, char *fmt, ...)
43 level &= XFS_ERR_MASK;
44 if (level > XFS_MAX_ERR_LEVEL)
45 level = XFS_MAX_ERR_LEVEL;
46 spin_lock_irqsave(&xfs_err_lock,flags);
48 if (*fmt == '!') fp++;
49 len = vsprintf(message, fp, ap);
50 if (message[len-1] != '\n')
51 strcat(message, "\n");
52 printk("%s%s", err_level[level], message);
54 spin_unlock_irqrestore(&xfs_err_lock,flags);
56 if (level == CE_PANIC)
61 icmn_err(register int level, char *fmt, va_list ap)
66 level &= XFS_ERR_MASK;
67 if(level > XFS_MAX_ERR_LEVEL)
68 level = XFS_MAX_ERR_LEVEL;
69 spin_lock_irqsave(&xfs_err_lock,flags);
70 len = vsprintf(message, fmt, ap);
71 if (message[len-1] != '\n')
72 strcat(message, "\n");
73 spin_unlock_irqrestore(&xfs_err_lock,flags);
74 printk("%s%s", err_level[level], message);
75 if (level == CE_PANIC)
80 assfail(char *expr, char *file, int line)
82 printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
86 #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
87 unsigned long random(void)
89 static unsigned long RandomValue = 1;
90 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
91 register long rv = RandomValue;
97 rv = 16807 * lo - 2836 * hi;
98 if (rv <= 0) rv += 2147483647;
99 return RandomValue = rv;
101 #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */