#include
#include
#include
#include
#include
#define err(msg) printk(KERN_ALERT "%s\n", msg)
#define HASHSIZE 512
#define DALIGN (sizeof(unsigned long) - 1)
static struct list_head hashlist[HASHSIZE];
struct buffinfo
{
struct list_head list;
char data[0];
};
static int hashlist_init(void)
{
char data[] = "hello linux";
struct buffinfo *t;
int len = (sizeof(struct buffinfo) + strlen(data) + DALIGN) & ~DALIGN;
int i;
struct list_head *p;
for (i = 0; i < HASHSIZE; i++)
INIT_LIST_HEAD(&hashlist[i]);
for (i = 0; i < HASHSIZE; i++)
{
t = kzalloc(len, GFP_KERNEL);
if (!t)
{
err("kmalloc");
continue;
}
memcpy(t->data, data, strlen(data));
list_add_tail(&t->list, &hashlist[i]);
}
for (i = 0; i < HASHSIZE; i++)
{
while (!list_empty(&hashlist[i]))
{
p = (&hashlist[i])->next;
list_del(p);
t = list_entry(p, struct buffinfo, list);
printk(KERN_ALERT "%s\n", t->data);
kfree(t);
}
}
return 0;
}
static void hashlist_exit(void)
{
printk(KERN_ALERT "hashlist_exit\n");
}
module_init(hashlist_init);
module_exit(hashlist_exit);
MODULE_LICENSE("GPL");
阅读(1151) | 评论(1) | 转发(5) |