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
22 static char message
[256]; /* keep it off the stack */
23 static DEFINE_SPINLOCK(xfs_err_lock
);
25 /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
26 #define XFS_MAX_ERR_LEVEL 7
27 #define XFS_ERR_MASK ((1 << 3) - 1)
28 static const char * const err_level
[XFS_MAX_ERR_LEVEL
+1] =
29 {KERN_EMERG
, KERN_ALERT
, KERN_CRIT
,
30 KERN_ERR
, KERN_WARNING
, KERN_NOTICE
,
31 KERN_INFO
, KERN_DEBUG
};
34 cmn_err(register int level
, char *fmt
, ...)
41 level
&= XFS_ERR_MASK
;
42 if (level
> XFS_MAX_ERR_LEVEL
)
43 level
= XFS_MAX_ERR_LEVEL
;
44 spin_lock_irqsave(&xfs_err_lock
,flags
);
46 if (*fmt
== '!') fp
++;
47 len
= vsprintf(message
, fp
, ap
);
48 if (level
!= CE_DEBUG
&& message
[len
-1] != '\n')
49 strcat(message
, "\n");
50 printk("%s%s", err_level
[level
], message
);
52 spin_unlock_irqrestore(&xfs_err_lock
,flags
);
54 BUG_ON(level
== CE_PANIC
);
58 icmn_err(register int level
, char *fmt
, va_list ap
)
63 level
&= XFS_ERR_MASK
;
64 if(level
> XFS_MAX_ERR_LEVEL
)
65 level
= XFS_MAX_ERR_LEVEL
;
66 spin_lock_irqsave(&xfs_err_lock
,flags
);
67 len
= vsprintf(message
, fmt
, ap
);
68 if (level
!= CE_DEBUG
&& message
[len
-1] != '\n')
69 strcat(message
, "\n");
70 spin_unlock_irqrestore(&xfs_err_lock
,flags
);
71 printk("%s%s", err_level
[level
], message
);
72 BUG_ON(level
== CE_PANIC
);
76 assfail(char *expr
, char *file
, int line
)
78 printk("Assertion failed: %s, file: %s, line: %d\n", expr
, file
, line
);
82 #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
83 unsigned long random(void)
85 static unsigned long RandomValue
= 1;
86 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
87 register long rv
= RandomValue
;
93 rv
= 16807 * lo
- 2836 * hi
;
94 if (rv
<= 0) rv
+= 2147483647;
95 return RandomValue
= rv
;
97 #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */