c - Single callback for multiple /proc entries - find the caller entry -
first of all, api /proc (linux 3.10+) seems different 1 specified in old kernel books.
i creating several /proc entries, have same write function associated callback. same stands read function.
if write or read 1 of /proc entries mentioned above, know entry written or read , able have information inside callback function.
i using proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops).
the callback functions have following list of arguments: (struct file *filp, char *buf, size_t count, loff_t *offp).
i can't figure out give me clue regarding file has call been triggered. first thought struct file* might help. i've found struct file contains struct path contains struct dentry contains struct qstr contains const unsigned char *name. way thing should handled or easier, more elegant way (haven't tested char *name yet)?
i recommend using struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops, void *data) in case, allows attach arbitrary private data each entry , act upon in other functions.
can implement .open callback in proc_fops struct. has signature int my_open(struct inode *inode, struct file *filp);. private data can accessed calling pde_data(inode) , should copied filp->private_data later use in other functions filp , don't inode.
Comments
Post a Comment