我已经编写了一个misc char驱动程序,当我将驱动程序的次要编号回显到misc字符驱动程序时,它没有收到第一个数字。
写函数是这样的,
static ssize_t hellowld_write(struct file *file, const char *buf,size_t len,
loff_t *ppos)
{
pr_debug("In hellowld_write len %d buf %s \n",len,buf);
minor[0] = '\0';
snprintf(minor, 20,"%d", hellowld_device.minor);
strncpy(inputminor, buf,len);
pr_debug("In hellowld_write -- minor %s -- recvNum %s end\n",minor, inputminor);
pr_debug("In hellowld_write -- strlen minor %d -- strlen inputminor %d end\n", strlen(minor), strlen(inputminor));
if( strncmp(minor, inputminor, strlen(minor)) == 0)
{
pr_debug("In hellowld_write -- strcmp passed \n");
return strlen(minor);
}
else
{
pr_debug("In hellowld_write -- strcmp failed \n");
return -EFAULT;
}
}
当我这样做的时候 回声" 54" >的/ dev / HELLOWLD
Dec 31 11:36:40 pavan-linux kernel: [16981.382424] In hellowld_write len 1 buf
Dec 31 11:36:40 pavan-linux kernel: [16981.382424]
Dec 31 11:36:40 pavan-linux kernel: [16981.382424] o
Dec 31 11:36:40 pavan-linux kernel: [16981.382437] In hellowld_write -- minor 54 -- recvNum
Dec 31 11:36:40 pavan-linux kernel: [16981.382437] 4
Dec 31 11:36:40 pavan-linux kernel: [16981.382437] end
Dec 31 11:36:40 pavan-linux kernel: [16981.382444] In hellowld_write -- strlen minor 2 -- strlen inputminor 3 end
Dec 31 11:36:40 pavan-linux kernel: [16981.382448] In hellowld_write -- strcmp failed
回声" 22" >的/ dev / HELLOWLD
Dec 31 11:36:52 pavan-linux kernel: [16993.356993] In hellowld_write len 3 buf 22
Dec 31 11:36:52 pavan-linux kernel: [16993.356993]
Dec 31 11:36:52 pavan-linux kernel: [16993.356993] o
Dec 31 11:36:52 pavan-linux kernel: [16993.357011] In hellowld_write -- minor 54 -- recvNum 22
Dec 31 11:36:52 pavan-linux kernel: [16993.357011] end
Dec 31 11:36:52 pavan-linux kernel: [16993.357017] In hellowld_write -- strlen minor 2 -- strlen inputminor 3 end
Dec 31 11:36:52 pavan-linux kernel: [16993.357021] In hellowld_write -- strcmp failed
为什么当我回显次要号码时,hellowld_write中收到的数据会被截断?