2011年4月22日 星期五

UTF-8 與 BIG5 轉換

Big-5 To Utf-8

iconv -f big5 -t utf-8 big5.txt -o utf8.txt

Utf-8 To Big-5

iconv -f utf-8 -t big5 utf8.txt -o big5.txt

2011年3月2日 星期三

TFTP Server

這邊記錄的是atftpd

參考這裡

修改/etc/default/atftpd
USE_INETD=false
OPTIONS="--tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr 10.1.1.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /tftp"

使剛剛的設定生效
~$sudo invoke-rc.d atftpd start

修改Server資料夾的權限
~$sudo chmod -R 777 /tftp
~$sudo chown -R nobody /tftp

重啟
~$sudo reboot

我沒有設定防火牆,所以不用去設定。假如有開防火牆,就要允許Client端進入

Git 二三事

不常用,但是還是會用,所以一定會忘記...

1. 第一次用Git,初始化Git
~$ git init

2. 將所有的code加入Git database
~$ git add .

3. 由於Git預設Editor是Nano(應該),改成習慣的vim
~$ vi .git/config
加入下面這一句
editor = vim

4. commit
~$ git commit -a
可以在此時記錄這一版修改了什麼

2011年2月18日 星期五

加快開機速度

這邊記錄如何加快開機速度

有兩種方式:
1. 將用不到的功能從核心中移除
2. 將用不到的服務從設定檔中移除

1的話請參考如何優化Linux Kernel
這邊只討論2的狀況

~$ runlevel 可以查目前環境的runlevel
N 2
所以runlvel = 2
那Linux載入時會去參考 /etc/rc2.d裡的設定

~$ ls /etc/rc2.d
README S20atftpd S20fancontrol ... S79sendmail... 略

我根本用不到mail啊...每次開機到 "Mail Transport Agent (MTA) Sendmail starting" 就會停在這一下,拖慢我的開機速度

看一下S79sendmail實際長啥樣
~$ ls -l /etc/rc2.d/S79sendmail
lrwxrwxrwx 1 root root 18 2011-02-18 18:50 S79sendmail -> ../init.d/sendmail

所以他實際上是/etc/init.d/sendmail

看一下rc.d的Readme
~$ cat /etc/rc2.d/README
To disable a service in this runlevel, rename its script in this
directory so that the new name begins with a 'K' and a two-digit
number, and run 'update-rc.d script defaults' to reorder the scripts according to dependencies.


man一下update-rc.d就知道如何開關服務
~$ sudo update-rc.d sendmail disable

這樣就不會在開機時開啟 sendmail這個script了

有空再解譯/etc/init.d/sendmail在做啥

2011年2月10日 星期四

Linux上的續傳軟體

公司的網路真是非常容易斷...而且有些人會開BT下載東西,造成下載速度很慢 囧

每次用chrome下載大一點的檔案,都很容易因為斷線就再也不動了...
就算暫停再啟動也是一樣...這不知道是chrome的關係還是Linux版chrome的關係

其實Linux就有非常好用的續傳軟體了~好用又小
wget -c (continue)

一般我是使用wget http://xxxx 就可以從網址抓下東西
斷了想要續傳就 wget -c http://xxxx

有帳號密碼的就
http: wget -d --http-user=xxx --http-passwd=xxx http://url
ftp: wget -d --ftp-user=xxx --ftp-password=xxx http://url

就這樣!

Useful website
http://www.cyberciti.biz/tips/linux-wget-your-ultimate-command-line-downloader.html

2011年1月13日 星期四

platfrom_match trace

在kernel內,許多結構內都會包含一個父結構成員,以利結構的轉換。
今天trace platform device,看如何利用platform device structure內的device structure pointer得知platform device structure的位址

呼叫platform_match in drivers/base/platform.c
static  __init struct platform_device *
early_platform_match(struct early_platform_driver *epdrv, int id)
{
    struct platform_device *pd;

    list_for_each_entry(pd, &early_platform_device_list, dev.devres_head)
        if (platform_match(&pd->dev, &epdrv->pdrv->driver))
            if (pd->id == id)
                return pd;

    return NULL;
}

這是platform_match的定義
static int platform_match(struct device *dev, struct device_driver *drv)
{
    struct platform_device *pdev = to_platform_device(dev);
    struct platform_driver *pdrv = to_platform_driver(drv);

    /* match against the id table first */
    if (pdrv->id_table)
        return platform_match_id(pdrv->id_table, pdev) != NULL;

    /* fall-back to driver name match */
    return (strcmp(pdev->name, drv->name) == 0);
}

主要今天目標是這行,之前上課時老師有說過,現在才拿出來看 T _ T
struct platform_device *pdev = to_platform_device(dev);

define to_platform_device in include/linux/platform_device.h
#define to_platform_device(x) container_of((x), struct platform_device, dev)


define container_of in include/linux/kernel.h
#define container_of(ptr, type, member) ({          \
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
    (type *)( (char *)__mptr - offsetof(type,member) );})

define offsetof in include/linux/stddef.h
#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#endif /* __KERNEL__ */

offsetof 將0轉換成(TYPE *),即指向0的TYPE指標,((size_t) &((TYPE *)0)->MEMBER)就可以取得此MEMBER在這結構內位址值。

比如說platform_device structure(pd) 內的 device structure(dev)成員位置在0x1004。
假設dev在pd內的相對位址為4,那0x1004減去4就可以得到pd的指標位址。

2010年12月16日 星期四

Virtualbox 上跑 ubuntu10.04 文字模式速度跟烏龜一樣!!

一肚子火...買了Q8400,想說支援VT-x,可以讓Virtualbox編譯快一點,但是事與願違阿...

開了四核,但是編譯速度跟單核差不多...(圖形化下)
但是我的Dell NB(Intel Core i5),在Win7下安裝Virtualbox跑ubuntu10.04多核心卻沒問題阿!!現在在ubuntu10.04下安裝Virtualbox來跑卻有這個大問題!!

想說會不會是ubuntu10.04太肥,那就開個文字模式來編譯,結果更是慘不忍睹...每一行文字都慢得不像話...一怒之下就換8.04.3來測試...文字模式比起10.04好太多了,但是依然要1小時才能make完8.04的kernel source code。

正在Virtualbox官網論壇找解決方法時,突然想到,會不會是因為現在那該死的kernel mode set造成的...所以8.04沒問題,10.04卻慢得可以。

就去google一下答案,果然很快就發現解決文字模式非常慢的方法:
參考網站 : 點我 (ubuntu 官方論壇)

~$ sudo vi /etc/modprobe.d/blacklist-framebuffer.conf
add "blacklist vga16fb" to blacklist-framebuffer.conf

就解決問題了...雖然文字模式不會慢的那麼離譜了...但是編譯時速度依然慢的跟烏龜一樣阿...(怒)

之後有解決方式再來寫...

嗯,不想多開文章,直接加在這。
因為我想要大一點的Console Mode,而Grub2.0與Grub1.5設定不同,故在此記錄。

~$ sudo vi /etc/default/grub
add two line
GRUB_GFXMODE=1024x768x32
GRUB_GFXPAYLOAD_LINUX=keep

~$ sudo update-grub
~$ reboot

這樣console mode就有1024x768啦