浏览模式: 标准 | 列表
分类:[原创]其他技术
Records:1712

[置顶] Snailium共享新闻

分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:1333

[置顶] Current Project List

This post gives you the projects I'm working on right now or soon later.

阅读全文...

分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:1497

多伦多街头的无线网

来多伦多的空档,在街头拿出电脑打算写点剧本,结果发现自动连上一个无线基站,速度还不错。

打开无线网络管理程序一看,竟然所处的位置上有这么多的AP。看来以后还是要保护好自己的AP,防止盗用。

地点:多伦多 Clarence Squre 北侧
时间:发帖时间
作案工具:Dell Latitude D630 (Wireless 802.11b/g)

大小: 67.38 K 尺寸: 400 x 360 浏览: 1 次点击打开新窗口浏览全图

貌似那个 One Zone 就是多伦多的城市无线网。

Tags: 无线网, 多伦多 | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:160

Bash编程笔记:swatchdog for WD-MBWE

Linux BusyBox 果真是个强大的东西。只要想做,什么都能做出来。正好最近正愁 My Book 的服务总是莫名其妙的挂掉,搞的在单位都无法访问文件。操起简单的 vi,开始制作 Bash Watchdog。(之所以没用 Perl,是考虑到 Perl 在预编译的时候比较耗费系统资源)

经过三个小时的现学现卖,雏形版的 Bash Watchdog - swatchdog 出炉。

/usr/sbin/swatchdog
  1. #! /bin/bash
  2. #
  3. # Watchdog for system service
  4. #  
  5.   
  6. while [ 0 ]  
  7. do
  8.   for PROC
  9.   do
  10.     PID=`ps -aef | grep -v grep | grep -v swatchdog | grep "$PROC"`
  11.     if [ -z "$PID" ] ; then
  12.       TIME=`date "+%Y-%m-%d %H:%M:%S %Z"`
  13.       echo "[$TIME] $PROC is not found, rebooting..." >> /etc/swatchdog/reboot.log
  14.       reboot
  15.       exit 1;
  16.     fi
  17.   done
  18.   sleep 600
  19. done
  20.  
  21. exit 0;

原理很简单,无限循环,检查命令行传入的进程是否存在。如果不存在则重启。

使用也很简单。

Command
  1. swatchdog cvm transmission amuled

自动侦测 cvm(mionet)、transmission 和 amuled。

Tags: mybook, shell, bash, watchdog, 编程 | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:404

WD MBWE Hack: nethostfs

Here is HOWTO add nethostfs on Western Digital My Book World Edition. For Chinese version, visit here(中文版).

Prerequisite: Enable SSH on My Book.

Step 1. Download nethostfs v1.5 source code, unpack and compile.

bash
  1. wget http://www.snailium.net/mbwe/nethostfs15src.tar.gz
  2. tar -xzvf nethostfs15src.tar.gz
  3. cd nethostfs15src
  4. make
  5. cp nethostfs /usr/sbin
  6. chmod 755 /usr/sbin/nethostfs
  7. chown root:root /usr/sbin/nethostfs

Step 2. Create shared folder /PSP/ through My Book Storage Manager.

Step 3. Create service script nethostfs under /etc/init.d/.

/etc/init.d/nethostfs
  1. #!/bin/sh
  2. #
  3. # Starts or stops the nethostfs for remote PSP access.
  4.  
  5. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  6. NAME="nethostfs"
  7. DESC="Remote PSP access"
  8.  
  9. case "$1" in
  10.   start)
  11.         echo -n "Starting $DESC: $NAME"
  12.         nice -n 10 nethostfs /shares/internal/PSP &
  13.         echo "..."
  14.         ;;
  15.    stop)
  16.         echo -n "Stopping $DESC: $NAME"
  17.         killall nethostfs
  18.         echo "."
  19.         ;;
  20.    *)
  21.         N=/etc/init.d/$NAME
  22.         echo "Usage: $N {start|stop}" >&2
  23.         exit 2
  24. esac
  25.  
  26. exit 0
  27.  

Step 4. Make start/stop link under /etc/init.d/.

bash
  1. cd /etc/init.d/
  2. ln -s /etc/init.d/nethostfs S91nethostfs
  3. ln -s /etc/init.d/nethostfs K09nethostfs

Step 5. Reboot My Book World Edition


Note 1 - nice -n 10 is used in service script to adjust process priorities, in order to avoid nethostfs consumes too much CPU resource.
Note 2 - This works perfect for iRshell, as well as PPA (which uses iRshell's WiFi code)

Tags: mybook, nethostfs, service | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:464

WD MBWE 改造 — nethostfs

Western Digital My Book 所使用的 BusyBox 可塑性还是很高的。

想到正好在用 PPA 在 PSP 上通过 WiFi 看电影,干脆把 nethostfs 服务也集成到 My Book 里面好了。(English Version

前期准备:在 My Book 上加装 SSH 服务

第一步:按照下面的方法下载 nethostfs v1.5 源代码,解包,编译。

bash
  1. wget http://www.snailium.net/mbwe/nethostfs15src.tar.gz
  2. tar -xzvf nethostfs15src.tar.gz
  3. cd nethostfs15src
  4. make
  5. cp nethostfs /usr/sbin
  6. chmod 755 /usr/sbin/nethostfs
  7. chown root:root /usr/sbin/nethostfs

第二步:通过 My Book 共享储存管理器建立 PSP 共享文件夹。

第三步:在 /etc/init.d/ 下建立 nethostfs 服务脚本。

/etc/init.d/nethostfs
  1. #!/bin/sh
  2. #
  3. # Starts or stops the nethostfs for remote PSP access.
  4.  
  5. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  6. NAME="nethostfs"
  7. DESC="Remote PSP access"
  8.  
  9. case "$1" in
  10.   start)
  11.         echo -n "Starting $DESC: $NAME"
  12.         nice -n 10 nethostfs /shares/internal/PSP &
  13.         echo "..."
  14.         ;;
  15.    stop)
  16.         echo -n "Stopping $DESC: $NAME"
  17.         killall nethostfs
  18.         echo "."
  19.         ;;
  20.    *)
  21.         N=/etc/init.d/$NAME
  22.         echo "Usage: $N {start|stop}" >&2
  23.         exit 2
  24. esac
  25.  
  26. exit 0
  27.  

