- 论坛徽章:
- 0
|
static void *my_seq_start(struct seq_file *s, loff_t *pos)
{
static unsigned long counter = 0;
printk(KERN_INFO"Invoke start\n");
/* beginning a new sequence ? */
if ( *pos < MAX_LINES )
{
/* yes => return a non null value to begin the sequence */
printk(KERN_INFO"pos == 0\n");
return &counter;
}
else
{
/* no => it's the end of the sequence, return end to stop reading */
*pos = 0;
printk(KERN_INFO"pos != 0\n");
return NULL;
}
}
static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
unsigned long *tmp_v = (unsigned long *)v;
printk(KERN_INFO"Invoke next\n");
(*tmp_v)++;
*pos = *tmp_v;
return tmp_v;
}
static void my_seq_stop(struct seq_file *s, void *v)
{
printk(KERN_INFO"Invoke stop\n");
/* nothing to do, we use a static value in start() */
}
static int my_seq_show(struct seq_file *s, void *v)
{
int i;
printk(KERN_INFO"Invoke show\n");
loff_t *spos = (loff_t *) v;
for (i = 0; i < 4; i++)
{
items[i].key = *spos;
}
items[0].value = '0';
items[1].value = '1';
items[2].value = '2';
items[3].value = '3';
seq_printf(s, "%ld=%c,%ld=%c,%ld=%c,%ld=%c\n", items[0].key,
items[0].value, items[1].key, items[1].value, items[2].key,
items[2].value, items[3].key, items[3].value);
return 0;
} |
上面是我start,next,show3个函数的实现MAX_LINES就是80,我测试的时候用的小点的数字
但是每次都是多输出几个...
还有个问题就是我cat /proc/net/test_proc后输出一串数字...
然后我接着在cat /proc/net/test_proc他接着输出了,我知道*pos有清0当时*tmp_v没有清0,可是就算这样的话,也是打印*pos < MAX_LINES 次阿.次数又明显不对...
真麻烦了阿,版主dreamice
[ 本帖最后由 ubuntuer 于 2008-11-13 19:23 编辑 ] |
|