proc fs の使いかた(kernel-2.4) Tue Sep 26 19:10:23 2000 - 構造体(linux/proc_fs.h) struct proc_dir_entry { unsigned short low_ino; unsigned short namelen; const char *name; mode_t mode; nlink_t nlink; uid_t uid; gid_t gid; unsigned long size; struct inode_operations * proc_iops; struct file_operations * proc_fops; get_info_t *get_info; struct module *owner; struct proc_dir_entry *next, *parent, *subdir; void *data; read_proc_t *read_proc; write_proc_t *write_proc; unsigned int count; /* use count */ int deleted; /* delete flag */ kdev_t rdev; }; - エントリを作る struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode, struct proc_dir_entry *parent) struct proc_dir_entry *create_proc_info_entry(const char *name, mode_t mode, struct proc_dir_entry *base, get_info_t *get_info) name : /proc/ 以下に作成するファイル名("sys/info"など) mode : ファイルのモード(0600など)、 linux/stat.hに定義されているモード(S_IRWXU)などを使用してもよい。 0の場合-r--r--r--になる。 parent : 親ディレクトリを作成しているproc_dir_entry構造体 base : 親ディレクトリを作成しているproc_dir_entry構造体 get_info: typedef int (get_info_t)(char *buf, char **start, off_t fpos, int length); - エントリの削除 void remove_proc_entry(const char *name, struct proc_dir_entry *parent) - その他 proc_dir_entry 構造体中の read_proc_t と write_proc_t は以下 typedef int (read_proc_t)(char *page, char **start, off_t off, int count, int *eof, void *data); typedef int (write_proc_t)(struct file *file, const char *buffer, unsigned long count, void *data);