May 10
"世间最痛苦的事莫过于等待。。。"

在Shell下进行大文件的复制时,常常要耗很长世间,这是一个相当乏味的过程,在GUI程序中常常会显示进度条或者完成百分比,但在Shell中如何来显示这些信息呢?

“把无尽的期待转换为有限的等待,原来生活如此美妙。。。”

首先想到在zsh中通过函数调用来完成我的需求,函数很简单:

# file copy with progress indicators
cp_p() {
    strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
        | awk '{
            count += $NF
                if (count % 10 == 0) {
                    percent = count / total_size * 100
                        for (i=0;i<=percent;i++)
                            printf("=");
                    printf(">");
                    printf ("%2.0f%%\r", percent);
                }
        }
    END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}

嗯。。。考虑到一部分人也许没有在用zsh,好吧,"条条大道通罗马",请看:

  • 使用打了补丁的cp --- Advanced Copy
    wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.4.tar.gz
    tar xvzf coreutils-8.4.tar.gz
    cd coreutils-8.4/
    wget http://beatex.org/web/advcopy/advcpmv-0.3-8.4.patch
    patch -p1 -i advcpmv-0.3-8.4.patch
    ./configure
    make
    
    sudo cp src/cp /usr/local/bin/cpg
    
    $vim ~/.bashrc
    alias cpg="/usr/local/cpg -g"
    
  • 使用bar
    #Copy a file
    bar -o outfile infile
    #Copy several files to another directory (showing a common progress bar)
    bar -c 'cat > outdir/${bar_file}' file1 file2 file3
    

关于bar的具体使用方法可以参见这里

三种方法各行其道,各有各的特点,使用zsh函数只有一个特点---简介!而打过补丁的cp则可以显示比较完整的信息,相对于前两者,bar比较折衷,十分优雅。。。
May 8

之前一直都是以Openbox+Feh+tint2来作为一个伪桌面环境,用Openbox确实十分高效,至少可以满足很多人装X的心理。但用久了难免会产生审美疲劳,所以也来试试Gnome3,不过在配置快捷键时遇到一点问题,在使用Win+t组合键来执行命令urxvt -e tmux时却没有任何反应。马上Google。。。 首先通过 Google 得知包含 Win 键的组合快捷键不起作用的原因是 Gnome3 将 Win 键作为触发活动大纲(Activity) 的快捷键提前截获了。使用 dconf-editor 编辑键值:/org/gnome/mutter/overlay-key为空的字符串,Alt-F2输入r然后enter即可禁用该快捷键的绑定。 然后用dconf-editor继续查看自己设定的快捷键(假定这是你第一个自定义的快捷键):/org/gnome/settings-daemon/plugins/media-keys/custom/keybindings/custom0/binding发现键值为 <Super>t,而 Linux 下常用的 Win 键名称为 Mod4,修改键值为 <Mod4>t,发现快捷键即时生效。 以上步骤可以直接在终端下完成:

dconf write /org/gnome/mutter/overlay-key "''"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom/keybindings/custom0/binding "'<Mod4>t'"

ps:话说这样定义快捷键真的很麻烦。。。Kiss在哪里???

May 8

官方说明

The Assignment

Add code to the kernel to create a new kernel mode thread. The kernel mode thread should print out ”Hello from xxx” where xxx is your name. It should then call the keyboard input routine Wait For Key() repeatly (and echo each character entered) until the termination character (control-d) is entered.

Hints

 

  1. This project will not require much code to be written. However, it may take some time to get things set up and debugged.
  2. Execution of the GeekOS kernel begins in the Main() function in the source file src/geekos/main.c.
  3. To start a new kernel mode thread you use the Start_Kernel_Thread() function. Look at the

comments before the definition of this function in src/geekos/kthread.c.

文档给了很多提示,比如在你需要开启一个内核级线程,你需要函数Start_Kernel_Thread(),而这个函数就在文件src/geekos/kthread.c中,先不忙看Start_Kernel_Thread()这个函数,看看Main()函数都做了些什么。
    /*
     * Kernel C code entry point.
     * Initializes kernel subsystems, mounts filesystems,
     * and spawns init process.
     */
    void Main(struct Boot_Info* bootInfo)
    {
        Init_BSS();
        Init_Screen();
        Init_Mem(bootInfo);
        Init_CRC32();
        Init_TSS();
        Init_Interrupts();
        Init_Scheduler();
        Init_Traps();
        Init_Timer();
        Init_Keyboard();


        Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT));
        Print("Welcome to GeekOS!\n");
        Set_Current_Attr(ATTRIB(BLACK, GRAY));


        TODO("Start a kernel thread to echo pressed keys and print counts");

        /* Now this thread is done. */
        Exit(0);
    }

从第一个函数开始,Init_BSS()

 

May 7

搭建实验环境

基本系统安装好后GeekOS实验环境需要安装的组件只有bochs和nasm,直接使用源中的软件包即可:

$ sudo pacman -S bochs nasm

这里下载geekos-0.3软件包。 解压缩后会得到一个geekos-0.3.0目录

开始GeekOS之路

首先试试第一个项目:

 

$ cd ~/workspace/geekos-0.3.0/src/project0/build$
$ make depend
$ make

make后会提示错误:

cc1: warnings being treated as errors
In file included from ../src/geekos/gdt.c:11:
../include/geekos/segment.h:43: error: ‘packed’ attribute ignored for field of type ‘uchar_t’
make: *** [geekos/gdt.o] 错误 1