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

📄 procfs.c

📁 在Linux下实现文件的拷贝
💻 C
字号:
#include <linux/kernel.h>#include <linux/module.h>#if CONFIG_MODVERSIONS == 1#define MODVERSIONS#include </zhangjian/ostask/linux-2.6.18/include/config/module/srcversion/modversions.h>#endif#include <linux/proc_fs.h>#ifndef KERNEL_VERSION#define KERNEL_VERSION(a,b,c) ((a)*65535+(b)*256+(c)#endifint procfile_read(char *buffer,char **buffer_location,off_t offset,int buffer_length,int zero){   int len;   static char my_buffer[80];   static int count = 1;   if(offset > 0)     return 0;    len = sprintf(my_buffer,"For the %d%s time,go away!\n",count,                        (count %100 > 10 && count %100 < 14)?"th":                           (count % 10 == 1)? "st":                              (count % 10 == 2)? "nd":                                 (count % 10 == 3)?"rd":"th");   count++;   *buffer_location = my_buffer;   return len;}struct proc_dir_entry Our_Proc_File={         0 ,        4 ,   "test",   S_IFREG | S_IRUGO,        1 ,        0 ,        0 ,        80 ,   NULL ,   procfile_read ,   NULL};int init_module(){      # if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)return proc_register(&proc_root,&Our_Proc_File);#else   return proc_register_dynamic(&proc_root,&Our_Proc_File);#endif}void clean_module(){     proc_unregister(&proc_root,&Our_Proc_File.low_ino);}   

⌨️ 快捷键说明

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