2011年12月28日 星期三

block driver學習資源

LDD3的範例程式無法在最新的(至少2.6.32以後的)kernel編譯,許多人為此付出心力,以下是找到較有用的資源

沒試過。聽說還是要手動改一些東西
http://lwn.net/Articles/58720/

這個work!!
http://blog.superpat.com/2010/05/04/a-simple-block-driver-for-linux-kernel-2-6-31/

沒試過
http://hi.baidu.com/zr1988/blog/item/c98e833d551397ca9e3d6215.html/cmtid/93ea1ffbc0b295186d22eb84

照他的做,不work。
https://github.com/jesstess/ldd3-examples/commit/02e3cdeade235fc27b4902c295bd5167a4b98d59

2011年12月26日 星期一

linux學習資源(Driver + kernel debugging)

Device Drivers系列文章,目前出到第12回。

Kernel Debugging Using Kprobe and Jprobe,這篇應該是必讀,但目前沒時間。


深入學習!重要文件大集合


以QS的角度觀之,在進入input context前,是scan code + 控制字符(opt、cmd、ctrl);從input context出來後,是單純的NSString/NSAttributedString。



解救QS輸入的關鍵

http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html
這篇文章詳細講解了Key Binding機制與客製化Key Binding的方法,
甚至可以做到MultiKey binding,即emacs風格的「組合技」。
更甚者,一個binding觸發一連串的methods call,其潛力不可想像。

當然可以用純文字編輯器做到,但令人感激的是,已經有個方便的Key binding編輯器:KeyBindingsEditor

對治「將奇技淫巧發揮到極致的QS」,要能完成向下相容與中文輸入的艱鉅挑戰,key binding或許是一盞明燈。




2011年12月24日 星期六

更改的原因

為何把keyDown中的

// if ([[theEvent charactersIgnoringModifiers] isEqualToString:@" "]) {
// [self insertSpace:nil];
// return;
// }
註解掉?因為中文輸入法一聲的字要用到空白鍵,因此不能在這裡被攔截。

為何把keyDown中呼叫的handleSlashEvent移走?
因為/代表「ㄥ」。

為何把handleBoundKey移走?
因為.代表「ㄡ」、;代表「ㄤ」。
.會執行transmogrify:
;會執行combine:

這個感覺要走正規解法,看能不能把keyBinding加入系統?

chinese compatible pane1&pane3 issues

issue #1: slash key ('/') functions conflict
slash key在QS原生的設計被賦與兩項功能。
功能一:長按0.25-0.5秒,pane1/pane3顯示root;長按超過0.5秒,pane1/pane3切進root。
功能二:「slash」與「shift + slash(其實是shift + ?)」扮演與「左箭頭」和「右箭頭」等效的功能。

因為中文keyboard layout上,slash代表「ㄥ」,要如何在維持「ㄥ」鍵權益與保留原初設計間取得平衡,是個很重要的議題。
在中文輸入法下,功能二是必定要捨棄的了。
所以考量的點只有,在英文輸入法下要保留功能二(維持原初設計),還是把功能二一併拿掉(保持一致性)?


issue #2: potential tidle key ('`') conflict
tidle key在中文輸入法沒有用到,理論上不成問題,只是擔心萬一哪個國家的keyboard layout用到tidle key,就必須考慮和slash key一樣的問題了。


issue #3: space bug (fixed)
之前發佈的
發現bug#1!Preference->Command下,Spacebar behavior請不要設成Normal!
這部份應該很可能修得好,當初改code時沒有太仔細研究原設計處理空白鍵的函式。
Normal的意思就是把空白鍵拿去搜尋,如此而已。keyDown -> insertSpace -> insertText:' '。
這個bug的來源是,insertText 呼叫 insertSpace,insertSpace又呼叫insertText,無窮function call直到stack爆掉為止。在修改insertSpace後,宣告解決。




issue #4: 計算機module
發現bug#2. 計算機module變得怪怪的
這個莫名的bug真的讓我頭皮發麻。按下'='鍵會跑去搜尋檔名有'='的檔案,而非交給計算機module處理。
與b63進行觀察比較後,發現這個bug根本的問題在於中文輸入法下根本無法開啟Text Mode,而計算機module僅僅是打開Text Mode罷了。
看了stringForEvent這個method,發現原來是QS自定的,之前還以為是系統函式庫ㄎㄎ。
把handleBoundKey還給keyDown後,就解決了。

但這又引出一個問題:'.'代表的「ㄡ」失效了。
應該把'.'移出DefaultBindings.qskeys嗎?
還是讓它在英文輸入法下繼續適用呢?
可是在DefaultBindings.qskeys中,'.'是唯一一個執行transmogrify:的key。
'"'和'''是conditionalTransmogrify:,或許'.'有它無可取代的地位吧?


issue #5: performance down
這是一個很大的隱憂阿!b63的反應速度十分令人滿意,但改過後會有稍微的延遲,少數勝過Alfred的優勢就少一個了>"<
Index不會變大,推測是花在搜尋的時間變長了。
或許要用profiling tool...?


-----
issue #1與issue #4的問題皆出在QS自定的DefaultBindings.qskeys,這種非官方的key binding實作了很強大的hacking,卻也帶來許多限制。

2011年12月23日 星期五

Setup git / git 學習資源

Setup
For Windows

For OSX

很棒的slide

分享 Trac 與 Git 的使用心得 @ 資拓宏宇
上面文章的投影片 (超推!!!!!)

寫給大家的git教學(次推)

我愛Git

Git版本控制系統(1) 一篇介紹git很棒的文章

指令一覽


windows-friendly教學XD


大兜提供的mercurial教學(了解分散式版本控制的好教材)


Git Study (很棒的兩人合作範例)



在找尋解決conflict的解答,發現rebase功能
使用 git rebase 避免無謂的 merge
Git rebase 的應用經驗
git 無法做 pull / push 時的解決方法


在"remote branch"有一組簡化指令的工具:git_remote_branch (grb)
不僅方便,其提供的explain還可以教你怎麼用git組合指令完成這項工作呢!




QS的github使用規範
(只能pull,不能push。請愛用"pull request" etc...)
pull request
何謂pull request?在github上,大型專案為了避免新人瞎搞,建議大家fork一個專案,這樣push出去的更動會在自己的fork上,而非原本的專案。如果你確定改好了,並且希望把自己的更改加入原專案,就發一個pull request給維護人員,「請他幫你merge。」
相對應的,兩三人的小專案,大家就直接push到remote master。


Git community 中文版

Learning git
內附更多學習資源

Why git is better then X
這種辯論的文章因為很務實所以寫的讓人容易吸收呢。


2011年12月22日 星期四

突破VirtualBox USB tablet!

擊破vbox的「VirtualBox USB tablet」屏障了!

只要輸入
sudo /etc/init.d/vboxadd stop
停用vbox功能,接著把滑鼠拔掉重插,這個USB mouse就不受virtualbox保護了!!
不過,沒辦法拔掉重插的multi-touch還是被保護著。


不過光是這樣,還是沒辦法看到dprobe插在mousedev_event的探針。
並非沒辦法--按fn+ctrl+option+F1進入命令列模式,這時再動一動滑鼠(要先動multi-touch,再動mouse,否則會抓不到的樣子。另外,我有開gpm。)
然後fn+ctrl+option+F7回到桌面,監視視窗就會顯示探針確實被執行過了!!


ref: https://forums.virtualbox.org/viewtopic.php?f=3&t=37614

2011年12月21日 星期三

筆記:kprobes_example用到的資料結構

find指令幫了很大的忙呢。

struct kprobe 定義在
linux/include/linux/kprobes.h

struct pt_regs 定義在
linux/arch/x86/include/asm/ptrace.h

pt_regs有超多不同的版本,端看你的CPU是哪種architecture。
看來是可以把暫存器通通印出來呢。雖然不知道印出來可以幹嘛= =

實驗

用kprobe真的很快就可以知道哪些function有被call,哪些沒有。
一個視窗輸入cat /proc/kmsg,等著看輸出;
一個視窗負責卸載、編譯、載入kprobe module;
一個文字編輯程式改kprobe要監視的function。

如果不是kprobe的資料結構必須靜態初始化,否則用module_param動態更改參數可以更快。

另外,用
find . | xargs grep '(struct input_handle *' | grep event
找出可能跑去註冊的event函式,結果如下:

fatsoft0415:drivers mac$ find . | xargs grep '(struct input_handle *' | grep event./char/keyboard.c:static void kbd_event(struct input_handle *handle, unsigned int event_type,
./input/apm-power.c:static void apmpower_event(struct input_handle *handle, unsigned int type,
./input/evbug.c:static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
./input/evdev.c:static void evdev_event(struct input_handle *handle,
./input/input.c:void input_inject_event(struct input_handle *handle,
./input/joydev.c:static void joydev_event(struct input_handle *handle,
./input/mousedev.c:static void mousedev_event(struct input_handle *handle,
fatsoft0415:drivers mac$

實驗結果是,kbd_event與evdev_event有反應,而且evdev_event對滑鼠和鍵盤都有反應。
偏偏mousedev_event一點動靜都沒有,不論是用multi-touch軌跡板還是外接USB滑鼠都一樣,關掉VirtualBox的滑鼠整合也一樣。這已經是在沒有裝GuestAddition的情況下了。
阿阿阿阿~~~~


-----
話說我發現有裝guestaddition的kernel,用lsmod看會找到3個跟vbox有關的module。其中有兩個說是在使用中,不能卸載呢。

kernel豆知識

/driver/input是與kernel綁在一起的(無法獨立成module)
/driver/hid是以module形式存在的。可動態卸載/載入。

搜尋字串超實用技巧:find | xarg grep 'string'

如果要搜尋某個struct的定義,如'struct probe {'這種含空白字元的字串,spotlight就會找出一拖拉庫的東西,顯得無用了。

是UNIX指令大顯身手的時候了:find | xarg grep 'string'

把string換成你要搜尋的字串吧。
ref: http://webcache.googleusercontent.com/search?q=cache:HNQfK9FDQSYJ:abort.pixnet.net/blog/post/23266493-linux---%E5%A4%9A%E5%80%8B%E6%AA%94%E6%A1%88%E4%B8%AD%E6%90%9C%E5%B0%8B%E5%AD%97%E4%B8%B2+linux+%E5%85%A7%E6%96%87%E6%90%9C%E5%B0%8B&cd=1&hl=zh-TW&ct=clnk&gl=tw

解決安裝相同kernel版本的問題

這篇文章學到的。

相同的版本號,如果不做任何區別一定分辨不出來。我目前的例子是還好,就是流水式的開發,沒有樹狀分支。不過即使如此,也會擔心有些東西在安裝完到重開機期間會出包,或者什麼要下指令重新產生一份(dep file之類的),自己會漏掉。

有一個很棒的解法,就是加上自定的版本號。在下編譯指令時用-rev選項指定,例如:

make-kpkg -rev Custom.1 --initrd kernel_image

我自己是下

$ sudo make-kpkg -rev custom.showInput --initrd kernel_image kernel_headers

在打這篇文章時,kernel還在編。等明天早上看結果囉!

------

結果似乎不行哪。
要在menuconfig時自行加上版本。上述方法只能改變.deb的版本而已。

usbmouse筆記

http://comments.gmane.org/gmane.linux.arch.general/16703
這篇文章提到,usbmouse與usbkbd是在特殊(如嵌入式)的場合才會用到,一般hid-core就夠了。我想這也是為何在arm與mips及少數arch下的config內才找得到CONFIG_USB_MOUSE的原因吧!

今天有點小小斬獲:在hid-core.c的init function中加入printk,編譯、安裝、卸載、載入後,終於在dmesg後看到印出的訊息了!想要動態觀察,可以用cat /proc/kmsg。
不知為何,並不是出現在/var/log/messages內呢!
另外,usbmouse.c改的東西完全沒有出現。

最後,一個加速編譯的方法:在越深層的資料夾編譯越快,例如在/driver/input下、在/driver/hid下,甚至在/driver/hid/usbhid下。不相干的實在沒有必要等它重編,這個方法節省很多時間,絕對值得學起來。


http://samzhen.blogspot.com/2009/05/linuxusb-hid-device-driver.html
這篇文章教我看Kconfig與Makefile,找出.ko檔是由哪些.o檔組合而成的,從而去找那個_CONFIG在/arch/x86下是否有啟用,來判斷這個.o檔究竟有沒有生效。

2011年12月19日 星期一

編譯與安裝特定linux module

這實在是太實用了。
只改了mousedev.c,卻要重編全部的modules實在等的很辛苦。

其實只要一行就行了。
make -C /usr/src/linux SUBDIR=$PWD modules
安裝也是同理。
make -C /usr/src/linux SUBDIR=$PWD modules_install

原本要超過三小時的編譯時間,縮減到不到5分鐘就可完成。


感謝Fred. 借轉囉!

ref:
http://fred-zone.blogspot.com/2008/09/linux-module.html

重新安裝kernel遇到警告:modules.dep要重製

解法:安裝完後立刻重開,然後執行sudo make modules_install

ref:
http://www.linuxquestions.org/questions/linux-newbie-8/modules-dep-needs-to-be-re-built-157041/

vboxaddtions會影響gpm

新發現。之前一直納悶為何gpm的游標會卡在螢幕正中間,幾乎失去作用。
回到之前的快照,發現在未安裝guest addition的情況下安裝gpm、並使用
sudo /etc/init.d/gpm force-reload
就能正常叫出gpm。

linux觀察event的方法

evbug在/drivers/input/底下,是一個module,它會dump所有的event。
看這些event的方法,是dmesg指令。

# sudo modprobe evbug
動一動滑鼠、按擠下鍵盤之類
# dmesg

通常enter一按下去就會噴一堆訊息,可用
# dmesg | tail
秀出最後的10個event。最後3個input3我認為是那一下enter,也就是鍵盤產生的event。
倒數第四個以上才是我們要看的。用這個方法測出來,滑鼠應該是input6。不論用軌跡板或USB滑鼠都一樣。
滑鼠的點擊(左右鍵都是)屬於input5。

USB學習資源

因為IO這門課有碰到USB driver,又要進入一片未知的大海冒險囉!
這裡有篇不錯的教學
http://fred-zone.blogspot.com/2009/08/usb.html
http://fred-zone.blogspot.com/2009/08/usb_10.html

這是usb.org官方看不完的文件~
http://www.usb.org/developers/docs/

快速瀏覽了下USB3.0的spec,採dual bus,usb3.0 hub中包含超高速hub與USB 2.0 hub。
還看到它分成physical layer、link layer、protocol。跟網路很像呢!後面還有硬體的規格等等,族繁不及備載XD

比較讓我在意的一點是,這份文件的組織跟軟工第一份作業「軟體需求規格書(SRS)」很像。一開始是目錄、簡介與動機、提供一份頭字語的表,接著描述整份文件的架構,然後才依序展開主題。
真是有趣呢!

2011年12月18日 星期日

Ubuntu重編kernel問題解決

找到兩派作法,一是沿用之前kpkg、dpkg指令的作法,Ubuntu 10.4需多做一步。因為是最快的作法,我照著做,成功了(痛哭)
sudo update-initramfs -c -k 2.6.32.27
參考網頁如下
http://cheerc.blogspot.com/2011/11/note-ubuntukernel.html
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=36258


另一派則是傳統的
# sudo make
# sudo make modules
# sudo make modules_install
# sudo make install 
之後還要再設定一下grub。這個我還沒試。


參考網頁
http://www.wretch.cc/blog/eternalwind/5383026

總之可以動囉~~~感動!
有圖有真相:

kernel panic not syncing vfs unable to mount root fs on unknown-block 0 0

裝完新kernel重開機就變成這樣囉

照著
http://wiki.ubuntu-tw.org/index.php?title=GRUB
http://ahhafree.blogspot.com/2010/11/livecdgrub.html
這兩篇的指示去做,是把grub裝好了。
不過要在3秒內按下esc,進入grub選單。選擇原本的2/6.32.-33-generic,可以像往常一樣正常開機,不過選擇新安裝的的2.6.32.27,就又會進入以上畫面了。

哎呀呀~怎麼辦呢?


2011年12月17日 星期六

VirtualBox調整硬碟大小

Keyword: VBoxManage指令、GParted

範例網站是以window XP做範例,檔案系統是NTFS
我想把Ubuntu的hda重劃成連續的40G,作法是在進入GParted後,把、swap整個往後拉(此時GParted已經警告,如果搬動含/boot的磁區,可能造成boot失敗),再把had拉到40G。
做完後雖能成功開機,卻無法登入。


事實上,在用VBoxManage把磁碟改成40G後開機仍正常,然而一旦用GParted將多出來的空間格式化成ext4檔案系統再開機,就無法登入了。

不懂fdisk等磁碟管理工具真是弱阿!!汗顏>"<

ref:
http://blog.xuite.net/autosun/study/50372704
http://www.my-guides.net/en/content/view/122/26/

在OS X上改變process priority的方法

會想做這件事是因為我在VirtualBox上的Ubuntu編譯linux核心,雖然它已經吃掉大部分的CPU時間,但還是跑了非常之久,我希望藉由提昇VirtualBox的priority來加速。
結論:renice指令

ref:

Changing Process Priority on Mac OS X



Is there any way to set the priority of a process in Mac OS X?



How to change process priority

2011年12月16日 星期五

入門級的git教學

git簡記

有時需要的只是這麼簡單的說明^^

在Ubuntu上安裝自編kernel的學習資源

為了IO的lab3,在載入重寫過的新mouse driver前要「卸載原本的mouse driver」,
故必須提供一個不把mouse跟kernel編在一起,而是編成獨立module的kernel,那就必須自己編啦!
基於這個理由,要學習編譯並安裝kernel。

Ubuntu 8.04 / linux 2.6.24.3
Ubuntu 7.04 / linux 2.6.22.9
Ubuntu 10.4-11.10 / linux 3.1

先照Ubuntu 8.04 / linux 2.6.24.3這篇做。
因為在這裡找不到Ubuntu 10.4使用的2.6.32-33,我抓的是2.6.32.27,2.6.32系列的最新版。

一些macbook與sysrq鍵的討論

https://bugs.launchpad.net/mactel-support/+bug/262408
http://ubuntuforums.org/archive/index.php/t-762665.html
http://ubuntuforums.org/archive/index.php/t-762665.html

sysrq鍵是linux在當機時一個緊急處理的指令鍵。
keyfuzz這個工具不知道有沒有用?
另外,直接外接一個USB鍵盤似乎是最經濟實惠的作法。

strace在mac上的替代品

方才在LDD3 p.99看到Linux上的debug利器--strace。
它可以秀出所有system call和參數、有意義的錯誤訊息。

這個工具mac OS X上是沒有的,但有替代品:dtruss,預設已經安裝好了。

ref:
http://stackoverflow.com/questions/1925978/equivalent-of-strace-feopen-command-on-mac-os-x
http://humberto.digi.com.br/blog/2008/02/25/strace-on-mac-os-x-leopard/

2011年12月14日 星期三

trie的學習資源

http://www.csie.ntnu.edu.tw/~u91029/String.html
http://tw.myblog.yahoo.com/chiuinan/article?mid=535&prev=536&next=534&l=f&fid=7
http://zh.wikipedia.org/wiki/Trie
http://en.wikipedia.org/wiki/Trie
似乎很快但很耗記憶體的樣子

2011年12月13日 星期二

在blogger貼上有語法標記的程式碼

根據這篇文章提供的tool,有一個很棒的線上服務:http://tohtml.com/
可以幫忙把純文字源碼轉換成有色彩標記的html格式。
超好用!很想寫成QS的plugin呢!

程設技巧:linux device driver如何在編譯期/載入期改變變數值

ldd3的scull提供了一個很優秀的範例,終於看懂了。

編譯期(compile time)改變的技巧很簡單,就是在標頭檔定義巨集;實作檔中再對把巨集賦值給目標變數。
這麼做的好處是如果要改,去標頭找就好了。方便集中管理。

如main.c(scull的實作檔)中接近開頭處宣告這些變數

int scull_major =   SCULL_MAJOR;
int scull_minor =   0;
int scull_nr_devs = SCULL_NR_DEVS;    /* number of bare scull devices */
int scull_quantum = SCULL_QUANTUM;
int scull_qset =    SCULL_QSET;

而scull.h(scull的標頭檔)中定義以下巨集


#define SCULL_MAJOR 0
#define SCULL_QUANTUM 10
#define SCULL_QSET 10

而載入期(load time)改變的技巧,是透過module_param這個巨集將宣告的變數釋出,讓insmod指令能夠接受額外參數,達到載入期賦值的效果。細節請參閱insmod的參數

值得一提的是,該範例將scull_major定義成0,如果沒有在上述兩個期間改變scull_major,driver將動態alloc一個給它。這段寫在scull_init_module()的程式碼如下:

if (scull_major) {
    dev = MKDEV(scull_major, scull_minor);
    result = register_chrdev_region(dev, scull_nr_devs, "scull");
} else {
    result = alloc_chrdev_region(&dev, scull_minor, scull_nr_devs,
            "scull");
    scull_major = MAJOR(dev);
}

軟工/OOAD資源

看了玩物尚誌的〈再談電子書原始碼製作:程式設計教學篇〉,令人目眩。
姑且不談作者大力推動的電子書自動化產生工具與其令人敬佩的理念,文中提到幾個強大的繪圖工具實在太強,想必會納入我愛不釋手的工具箱中,故誌之。

command-line tool
Graphviz,前文提供繪製png檔案格式UML圖的範例,但它的潛力不止於此。

網頁服務
yUML,使用標記語法線上產生UML圖。
websequencediagrams,使用標記語法線上產生循序圖。

應用程式
ArgoUML,一套與Visual Paradigm類似的開源軟體。附上使用手冊

insmod的參數

不像一般程式的command line參數,直接加在指令後面;insmod的參數格式長這樣:
insmod 變數=值 變數=值

ldd3中文版p.36有解說與範例,如
insmod howmany=10 whom="mom"

變數是在module中用module_param巨集宣告出來的。
看來用變數名稱辨別的方法,各參數順序並無意義呢。

所以要在load time指定scull的major number的作法是:
sudo ./scull_load scull_major=280

2011年12月8日 星期四

scull奇怪問題

echo與cat都會當掉
不過第一次存取不會怎樣,第二次就毀了!

Mac OS X internals: a systems approach

Mac OS X internals: a systems approach


這本書可以在google圖書上預覽一部分

http://books.google.com.tw/books?id=K8vUkpOXhN4C&pg=PA1362&lpg=PA1362&dq=mac+os+x+devfs&source=bl&ots=OKjiR_RqUw&sig=Rip2IoLb0OnPwaN71Vj8ZzPSy1c&hl=zh-TW&ei=5qbfTr-qLsL0mAWY0tGiBQ&sa=X&oi=book_result&ct=result&resnum=4&ved=0CD8Q6AEwAw#v=onepage&q=mac%20os%20x%20devfs&f=false

另外,中央大學也有館藏喔!
http://opac.lib.ncu.edu.tw/search~S0*cht?/YMAC+OS+X+Internals%3A+A+Systems+Approach&SORT=D/YMAC+OS+X+Internals%3A+A+Systems+Approach&SORT=D&SUBKEY=MAC+OS+X+Internals%3A+A+Systems+Approach/1%2C24857%2C24857%2CB/frameset&FF=YMAC+OS+X+Internals%3A+A+Systems+Approach&SORT=D&2%2C2%2C


先筆記之,以後如果有興趣的話可供參考。

用stat檢視device node (device file)


hjkao@hjkao-laptop:~/io/scull_char_driver$ stat /dev/urandom
  File: 「/dev/urandom」
  Size: 0         Blocks: 0          IO Block: 4096   字元特殊檔案
Device: 5h/5d Inode: 796         Links: 1     Device type: 1,9
Access: (0666/crw-rw-rw-)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2011-12-07 12:08:48.303169994 +0000
Modify: 2011-12-07 12:08:48.303169994 +0000
Change: 2011-12-07 12:08:48.303169994 +0000


hjkao@hjkao-laptop:~/io/scull_char_driver$ stat /dev/demo
  File: 「/dev/demo」
  Size: 0         Blocks: 0          IO Block: 4096   字元特殊檔案
Device: 5h/5d Inode: 10218       Links: 1     Device type: fa,0
Access: (0644/crw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2011-12-07 17:41:55.376874406 +0000
Modify: 2011-12-07 17:41:55.376874406 +0000
Change: 2011-12-07 17:41:55.376874406 +0000

Linux driver的major number 與 minor number

根據維基百科http://en.wikipedia.org/wiki/Device_node


Generally, the major number identifies the device driver and the minor number identifies a particular device (possibly out of many) that the driver controls: in this case, the system may pass the minor number to a driver. However, in the presence of dynamic number allocation, this may not be the case (e.g. on FreeBSD 5 and up).


major#分辨driver;minor#分辨一個driver所控制的特定device。
看來是一個driver可以控很多device,所以是以driver:device的方式來分辨每一個不同的device的。
感覺是個不錯的設計!




再回頭看看ldd(第三版)第三章是怎麼寫的:



Traditionally, the major number identifies the driver associated with the device. For example, /dev/null and /dev/zero are both managed by driver 1, whereas virtual con- soles and serial terminals are managed by driver 4; similarly, both vcs1 and vcsa1 devices are managed by driver 7. Modern Linux kernels allow multiple drivers to share major numbers, but most devices that you will see are still organized on the one-major-one-driver principle.

The minor number is used by the kernel to determine exactly which device is being referred to. Depending on how your driver is written (as we will see below), you can either get a direct pointer to your device from the kernel, or you can use the minor number yourself as an index into a local array of devices. Either way, the kernel itself knows almost nothing about minor numbers beyond the fact that they refer to devices implemented by your driver.

嗯,還是看的霧煞煞XDDDDDD

2011年12月7日 星期三

IO作業3筆記II

不知是做了什麼讓gmp壞掉了QQ
guest addition? Sublime text?
(是guest addition)

------以下是正題-----
vms與coord.c都寫好編好了gpm也裝好了,最後一步-gpm要對應到哪個event?
/dev/input/event0
/dev/input/event1
/dev/input/event2
/dev/input/event3
/dev/input/event4
/dev/input/event5
/dev/input/event6
/dev/input/mouse0
/dev/input/mouse1

/dev/input/mouse2
是哪個呢?

看到這篇問題的回覆
http://www.linuxforums.org/forum/kernel/155259-virtual-mouse-driver.html

學到hd這個指令。hd 某個event,接著去動相對應的device讓它產生資料,就會印在螢幕上!
用它試試每個event,再動動滑鼠,就知道哪個才是你的滑鼠的event了!
經過實驗,我家的ubuntu 10.4 (VM on macbook) 的
 /dev/input/event3    對鍵盤有反應

 /dev/input/event4    對滑鼠有反應
 /dev/input/mouse1  對滑鼠有反應,但較慢


--2011/12/21新增,multi-touch與USB mouse的比較實驗。
/dev/input/mice: 兩者都有效
/dev/input/mouse1: 兩者都有效
/dev/input/event4: 兩者都有效,不過有觀察到差別。
上面是移動multi-touch,下面是移動USB mouse的輸出


以不是有意義的訊息輸出稍嫌可惜,不過還是能觀察出一些不同。雖然我一直很擔心VirtualBox會把各種滑鼠輸出以統一的方式交給VM,不過我在mousedev.c內印出訊息後解開了疑惑。移動multi-touch會去call mousedev_abs_event();USB mouse則會去call mousedev_rel_event()。
multi-touch與USB mouse最大的差別,在於前者產生絕對座標,後者產生相對座標。我想知道這兩者是否對應到不同的device file?

實驗結果顯示,不同的硬體輸入裝置,以滑鼠為例,對應到相同的device file。仔細一想,這樣的設計是很合理的。


---
後來發現,這件事用evbug解最快。它會告訴你現在動的硬體是哪個event。

2011年12月2日 星期五

IO作業3筆記

本文重點:
1. Ubuntu如何在GUI mode與command mode間切換(virtual box on mac)
2. 如何在command mode下用gpm開啟滑鼠


根據ref1,按下ctrl-alt-F1切換到文字模式;按下ctrl-alt-F7切換到圖形介面。
但macbook的F1-F12預設是特殊功能,需加上fn鍵才會變成真正的F1-F12,
所以變成fn-ctrl-alt-F1切換到文字模式;fn-ctrl-alt-F7切換到圖形介面。


sudo apt-get install gpm安裝gpm後,執行
sudo /etc/init.d/gpm force-reload
就會看到滑鼠滑過的位置反白了。

reference:
1. Ubuntu圖形/文字介面切換
http://linux.about.com/od/ubuntu_doc/a/ubudg24t8.htm

2. 安裝與開啟gpm教學
http://www.cyberciti.biz/tips/howto-linux-configure-the-mouse-at-a-text-based-terminal-for-copy-and-paste-operation.html

3. gpm的man page
http://linux.about.com/library/cmd/blcmdl8_gpm.htm