You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
#
|
||||
# Library configuration
|
||||
#
|
||||
|
||||
menu "Library routines"
|
||||
|
||||
config CRC_CCITT
|
||||
tristate "CRC-CCITT functions"
|
||||
help
|
||||
This option is provided for the case where no in-kernel-tree
|
||||
modules require CRC-CCITT functions, but a module built outside
|
||||
the kernel tree does. Such modules that use library CRC-CCITT
|
||||
functions require M here.
|
||||
|
||||
config CRC32
|
||||
tristate "CRC32 functions"
|
||||
default y
|
||||
help
|
||||
This option is provided for the case where no in-kernel-tree
|
||||
modules require CRC32 functions, but a module built outside the
|
||||
kernel tree does. Such modules that use library CRC32 functions
|
||||
require M here.
|
||||
|
||||
config LIBCRC32C
|
||||
tristate "CRC32c (Castagnoli, et al) Cyclic Redundancy-Check"
|
||||
help
|
||||
This option is provided for the case where no in-kernel-tree
|
||||
modules require CRC32c functions, but a module built outside the
|
||||
kernel tree does. Such modules that use library CRC32c functions
|
||||
require M here. See Castagnoli93.
|
||||
Module will be libcrc32c.
|
||||
|
||||
#
|
||||
# compression support is select'ed if needed
|
||||
#
|
||||
config ZLIB_INFLATE
|
||||
tristate
|
||||
|
||||
config ZLIB_DEFLATE
|
||||
tristate
|
||||
|
||||
#
|
||||
# reed solomon support is select'ed if needed
|
||||
#
|
||||
config REED_SOLOMON
|
||||
tristate
|
||||
|
||||
config REED_SOLOMON_ENC8
|
||||
boolean
|
||||
|
||||
config REED_SOLOMON_DEC8
|
||||
boolean
|
||||
|
||||
config REED_SOLOMON_ENC16
|
||||
boolean
|
||||
|
||||
config REED_SOLOMON_DEC16
|
||||
boolean
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
|
||||
config PRINTK_TIME
|
||||
bool "Show timing information on printks"
|
||||
help
|
||||
Selecting this option causes timing information to be
|
||||
included in printk output. This allows you to measure
|
||||
the interval between kernel operations, including bootup
|
||||
operations. This is useful for identifying long delays
|
||||
in kernel startup.
|
||||
|
||||
|
||||
config DEBUG_KERNEL
|
||||
bool "Kernel debugging"
|
||||
help
|
||||
Say Y here if you are developing drivers or trying to debug and
|
||||
identify kernel problems.
|
||||
|
||||
config MAGIC_SYSRQ
|
||||
bool "Magic SysRq key"
|
||||
depends on DEBUG_KERNEL && !UML
|
||||
help
|
||||
If you say Y here, you will have some control over the system even
|
||||
if the system crashes for example during kernel debugging (e.g., you
|
||||
will be able to flush the buffer cache to disk, reboot the system
|
||||
immediately or dump some status information). This is accomplished
|
||||
by pressing various keys while holding SysRq (Alt+PrintScreen). It
|
||||
also works on a serial console (on PC hardware at least), if you
|
||||
send a BREAK and then within 5 seconds a command keypress. The
|
||||
keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
|
||||
unless you really know what this hack does.
|
||||
|
||||
config LOG_BUF_SHIFT
|
||||
int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" if DEBUG_KERNEL
|
||||
range 12 21
|
||||
default 17 if ARCH_S390
|
||||
default 16 if X86_NUMAQ || IA64
|
||||
default 15 if SMP
|
||||
default 14
|
||||
help
|
||||
Select kernel log buffer size as a power of 2.
|
||||
Defaults and Examples:
|
||||
17 => 128 KB for S/390
|
||||
16 => 64 KB for x86 NUMAQ or IA-64
|
||||
15 => 32 KB for SMP
|
||||
14 => 16 KB for uniprocessor
|
||||
13 => 8 KB
|
||||
12 => 4 KB
|
||||
|
||||
config SCHEDSTATS
|
||||
bool "Collect scheduler statistics"
|
||||
depends on DEBUG_KERNEL && PROC_FS
|
||||
help
|
||||
If you say Y here, additional code will be inserted into the
|
||||
scheduler and related routines to collect statistics about
|
||||
scheduler behavior and provide them in /proc/schedstat. These
|
||||
stats may be useful for both tuning and debugging the scheduler
|
||||
If you aren't debugging the scheduler or trying to tune a specific
|
||||
application, you can say N to avoid the very slight overhead
|
||||
this adds.
|
||||
|
||||
config DEBUG_SLAB
|
||||
bool "Debug memory allocations"
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
Say Y here to have the kernel do limited verification on memory
|
||||
allocation as well as poisoning memory on free to catch use of freed
|
||||
memory. This can make kmalloc/kfree-intensive workloads much slower.
|
||||
|
||||
config DEBUG_PREEMPT
|
||||
bool "Debug preemptible kernel"
|
||||
depends on DEBUG_KERNEL && PREEMPT
|
||||
default y
|
||||
help
|
||||
If you say Y here then the kernel will use a debug variant of the
|
||||
commonly used smp_processor_id() function and will print warnings
|
||||
if kernel code uses it in a preemption-unsafe way. Also, the kernel
|
||||
will detect preemption count underflows.
|
||||
|
||||
config DEBUG_SPINLOCK
|
||||
bool "Spinlock debugging"
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
Say Y here and build SMP to catch missing spinlock initialization
|
||||
and certain other kinds of spinlock errors commonly made. This is
|
||||
best used in conjunction with the NMI watchdog so that spinlock
|
||||
deadlocks are also debuggable.
|
||||
|
||||
config DEBUG_SPINLOCK_SLEEP
|
||||
bool "Sleep-inside-spinlock checking"
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
If you say Y here, various routines which may sleep will become very
|
||||
noisy if they are called with a spinlock held.
|
||||
|
||||
config DEBUG_KOBJECT
|
||||
bool "kobject debugging"
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
If you say Y here, some extra kobject debugging messages will be sent
|
||||
to the syslog.
|
||||
|
||||
config DEBUG_HIGHMEM
|
||||
bool "Highmem debugging"
|
||||
depends on DEBUG_KERNEL && HIGHMEM
|
||||
help
|
||||
This options enables addition error checking for high memory systems.
|
||||
Disable for production systems.
|
||||
|
||||
config DEBUG_BUGVERBOSE
|
||||
bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EMBEDDED
|
||||
depends on ARM || ARM26 || M32R || M68K || SPARC32 || SPARC64 || (X86 && !X86_64) || FRV
|
||||
default !EMBEDDED
|
||||
help
|
||||
Say Y here to make BUG() panics output the file name and line number
|
||||
of the BUG call as well as the EIP and oops trace. This aids
|
||||
debugging but costs about 70-100K of memory.
|
||||
|
||||
config DEBUG_INFO
|
||||
bool "Compile the kernel with debug info"
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
If you say Y here the resulting kernel image will include
|
||||
debugging info resulting in a larger kernel image.
|
||||
Say Y here only if you plan to debug the kernel.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config DEBUG_IOREMAP
|
||||
bool "Enable ioremap() debugging"
|
||||
depends on DEBUG_KERNEL && PARISC
|
||||
help
|
||||
Enabling this option will cause the kernel to distinguish between
|
||||
ioremapped and physical addresses. It will print a backtrace (at
|
||||
most one every 10 seconds), hopefully allowing you to see which
|
||||
drivers need work. Fixing all these problems is a prerequisite
|
||||
for turning on USE_HPPA_IOREMAP. The warnings are harmless;
|
||||
the kernel has enough information to fix the broken drivers
|
||||
automatically, but we'd like to make it more efficient by not
|
||||
having to do that.
|
||||
|
||||
config DEBUG_FS
|
||||
bool "Debug Filesystem"
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
debugfs is a virtual file system that kernel developers use to put
|
||||
debugging files into. Enable this option to be able to read and
|
||||
write to these files.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config FRAME_POINTER
|
||||
bool "Compile the kernel with frame pointers"
|
||||
depends on DEBUG_KERNEL && ((X86 && !X86_64) || CRIS || M68K || M68KNOMMU || FRV)
|
||||
help
|
||||
If you say Y here the resulting kernel image will be slightly larger
|
||||
and slower, but it will give very useful debugging information.
|
||||
If you don't debug the kernel, you can say N, but we may not be able
|
||||
to solve problems without frame pointers.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# Makefile for some libs needed in the kernel.
|
||||
#
|
||||
|
||||
lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
|
||||
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
|
||||
kobject.o kref.o idr.o div64.o int_sqrt.o \
|
||||
bitmap.o extable.o kobject_uevent.o prio_tree.o sha1.o \
|
||||
halfmd4.o
|
||||
|
||||
obj-y += sort.o parser.o
|
||||
|
||||
ifeq ($(CONFIG_DEBUG_KOBJECT),y)
|
||||
CFLAGS_kobject.o += -DDEBUG
|
||||
CFLAGS_kobject_uevent.o += -DDEBUG
|
||||
endif
|
||||
|
||||
lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
|
||||
lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
|
||||
lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
|
||||
obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
|
||||
|
||||
ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
|
||||
lib-y += dec_and_lock.o
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
|
||||
obj-$(CONFIG_CRC32) += crc32.o
|
||||
obj-$(CONFIG_LIBCRC32C) += libcrc32c.o
|
||||
obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
|
||||
|
||||
obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/
|
||||
obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/
|
||||
obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
|
||||
|
||||
hostprogs-y := gen_crc32table
|
||||
clean-files := crc32table.h
|
||||
|
||||
$(obj)/crc32.o: $(obj)/crc32table.h
|
||||
|
||||
quiet_cmd_crc32 = GEN $@
|
||||
cmd_crc32 = $< > $@
|
||||
|
||||
$(obj)/crc32table.h: $(obj)/gen_crc32table
|
||||
$(call cmd,crc32)
|
||||
+595
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* lib/bust_spinlocks.c
|
||||
*
|
||||
* Provides a minimal bust_spinlocks for architectures which don't have one of their own.
|
||||
*
|
||||
* bust_spinlocks() clears any spinlocks which would prevent oops, die(), BUG()
|
||||
* and panic() information from reaching the user.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/tty.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/vt_kern.h>
|
||||
|
||||
|
||||
void bust_spinlocks(int yes)
|
||||
{
|
||||
if (yes) {
|
||||
oops_in_progress = 1;
|
||||
} else {
|
||||
int loglevel_save = console_loglevel;
|
||||
#ifdef CONFIG_VT
|
||||
unblank_screen();
|
||||
#endif
|
||||
oops_in_progress = 0;
|
||||
/*
|
||||
* OK, the message is on the console. Now we call printk()
|
||||
* without oops_in_progress set so that printk() will give klogd
|
||||
* and the blanked console a poke. Hold onto your hats...
|
||||
*/
|
||||
console_loglevel = 15; /* NMI oopser may have shut the console up */
|
||||
printk(" ");
|
||||
console_loglevel = loglevel_save;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* linux/lib/cmdline.c
|
||||
* Helper functions generally used for parsing kernel command line
|
||||
* and module options.
|
||||
*
|
||||
* Code and copyrights come from init/main.c and arch/i386/kernel/setup.c.
|
||||
*
|
||||
* This source code is licensed under the GNU General Public License,
|
||||
* Version 2. See the file COPYING for more details.
|
||||
*
|
||||
* GNU Indent formatting options for this file: -kr -i8 -npsl -pcs
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
|
||||
/**
|
||||
* get_option - Parse integer from an option string
|
||||
* @str: option string
|
||||
* @pint: (output) integer value parsed from @str
|
||||
*
|
||||
* Read an int from an option string; if available accept a subsequent
|
||||
* comma as well.
|
||||
*
|
||||
* Return values:
|
||||
* 0 : no int in string
|
||||
* 1 : int found, no subsequent comma
|
||||
* 2 : int found including a subsequent comma
|
||||
*/
|
||||
|
||||
int get_option (char **str, int *pint)
|
||||
{
|
||||
char *cur = *str;
|
||||
|
||||
if (!cur || !(*cur))
|
||||
return 0;
|
||||
*pint = simple_strtol (cur, str, 0);
|
||||
if (cur == *str)
|
||||
return 0;
|
||||
if (**str == ',') {
|
||||
(*str)++;
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_options - Parse a string into a list of integers
|
||||
* @str: String to be parsed
|
||||
* @nints: size of integer array
|
||||
* @ints: integer array
|
||||
*
|
||||
* This function parses a string containing a comma-separated
|
||||
* list of integers. The parse halts when the array is
|
||||
* full, or when no more numbers can be retrieved from the
|
||||
* string.
|
||||
*
|
||||
* Return value is the character in the string which caused
|
||||
* the parse to end (typically a null terminator, if @str is
|
||||
* completely parseable).
|
||||
*/
|
||||
|
||||
char *get_options(const char *str, int nints, int *ints)
|
||||
{
|
||||
int res, i = 1;
|
||||
|
||||
while (i < nints) {
|
||||
res = get_option ((char **)&str, ints + i);
|
||||
if (res == 0)
|
||||
break;
|
||||
i++;
|
||||
if (res == 1)
|
||||
break;
|
||||
}
|
||||
ints[0] = i - 1;
|
||||
return (char *)str;
|
||||
}
|
||||
|
||||
/**
|
||||
* memparse - parse a string with mem suffixes into a number
|
||||
* @ptr: Where parse begins
|
||||
* @retptr: (output) Pointer to next char after parse completes
|
||||
*
|
||||
* Parses a string into a number. The number stored at @ptr is
|
||||
* potentially suffixed with %K (for kilobytes, or 1024 bytes),
|
||||
* %M (for megabytes, or 1048576 bytes), or %G (for gigabytes, or
|
||||
* 1073741824). If the number is suffixed with K, M, or G, then
|
||||
* the return value is the number multiplied by one kilobyte, one
|
||||
* megabyte, or one gigabyte, respectively.
|
||||
*/
|
||||
|
||||
unsigned long long memparse (char *ptr, char **retptr)
|
||||
{
|
||||
unsigned long long ret = simple_strtoull (ptr, retptr, 0);
|
||||
|
||||
switch (**retptr) {
|
||||
case 'G':
|
||||
case 'g':
|
||||
ret <<= 10;
|
||||
case 'M':
|
||||
case 'm':
|
||||
ret <<= 10;
|
||||
case 'K':
|
||||
case 'k':
|
||||
ret <<= 10;
|
||||
(*retptr)++;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
EXPORT_SYMBOL(memparse);
|
||||
EXPORT_SYMBOL(get_option);
|
||||
EXPORT_SYMBOL(get_options);
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* linux/lib/crc-ccitt.c
|
||||
*
|
||||
* This source code is licensed under the GNU General Public License,
|
||||
* Version 2. See the file COPYING for more details.
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/crc-ccitt.h>
|
||||
|
||||
/*
|
||||
* This mysterious table is just the CRC of each possible byte. It can be
|
||||
* computed using the standard bit-at-a-time methods. The polynomial can
|
||||
* be seen in entry 128, 0x8408. This corresponds to x^0 + x^5 + x^12.
|
||||
* Add the implicit x^16, and you have the standard CRC-CCITT.
|
||||
*/
|
||||
u16 const crc_ccitt_table[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
EXPORT_SYMBOL(crc_ccitt_table);
|
||||
|
||||
/**
|
||||
* crc_ccitt - recompute the CRC for the data buffer
|
||||
* @crc - previous CRC value
|
||||
* @buffer - data pointer
|
||||
* @len - number of bytes in the buffer
|
||||
*/
|
||||
u16 crc_ccitt(u16 crc, u8 const *buffer, size_t len)
|
||||
{
|
||||
while (len--)
|
||||
crc = crc_ccitt_byte(crc, *buffer++);
|
||||
return crc;
|
||||
}
|
||||
EXPORT_SYMBOL(crc_ccitt);
|
||||
|
||||
MODULE_DESCRIPTION("CRC-CCITT calculations");
|
||||
MODULE_LICENSE("GPL");
|
||||
+529
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* There are multiple 16-bit CRC polynomials in common use, but this is
|
||||
* *the* standard CRC-32 polynomial, first popularized by Ethernet.
|
||||
* x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
|
||||
*/
|
||||
#define CRCPOLY_LE 0xedb88320
|
||||
#define CRCPOLY_BE 0x04c11db7
|
||||
|
||||
/* How many bits at a time to use. Requires a table of 4<<CRC_xx_BITS bytes. */
|
||||
/* For less performance-sensitive, use 4 */
|
||||
#ifndef CRC_LE_BITS
|
||||
# define CRC_LE_BITS 8
|
||||
#endif
|
||||
#ifndef CRC_BE_BITS
|
||||
# define CRC_BE_BITS 8
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Little-endian CRC computation. Used with serial bit streams sent
|
||||
* lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC.
|
||||
*/
|
||||
#if CRC_LE_BITS > 8 || CRC_LE_BITS < 1 || CRC_LE_BITS & CRC_LE_BITS-1
|
||||
# error CRC_LE_BITS must be a power of 2 between 1 and 8
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Big-endian CRC computation. Used with serial bit streams sent
|
||||
* msbit-first. Be sure to use cpu_to_be32() to append the computed CRC.
|
||||
*/
|
||||
#if CRC_BE_BITS > 8 || CRC_BE_BITS < 1 || CRC_BE_BITS & CRC_BE_BITS-1
|
||||
# error CRC_BE_BITS must be a power of 2 between 1 and 8
|
||||
#endif
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* linux/lib/ctype.c
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
unsigned char _ctype[] = {
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
|
||||
_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
|
||||
_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
|
||||
_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
|
||||
_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
|
||||
_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
|
||||
_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
|
||||
_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
|
||||
_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
|
||||
_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
|
||||
_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */
|
||||
_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */
|
||||
|
||||
EXPORT_SYMBOL(_ctype);
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <asm/atomic.h>
|
||||
|
||||
/*
|
||||
* This is an architecture-neutral, but slow,
|
||||
* implementation of the notion of "decrement
|
||||
* a reference count, and return locked if it
|
||||
* decremented to zero".
|
||||
*
|
||||
* NOTE NOTE NOTE! This is _not_ equivalent to
|
||||
*
|
||||
* if (atomic_dec_and_test(&atomic)) {
|
||||
* spin_lock(&lock);
|
||||
* return 1;
|
||||
* }
|
||||
* return 0;
|
||||
*
|
||||
* because the spin-lock and the decrement must be
|
||||
* "atomic".
|
||||
*
|
||||
* This slow version gets the spinlock unconditionally,
|
||||
* and releases it if it isn't needed. Architectures
|
||||
* are encouraged to come up with better approaches,
|
||||
* this is trivially done efficiently using a load-locked
|
||||
* store-conditional approach, for example.
|
||||
*/
|
||||
|
||||
#ifndef ATOMIC_DEC_AND_LOCK
|
||||
int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
|
||||
{
|
||||
spin_lock(lock);
|
||||
if (atomic_dec_and_test(atomic))
|
||||
return 1;
|
||||
spin_unlock(lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(_atomic_dec_and_lock);
|
||||
#endif
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
|
||||
*
|
||||
* Based on former do_div() implementation from asm-parisc/div64.h:
|
||||
* Copyright (C) 1999 Hewlett-Packard Co
|
||||
* Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
*
|
||||
*
|
||||
* Generic C version of 64bit/32bit division and modulo, with
|
||||
* 64bit result and 32bit remainder.
|
||||
*
|
||||
* The fast case for (n>>32 == 0) is handled inline by do_div().
|
||||
*
|
||||
* Code generated for this function might be very inefficient
|
||||
* for some CPUs. __div64_32() can be overridden by linking arch-specific
|
||||
* assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S.
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/module.h>
|
||||
#include <asm/div64.h>
|
||||
|
||||
/* Not needed on 64bit architectures */
|
||||
#if BITS_PER_LONG == 32
|
||||
|
||||
uint32_t __div64_32(uint64_t *n, uint32_t base)
|
||||
{
|
||||
uint64_t rem = *n;
|
||||
uint64_t b = base;
|
||||
uint64_t res, d = 1;
|
||||
uint32_t high = rem >> 32;
|
||||
|
||||
/* Reduce the thing a bit first */
|
||||
res = 0;
|
||||
if (high >= base) {
|
||||
high /= base;
|
||||
res = (uint64_t) high << 32;
|
||||
rem -= (uint64_t) (high*base) << 32;
|
||||
}
|
||||
|
||||
while ((int64_t)b > 0 && b < rem) {
|
||||
b = b+b;
|
||||
d = d+d;
|
||||
}
|
||||
|
||||
do {
|
||||
if (rem >= b) {
|
||||
rem -= b;
|
||||
res += d;
|
||||
}
|
||||
b >>= 1;
|
||||
d >>= 1;
|
||||
} while (d);
|
||||
|
||||
*n = res;
|
||||
return rem;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(__div64_32);
|
||||
|
||||
#endif /* BITS_PER_LONG == 32 */
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Provide a default dump_stack() function for architectures
|
||||
* which don't implement their own.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
void dump_stack(void)
|
||||
{
|
||||
printk(KERN_NOTICE
|
||||
"This architecture does not implement dump_stack()\n");
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(dump_stack);
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
* linux/lib/errno.c
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
int errno;
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* lib/extable.c
|
||||
* Derived from arch/ppc/mm/extable.c and arch/i386/mm/extable.c.
|
||||
*
|
||||
* Copyright (C) 2004 Paul Mackerras, IBM Corp.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version
|
||||
* 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/sort.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
extern struct exception_table_entry __start___ex_table[];
|
||||
extern struct exception_table_entry __stop___ex_table[];
|
||||
|
||||
#ifndef ARCH_HAS_SORT_EXTABLE
|
||||
/*
|
||||
* The exception table needs to be sorted so that the binary
|
||||
* search that we use to find entries in it works properly.
|
||||
* This is used both for the kernel exception table and for
|
||||
* the exception tables of modules that get loaded.
|
||||
*/
|
||||
static int cmp_ex(const void *a, const void *b)
|
||||
{
|
||||
const struct exception_table_entry *x = a, *y = b;
|
||||
|
||||
/* avoid overflow */
|
||||
if (x->insn > y->insn)
|
||||
return 1;
|
||||
if (x->insn < y->insn)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sort_extable(struct exception_table_entry *start,
|
||||
struct exception_table_entry *finish)
|
||||
{
|
||||
sort(start, finish - start, sizeof(struct exception_table_entry),
|
||||
cmp_ex, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ARCH_HAS_SEARCH_EXTABLE
|
||||
/*
|
||||
* Search one exception table for an entry corresponding to the
|
||||
* given instruction address, and return the address of the entry,
|
||||
* or NULL if none is found.
|
||||
* We use a binary search, and thus we assume that the table is
|
||||
* already sorted.
|
||||
*/
|
||||
const struct exception_table_entry *
|
||||
search_extable(const struct exception_table_entry *first,
|
||||
const struct exception_table_entry *last,
|
||||
unsigned long value)
|
||||
{
|
||||
while (first <= last) {
|
||||
const struct exception_table_entry *mid;
|
||||
|
||||
mid = (last - first) / 2 + first;
|
||||
/*
|
||||
* careful, the distance between entries can be
|
||||
* larger than 2GB:
|
||||
*/
|
||||
if (mid->insn < value)
|
||||
first = mid + 1;
|
||||
else if (mid->insn > value)
|
||||
last = mid - 1;
|
||||
else
|
||||
return mid;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/* find_next_bit.c: fallback find next bit implementation
|
||||
*
|
||||
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
|
||||
* Written by David Howells (dhowells@redhat.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version
|
||||
* 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/bitops.h>
|
||||
|
||||
int find_next_bit(const unsigned long *addr, int size, int offset)
|
||||
{
|
||||
const unsigned long *base;
|
||||
const int NBITS = sizeof(*addr) * 8;
|
||||
unsigned long tmp;
|
||||
|
||||
base = addr;
|
||||
if (offset) {
|
||||
int suboffset;
|
||||
|
||||
addr += offset / NBITS;
|
||||
|
||||
suboffset = offset % NBITS;
|
||||
if (suboffset) {
|
||||
tmp = *addr;
|
||||
tmp >>= suboffset;
|
||||
if (tmp)
|
||||
goto finish;
|
||||
}
|
||||
|
||||
addr++;
|
||||
}
|
||||
|
||||
while ((tmp = *addr) == 0)
|
||||
addr++;
|
||||
|
||||
offset = (addr - base) * NBITS;
|
||||
|
||||
finish:
|
||||
/* count the remaining bits without using __ffs() since that takes a 32-bit arg */
|
||||
while (!(tmp & 0xff)) {
|
||||
offset += 8;
|
||||
tmp >>= 8;
|
||||
}
|
||||
|
||||
while (!(tmp & 1)) {
|
||||
offset++;
|
||||
tmp >>= 1;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include "crc32defs.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#define ENTRIES_PER_LINE 4
|
||||
|
||||
#define LE_TABLE_SIZE (1 << CRC_LE_BITS)
|
||||
#define BE_TABLE_SIZE (1 << CRC_BE_BITS)
|
||||
|
||||
static uint32_t crc32table_le[LE_TABLE_SIZE];
|
||||
static uint32_t crc32table_be[BE_TABLE_SIZE];
|
||||
|
||||
/**
|
||||
* crc32init_le() - allocate and initialize LE table data
|
||||
*
|
||||
* crc is the crc of the byte i; other entries are filled in based on the
|
||||
* fact that crctable[i^j] = crctable[i] ^ crctable[j].
|
||||
*
|
||||
*/
|
||||
static void crc32init_le(void)
|
||||
{
|
||||
unsigned i, j;
|
||||
uint32_t crc = 1;
|
||||
|
||||
crc32table_le[0] = 0;
|
||||
|
||||
for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) {
|
||||
crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
|
||||
for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
|
||||
crc32table_le[i + j] = crc ^ crc32table_le[j];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* crc32init_be() - allocate and initialize BE table data
|
||||
*/
|
||||
static void crc32init_be(void)
|
||||
{
|
||||
unsigned i, j;
|
||||
uint32_t crc = 0x80000000;
|
||||
|
||||
crc32table_be[0] = 0;
|
||||
|
||||
for (i = 1; i < BE_TABLE_SIZE; i <<= 1) {
|
||||
crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
|
||||
for (j = 0; j < i; j++)
|
||||
crc32table_be[i + j] = crc ^ crc32table_be[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void output_table(uint32_t table[], int len, char *trans)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len - 1; i++) {
|
||||
if (i % ENTRIES_PER_LINE == 0)
|
||||
printf("\n");
|
||||
printf("%s(0x%8.8xL), ", trans, table[i]);
|
||||
}
|
||||
printf("%s(0x%8.8xL)\n", trans, table[len - 1]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("/* this file is generated - do not edit */\n\n");
|
||||
|
||||
if (CRC_LE_BITS > 1) {
|
||||
crc32init_le();
|
||||
printf("static const u32 crc32table_le[] = {");
|
||||
output_table(crc32table_le, LE_TABLE_SIZE, "tole");
|
||||
printf("};\n");
|
||||
}
|
||||
|
||||
if (CRC_BE_BITS > 1) {
|
||||
crc32init_be();
|
||||
printf("static const u32 crc32table_be[] = {");
|
||||
output_table(crc32table_be, BE_TABLE_SIZE, "tobe");
|
||||
printf("};\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/cryptohash.h>
|
||||
|
||||
/* F, G and H are basic MD4 functions: selection, majority, parity */
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/*
|
||||
* The generic round function. The application is so specific that
|
||||
* we don't bother protecting all the arguments with parens, as is generally
|
||||
* good macro practice, in favor of extra legibility.
|
||||
* Rotation is separate from addition to prevent recomputation
|
||||
*/
|
||||
#define ROUND(f, a, b, c, d, x, s) \
|
||||
(a += f(b, c, d) + x, a = (a << s) | (a >> (32 - s)))
|
||||
#define K1 0
|
||||
#define K2 013240474631UL
|
||||
#define K3 015666365641UL
|
||||
|
||||
/*
|
||||
* Basic cut-down MD4 transform. Returns only 32 bits of result.
|
||||
*/
|
||||
__u32 half_md4_transform(__u32 buf[4], __u32 const in[8])
|
||||
{
|
||||
__u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
/* Round 1 */
|
||||
ROUND(F, a, b, c, d, in[0] + K1, 3);
|
||||
ROUND(F, d, a, b, c, in[1] + K1, 7);
|
||||
ROUND(F, c, d, a, b, in[2] + K1, 11);
|
||||
ROUND(F, b, c, d, a, in[3] + K1, 19);
|
||||
ROUND(F, a, b, c, d, in[4] + K1, 3);
|
||||
ROUND(F, d, a, b, c, in[5] + K1, 7);
|
||||
ROUND(F, c, d, a, b, in[6] + K1, 11);
|
||||
ROUND(F, b, c, d, a, in[7] + K1, 19);
|
||||
|
||||
/* Round 2 */
|
||||
ROUND(G, a, b, c, d, in[1] + K2, 3);
|
||||
ROUND(G, d, a, b, c, in[3] + K2, 5);
|
||||
ROUND(G, c, d, a, b, in[5] + K2, 9);
|
||||
ROUND(G, b, c, d, a, in[7] + K2, 13);
|
||||
ROUND(G, a, b, c, d, in[0] + K2, 3);
|
||||
ROUND(G, d, a, b, c, in[2] + K2, 5);
|
||||
ROUND(G, c, d, a, b, in[4] + K2, 9);
|
||||
ROUND(G, b, c, d, a, in[6] + K2, 13);
|
||||
|
||||
/* Round 3 */
|
||||
ROUND(H, a, b, c, d, in[3] + K3, 3);
|
||||
ROUND(H, d, a, b, c, in[7] + K3, 9);
|
||||
ROUND(H, c, d, a, b, in[2] + K3, 11);
|
||||
ROUND(H, b, c, d, a, in[6] + K3, 15);
|
||||
ROUND(H, a, b, c, d, in[1] + K3, 3);
|
||||
ROUND(H, d, a, b, c, in[5] + K3, 9);
|
||||
ROUND(H, c, d, a, b, in[0] + K3, 11);
|
||||
ROUND(H, b, c, d, a, in[4] + K3, 15);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
|
||||
return buf[1]; /* "most hashed" word */
|
||||
}
|
||||
EXPORT_SYMBOL(half_md4_transform);
|
||||
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
* 2002-10-18 written by Jim Houston jim.houston@ccur.com
|
||||
* Copyright (C) 2002 by Concurrent Computer Corporation
|
||||
* Distributed under the GNU GPL license version 2.
|
||||
*
|
||||
* Modified by George Anzinger to reuse immediately and to use
|
||||
* find bit instructions. Also removed _irq on spinlocks.
|
||||
*
|
||||
* Small id to pointer translation service.
|
||||
*
|
||||
* It uses a radix tree like structure as a sparse array indexed
|
||||
* by the id to obtain the pointer. The bitmap makes allocating
|
||||
* a new id quick.
|
||||
*
|
||||
* You call it to allocate an id (an int) an associate with that id a
|
||||
* pointer or what ever, we treat it as a (void *). You can pass this
|
||||
* id to a user for him to pass back at a later time. You then pass
|
||||
* that id to this code and it returns your pointer.
|
||||
|
||||
* You can release ids at any time. When all ids are released, most of
|
||||
* the memory is returned (we keep IDR_FREE_MAX) in a local pool so we
|
||||
* don't need to go to the memory "store" during an id allocate, just
|
||||
* so you don't need to be too concerned about locking and conflicts
|
||||
* with the slab allocator.
|
||||
*/
|
||||
|
||||
#ifndef TEST // to test in user space...
|
||||
#include <linux/slab.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#endif
|
||||
#include <linux/string.h>
|
||||
#include <linux/idr.h>
|
||||
|
||||
static kmem_cache_t *idr_layer_cache;
|
||||
|
||||
static struct idr_layer *alloc_layer(struct idr *idp)
|
||||
{
|
||||
struct idr_layer *p;
|
||||
|
||||
spin_lock(&idp->lock);
|
||||
if ((p = idp->id_free)) {
|
||||
idp->id_free = p->ary[0];
|
||||
idp->id_free_cnt--;
|
||||
p->ary[0] = NULL;
|
||||
}
|
||||
spin_unlock(&idp->lock);
|
||||
return(p);
|
||||
}
|
||||
|
||||
static void free_layer(struct idr *idp, struct idr_layer *p)
|
||||
{
|
||||
/*
|
||||
* Depends on the return element being zeroed.
|
||||
*/
|
||||
spin_lock(&idp->lock);
|
||||
p->ary[0] = idp->id_free;
|
||||
idp->id_free = p;
|
||||
idp->id_free_cnt++;
|
||||
spin_unlock(&idp->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* idr_pre_get - reserver resources for idr allocation
|
||||
* @idp: idr handle
|
||||
* @gfp_mask: memory allocation flags
|
||||
*
|
||||
* This function should be called prior to locking and calling the
|
||||
* following function. It preallocates enough memory to satisfy
|
||||
* the worst possible allocation.
|
||||
*
|
||||
* If the system is REALLY out of memory this function returns 0,
|
||||
* otherwise 1.
|
||||
*/
|
||||
int idr_pre_get(struct idr *idp, unsigned gfp_mask)
|
||||
{
|
||||
while (idp->id_free_cnt < IDR_FREE_MAX) {
|
||||
struct idr_layer *new;
|
||||
new = kmem_cache_alloc(idr_layer_cache, gfp_mask);
|
||||
if(new == NULL)
|
||||
return (0);
|
||||
free_layer(idp, new);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
EXPORT_SYMBOL(idr_pre_get);
|
||||
|
||||
static int sub_alloc(struct idr *idp, void *ptr, int *starting_id)
|
||||
{
|
||||
int n, m, sh;
|
||||
struct idr_layer *p, *new;
|
||||
struct idr_layer *pa[MAX_LEVEL];
|
||||
int l, id;
|
||||
long bm;
|
||||
|
||||
id = *starting_id;
|
||||
p = idp->top;
|
||||
l = idp->layers;
|
||||
pa[l--] = NULL;
|
||||
while (1) {
|
||||
/*
|
||||
* We run around this while until we reach the leaf node...
|
||||
*/
|
||||
n = (id >> (IDR_BITS*l)) & IDR_MASK;
|
||||
bm = ~p->bitmap;
|
||||
m = find_next_bit(&bm, IDR_SIZE, n);
|
||||
if (m == IDR_SIZE) {
|
||||
/* no space available go back to previous layer. */
|
||||
l++;
|
||||
id = (id | ((1 << (IDR_BITS*l))-1)) + 1;
|
||||
if (!(p = pa[l])) {
|
||||
*starting_id = id;
|
||||
return -2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (m != n) {
|
||||
sh = IDR_BITS*l;
|
||||
id = ((id >> sh) ^ n ^ m) << sh;
|
||||
}
|
||||
if ((id >= MAX_ID_BIT) || (id < 0))
|
||||
return -3;
|
||||
if (l == 0)
|
||||
break;
|
||||
/*
|
||||
* Create the layer below if it is missing.
|
||||
*/
|
||||
if (!p->ary[m]) {
|
||||
if (!(new = alloc_layer(idp)))
|
||||
return -1;
|
||||
p->ary[m] = new;
|
||||
p->count++;
|
||||
}
|
||||
pa[l--] = p;
|
||||
p = p->ary[m];
|
||||
}
|
||||
/*
|
||||
* We have reached the leaf node, plant the
|
||||
* users pointer and return the raw id.
|
||||
*/
|
||||
p->ary[m] = (struct idr_layer *)ptr;
|
||||
__set_bit(m, &p->bitmap);
|
||||
p->count++;
|
||||
/*
|
||||
* If this layer is full mark the bit in the layer above
|
||||
* to show that this part of the radix tree is full.
|
||||
* This may complete the layer above and require walking
|
||||
* up the radix tree.
|
||||
*/
|
||||
n = id;
|
||||
while (p->bitmap == IDR_FULL) {
|
||||
if (!(p = pa[++l]))
|
||||
break;
|
||||
n = n >> IDR_BITS;
|
||||
__set_bit((n & IDR_MASK), &p->bitmap);
|
||||
}
|
||||
return(id);
|
||||
}
|
||||
|
||||
static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
|
||||
{
|
||||
struct idr_layer *p, *new;
|
||||
int layers, v, id;
|
||||
|
||||
id = starting_id;
|
||||
build_up:
|
||||
p = idp->top;
|
||||
layers = idp->layers;
|
||||
if (unlikely(!p)) {
|
||||
if (!(p = alloc_layer(idp)))
|
||||
return -1;
|
||||
layers = 1;
|
||||
}
|
||||
/*
|
||||
* Add a new layer to the top of the tree if the requested
|
||||
* id is larger than the currently allocated space.
|
||||
*/
|
||||
while ((layers < MAX_LEVEL) && (id >= (1 << (layers*IDR_BITS)))) {
|
||||
layers++;
|
||||
if (!p->count)
|
||||
continue;
|
||||
if (!(new = alloc_layer(idp))) {
|
||||
/*
|
||||
* The allocation failed. If we built part of
|
||||
* the structure tear it down.
|
||||
*/
|
||||
for (new = p; p && p != idp->top; new = p) {
|
||||
p = p->ary[0];
|
||||
new->ary[0] = NULL;
|
||||
new->bitmap = new->count = 0;
|
||||
free_layer(idp, new);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
new->ary[0] = p;
|
||||
new->count = 1;
|
||||
if (p->bitmap == IDR_FULL)
|
||||
__set_bit(0, &new->bitmap);
|
||||
p = new;
|
||||
}
|
||||
idp->top = p;
|
||||
idp->layers = layers;
|
||||
v = sub_alloc(idp, ptr, &id);
|
||||
if (v == -2)
|
||||
goto build_up;
|
||||
return(v);
|
||||
}
|
||||
|
||||
/**
|
||||
* idr_get_new_above - allocate new idr entry above a start id
|
||||
* @idp: idr handle
|
||||
* @ptr: pointer you want associated with the ide
|
||||
* @start_id: id to start search at
|
||||
* @id: pointer to the allocated handle
|
||||
*
|
||||
* This is the allocate id function. It should be called with any
|
||||
* required locks.
|
||||
*
|
||||
* If memory is required, it will return -EAGAIN, you should unlock
|
||||
* and go back to the idr_pre_get() call. If the idr is full, it will
|
||||
* return -ENOSPC.
|
||||
*
|
||||
* @id returns a value in the range 0 ... 0x7fffffff
|
||||
*/
|
||||
int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
|
||||
{
|
||||
int rv;
|
||||
rv = idr_get_new_above_int(idp, ptr, starting_id);
|
||||
/*
|
||||
* This is a cheap hack until the IDR code can be fixed to
|
||||
* return proper error values.
|
||||
*/
|
||||
if (rv < 0) {
|
||||
if (rv == -1)
|
||||
return -EAGAIN;
|
||||
else /* Will be -3 */
|
||||
return -ENOSPC;
|
||||
}
|
||||
*id = rv;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(idr_get_new_above);
|
||||
|
||||
/**
|
||||
* idr_get_new - allocate new idr entry
|
||||
* @idp: idr handle
|
||||
* @ptr: pointer you want associated with the ide
|
||||
* @id: pointer to the allocated handle
|
||||
*
|
||||
* This is the allocate id function. It should be called with any
|
||||
* required locks.
|
||||
*
|
||||
* If memory is required, it will return -EAGAIN, you should unlock
|
||||
* and go back to the idr_pre_get() call. If the idr is full, it will
|
||||
* return -ENOSPC.
|
||||
*
|
||||
* @id returns a value in the range 0 ... 0x7fffffff
|
||||
*/
|
||||
int idr_get_new(struct idr *idp, void *ptr, int *id)
|
||||
{
|
||||
int rv;
|
||||
rv = idr_get_new_above_int(idp, ptr, 0);
|
||||
/*
|
||||
* This is a cheap hack until the IDR code can be fixed to
|
||||
* return proper error values.
|
||||
*/
|
||||
if (rv < 0) {
|
||||
if (rv == -1)
|
||||
return -EAGAIN;
|
||||
else /* Will be -3 */
|
||||
return -ENOSPC;
|
||||
}
|
||||
*id = rv;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(idr_get_new);
|
||||
|
||||
static void idr_remove_warning(int id)
|
||||
{
|
||||
printk("idr_remove called for id=%d which is not allocated.\n", id);
|
||||
dump_stack();
|
||||
}
|
||||
|
||||
static void sub_remove(struct idr *idp, int shift, int id)
|
||||
{
|
||||
struct idr_layer *p = idp->top;
|
||||
struct idr_layer **pa[MAX_LEVEL];
|
||||
struct idr_layer ***paa = &pa[0];
|
||||
int n;
|
||||
|
||||
*paa = NULL;
|
||||
*++paa = &idp->top;
|
||||
|
||||
while ((shift > 0) && p) {
|
||||
n = (id >> shift) & IDR_MASK;
|
||||
__clear_bit(n, &p->bitmap);
|
||||
*++paa = &p->ary[n];
|
||||
p = p->ary[n];
|
||||
shift -= IDR_BITS;
|
||||
}
|
||||
n = id & IDR_MASK;
|
||||
if (likely(p != NULL && test_bit(n, &p->bitmap))){
|
||||
__clear_bit(n, &p->bitmap);
|
||||
p->ary[n] = NULL;
|
||||
while(*paa && ! --((**paa)->count)){
|
||||
free_layer(idp, **paa);
|
||||
**paa-- = NULL;
|
||||
}
|
||||
if ( ! *paa )
|
||||
idp->layers = 0;
|
||||
} else {
|
||||
idr_remove_warning(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* idr_remove - remove the given id and free it's slot
|
||||
* idp: idr handle
|
||||
* id: uniqueue key
|
||||
*/
|
||||
void idr_remove(struct idr *idp, int id)
|
||||
{
|
||||
struct idr_layer *p;
|
||||
|
||||
/* Mask off upper bits we don't use for the search. */
|
||||
id &= MAX_ID_MASK;
|
||||
|
||||
sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
|
||||
if ( idp->top && idp->top->count == 1 &&
|
||||
(idp->layers > 1) &&
|
||||
idp->top->ary[0]){ // We can drop a layer
|
||||
|
||||
p = idp->top->ary[0];
|
||||
idp->top->bitmap = idp->top->count = 0;
|
||||
free_layer(idp, idp->top);
|
||||
idp->top = p;
|
||||
--idp->layers;
|
||||
}
|
||||
while (idp->id_free_cnt >= IDR_FREE_MAX) {
|
||||
|
||||
p = alloc_layer(idp);
|
||||
kmem_cache_free(idr_layer_cache, p);
|
||||
return;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(idr_remove);
|
||||
|
||||
/**
|
||||
* idr_find - return pointer for given id
|
||||
* @idp: idr handle
|
||||
* @id: lookup key
|
||||
*
|
||||
* Return the pointer given the id it has been registered with. A %NULL
|
||||
* return indicates that @id is not valid or you passed %NULL in
|
||||
* idr_get_new().
|
||||
*
|
||||
* The caller must serialize idr_find() vs idr_get_new() and idr_remove().
|
||||
*/
|
||||
void *idr_find(struct idr *idp, int id)
|
||||
{
|
||||
int n;
|
||||
struct idr_layer *p;
|
||||
|
||||
n = idp->layers * IDR_BITS;
|
||||
p = idp->top;
|
||||
|
||||
/* Mask off upper bits we don't use for the search. */
|
||||
id &= MAX_ID_MASK;
|
||||
|
||||
if (id >= (1 << n))
|
||||
return NULL;
|
||||
|
||||
while (n > 0 && p) {
|
||||
n -= IDR_BITS;
|
||||
p = p->ary[(id >> n) & IDR_MASK];
|
||||
}
|
||||
return((void *)p);
|
||||
}
|
||||
EXPORT_SYMBOL(idr_find);
|
||||
|
||||
static void idr_cache_ctor(void * idr_layer,
|
||||
kmem_cache_t *idr_layer_cache, unsigned long flags)
|
||||
{
|
||||
memset(idr_layer, 0, sizeof(struct idr_layer));
|
||||
}
|
||||
|
||||
static int init_id_cache(void)
|
||||
{
|
||||
if (!idr_layer_cache)
|
||||
idr_layer_cache = kmem_cache_create("idr_layer_cache",
|
||||
sizeof(struct idr_layer), 0, 0, idr_cache_ctor, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* idr_init - initialize idr handle
|
||||
* @idp: idr handle
|
||||
*
|
||||
* This function is use to set up the handle (@idp) that you will pass
|
||||
* to the rest of the functions.
|
||||
*/
|
||||
void idr_init(struct idr *idp)
|
||||
{
|
||||
init_id_cache();
|
||||
memset(idp, 0, sizeof(struct idr));
|
||||
spin_lock_init(&idp->lock);
|
||||
}
|
||||
EXPORT_SYMBOL(idr_init);
|
||||
+1210
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user