要在/proc文件系统中创建一个虚拟文件,要用proc_create()或proc_create_data()函数。这个函数可以接收一个文件名、一组权限和这个文件在/proc文件系统中出现的位置。这两个函数的返回值是一个proc_dir_entry类型指针(或者为NULL,说明在发生了错误时)。然后就可以使用这个返回的指针来配置这个虚拟文件的其他参数,例如在对该文件执行读操作时应该调用的函数。函数的原型和proc_dir_entry结构中的一部分如下图所示。
struct proc_dir_entry {
/*
* number of callers into module in progress;
* negative -> it's going away RSN
*/
atomic_t in_use;
atomic_t count; /* use count */
struct list_head pde_openers; /* who did ->open, but not ->release */
/* protects ->pde_openers and all struct pde_opener instances */
spinlock_t pde_unload_lock;
struct completion *pde_unload_completion;
const struct inode_operations *proc_iops; //Inode operations functions
const struct file_operations *proc_fops; //File operations functions
void *data; //私有数据指针,在操作函数中可以使用的到
unsigned int low_ino;