linux - Kernel Module not assigning variables in llseek -
i writting character device kernel module , running weird issue. setting variables values, not values when print them printk(). here code (with excessive printk):
loff_t llseek(struct file *filp, loff_t off, int whence) { printk(kern_notice "in llseek\n"); printk(kern_notice "filp->f_pos = 0x%llx\n",filp->f_pos); printk(kern_notice "off = 0x%llx\n", off); loff_t newpos; switch(whence) { case 0: /* seek_set */ printk(kern_notice "seek_set\n"); newpos = off; printk(kern_notice "1] newpos = 0x%x\n",newpos); printk(kern_notice "2] newpos = 0x%x\n",newpos); break; case 1: /* seek_cur */ newpos = filp->f_pos + off; printk(kern_notice "seek_cur\n"); break; case 2: /* seek_end */ newpos = 0x1000 + off; printk(kern_notice "seek_end\n"); break; default: /* can't happen */ homecoming -einval; } printk(kern_notice "3] newpos = 0x%x\n",newpos); if (newpos < 0) homecoming -einval; printk(kern_notice "4] newpos = 0x%x\n",newpos); filp->f_pos = newpos; printk(kern_notice "5] newpos = 0x%lx\n", newpos); homecoming newpos; }
this called userspace this:
lseek(dev_fd, 0x90, 0);
here console output:
[ 53.764351] in llseek [ 53.766208] filp->f_pos = 0x0 [ 53.768629] off = 0x90 [ 53.770560] seek_set [ 53.772341] 1] newpos = 0xc139d40c [ 53.775117] 2] newpos = 0x0 [ 53.777395] 3] newpos = 0x0 [ 53.779680] 4] newpos = 0x0 [ 53.781959] 5] newpos = 0xc139d40c
i have expected output be:
[ 53.764351] in llseek [ 53.766208] filp->f_pos = 0x0 [ 53.768629] off = 0x90 [ 53.770560] seek_set [ 53.772341] 1] newpos = 0x90 [ 53.775117] 2] newpos = 0x90 [ 53.777395] 3] newpos = 0x90 [ 53.779680] 4] newpos = 0x90 [ 53.781959] 5] newpos = 0x90
why value of newpos
alter 2 consecutive calls of printk
sometimes utilize "%x" "%lx" "%llx". expect different types passed in variable arguments.
with loff_t, should "%llx"
linux linux-device-driver kernel-module
No comments:
Post a Comment