花果山札记cutbag.blog.chinaunix.net
T-Bagwell
熟悉Linux下程序设计及各种应用程序 熟悉C Language 熟悉Glusterfs、FFmpeg、CDN 系统设计,计算机图形系统设计、分布式程序设计 目前主要研究方向:流媒体
全部博文(141)
分类: LINUX
2010-08-08 18:37:29
#include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/fs.h> #define CUTBAG_DIR "CU_T-bagwell" #define MAX_STRING_TEST 20 static struct kmem_cache *T_bagwell_slab_test; struct test{ int count; unsigned char test_string[MAX_STRING_TEST]; }; struct test *test_for_cu; static int __init test_init(void) { T_bagwell_slab_test = kmem_cache_create(CUTBAG_DIR, sizeof(struct test), 0, SLAB_RECLAIM_ACCOUNT, NULL ); if(!T_bagwell_slab_test){ printk(KERN_WARNING "kmem_cache_create faild\n"); return -1; } test_for_cu = kmem_cache_alloc(T_bagwell_slab_test, GFP_KERNEL); if(!test_for_cu){ printk(KERN_WARNING "kmem_cache_alloc faild\n"); kmem_cache_destroy(T_bagwell_slab_test); return -1; } memset(test_for_cu, 0 ,sizeof(struct test)); test_for_cu->count = 100; memcpy(test_for_cu->test_string, "test_for_chinaunix", MAX_STRING_TEST); return 0; } static void __exit test_cleanup(void) { printk(KERN_WARNING "%s %d\n", test_for_cu->test_string, test_for_cu->count); kmem_cache_free(T_bagwell_slab_test, test_for_cu); kmem_cache_destroy(T_bagwell_slab_test); } module_init(test_init); module_exit(test_cleanup); MODULE_LICENSE("GPL");
KERNELDIR = /lib/modules/`uname -r`/build PWD := $(shell pwd) obj-m := slab.o modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf *.o *.ko Module.* module* *.mod.c
上一篇:创建proc中的节点
下一篇:putty使用ssh证书免密码登陆
登录 注册