第四步:在 /etc/init.d/ 下建立相关启动/关闭服务链接。

bash
  1. cd /etc/init.d/
  2. ln -s /etc/init.d/nethostfs S91nethostfs
  3. ln -s /etc/init.d/nethostfs K09nethostfs

第五步:重启 My Book。


注意 1:在服务脚本中,使用了 nice -n 10 调整进程的优先级,防止 nethostfs 占用过多资源。
注意 2:此方法也适用于 iRshell。(PPA 的 WiFi 部分使用的是 iRshell 的源代码)

Tags: mybook, nethostfs, service | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:430

PS2游戏改造 Iteration 1

闲来无事,改个PS2游戏玩玩。最近正在玩《无双·远吕智》,就拿它开刀。最终目标是替换全媒体文件。第一回只完成了替换片头。

阅读全文...

Tags: ps2, 游戏, 改造 | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:462

Facebook,强大的背后是无耻

今天喝酒的时候朋友提到了Facebook的强大,很多朋友都可以在Facebook上找到。后来自己申请了一个帐号研究了一下,发现Facebook不过是美国版的某“白领网”罢了。本文大略分析了一下Facebook是怎样工作的。

阅读全文...

Tags: facebook, 社交, 分析 | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:450

安装国产操作系统“银河麒麟2.1”初体验,失败

本着支持国货的心理,下载了一个银河麒麟2.1,看看最近国产操作系统发展得怎么样。

阅读全文...

Tags: 麒麟, 安装, os, kylin, installation | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:1121

Java中byte使用注意事项

目前在做的SYSC 3303 Project是关于使用Java编写TFTP服务器/客户端。其中Java的发送数据包要用byte数组。凭着C语言的扎实基础,想当然的认为byte就是8位无符号整数。于是每一个数据包都由String转为byte发送。

但是,问题出现了。在发送ACK和DATA包时,传出的Block #有一部分不正确(例如:65535)。调试的时候显示在创建数据包的时候数据为0xFF_0xFF(65535),但是接收到的数据为0x3F_0x3F(16191)。

看了一下Java Specification,发现在Java中byte和int都是带符号的整数(signed integer),而且唯一的无符号整数(unsigned integer)是char。再往下看,原来char是按照UTF-16编码储存的(16位无符号整数)。郁闷啊。

接下来的工作就是查怎样从byte转换到int。因为带符号整数都是要做带符号扩展(signed extend),也就是说值为0xFF的byte在转成int之后,值为0xFFFFFFFF。终于在网上查到byte与int无符号转换方法,如下:

Java代码
  1. int firstByte = 0;  
  2. int secondByte = 0;  
  3. int thirdByte = 0;  
  4. int fourthByte = 0;  
  5.   
  6. firstByte = (0x000000FF & ((int)buf[index]));  
  7. secondByte = (0x000000FF & ((int)buf[index+1]));  
  8. thirdByte = (0x000000FF & ((int)buf[index+2]));  
  9. fourthByte = (0x000000FF & ((int)buf[index+3]));  
  10.   
  11. long anUnsignedInt = 0;  
  12.   
  13. buf[0] = (anUnsignedInt & 0xFF000000L) >> 24;  
  14. buf[1] = (anUnsignedInt & 0x00FF0000L) >> 16;  
  15. buf[2] = (anUnsignedInt & 0x0000FF00L) >> 8;  
  16. buf[3] = (anUnsignedInt & 0x000000FFL);  

但是,问题并没有解决。看来不是cast问题。猛然醒悟,原来是从String转成byte的时候出问题了!看来整个Class都要修改了,再次郁闷一下。

总结:Java去掉了无符号的整数,据说本意是为了简化编程,但是事实上在做网络程序时,我们需要应用大量的无符号整数。另外,Java的一些内部机制也会对编程造成困惑,例如从String生成byte数组的算法。但是这些特别的地方一般的教授或者教材并不作介绍。因此,Java特别适合做Top-level程序(最高等级,即应用程序级)。

最后的一点个人总结:我这个智商没办法凌驾于Java之上,最多也就只能用用C语言了……


注:有关Java中unsigned number的详见 http://darksleep.com/player/JavaAndUnsignedTypes.html

Tags: java, 编程, 整数, byte | 分类:[原创]其他技术 | 评论:0 | Trackbacks:0 | 阅读:1981
Records:1712