發表文章

目前顯示的是 3月, 2010的文章

[Linux] 開機自動掛載磁碟

[Linux] 開機自動掛載磁碟 編輯 /etc/fstab /dev/sda5 /home/user/backup auto defaults 0 0 重新開機即可。 /dev/sda5 --> 要掛載的磁區代號 /home/user/backup --> 被掛載的資料夾 auto --> 磁區的格式,也可以用 ext3, ntfs, fat32 等... 可以用 mount -a 測試,是否成功。

misc_register 的用法

misc_register 的用法: 通常要註冊一個 char device 都是用 register_chrdev。這會 註冊 major / minor number,即便可能只需要1個 minor number,往往卻佔住 major number 底下的所有 minor number, 所以  Linux 2.0 有了 miscellaneous character drivers 的誕生,misc driver 使用 major number 10 ,然後使用者如果需要這樣的"小驅動程式",便可以指明 minor number 即可。 使用 misc device 必須 include ,裡面包含了許多的官方的 minor number ,您可以挑選您適合的 minor number ,裡面也包含了兩個 API ,misc_register() / misc_deregister() 。 一般您只要填好 struct miscdevice 的內容,再使用 misc_register() 進行註冊,或者使用 misc_deregister() 進行移除即可。 struct miscdevice { int minor; const char *name; const struct file_operations *fops; struct list_head list; struct device *parent; struct device *this_device; const char *devnode; };  minor:就是您要註冊的minor number。 name:device的name。 fops:file operations。 其他的就不用理會了。 下面為範例: #include #include #include #include MODULE_LICENSE("GPL"); #define DEV_BUFSIZE 1024 static int dev_open(struct inode*, struct file*); static int dev_release(struct inode*, struct file*)

static、shared與dynamically loaded Library (.a & .so)

Library可分成三種,static、shared與dynamically loaded。 1. Static libraries Static 程式庫用於靜態連結,簡單講是把一堆object檔用ar(archiver) 包裝集合起來,檔名以 `.a' 結尾。優點是執行效能通常會比後兩者快, 而且因為是靜態連結,所以不易發生執行時找不到library或版本錯置而 無法執行的問題。缺點則是檔案較大,維護度較低;例如library如果發 現bug需要更新,那麼就必須重新連結執行檔。 1.1 編譯 編譯方式很簡單,先例用 `-c' 編出 object 檔,再用 ar 包起來即可。 ____ hello.c ____ #include void hello(){ printf("Hello "); } ____ world.c ____ #include void world(){ printf("world."); } ____ mylib.h ____ void hello(); void world(); $ gcc -c hello.c world.c /* 編出 hello.o 與 world.o */ $ ar rcs libmylib.a hello.o world.o /* 包成 limylib.a */ 這樣就可以建出一個檔名為 libmylib.a 的檔。輸出的檔名其實沒有硬性規定, 但如果想要配合 gcc 的 '-l' 參數來連結,一定要以 `lib' 開頭,中間是你要 的library名稱,然後緊接著 `.a' 結尾。 1.2 使用 ____ main.c ____ #include "mylib.h" int main() { hello(); world(); } 使用上就像與一般的 object 檔連結沒有差別。 $ gcc main.c libmylib.a 也可以配合 gcc 的 `-l' 參數使用 $ gcc main.c -L. -lmylib `-Ldir' 參數用來指定要搜尋程式庫的目錄,`.' 表示搜尋現在所在的目錄。 通常預設會

GCC常用編譯參數

GCC常用編譯參數 gcc是在unix like system上最常用的編譯程式,而它的參數實在非常的多,功能非常的強大,不過常常會用到的也只有那幾個而已,列出幾個代表性的編譯選項。 ※ 使用方式 gcc [option] filename ※ 選項 * -c : 只做編譯(不做連結) * -S : 輸出組譯碼 * -E : 將預處理結果顯示 * -o filename : 指定輸出檔名 * -ansi : 程式要求依據ansi c標準 * -Dmacro : 使定義巨集(marco)為有效 * -Dmarco=defn : 使定義巨集(marco)為defn * -Wa,option : 將選項(option)傳給組譯器 * -wl,option : 將選項(option)傳給連結器 * -I : 追加include檔案的搜尋路徑 * -L : 追加library檔案的搜尋路徑 * -l : 指定連結的函式庫 * -Wall : 顯示所有的警告訊息 * -g : 編入除錯資訊(要使用GDB除錯一定要加) * -O2 : 做最佳化 ※ 使用範例 Example: gcc -o file a.c b.c c.c gcc -Wall -g -o test test.c gcc -Iinclude -Llibrary -lmy_lib -o test1 test1.c gcc -DDEBUG_ON -o test2 test2.c gcc -c -o test3 test.c Reference: http://hsian-studio.blogspot.com/search/label/C_C%2B%2B

Git 的 public/private key 多台 PC 共用。

Git 的 public/private key 多台 PC 共用。 基本設定 # git config --global user.name "Joseph Lin" # git config --global user.email "joseph.lin@avermedia.com" 產生 public/private key # ssh-keygen –t rsa –C "joseph.lin@avermedia.com"                  // 然後一直按 Enter 會產生 id_rsa & id_rsa.pub -rw------- 1 root root 1675 2010-03-09 13:55 id_rsa -rw-r--r-- 1 root root 406 2010-03-09 13:55 id_rsa.pub 記得這兩個的權限為:600 & 644。 當有其他的 PC 要使用 git 時,可以重複上述步驟。然後將 id_rsa & id_rsa.pub 複製到 .ssh 目錄。 記得檔案權限要相同。 這樣應該就可以使用了。

break & continue

break是跳出他所屬的for、while、或case等 continue 的意思是立即中斷最接近 continue 的迴圈的執行,回到迴圈的開頭。