[問題] ioctl case 有些不會被執行

看板LinuxDev作者 (nikeasyanzi)時間10年前 (2015/04/03 01:39), 10年前編輯推噓0(006)
留言6則, 3人參與, 最新討論串1/1
小弟最近練習ioctl 定義了3個command print,set and get 因為基本上在driver的 kernel module ioctl 一定會需要用到switch 所以可能像 switch (cmd){ case "print": ... break; case "set": ... break; case "get": ... break; default: ... break; } 現在問題來了~ 我利用user space function 驗證 只有print成功 set&get都不會過 在呼叫user space ioctl時 就掛了 output是 [ 2682.940000] mymem_ioctl: <---Switch Command =27395---> [ 2682.940000] getdata=80046b01 80046b01setdata=40046b02 40046b02print=6b03 6b03 [ 2682.950000] <---ORG IOCPRINT :test_var=-1095999702---> [ 2682.960000] <---IOCPRINT complete:test_var=111---> cmd:6b03, arg=10 success SETDATA cmd:40046b02 ioctl_setdata error GETDATA cmd:80046b01 ioctl_getdata error 我有試著對ioctl 解碼 getdata=0x80046b01 => 1000 0000 0000 0100 .... setdata=0x40046b02 => 0100 0000 0000 0100 .... print=0x6b03 0100 is size of int 6b is my magic number 'k' 01,02,03 is the number of function(get,set,print) 看起來也沒問題 不知道板上先進 有無任何想法 mymemdev.c https://github.com/nikeasyanzi/DeviceDriverLabTiny6410/blob/master/lab4ioctlDev/mymemdev.c mymemdev.h https://github.com/nikeasyanzi/DeviceDriverLabTiny6410/blob/master/lab4ioctlDev/mymemdev.h mymemdev_ioctl.h https://github.com/nikeasyanzi/DeviceDriverLabTiny6410/blob/master/lab4ioctlDev/mymemdev_ioctl.h user space test program https://github.com/nikeasyanzi/DeviceDriverLabTiny6410/blob/master/lab4ioctlDev/app-mem.c -- CyberPanel 5000CP 換 NT.500 http://myurl.com.tw/05bd EmailCash 5000e 換 NT.500 http://myurl.com.tw/rgdq -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.5.200 ※ 文章網址: https://www.ptt.cc/bbs/LinuxDev/M.1427996386.A.6A2.html ※ 編輯: nikeasyanzi (114.34.5.200), 04/03/2015 01:54:54 ※ 編輯: nikeasyanzi (114.34.5.200), 04/03/2015 19:00:02

04/03 20:15, , 1F
小弟見識不多 但是C可以switch string??????
04/03 20:15, 1F

04/04 09:03, , 2F
你有看ioctl的function宣告長什麼樣子嗎..= =?
04/04 09:03, 2F

04/06 00:42, , 3F
先謝謝樓上兩位~ 已經解決了~ switch 只是示意
04/06 00:42, 3F

04/06 00:44, , 4F
不好意思 造成大家誤解@@
04/06 00:44, 4F

04/06 00:46, , 5F
mymemdev.c driver code 後來發現錯在這@@
04/06 00:46, 5F

04/06 00:47, , 6F
_IOC_NR(cmd)!=MYMEMDEV_IOC_MAXNR所以只有print會過
04/06 00:47, 6F
文章代碼(AID): #1L7NxYQY (LinuxDev)
文章代碼(AID): #1L7NxYQY (LinuxDev)