• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            seq_file源碼分析

            struct seq_operations {
            void * (*start) (struct seq_file *m, loff_t *pos);
            void (*stop) (struct seq_file *m, void *v);
            void * (*next) (struct seq_file *m, void *v, loff_t *pos);
            int (*show) (struct seq_file *m, void *v);
            };
            seq_file的使用
            struct file_operations exam_seq_file_ops = {
            .owner   = THIS_MODULE,
            .open    = exm_seq_open,
            .read    = seq_read,
            .llseek  = seq_lseek,
            .release = seq_release
            };
            static int exam_seq_open(struct inode *inode, struct file *file)
            {
            return seq_open(file, &exam_seq_ops);
            };

            struct proc_dir_entry *entry;
                        entry = create_proc_entry("exam_seq_file", 0, NULL);
                        if (entry)
                        entry->proc_fops = &exam_seq_file_ops;


            當用戶態的程序打開這個對應的proc目錄時,open->sysopen->exm_seq_open->seq_open(file,&exam_seq_ops),下面我們主要來看下seq_open函數
            int seq_open(struct file *file, const struct seq_operations *op)
            {
             struct seq_file *p = file->private_data;

             if (!p) {
              p = kmalloc(sizeof(*p), GFP_KERNEL); 
              if (!p)
               return -ENOMEM;
              file->private_data = p;
             }
             memset(p, 0, sizeof(*p));
             mutex_init(&p->lock);
             p->op = op;

             /*
              * Wrappers around seq_open(e.g. swaps_open) need to be
              * aware of this. If they set f_version themselves, they
              * should call seq_open first and then set f_version.
              */
             file->f_version = 0;

             /* SEQ files support lseek, but not pread/pwrite */
             file->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
             return 0;
            }
            struct seq_file {
             char *buf;
             size_t size;
             size_t from;
             size_t count;
             loff_t index;
             u64 version;
             struct mutex lock;
             const struct seq_operations *op;
             void *private;
            };
            再來看下seq_read函數
            /**
             * seq_read - ->read() method for sequential files.
             * @file: the file to read from
             * @buf: the buffer to read to
             * @size: the maximum number of bytes to read
             * @ppos: the current position in the file
             *
             * Ready-made ->f_op->read()
             */
            ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
            {
             struct seq_file *m = (struct seq_file *)file->private_data;
             /* grab buffer if we didn't have one */
             if (!m->buf) {
              m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
              if (!m->buf)
               goto Enomem;
             }
             p = m->op->start(m, &pos);
             while (1) {
              err = m->op->show(m, p);

               p = m->op->next(m, p, &pos);

              m->op->stop(m, p);
              }
            } //可見seq_read函數分別調用了自定義的seq_operation結構中的回調函數start,show,next,stop等函數。
            這樣就將vfs層的sys_read->seq_read(調用我們自己定義的seq_operation的start,show,next,stop等函數),從而可以根據我們自己選擇的方式去顯示我們的數據。

             關于proc,seq_file的使用和介紹參考:

            在 Linux 下用戶空間與內核空間數據交換的方式,第 2 部分: procfs、seq_file、debugfs和relayfs

             

            http://www.ibm.com/developerworks/cn/linux/l-kerns-usrs2/index.html

            posted on 2010-12-16 22:40 lstar 閱讀(1555) 評論(0)  編輯 收藏 引用

            導航

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統計

            常用鏈接

            留言簿

            文章檔案

            搜索

            最新評論

            a级成人毛片久久| 大香伊人久久精品一区二区 | 久久成人国产精品二三区| 久久播电影网| 久久久久国产精品| 日韩久久久久中文字幕人妻| 伊人久久大香线焦AV综合影院| 久久国产高清字幕中文| 久久久久综合中文字幕| 久久男人Av资源网站无码软件 | 91久久九九无码成人网站| 亚洲国产成人久久综合区| 欧美综合天天夜夜久久| 亚洲人成精品久久久久| 久久亚洲中文字幕精品一区四| 久久精品亚洲一区二区三区浴池| 久久久久综合中文字幕| 久久99精品久久久久久野外 | 欧美精品国产综合久久| 久久婷婷综合中文字幕| 色8久久人人97超碰香蕉987| 久久久久99精品成人片牛牛影视| 久久亚洲精品人成综合网| 久久久久久曰本AV免费免费| 国产精品美女久久久网AV| 久久精品嫩草影院| 久久婷婷五月综合97色一本一本| 热久久视久久精品18| 色婷婷噜噜久久国产精品12p | 色噜噜狠狠先锋影音久久| 久久久久久午夜成人影院| 久久人人爽人人爽人人片AV麻烦| 久久久精品国产Sm最大网站| 99热热久久这里只有精品68| 久久99国产精品一区二区| 久久亚洲国产精品一区二区| 色婷婷久久综合中文久久蜜桃av| 精品无码久久久久国产动漫3d| 久久婷婷五月综合成人D啪| 久久精品免费一区二区| 亚洲精品无码久久一线|