一直在想起一個什麼題目好一些,題目只是最初的現實,經過不斷調試最後很是其它問題,想要起一個其它名字比如《印表機驅動中熱插拔事件中添加DEVTYPE》。但是最後想了想還是回到最初才是好的。 具體現象:源碼位置NativeDaemonConnector.java(查看VOLD的TAG)02-10 01:21:02.340: E/VoldConnector(11051): got -1 reading with start = 002-10 01:21:02.340: E/VoldConnector(11051): closing stream for vold02-10 01:21:02.340: E/VoldConnector(11051): Communications error: java.io.IOException: No such file or directory02-10 01:21:02.340: E/VoldConnector(11051): Error in NativeDaemonConnector: java.io.IOException: No such file or directory 分析:在不做任何程式上的修改的情況下,插入USB無線網卡是沒有問題的。目前印表機和無線網卡都是沒有上報資訊的,這就排除了上報訊息的原因了。目前的區別是DEVTYPE,前者是無,後者是有的。 查看所有error時找出了問題所在: NetlinkEvent::FindParam(): Parameter 'DEVTYPE' not found 果真是之前的假設問題,在擷取DEVTYPE時出的問題。
以下就是如何在核心的usb印表機驅動中添加DEVTYPE的問題,花費了一下午的時間以下的diff檔案:
diff --git a/kernel/drivers/usb/class/usblp.c b/kernel/drivers/usb/clindex 9eca405..b528437 100755--- a/kernel/drivers/usb/class/usblp.c+++ b/kernel/drivers/usb/class/usblp.c@@ -1046,8 +1046,13 @@ static const struct file_operations usblp_fops .llseek = noop_llseek, }; +static struct device_type printer_type = {+ .name = "printer",+};+ static char *usblp_devnode(struct device *dev, mode_t *mode) {+ dev->type=&printer_type; return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); } @@ -1072,6 +1077,7 @@ static ssize_t usblp_show_ieee1284_id(struct de static DEVICE_ATTR(ieee1284_id, S_IRUGO, usblp_show_ieee1284_id, NUL + static int usblp_probe(struct usb_interface *intf, const struct usb_device_id *id) {@@ -1079,6 +1085,8 @@ static int usblp_probe(struct usb_interface *in struct usblp *usblp; int protocol; int retval;+ //dev->children[0]->dev.type=&printer_type;+ //dev->dev.type=&printer_type; /* Malloc and start initializing usblp structure so we can us * directly. */ 註:
注釋的那兩條是測試的過但是不成功的方法。
這裡點名感謝一下《Linux驅動》群中的
LinuxDrv群主。一步步指點著添加成功了。如: