Kernel 程式裡的命名規則 === ###### tags: `twlkh`, `naming` # Kernel naming convention 找到幾篇關於 kernel 裡的命名規則,關於 `__` 開頭的函數與 `sys_` 與 `do_` 之間的關係。總結如下: ## `__` 開頭的函數 原本的函數在確認完輸入沒有問題[2]、處理完 lock 之後[1],由 `__` 開頭的函數提供真正的實作。 ~~~ In internal code, the convention usually is that symbol __something is workhorse for something excluding some management, often locking. That is a reason for things like __d_lookup . ~~~ ## `sys_` 與 `do_` `sys_` 作為 syscall 的 C 的起始進入點,做完一些參數檢查後,真正的實作為 `do_` 開頭的函數。[3] ~~~ Functions implementing system calls under Linux are prefixed with sys_, but they are usually concerned only with argument checking or arch-specific ways to pass some information and the actual work is done by do_ functions. ~~~ # Reference 1. [What is the meaning of leading and trailing underscores in Linux kernel identifiers?](http://stackoverflow.com/questions/9432111/what-is-the-meaning-of-leading-and-trailing-underscores-in-linux-kernel-identifi) 2. [Re: double underscores](http://www.spinics.net/lists/newbies/msg02920.html) 3. [Linux Kernel 2.4 Internal: section 2.2](http://www.tldp.org/LDP/lki/lki-2.html)