Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65776
  • 博文数量: 12
  • 博客积分: 580
  • 博客等级: 中士
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-01 21:22
文章分类
文章存档

2010年(1)

2009年(5)

2008年(6)

我的朋友

分类: LINUX

2009-02-20 16:24:11

#include linux/module.h>
#include linux/init.h>
#include linux/list.h>
#include linux/string.h>
#include linux/slab.h>
static struct list_head head;
struct myinfo
{
    struct list_head list;
    int var;
};
static int __init sky_init(void)
{
    struct myinfo *ptr;
    struct list_head *p;
    int i;
   
    INIT_LIST_HEAD(&head);
    for (i = 0; i  10; i++)
    {
        ptr = kmalloc(sizeof(struct myinfo), GFP_KERNEL);
        if (ptr)
        {
            memset(ptr, '\0', sizeof(struct myinfo));
            ptr->var = i;
            list_add_tail(&ptr->list, &head);
        }
    }
    list_for_each(p, &head)
    {
        ptr = list_entry(p, struct myinfo, list);
        printk(KERN_NOTICE "var = %d\n", ptr->var);   
    }
   
    while (!list_empty(&head))
    {
        p = (&head)->next;
        list_del(p);
        ptr = list_entry(p, struct myinfo, list);
        kfree(ptr);
    }
    return 0;
}
static void __exit sky_exit(void)
{
}
module_init(sky_init);
module_exit(sky_exit);
MODULE_LICENSE("GPL");

阅读(1826) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~