Ядро ОС Linux



         

Пpогpамиpование файловой системы /proc. - часть 3


  • Затем вам нужно обеспечить содеpжание файла в каталоге foo. Создайте файл proc/foo.c следуя указанной модели.

    * linux/fs/proc/foo.c * * Copyright (C) 1993 Lunus Torvalds, Michael K. Johnson, and Your N. Here * * proc foo directory handling functions * * inode numbers 200 - 256 are reserved for this directory * (/proc/foo/ and its subdirectories) */

    #include #include #include #include #include

    static int proc_readfoo(struct inode *, struct file *, struct dirent *, int); static int proc-lookupfoo(struct inode *,const char *,int,struct inode **); static int proc_read(struct inode * inode, struct file * file, char * buf, int count), static struct file_operations proc_foo_operations = { NULL, /* lseek - default */ proc_read, /* read */ NULL, /* write - bad */ proc_readfoo, /* readdir */ NULL, /* select - default */ NULL, /* ioctl - default */ /* danlap */ NULL, /* mmap */ NULL, /* no special open code */ NULL /* no special release code */ };

    /* * proc directories can do almost nothing.. */ struct inode_operations proc_foo_inode_operations = { &proc_foo_operations, /* default foo directory file-ops */ NULL, /* create */ proc_lookupfoo, /* lookup */ NULL, /* link */ NULL, /* unlink */ NULL, /* symlink */ NULL, /* mkdir */ NULL, /* rmdir */ NULL, /* mknod */

    NULL, /* rename */ NULL, /* readlink */ NULL, /* follow_link */ NULL, /* bmap */ NULL, /* truncate */ NULL /* permission */ } ;

    static struct proc_dir_entry foo_dir[] = { { 1,2,".." }, { 9,1,"." }, { 200,3,"bar" }, { 201,4,"suds" }, { 202,5,"xyzzy" }, { 203,3,"baz" }, { 204,4,"dir1" }, { 205,4,"dir2'' }, { 206,8,"rootfile" } };

    #define NR_FOO-DIRENTRY ((sizeof (foo_dir))/(sizeof (foo_dir[0])))

    unsigned int get_bar(char * buffer); unsigned int get_suds(char * buffer); unsigned int get_xyzzy(char * buffer); unsigned int get_baz(char * buffer); unsigned int get_rootfile(char * buffer);

    static int proc_read(struct inode * inode, struct file * file, char * buf, int count) { char * page; int length; int end; unsigned int ino;




    Содержание  Назад  Вперед