⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.c

📁 在linux下使用c语言编写的一个文件拷贝的源码
💻 C
字号:
#include <linux/module.h>#include <linux/config.h>#include <linux/version.h>#include <linux/types.h>#include <linux/fs.h>#include <linux/mm.h>#include <linux/errno.h>#include <asm/segment.h>unsigned int test_major = 0;char kernel_version[] = UTS_RELEASE;static ssize_t read_test(struct file *file, char *buf, size_t size,			 loff_t * loff){    printk("<0>Hello!This is the program written by Nick Cen.\n");    return size;}static ssize_t write_test(struct file *file, const char *buf, size_t size,			  loff_t * loff){    return size;}static int open_test(struct inode *inode, struct file *file){    MOD_INC_USE_COUNT;    return 0;}static int release_test(struct inode *inode, struct file *file){    MOD_DEC_USE_COUNT;    return 0;}struct file_operations test_fops = {    NULL,    NULL,    read_test,    write_test,    NULL,    NULL,    NULL,    NULL,    open_test,    NULL,    release_test,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,};int init_module(void){    int result;    result = register_chrdev(0, "test", &test_fops);    if (result < 0) {	printk(KERN_INFO "test: can't get major number\n");	return result;    }    if (test_major == 0)	test_major = result;	/* dynamic */    return 0;}void cleanup_module(void){    unregister_chrdev(test_major, "test");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -