2008年1月31日 星期四

ENOSYS

ENOSYS:
error code

svn

co:
co = checkout,將程式donwload下來
svn co http://SVN_PATH/svn_project

svn import . svn://192.168.1.200/projects/tickets --message "initial import" –username eldon
將程式存放到repository

svn checkout svn://192.168.1.200/projects/tickets tickets
將repository上的程式download下來

svn remove log/*
svn commit --message "removing all log files from subversion"
移除repository上log/下的files

svn propset svn:ignore "*.log" log/
svn commit –message "Ignore all log files in the log directory"
除止log下的files上傳到repository

create SCSI command

IOSCSIPrimaryCommandsDevice.h.

create matching directory

I/O Kit dictionary-creation function

IOServiceMatching:
creates a dictionary you can use to match on an object’s class or superclass.
use IOProviderClass key

ex:
CFMutableDictionaryRef myUSBMatchDictionary = NULL;
myUSBMatchDictionary = IOServiceMatching(kIOUSBDeviceName);

scsi inquiry

inquiry command




If EVPD = 1, server should return VPD specified by the page code
If EVPD = 0, server shall return the standard INQUIRY data

ShiftOne JRat

可trace Java程式運行過程中的function call。

如何trace
在觀察的java程式的VM arguments加上
-javaagent:shiftone-jrat.jar

jar

建jar檔
jar cvfm myJAR.jar manifest *.class

mainfest : 說明main在哪個class
Main-Class:<空一格>類別名稱
<空白行>

run多個jar檔:
java -cp x.jar:y.jar abc.mainApp
-cp後接相關的jar檔, mainApp表示main所在的class, abc表 mainApp所在的package

shark( profile program in MAC)

ex:
如果test是java的程式,
java -agentlib:Shark test 使得此程式可被shark觀看,
然後在shark的程式裡選擇start開始sample。
選擇java call trace可觀看程式運行時的function call呼叫情形。

2008年1月30日 星期三

log4j

It allows the developer to control which log statements are output with arbitrary granularity

ex:
log4j.logger.idv.ben.MyTestClass=DEBUG, stdout, F
定義"idv.ben.MyTestClass",
輸出到stdout和F,

static Logger logger = Logger.getLogger("idv.ben.MyTestClass");
取得定義的logger

logger.debug("Hello Log4j");
印出Hello Log4j

TIME SIGNATURE and staff

4
4

上面的4表示一小節(measure)有4拍,
下面的4表示which type of note will receive one beat,這裡表示4分音符代表一拍

staff(五線譜)

C chord, G7 chord

C


G7

darwin port

http://darwinports.com/

update
sudo port -d selfupdate

install ethereal
sudo port install ethereal

2008年1月29日 星期二

手指力氣

訓練手指力氣,
彈奏的時候,想像你的力量是直接向下
彈下去的一瞬間,手腕放鬆

practice 1

左右手一起彈,
一次五個音,
範圍是1,2,3 ,4,5

ex: 右手彈23145
左手也彈23145

black keys,C, Treble Clef, QUARTER REST

black keys有兩種,
2個black keys連在一起
3個black keys連在一起

C: on the left side of each group of two black keys

MIDDLE C: the C that is closest to the EXACT middle of piano

Each section starts with a C and includes the next 6 white keys, making 7 keys in a section.
Notice that each section of 7 keys includes a group of 2 black keys and a group of 3 black keys.

The Treble Clef tells you to use your right hand

quarter rest tells you to do is REST for 1 beat

合弦

C 1 3 5
Dm 2 4 6
Em 3 5 7
F 4 6 1'
G 5 7 2'
Am 6 1' 3'
Bdim 7 2' 4'

大(三)合弦(major triad)
從根音開始,先4個半音,後3個半音
C,F,G

小(三)合弦(minor triad)
從根音開始,先3個半音,後4個半音
Dm,Em,Am

減三和弦( diminished triad)
從根音開始先3個半音,後3個半音
Bdim

smartmontools

smartd -q onecheck Registers devices, and checks the status of the devices exactly once

killall

killall -9 test
終止所有叫test的process

sudo

sudo -s
輸入自己的密碼,獲得root權限

s: The -s (shell) option runs the shell specified by the SHELL envi-ronment environment
ronment variable if it is set or the shell as specified in
passwd

java command 參數

-cp: class search path of directories and zip/jar files

SystemStarter

Start, stop, and restart system services

SystemStarter [-gvxdDqn] [action [service]]

Actions:
start, stop, restart

2008年1月28日 星期一

IPv6 on java

連線的IP字串格式:
fe80::21d:7dff:fe91:b561%en0
IP後面要加上%和出去的interface

2008年1月27日 星期日

Java Socket

InetAddress getLocalAddress():
Gets the local address to which the socket is bound.

public class InetAddress
An IP address is either a 32-bit or 128-bit unsigned number used by IP

2008年1月26日 星期六

想買的耳機

ATH EW9



$ 4500

品嘉: 台北市開封一街98號

2008年1月24日 星期四

native method

A native method is a Java method whose implementation is provided by non-java code

java 輸出

boolean 的變數:
印出true or false

2008年1月23日 星期三

IPv6

16 bytes

ping6

測試IPv6是否可正常使用
ping6 ::1


用local-addresses 作為ping6 目標必需指定一個界面. 否則核心將不知道數據包發往哪個設備
ping6 -I lo0 fe80:0:0:0:0:0:0:1

instanceof

判斷一個物件是否是某個type
ex: if(x instanceof Dog)

如果x的type是dog,and dog extends Animal
x instanceof Dog and x instanceof Animal are both true

如果y的type是Animal,
y instanceof Animal is ture. But y instanceof Dog is false

enumeration

java.util Interface Enumeration

for traverse sequence of elements

hasMoreElements()

E nextElement()

Collections' method
static Enumeration enumeration(Collection c):
Returns an enumeration over the specified collection.

NetworkInterface, InetAddress, Inet6Address

java.net.NetworkInterface

public final class NetworkInterface extends Object

A Network Interface made up of a name, and a list of IP addresses assigned to this interface.

static Enumeration getNetworkInterfaces()
Returns all the interfaces on this machine

java.net Class InetAddress
public class InetAddressextends Object implements Serializable
An instance of an InetAddress consists of an IP address and possibly its corresponding host name

String getHostAddress()
Returns the IP address string in textual presentation

byte[] getAddress()
Returns the raw IP address of this InetAddress object.

java.net Class Inet6Address
public final class Inet6Address extends InetAddress
preferred form is x:x:x:x:x:x:x:x, x is 16進位,16 bits
ex: 1080:0:0:0:8:800:200C:417A

lsof

lsof (lists open files)

Show all connections with -i
lsof -i

Show only TCP (works the same for UDP)
lsof -iTCP

Show IPv6 connection
lsof -i 6

how to get resource

1. get Class object of the class that has resource

2. if resource is image or audio , use getResource(String name) to get resource as a URL.
Then read it with getImage or getAudioClip

3. other resource use getResourceAsStream(String name) to get InputStream to read.

property

The keys & values are strings

java.util.Properties

property file format:
key = value

ex:
Properties settings = new Properties();
settings.put("PROMPT", "$p$g");
settings.put("TEMP", "C:\\Windows\\Temp");
settings.put("CLASSPATH", "c:\\jdk\\lib;.");
settings.store(System.out, "Environment settings");

output:
#Environment settings
#Sun Jan 21 07:22:52 1996
CLASSPATH=c:\\jdk\\lib;.
TEMP=C:\\Windows\\Temp
PROMPT=$p$g

store(OutputStream out, String comments):
Writes this property list (key and element pairs) in this Properties table to the output stream

to load properties from a file:
FileInputStream in = new FileInputStream("text.properties");
settings.load(in);

use getProperty(String key) to get property

2008年1月22日 星期二

eclipse cvs

Synchronize with Repository
顯示本地端檔案與CVS的差異
Commit
將檔案更改送上CVS, 參考 Eclipse/CVS Commit
Update
更新本地端檔案, 參考 Eclipse/CVS Update

root 權限

啟動root權限
sudo passwd root

widget

Wiget: Screen Capture Widget

ln

建立link,project指到 /Volumes/1222/Users/deeplove/Documents/project
ln -s /Volumes/1222/Users/deeplove/Documents/project project

ls -l
lrwxr-xr-x 1 pan staff 46 Jan 22 18:06 project -> /Volumes/1222/Users/deeplove/Documents/project

2008年1月21日 星期一

Enable hidden disk image formats in Disk Utility

defaults write com.apple.DiskUtility advanced-image-options 1

/System/Library directory

/System/Library/Extensions contains device drivers and other kernel extensions

/System/Library/Frameworks contains frameworks and shared libraries that have published API

/System/Library/PrivateFrameworks contains frameworks and shared libraries that are private to Apple

/System/Library/FileSystems contins loadable file systems

mach, darwin , xnu

port: in-kernel message queue

a process can have several ports within itself, each of which can be used to wait for a message

darwin's kernel is called xnu

2008年1月20日 星期日

cut

print selected columns or fields
-d
set field delimiter

-f
print field

ex:
KERNEL = $(uname -r)
VERSION=$(echo $KERNEL | cut -dE -f1)
echo $VERSION

output: 2.6.9-42.ELsmp
explain: 以E分隔2.6.9-42.ELsmp,f1= 2.6.9-42. f2= Lsmp

2008年1月19日 星期六

考慮買的琴

yamaha DGX-620
$25000





NP-30
$11800




功學社
台北市復興南路一段322號 忠孝復興站 2號出口
台北市博愛路115號

2008年1月18日 星期五

關機

shutdown -h now

2008年1月17日 星期四

文字模式

[Ctrl] + [Alt] + [F1] ~ [F6] :文字介面登入 tty1 ~ tty6 終端機

0 - halt (系統直接關機)
1 - single user mode (單人維護模式,用在系統出問題時的維護)
2 - Multi-user, without NFS (類似底下的 runlevel 3,但無 NFS 服務)
3 - Full multi-user mode (完整的含有網路功能的純文字模式)
4 - unused (系統保留功能)
5 - X11 (與 runlevel 3 類似,但使用 X Window)
6 - reboot (重新開機)

修改/etc/inittab
開機預設的 run level 設定項目
id:3:initdefault:

彌勒之掌

我孫子武丸的新書,
前幾天買的,
讀後感之後再補上。

影片. 舒服音樂會. 淳佳

台中:
望春風
http://youtube.com/watch?v=266pfx6i1Zc

慶幸有你愛我(新專輯主打歌)
http://youtube.com/watch?v=BnjizwPDiFc

有心人。有情人(和歌迷合唱)
http://youtube.com/watch?v=x5nri5r10X4

angel(英文歌)
http://youtube.com/watch?v=wg-kpoMuoso

女人們的咖啡(獨唱專輯裡的合唱版)
http://youtube.com/watch?v=U3lO4b6wwP8

約好的以後(淳佳覺得歌詞很感人的新歌)
http://youtube.com/watch?v=ePzz1jOsTr8

遇見(熊天平寫的新歌)+有一天我會
http://youtube.com/watch?v=rSxTmds28Lg

我想聽妳說(清唱)
http://youtube.com/watch?v=swqUpPRtGXg

未知的以後(清唱)
http://youtube.com/watch?v=MFPGeFQd0gQ

愛如潮水
http://youtube.com/watch?v=VEMXC3aaoRs

redundant controller

LG can be assigned to the primary or secondary controller.
The I/O to drive is managed by the controller taht owns LG
If the controller owns LG fais, the I/O will be managed by another controller

scsi channel, lun and host ID

a SCSI channel( bus) 最多可接15個drives(不包括RAID controller)
So a channel can have 15個ID

SCSI-based subsystem: 8個drives在一個drive channel上,
SATA-based subsystem:一個drive channel,一個drive



host ID is link cabinet, and the drawers are like LUNs(Logical Unit Number)
一個host ID可以有32個LUN。

Connection between RAID controllers & drives


physical location of physical drives


Mapping partitions to host ID/ LUN

2008年1月16日 星期三

ioRegistryExplorer and ioreg

ioRegistryExplorer
show key/value of devices in I/O Registry in GUI mode

ioreg:
show key/value of devices in I/O Registry in command mode

ex:
hard disk in ioRegistryExplorer
IOService : Root:Macmini1,1:Macmini1,1:AppleACPIPlatformExpert:PCI0@0:AppleACPIPCI:SATA@1F,2: AppleAHCI:PRT2@2:IOAHCIDevice@0:AppleAHCIDiskDriver:IOAHCIBlockStorageDevice:
IOBlockStorageDriver:FUJITSU MHV2080BHPL Media



FUJITSU MHV2080BHPL Media


IOAHCIBlockStorageDevice

struct

可以直接copy
ex: struct A a;
struct A b;
a =b;

mach_port_t and io_object_t

in /System/Library/Frameworks/IOKit.framework/Headers/IOTypes.h

typedef mach_port_t io_object_t;
typedef io_object_t io_iterator_t;

grep

search string in files

-n: show line number

ex: grep abc Desktop/*
search abc in files under directory Desktop

find

(1) find file
ex: find Headers/ -name ipc_types.h
recursive find ipc_types.h from Headers directory

(2) show content of directory
find directory_name

find

(1) find file
ex: find Headers/ -name ipc_types.h
recursive find ipc_types.h from Headers directory

(2) show content of directory
find directory_name

scsi device type in mac

defined in /System/Library/Frameworks/IOKit.framework/Headers/scsi-commands.h

kINQUIRY_PERIPHERAL_TYPE_DirectAccessSBCDevice = 0x00,

kINQUIRY_PERIPHERAL_TYPE_SequentialAccessSSCDevice = 0x01,

kINQUIRY_PERIPHERAL_TYPE_PrinterSSCDevice = 0x02,

kINQUIRY_PERIPHERAL_TYPE_ProcessorSPCDevice = 0x03,

kINQUIRY_PERIPHERAL_TYPE_WriteOnceSBCDevice = 0x04,

kINQUIRY_PERIPHERAL_TYPE_CDROM_MMCDevice = 0x05,

kINQUIRY_PERIPHERAL_TYPE_ScannerSCSI2Device = 0x06,

kINQUIRY_PERIPHERAL_TYPE_OpticalMemorySBCDevice = 0x07,

kINQUIRY_PERIPHERAL_TYPE_MediumChangerSMCDevice = 0x08,

kINQUIRY_PERIPHERAL_TYPE_CommunicationsSSCDevice = 0x09,

/* 0x0A - 0x0B ASC IT8 Graphic Arts Prepress Devices */
kINQUIRY_PERIPHERAL_TYPE_StorageArrayControllerSCC2Device= 0x0C,

kINQUIRY_PERIPHERAL_TYPE_EnclosureServicesSESDevice = 0x0D,

kINQUIRY_PERIPHERAL_TYPE_SimplifiedDirectAccessRBCDevice = 0x0E,

kINQUIRY_PERIPHERAL_TYPE_OpticalCardReaderOCRWDevice = 0x0F,

/* 0x10 - 0x1E Reserved Device Types */
kINQUIRY_PERIPHERAL_TYPE_ObjectBasedStorageDevice = 0x11,

kINQUIRY_PERIPHERAL_TYPE_AutomationDriveInterface = 0x12,

kINQUIRY_PERIPHERAL_TYPE_WellKnownLogicalUnit = 0x1E,

kINQUIRY_PERIPHERAL_TYPE_UnknownOrNoDeviceType = 0x1F,

kINQUIRY_PERIPHERAL_TYPE_Mask = 0x1F

gcc

參數:
-Wall
輸出較多的警告訊息

2008年1月15日 星期二

scsi command

0x1d: SEND DIAGNOSTIC


0x1c: RECEIVE DIAGNOSTIC RESULTS

macbook air



the thinest notebook from Apple

thin: 0.4~1.94cm

light: 1.36kg

ERR_PTR and IS_ERR

defined in linux/err.h

void *ERR_PTR(long error) :
A function returning a pointer type can return an error value

long IS_ERR(const void *ptr)
test whether a returned pointer is an error code or not:

long PTR_ERR(const void *ptr)
get the actual error code

2008年1月14日 星期一

java compile 參數

-Xmx512m :
give java 512m memory

2008年1月13日 星期日

i/o kit and nub

nub:
an object that defines an access point and communication channel for a phyiscal device(such as disk drive and bus) or a logical service(such as driver matcing)

I/O registry: track live(instantiated) object
I/O category: track all I/O kit classes available on the system

(1) get the i/o kit master port
use kIOMasterPortDefault ( pass kIOMasterPortDefault to the function that requires master port)

(2) create a matching dictionary:
method 1( match IOProviderClass):
ex:
CFMutableDictionaryRef myUSBMatchDictionary = NULL;
myUSBMatchDictionary = IOServiceMatching("IOUSBInterface");

find the devices with IOProviderClass = "IOUSBInterface"



method 2:
create a matching dictionary that defines which device to access
a matching directory is a CFMutableDictionaryRef object, containing a set of key-value pairs that describe device properties
use CFDictionaryCreateMutable to create. CFDictionaryCreateMutable is defined in CoreFoundation.
use CFDictionarySetValue to set property.
ex:
CFMutableDictionaryRef mySubDictionary;
mySubDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(mySubDictionary, CFSTR(kMyDevicePropertyKey),
CFSTR(kMyDevicePropertyValue));

CFMutableDictionaryRef myMatchingDictionary;
myMatchingDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myMatchingDictionary, CFSTR(kIOPropertyMatchKey),
mySubDictionary);

(3) looking up devices in I/O registry
use IOServiceGetMatchingServices to find devices that match the passed-in matching dictionary. It suppies IOIterator object that you can use to access matching devices

compile with framework

ex:
gcc -Wall diskarb_info.c -framework DiskArbitration -framework CoreFoundation

framework 種類:
Carbon, Security, CoreFoundation, Foundation, IOKit, ApplicationServices, DiskArbitration, CoreServices,

2008年1月12日 星期六

照片. 台中. 舒服音樂會. 淳佳

感謝其它淳佳歌迷提供的好照片


















其它更多的照片在以下連結
http://www.pixnet.net/album/whotogether/13418699
http://www.wretch.cc/album/album.php?id=bigcat9kit&book=1

感受 .台中. 舒服音樂會. 淳佳





今天從板橋南下台中,
為了聆聽免費的音樂會,
雖然交通費花了不少,
但享受了一場十全十美的音樂會,
只恨我相機到了中途沒電,而且沒有錄影功能。
但我還是可以用文字簡單說明一下是哪十點達成十全十美。
1. 現在聽淳佳唱歌的感覺,比起cd更令人感動。
2. 淳佳唱了些其它語言的歌,例如台語的望春風,Sarah Mclanchlan的Angel。
3. 淳佳本人在現場看來比專輯上更漂亮。
4. 為淳佳伴奏的兩位吉它手的演出也讓表演更加精彩。
5. 現場有吃到飽的蛋糕,餅乾和飲料。
6. 歌迷們都很親切,彼此聊得很開心。
7. 每個人都能和淳佳"一對一"的合照。
8. 淳佳和從來沒搭配過的歌迷合唱有心人有情人,出人意料地好聽。
9. 音樂會後歌迷們和淳佳近距離的聊天。
10.最後,淳佳在現場展現平常電視上看不到的活潑的一面唷。

我想唯一不滿意的就是沒電前拍的照片都太差了,
之後有更好的活動照片或影片,
再和大家分享。

2008年1月11日 星期五

comile error in mac

problem
mac_scsi.c:1: error: stray '\239' in program
mac_scsi.c:1: error: stray '\187' in program
mac_scsi.c:1: error: stray '\191' in program

answer:
save file with Western(Mac OS Roman)

mac scsi

example code:
Developer/Examples/IOKit/scsi/SCSITaskLib/Authoring/UnixTool/AuthoringUnitTestUnixTool.c

IOSCSIPeripheralDeviceType00 for block storage devices such as internal disk drives
IOSCSIPeripheralDeviceType05 for multimedia devices such as CD and DVD drives
IOSCSIPeripheralDeviceType07 for magneto-optical devices
IOSCSIPeripheralDeviceType0E for reduced block command devices such as flash cards and
smart media devices

SCSI CDB

CDB( Command Descriptor Block)

programming use CDB to perform scsi command

2008年1月10日 星期四

memset

void *memset(void *s, int c, size_t n);

copies c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s.

2008年1月9日 星期三

fink and install ethereal

The Fink project wants to bring the full world of Unix Open Source software to Darwin and Mac OS X

http://www.finkproject.org/

download fink
http://www.finkproject.org/download/index.php?phpLang=en
(1) install Fink 0.8.1 XYZ Installer.pkg
(2) install FinkCommander GUI application

lauch FinkCommander GUI application
(1) Source->scanpackages
(2) Source->Utilities->index

ex: install ethereal
(1) find ethereal from FinkCommander GUI application
(2) Binary->Install
(3) install AquaEthereal, which provides a convenient way to launch ethereal in Mac OSX

exit

defined in <stdlib.h>

O_RDONLY

defined in ≷fcntl.h>

extern

當多個檔案要共享變數A時,
在某一個.c檔定義變數A,
然後在.h檔利用extern宣告變數A,
其它的.c檔則include .h檔,
如此則可防止multiple definition。

2008年1月8日 星期二

IOKit Driver's plist

example

load and unload driver

cp -r test.kext /tmp
kextload -v test.kext

show loaded kernel extension
kextstat

/System/Library/Extensions/ is the standard location of kernel extensions

sudocp-R MyKEXT.kext /tmp :
使得kext的權限變成root/whale

2008年1月7日 星期一

major number and minor number

type dev_t:
major & minor numbers are store in variable of type dev_t, which is 32bit

mass storage driver stack





special character in html

<q> and <blockquote>

<q>:
for short quotes that are part of an existing paragraph

<blockquote>:
for longer qoutes taht need to be displayed on their own

list in html

(1) put each list item in <li> element
li = list item

(2) enclouse list items with either <ol> or <ul> element
ol = ordered list
ul = unordered list

pointer to function

ex: int (*comp)( void*, void*)
comp is a pointer to a function that has two void* arguments and return an int

device without request queue

Some devices have no real need for a request queue. They can hande requests directly as they are generated.

However, the request queue must still be created. The queue will not be used to handle the actual requests, but it contains other infrastructure needed by the block subsystem

(1) create queue
request_queue_t *blk_alloc_queue(int gfp_mask);

(2) set up the request function
typedef int (make_request_fn) (request_queue_t *q, struct bio *bio);

(3) To arrange for your driver's function to be called
void blk_queue_make_request(request_queue_t *q, make_request_fn *func);

(4) when your driver shuts down, be sure to return the request queue to the system
void blk_put_queue(request_queue_t *queue);

request queue

represented by a pointer to struct request_queue

initialization:
request_queue_t *blk_init_queue(request_fn_proc *request_fn, spinlock_t *lock);
// request_fn is the driver's function which will process requests

remove queue
void blk_cleanup_queue(request_queue_t *q);

Note that neither of these functions is normally called if a "make request" function is being used

find the next request to process with
struct request *elv_next_request(request_queue_t *q);

a request contains a list of BIO structures. iterating through a request's BIOs
struct bio *bio;
rq_for_each_bio(bio, req) {
/* Process this BIO */
}

As your driver performs the transfers described by the BIO structures, it will need to update the kernel on its progress.
int end_that_request_first(struct request *req, int uptodate, int nsectors);

remove request from queue
void blkdev_dequeue_request(struct request *req);
void end_that_request_last(struct request *req);

vim

G: go to last line

vimrc的修改( in /usr/share/vim under mac)
顏色:
syntax on

show line number:
set number

ps

process monitoring

ex: ps -aux
-a: show processes that are owned by other users & attatched to a terminal
-u: user format
-x: include processes without controlling terminals( such as daemon process)

dd

copy data from device to files and vice versa.

ex: dd if=/dev/from of=/dev/too

2008年1月6日 星期日

linux driver command

lsmod 顯示目前已經載入的模組清單

insmod moduleName
load module into kernel
ex: insmod hello.ko

rmmod:
remove module

printk

the message is writed to /var/log/messages

use tail -f /var/log/messages to show log messages

can use dmesg to show latest log messages

ex: printk(KERN_ALERT "hello\n");

create block device driver

example: sbd( simple block driver)
ps: referenc http://lwn.net/Articles/58719/

(1) define a sturcture to represent the disk
static struct sbd_device {
unsigned long size;
spinlock_t lock;
u8 *data;
struct gendisk *gd;
} Device;

(2) disk initializtion
Device.size = nsectors*hardsect_size;
spin_lock_init(&Device.lock);
Device.data = vmalloc(Device.size);
if (Device.data == NULL)
return -ENOMEM;

(3) register with kernel( assignment of a dynamic major number (if requested), and causing the block
driver to show up in /proc/devices.)
major_num = register_blkdev(major_num, "sbd");

(4) gendisk( general disk) initializtion
Device.gd = alloc_disk(16);
Device.gd->major = major_num;
Device.gd->first_minor = 0;
Device.gd->fops = &sbd_ops;
Device.gd->private_data = &Device;
strcpy (Device.gd->disk_name, "sbd0");
set_capacity(Device.gd, nsectors*(hardsect_size/KERNEL_SECTOR_SIZE));

//The fops field is a pointer to the block_device_operations structure
//The private_data field can be used by the driver, so we stick a pointer to our sbd_device structure

(5) set up the request queue
static struct request_queue *Queue;
/* ... */
Queue = blk_init_queue(sbd_request, &Device.lock);
if (Queue == NULL)
goto out;
blk_queue_hardsect_size(Queue, hardsect_size);
Device.gd->queue = Queue;

// sbd_request is the request function
// the lock used by the driver to serialize access to internal resources is the best choice for controlling
access to the request queue as well

(6) add the disk to the system
add_disk(Device.gd);

(7) open and release( ( kept in the block_device_operations structure)
Drivers for real hardware may need to lock and unlock doors, check for media

(8) the request method
static void sbd_request(request_queue_t *q)
{
struct request *req;

while ((req = elv_next_request(q)) != NULL) {
if (! blk_fs_request(req)) {
end_request(req, 0);
continue;
}
sbd_transfer(&Device, req->sector, req->current_nr_sectors,
req->buffer, rq_data_dir(req));
end_request(req, 1);
}
}

// elv_next_request(): getting the first request in the queue. this function does not actually remove the
// request from the queue
// there can be multiple types of requests
// A nonzero return value from the blk_fs_request() macro says "this is a normal filesystem request."
// sbd_transfer(): just a memcpy() with some checking
// rq_data_dir(): A nonzero value (WRITE) indicates that this is a write request
// end_request(): finish processing of this request

(9) ioctl
int sbd_ioctl (struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
long size;
struct hd_geometry geo;

switch(cmd) {
/*
* The only command we need to interpret is HDIO_GETGEO, since
* we can't partition the drive otherwise. We have no real
* geometry, of course, so make something up.
*/
case HDIO_GETGEO:
size = Device.size*(hardsect_size/KERNEL_SECTOR_SIZE);
geo.cylinders = (size & ~0x3f) >> 6;
geo.heads = 4;
geo.sectors = 16;
geo.start = 4;
if (copy_to_user((void *) arg, &geo, sizeof(geo)))
return -EFAULT;
return 0;
}
return -ENOTTY; /* unknown command */
}

open iscsi

start:
rcopen-iscsi start
or
service open-iscsi start

show status:
rcopen-iscsi status
connect to target
iscsiadm -m discovery -t st -p 192.168.111.11
show connected target
iscsiadm -m node
[a3f400] 192.168.111.11:3260,1 iqn.2006-05.net.anything:store0
login
iscsiadm -m node -r a3f400 -l
stop open-iscsi
rcopen-iscsi stop
mount:


run iscsi daemon
/sbin/iscsid -f

loginall
iscsiadm -m node --loginall=all

important macro

#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
return variable whose type is “type” & has member “member”, 
the member is pointed by “ptr”

#define list_entry(ptr, type, member) \
container_of(ptr, type, member)

SG_IO ioctl, sg_io_hdr_t structure and to_scsi_device



evpd(enable vital product data):
the server shall return VPD specified by Page Code when evpd=1

The SG_IO ioctl permits user applications to send SCSI commands to a device

defined in /scsi/sg.h

sg_io_hdr_t structure is the main control structure for the version 3 SCSI generic driver

typedef struct sg_io_hdr
{
int interface_id; /* [i] 'S' (required) */
int dxfer_direction; /* [i] */
unsigned char cmd_len; /* [i] */
unsigned char mx_sb_len; /* [i] */
unsigned short iovec_count; /* [i] */
unsigned int dxfer_len; /* [i] */

// If 'iovec_count' is zero then this value is a pointer to user memory of at least 'dxfer_len' bytes in
// length. If there is a data
//transfer associated with the command then the data will be transferred to or from this user memory.
void * dxferp; /* [i], [*io] */

// This value points to the SCSI command to be executed. The command is assumed to be 'cmd_len'
// bytes long.
unsigned char * cmdp; /* [i], [*i] */

//This value points to user memory of at least 'mx_sb_len' bytes length where the SCSI sense buffer will
//be output. Most successful commands do not output a sense buffer and this will be indicated by
// 'sb_len_wr' being zero
unsigned char * sbp; /* [i], [*o] */

unsigned int timeout; /* [i] unit: millisecs */
unsigned int flags; /* [i] */
int pack_id; /* [i->o] */
void * usr_ptr; /* [i->o] */
unsigned char status; /* [o] */
unsigned char masked_status;/* [o] */
unsigned char msg_status; /* [o] */
unsigned char sb_len_wr; /* [o] */
unsigned short host_status; /* [o] */
unsigned short driver_status;/* [o] */
int resid; /* [o] */
unsigned int duration; /* [o] */
unsigned int info; /* [o] */
} sg_io_hdr_t; /* 64 bytes long (on i386) */

ex:
struct sg_io_hdr io_hdr;
ioctl(fd, SG_IO, &io_hdr)

in scsi_device.h
#define to_scsi_device ( d ) container_of(d, struct scsi_device, sdev_gendev)

unsigned char * cmdp;
ex: Inquiry Command: 0x12

command code:
inquiry 0x12
send diagnostic 1d
receive diagnostic results 1c

page code:
00: Supported vital product data pages
80: Unit Serial Number Page
83: Device Identification
c0: Vendor specific, Physical Device Identification
c1: Vendor specific, Logical Drive Geometry

vpd( vital projuct data) page:
ex:
unit serial number VPD page:


The PAGE LENGTH field specifies the length of the product serial number

strstr

const char * strstr ( const char * str1, const char * str2 );

Returns a pointer to the first occurrence of str2 in str1, or a null pointer if there str2 is not part of str1.

fscanf and fgets

reading from file

#include
int fscanf(FILE *stream, const char *format, ... );

pass a FILE pointer as the first argument of fscanf. The second argument is like the first argument of scanf i.e. a string containing format specifiers. Then follows a list variable addresses so that you can store the inputted data.

#include
char * fgets ( char * str, int num, FILE * stream );

Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached

getopt() in Linux

getopt (int argc, char **argv, const char *options)

The getopt function gets the next option argument from the argument list specified by the argv and argc arguments.
The options argument is a string that specifies the option characters that are valid for this program

cfdisk, mkfs, mount

cfdisk
分割disk
ex: cfdisk /dev/hdb

mkfs
format disk
ex: mkfs -t vfat /dev/hdb0

mount device directory
ex: mount /dev/hda3 /mnt/disk1
mount /dev/hda3 to /mnt/disk1 directory

ex: mount -t vfat /dev/hda3 /mnt/disk1
format = vfat

typedef

refer to the type of an expression

ex: typeof(*x) y
declare y with the type of what x points to
ex: typeof( ((struct ABC *)0)->member ) y;
declare y with the type of member

我的software list

網路
上網: safari
BBS: AlienBBS
p2p: aMule
寫blog: blogger, iWeb
FTP: CyberDuck
VNC: Chicken of the VNC

音樂,影片
聽音樂,看影片: iTunes,QuickTime Player
看DVD: DVD Player
錄音: Audio Hijack Pro
剪接音樂: GarageBand
copy DVD to computer: MacTheRipper

圖片,投影片:
iPhoto: 管理照片
修改圖片: ImageWell
投影片: keynote
做圖: OmniGraffle Professional

工具:
螢幕亮度調整: Brightness Control

其它
計帳: MacMoney
Dictionary: MDict
Virtunal machine: Vmware Vusion
通訊: Skype

程式:
Java: JBuilder 2007
Mac程式: XCode

淳佳的眼裡眉間

從淳佳發表第一張專輯"有心人有情人"後,
就喜歡上淳佳溫暖的聲音,
最近她發行新專輯了,
專輯名稱是"慶幸擁有.蔡淳佳",
果然是一張適合在冬天聆聽的專輯。
整張專輯裡,
我最喜歡"眼裡眉間"這首歌,
帶點中國風的歌,
陳樂融老師填的詞,
在這裡和大家分享歌詞,
如果要聽到這首好聽的歌,
最簡單的方式就是買專輯支持一下唷!

人一別 枯萎了花蕊
茶和飯 減少了滋味
要如何 拿捏我潺潺的依戀
細細思念 不會累

*睡不著 不如聽風吹
 數星星 照亮誰家屋簷
 我明白要給彼此幸福的機會
 臨行的誓約 不能有缺*

#你放了太多愛 在我眼裡眉間
 可以不用眺望天邊也能喜悅
 有情人不能朝夕相對
 也不會傷痛欲絕 自信的人不自憐

 我放了很多愛 隨你披星戴月
 好好把握這次緣分去看世界
 放心我不會就此狼狽 也不會以淚洗面
 我的微笑 請你帶著  一路上回味#