当前位置: 技术问答>linux和unix
利用模块,在/proc文件系统下创建文件,并读写时出现错误
来源: 互联网 发布时间:2016-08-14
本文导语: 运行时出错,没法显示正确的/proc文件中的信息,不知道哪里错误了。。。应用程序有点长,主要看shenqing(),就好了 #define __KERNEL__ #define MODULE #ifdef MODVERSIONS #include #endif #include #include #include #include #include #include #includ...
运行时出错,没法显示正确的/proc文件中的信息,不知道哪里错误了。。。应用程序有点长,主要看shenqing(),就好了
#define __KERNEL__
#define MODULE
#ifdef MODVERSIONS
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#define SYSTEM "system"
#define RECORD "record"
#define COMPUTER "computer"
#define N 32
#define MAX 100
#define LEN 11
int read_record(char *,char **,off_t,int);
int write_record(struct file *,const char*,unsigned long,void *);
int read_computer(char *,char **,off_t,int);
int write_computer(struct file *,const char*,unsigned long ,void *);
struct proc_dir_entry *record,*system;
struct proc_dir_entry *computer;
int top; /*for record */
char bitmap[N]; /*for computer*/
char table[MAX][LEN]; /*two files share the table and bitmap*/
int init_module() {
int i;
/*create file system*/
system = proc_mkdir(SYSTEM,NULL);
record = create_proc_entry(RECORD,0644,system);
computer = create_proc_entry(COMPUTER,0644,system);
record->read_proc = read_record;
record->write_proc = write_record;
computer->read_proc = read_computer;
/*initialize bitmap and top implies no students here*/
for(i=0; i
#define __KERNEL__
#define MODULE
#ifdef MODVERSIONS
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#define SYSTEM "system"
#define RECORD "record"
#define COMPUTER "computer"
#define N 32
#define MAX 100
#define LEN 11
int read_record(char *,char **,off_t,int);
int write_record(struct file *,const char*,unsigned long,void *);
int read_computer(char *,char **,off_t,int);
int write_computer(struct file *,const char*,unsigned long ,void *);
struct proc_dir_entry *record,*system;
struct proc_dir_entry *computer;
int top; /*for record */
char bitmap[N]; /*for computer*/
char table[MAX][LEN]; /*two files share the table and bitmap*/
int init_module() {
int i;
/*create file system*/
system = proc_mkdir(SYSTEM,NULL);
record = create_proc_entry(RECORD,0644,system);
computer = create_proc_entry(COMPUTER,0644,system);
record->read_proc = read_record;
record->write_proc = write_record;
computer->read_proc = read_computer;
/*initialize bitmap and top implies no students here*/
for(i=0; i