Skip to main content

Posts

Showing posts from April, 2010

Linux kernel module to add a proc file entry

A look at the proc_dir_entry structurestruct proc_dir_entry {
unsigned int low_ino;
unsigned short namelen;
const char *name; // name of our module
mode_t mode; // permissions ,who can read and write to it
nlink_t nlink;
uid_t uid;
gid_t gid;
loff_t size;
const struct inode_operations *proc_iops;
const struct file_operations *proc_fops;
struct proc_dir_entry *next, *parent, *subdir;
void *data;
read_proc_t *read_proc; // pointer to the function to be called when we
do a read to the proc entry
write_proc_t *write_proc;// pointer to the function to be called when we
do a write to the proc entry
atomic_t count;
int pde_users;
spinlock_t pde_unload_lock;
struct completion *pde_unload_completion;
struct list_head pde_openers;
};
Now let us write a LKM to add a proc entry . When you write to our proc entry it stores the msg you write and when you read from it , it displays the m…