??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲 欧洲 日韩 综合在线,亚洲中文字幕久久精品蜜桃 ,狠狠色香婷婷久久亚洲精品http://m.tkk7.com/lihao336/category/43733.html成于坚忍Q毁于Qw?/description>zh-cnWed, 14 Dec 2011 00:27:46 GMTWed, 14 Dec 2011 00:27:46 GMT60[转]unix/linux中的dup()pȝ调用http://m.tkk7.com/lihao336/archive/2011/12/13/366231.htmlcalvincalvinTue, 13 Dec 2011 06:20:00 GMThttp://m.tkk7.com/lihao336/archive/2011/12/13/366231.htmlhttp://m.tkk7.com/lihao336/comments/366231.htmlhttp://m.tkk7.com/lihao336/archive/2011/12/13/366231.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/366231.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/366231.html    sys_dup()的主要工作就是用来“复制”一个打开的文件号Q两个文g号都指向同一个文件。既然说单,我们首先来看一下它的代码(定义在fs/fcntl.c中)Q?br />
 1 asmlinkage long sys_dup(unsigned int fildes)
 2 {
 3     int ret = -EBADF;
 4     struct file * file = fget(fildes);
 5 
 6     if (file)
 7         ret = dupfd(file, 0);
 8     return ret;
 9 }
10 

而sys_dup()的主体是dupfd()Q定义在同一个文件中Q:

 1 static int dupfd(struct file *file, int start)
 2 {
 3     struct files_struct * files = current->files;
 4     int ret;
 5 
 6     ret = locate_fd(files, file, start);
 7     if (ret < 0)
 8         goto out_putf;
 9     allocate_fd(files, file, ret);
10     return ret;
11 
12 out_putf:
13     write_unlock(&files->file_lock);
14     fput(file);
15     return ret;
16 }
17 

注:dup和dup2的原型如下:
#include <unistd.h>

int dup(int file_descriptor);
int dup2(int file_descriptor1, int file_descriptor2)
dupq回的文件描q符L取最的可用?br />dup2q回的文件描q符或者与file_descriptor2相同Q或者是W一个大于该参数的可用倹{?/font>

    而这么一个简单的pȝ调用是如何完成重定向q个艰巨的Q务的呢?我们不妨先看个例子?br />    当我们在shell下输入如下命令:“echo hello!”,q条命o要求shellq程执行一个可执行文gechoQ参Cؓ“hello!”。当shell接收到命令之后,先找? bin/echoQ然后fork()Z个子q程让他执行bin/echoQƈ参C递给它,而这个进E从shelll承了三个标准文Ӟx准输? QstdinQ,标准输出QstdoutQ和标准出错信息QstderrQ,他们三个的文件号分别????/font>而至于echoq程的工作很单,是参数“hello!”写到标准输出文件中去,通常都是我们的显C器上。但是如果我们将命oҎ“echo hello! > foo”,则在执行时输出将会被重定向到盘文gfoo?font color="#0000FF">Q注Q重定向于文件描q符有关Q?/font>。我们假定在此之前该shellq程只有三个标准文g打开Q文件号分别???Q以上命令行按如下序列执行Q?br />    (1) 打开或创建磁盘文件fooQ如果foo中原来有内容Q则清除原来内容Q其文g号ؓ3?br />    (2) 通过dup()复制文gstdoutQ即文件号1出的filel构指针复制到文件号4处,目的是将stdout的file指针暂时保存一?br />    (3) 关闭stdoutQ即1hӞ但是׃4h件对stdout也同时有个引用,所以stdout文gq未真正关闭Q只是腾?h件号位置?br />    (4) 通过dup()Q复?hӞ即磁盘文件fooQ,׃1h件关闭,其位|空~,?h件被复制?P卌E中原来指向stdout的指针指向了foo?br />    (5) 通过pȝ调用fork()和exec()创徏子进Eƈ执行echoQ子q程在执行echo前夕关闭3号和4hӞ只留???三个文gQ请注意Q这 时的1h件已l不是stdout而是盘文gfoo了。当echo惛_stdout文g写入“hello!”时自然写入到了foo中?br />    (6) 回到shell后,关闭指向foo?号与3h件文Ӟ再用dup()和close()?h复至stdoutQ这样shell恢复了0??三个标准输入/输出文g?br />
    由此可见Q?font color="#FF0000">当echoE序Q或其他Q在q行的时候ƈ不知道stdoutQ对于stdin和stderr同样Q指向什么,q程与实际输出文件或讑֤的结合是在运行时由其父进E“包办”的。这样就化了子进E的E序设计Q因为在设计时只要跟三个逻辑上存在的文g打交道就可以?/font>。可能有Z觉得q很像面向对象中 的多态和重蝲Q没有什么新奇之处,但是如果你活?0甚至40q前Q可能你会改变你的看法。?

calvin 2011-12-13 14:20 发表评论
]]>
Ubuntu10.04安装无线|卡ath9k_htc驱动http://m.tkk7.com/lihao336/archive/2011/10/18/361521.htmlcalvincalvinTue, 18 Oct 2011 05:55:00 GMThttp://m.tkk7.com/lihao336/archive/2011/10/18/361521.htmlhttp://m.tkk7.com/lihao336/comments/361521.htmlhttp://m.tkk7.com/lihao336/archive/2011/10/18/361521.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/361521.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/361521.html型号为TL_WN721NQ插在Ubuntu10.04上没有反应。据?0.10以后插上可以用了,没有试?br />
W一?定
ath9k_htc驱动支持你的|卡型号
http://linuxwireless.org/en/users/Drivers/ath9k_htc/devices 列出了支持的型号列表Q你可以通过lsusb查看自己的网卡型h否在列表当中?br />
W二?安装firmwire
?a >q里下蝲
htc_9271.fwQ拷贝到/lib/firmwire?br />
W三?安装compact wireless
安装compact wireless有打包好的deb包,?a >q里下蝲GUI Program to install ath9k_htcQ安装完后直接运行,{待安装完成重启机器可以了?br />爱折腄也可以到http://wireless.kernel.org/download/
最新的compact wireless驱动Q然后编译安装:
sudo make
sudo make install
sudo make unload
sudo make load ath9k_htc
重启机器卛_?br />
http://forum.ubuntu.com.cn/viewtopic.php?f=116&t=326568&p=2388841
http://blog.chinaunix.net/space.php?uid=20620288&do=blog&id=2691282


calvin 2011-10-18 13:55 发表评论
]]>
Process state codes in ps outputhttp://m.tkk7.com/lihao336/archive/2011/06/08/351927.htmlcalvincalvinWed, 08 Jun 2011 09:38:00 GMThttp://m.tkk7.com/lihao336/archive/2011/06/08/351927.htmlhttp://m.tkk7.com/lihao336/comments/351927.htmlhttp://m.tkk7.com/lihao336/archive/2011/06/08/351927.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/351927.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/351927.html
Code Meaning
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct (“zombie? process, terminated but not reaped by its parent.

For BSD formats and when the stat keyword is used, additional characters may be displayed:

Code Meaning
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group

Process in D state

If there are a lot of processes in D state in your system, then something is wrong with it.

What is D state and a process state in general? A process in Linux can be in several states: running, sleeping, etc. Running process runs on a CPU just now, sleeping process waits for its turn on CPU or for some other event. Using ps command you can obtain information about state of each process in the system: STAT column shows that:

# ps a
  PID TTY      STAT   TIME COMMAND
 4975 tty1     Ss+    0:00 /sbin/mingetty tty1
 4976 tty2     Ss+    0:00 /sbin/mingetty tty2
 6202 pts/0    Ss+    0:01 -bash
10312 pts/1    Ss     0:00 -bash
  639 pts/1    R+     0:00 ps a

First big S stands for Sleeping, R stands for running ("+" means that the process is foreground and small "s" means that the process is session leader, but it is not relevant for this article).

D state occurs then the process is in uninterruptible sleep. This state is bad, because you can't do anything with the process in D state. Fortunately, process normally remains in such state not for so long. But if you have a heap of D state processes then some logic in system is disrupt. If that is happening, the very important thing is to determine where this unlucky sleep occurs. It is easy to do with ps command with l option. WCHAN column shows the name of the kernel function where the process is sleeping:

# ps axl | grep D
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
vass     13478  7.2  0.0   1732   624 pts/1    D+   17:36   0:00 find ./

http://wiki.preshweb.co.uk/doku.php?id=linux:psflags
http://wiki.openvz.org/Processes_in_D_state


calvin 2011-06-08 17:38 发表评论
]]>
Shell heredochttp://m.tkk7.com/lihao336/archive/2011/05/26/351120.htmlcalvincalvinThu, 26 May 2011 10:12:00 GMThttp://m.tkk7.com/lihao336/archive/2011/05/26/351120.htmlhttp://m.tkk7.com/lihao336/comments/351120.htmlhttp://m.tkk7.com/lihao336/archive/2011/05/26/351120.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/351120.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/351120.htmlhere document是一D带有特D目的的代码D? 它用IO重定向的形式一个命令序列传递到一个交互程序或者命令中, 比如frpQcat或?i class="FIRSTTERM">ex文本~辑?
interactive-program <<delimiter
command #1
command #2
...
delimiter

默认情况下,变量会被替换Q?br /> $ cat << EOF
 > Working dir $PWD
 > EOF
 Working dir /home/user

如果delimiter用双引号引v来,则不会有变量替换Q?br /> $ cat << "EOF"
 > Working dir $PWD
 > EOF
 Working dir $PWD

重定?W号 << 可以使用 <<- Q在q种情况下,heredoc 文本中的前导 tab 字符会被删除Q但是空g会被删除Q?br />
注意Q?br />l束标记前一定不能有MI格或者tabQ否则执行失败!

heredoc 另外一个比较有用的是显C消息块Q如Usage信息Q?br />
cat <<End-of-message
-------------------------------------
This is line 1 of the message.
This is line 2 of the message.
This is line 3 of the message.
This is line 4 of the message.
This is the last line of the message.
-------------------------------------
End-of-message

参考:
http://tldp.org/LDP/abs/html/here-docs.html
http://febird.iteye.com/blog/588509
http://en.wikipedia.org/wiki/Here_document

calvin 2011-05-26 18:12 发表评论
]]>
shell逐行处理文本http://m.tkk7.com/lihao336/archive/2011/05/17/350418.htmlcalvincalvinTue, 17 May 2011 08:59:00 GMThttp://m.tkk7.com/lihao336/archive/2011/05/17/350418.htmlhttp://m.tkk7.com/lihao336/comments/350418.htmlhttp://m.tkk7.com/lihao336/archive/2011/05/17/350418.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/350418.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/350418.html
1 cat data.dat | while read line
2 do
3     echo "File: ${line}"
4 done
5  
6 while read line
7 do
8     echo "File: ${line}"
9 done < data.dat

如果输入文本每行中没有空|也可以采用以下两U进行处理,代码如下Q?br />
1 for line in $(cat data.dat)
2 do
3     echo "File: ${line}"
4 done
5  
6 for line in `cat data.dat`
7 do
8     echo "File: ${line}"
9 done

如输入文本行中包括空|那么会以I格来区分开多个元素Q结果就不是按行d了?br />
当然如果只是单纯的数据或文本的按行读取和昄的话Q用awk命o会更为方ѝ?/span>

http://witmax.cn/shell-read-line.html


calvin 2011-05-17 16:59 发表评论
]]>
Upgrade Alsa(1.0.24) on Ubuntu10.04http://m.tkk7.com/lihao336/archive/2011/05/15/350281.htmlcalvincalvinSun, 15 May 2011 09:37:00 GMThttp://m.tkk7.com/lihao336/archive/2011/05/15/350281.htmlhttp://m.tkk7.com/lihao336/comments/350281.htmlhttp://m.tkk7.com/lihao336/archive/2011/05/15/350281.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/350281.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/350281.html W记本外放有声音Q插上x没有声音

pȝ声卡信息为:
$ lspci -v|grep -i audio
00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 05)
$ cat /proc/asound/card0/codec* | grep Codec
Codec: IDT 92HD81B1X5
Codec: Intel G45 DEVIB

google一通,有帖子说要修?/etc/modprobe.d/alsa-base.conf
加上Q?br /> alias snd-card-0 snd-hda-intel
alias sound-slot-0 snd-hda-intel
options snd-hda-intel model=hp(q里需要找到和你机器匹配的mode)
options snd-hda-intel enable_msi=1

重启后不用?br />
查看机器上的alsa驱动的版本:
cat /proc/asound/version
昄版本?.0.21Q怀疑是不是版本太低了,于是试更新alsa驱动版本Q搜索到q篇帖子Q?br /> http://monespaceperso.org/blog-en/2010/05/02/upgrade-alsa-1-0-23-on-ubuntu-lucid-lynx-10-04/
升alsa驱动?.0.24版本后,故障排除?br /> $ cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.24.
Compiled on May 15 2011 for kernel 2.6.32-31-generic (SMP).

只是不知道ؓ什么设备信息变成了Q?br /> $ cat /proc/asound/card0/codec* | grep Codec
Codec: IDT 92HD81B1X5
Codec: Intel IbexPeak HDMI



calvin 2011-05-15 17:37 发表评论
]]>
tar命o结http://m.tkk7.com/lihao336/archive/2011/05/14/350239.htmlcalvincalvinSat, 14 May 2011 06:03:00 GMThttp://m.tkk7.com/lihao336/archive/2011/05/14/350239.htmlhttp://m.tkk7.com/lihao336/comments/350239.htmlhttp://m.tkk7.com/lihao336/archive/2011/05/14/350239.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/350239.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/350239.html tar命o有几U主要模式:
* 打包Q?br /> tar cf allfile.tar *.jpg

* 解包到指定的目录Q?br /> tar xf allfile.tar -C ~/Pictures

* 列出tar包中的所有文Ӟ
tar tf allfile.tar

* 往已有的tar包中增加新文Ӟ
tar rf allfile.tar *.png

使用tar命o处理其它压羃法
* gzip(.tar.gz或?tgz)
tar zcf allfile.tar.gz *.jpg
tar zxf allfile.tar.gz -C ~/Pictures

* bzip2(.tar.bz2或?bz2)
tar jcf allfile.tar.bz2 *.jpg
tar jxf allfile.tar.bz2 -C ~/Pictures

归档里面的所有文件均是相对引用,归档解压~(释放Q在了当前目录。归档文件L释放到当前目录,为的是防止破坏文件系l中重名的文件?br /> 如果惌盖的话,在归档和解压时请使用-P参数Q?br /> tar zcvf mysql.tar.gz -P /var/lib/mysql
tar -Pzxvf mysql.tar.gz(q会覆盖本地?var/lib/mysql目录)

Tar炸弹

d者利用绝对\径,或者“tar -cf bomb.tar *”的方式创徏的tar文gQ然后诱骗受完在根目录下解压Q或者用绝对\径解压。可能受害pȝ上已有的文g被覆盖掉Q或者导致当前工作目录凌׃ 堪,q就是所谓的“tar炸弹”。因此,要养成良好的解压习惯Q?/p>

  • 解压前用“t”查看tar的文件内宏V?/li>
  • 拒绝使用l对路径?/li>
  • 新徏一个时子目录Q然后在q个子目录里解压?/li>



calvin 2011-05-14 14:03 发表评论
]]>
hide title bar firefox 4.0.1 on Ubuntu linuxhttp://m.tkk7.com/lihao336/archive/2011/05/11/350040.htmlcalvincalvinWed, 11 May 2011 14:25:00 GMThttp://m.tkk7.com/lihao336/archive/2011/05/11/350040.htmlhttp://m.tkk7.com/lihao336/comments/350040.htmlhttp://m.tkk7.com/lihao336/archive/2011/05/11/350040.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/350040.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/350040.html 下蝲userChromeJS插gQhttp://downloads.mozdev.org/userchromejs/userChromeJS-1.3.xpi
~辑Q?br /> ~/.mozilla/firefox/XXXXXX.default/chrome/userChrome.jsQ?br />
(function() {
var win_ctrl = document.getElementById("window-controls");
win_ctrl.setAttribute("fullscreencontrol", "false");
win_ctrl.setAttribute("hidden", "false");

var mainWindow = document.getElementById("main-window");
mainWindow.setAttribute("hidechrome", "true");

})();

That's all.

calvin 2011-05-11 22:25 发表评论
]]>
用touchpadhttp://m.tkk7.com/lihao336/archive/2011/05/04/349460.htmlcalvincalvinTue, 03 May 2011 17:13:00 GMThttp://m.tkk7.com/lihao336/archive/2011/05/04/349460.htmlhttp://m.tkk7.com/lihao336/comments/349460.htmlhttp://m.tkk7.com/lihao336/archive/2011/05/04/349460.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/349460.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/349460.html xinput --list

查找触摸板的idQ?br /> ?Virtual core pointer id=2 [master pointer (3)]
? ?Virtual core XTEST pointer id=4 [slave pointer (2)]
? ?USB Optical Mouse id=10 [slave pointer (2)]
? ?PS/2 Synaptics TouchPad id=13 [slave pointer (2)]
? ?Macintosh mouse button emulation id=14 [slave pointer (2)]
?Virtual core keyboard id=3 [master keyboard (2)]
?Virtual core XTEST keyboard id=5 [slave keyboard (3)]
?Power Button id=6 [slave keyboard (3)]
?Video Bus id=7 [slave keyboard (3)]
?Video Bus id=8 [slave keyboard (3)]
?Power Button id=9 [slave keyboard (3)]
?HP Webcam-101 id=11 [slave keyboard (3)]
?AT Translated Set 2 keyboard id=12 [slave keyboard (3)]

触摸板的ID?3Q?br /> 用Q?br /> 代码:
xinput set-prop 13 "Device Enabled" 0

启用Q?br /> 代码:
xinput set-prop 13 "Device Enabled" 1


calvin 2011-05-04 01:13 发表评论
]]>
shell字符串比?/title><link>http://m.tkk7.com/lihao336/archive/2011/04/13/348234.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Wed, 13 Apr 2011 10:04:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2011/04/13/348234.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/348234.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2011/04/13/348234.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/348234.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/348234.html</trackback:ping><description><![CDATA[<span id="7979z97" class="Apple-style-span" style="border-collapse: separate; color: #000000; font-family: 'WenQuanYi Micro Hei'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span id="rxzhh71" class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23px; ">比较两个字符串是否相{的办法是:<span id="7j9jnn9" class="Apple-converted-space"> </span><br /> if [ "$test"x = "test"x ]; then<br /> q里的关键有几点Q?br /> 1 使用单个{号Q也可以使用两个{号<br /> 2 注意到等号两边各有一个空|q是unix shell的要?br /> 3 注意?$test"x最后的xQ这是特意安排的Q因为当$test为空的时候,上面的表辑ּ变成了x = testxQ显然是不相{的。而如果没有这个xQ表辑ּ׃报错Q[: =: unary operator expected<br /> <br /> 以上在android shell下不能运行,android shell不认识?br /> </span></span> <img src ="http://m.tkk7.com/lihao336/aggbug/348234.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2011-04-13 18:04 <a href="http://m.tkk7.com/lihao336/archive/2011/04/13/348234.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu安装sun-java5-jdkhttp://m.tkk7.com/lihao336/archive/2011/03/17/346459.htmlcalvincalvinThu, 17 Mar 2011 04:58:00 GMThttp://m.tkk7.com/lihao336/archive/2011/03/17/346459.htmlhttp://m.tkk7.com/lihao336/comments/346459.htmlhttp://m.tkk7.com/lihao336/archive/2011/03/17/346459.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/346459.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/346459.html
1.~辑/etc/apt/sources.list文gQ将安装源更改ؓUbuntu 9.04的安装源为:

deb http://archive.Ubuntu.com/ubuntu/ jaunty main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ jaunty-security main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ jaunty-updates main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ jaunty-proposed main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ jaunty main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ jaunty-security main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ jaunty-updates main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ jaunty-proposed main restricted universe multiverse

2. sudo apt-get install sun-java5-jdk


calvin 2011-03-17 12:58 发表评论
]]>
[转]ioctl函数的作?/title><link>http://m.tkk7.com/lihao336/archive/2011/03/03/345548.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Wed, 02 Mar 2011 16:28:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2011/03/03/345548.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/345548.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2011/03/03/345548.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/345548.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/345548.html</trackback:ping><description><![CDATA[<strong>Ҏ的read,write, 当你用readQwrite不能完成某一功能Ӟqioctl</strong><br /> <br /> [转蝲]来源http://www.linuxeden.com/edu/doctext.php?docid=1860<br /> <br /> 我这里说的ioctl函数是在驱动E序里的Q因为我不知道还有没有别的场合用CioctlQ?br /> 所以就规定了我们讨论的范围。ؓ什么要写篇文章呢,是因为我前一阵子被ioctll搞?br /> 了,q几天才弄明白它Q于是在q里清理一下头脑?<br /> <br /> 一?什么是ioctl?<br /> ioctl是设备驱动程序中对设备的I/O通道q行理的函数。所谓对I/O通道q行理Q就<br /> 是对讑֤的一些特性进行控Ӟ例如串口的传输L特率、马辄转速等{。它的调用个?br /> 如下Q?<br /> int ioctl(int fd, ind cmd, …)Q?<br /> 其中fd是用户E序打开讑֤时用open函数q回的文件标C符Qcmd是用户E序对设<br /> 备的控制命oQ至于后面的省略P那是一些补充参敎ͼ一般最多一个,有或没有是和<br /> cmd的意义相关的?<br /> ioctl函数是文件结构中的一个属性分量,是说如果你的驱动程序提供了对ioctl的支<br /> 持,用户可以在用户E序中用ioctl函数控制讑֤的I/O通道?【所以说q些cmd不能和内怸的相同,否则有冲突了?br /> <br /> 二?ioctl的必要?<br /> 如果不用ioctl的话Q也可以实现对设备I/O通道的控Ӟ但那是蛮拧了。例如,我们?br /> 以在驱动E序中实现write的时候检查一下是否有ҎU定的数据流通过Q如果有的话Q?br /> 那么后面p着控制命oQ一般在socket~程中常常这样做Q。但是如果这样做的话Q会<br /> D代码分工不明Q程序结构؜乱,E序员自׃会头昏眼q?<br /> 所以,我们׃用ioctl来实现控制的功能。要CQ用L序所作的只是通过命o码告<br /> 诉驱动程序它惛_什么,至于怎么解释q些命o和怎么实现q些命oQ这都是驱动E序?br /> 做的事情?<br /> <br /> 三?ioctl如何实现 <br /> q是一个很ȝ的问题,我是能省则省。要说清楚它Q没有四五千字是不行的,所以我q?br /> 里是不可能把它说得非常清楚了Q不q如果有读者对用户E序怎么和驱动程序联pv来感<br /> 兴趣的话Q可以看我前一阵子写的《write的奥U》。读者只要把write换成ioctlQ就?br /> 道用L序的ioctl是怎么和驱动程序中的ioctl实现联系在一L了?<br /> 我这里说一个大概思\Q因为我觉得《Linux讑֤驱动E序》这本书已经说的非常清楚<br /> 了,但是得化一些时间来看?<br /> 在驱动程序中实现的ioctl函数体内Q实际上是有一个switch{case}l构Q每一个case?br /> 应一个命令码Q做Z些相应的操作。怎么实现q些操作Q这是每一个程序员自己的事<br /> 情,因ؓ讑֤都是特定的,q里也没法说。关键在于怎么Ll命令码Q因为在ioctl?br /> 命o码是唯一联系用户E序命o和驱动程序支持的途径?<br /> 命o码的l织是有一些讲I的Q因为我们一定要做到命o和设备是一一对应的,q样才不<br /> 会将正确的命令发l错误的讑֤Q或者是把错误的命o发给正确的设备,或者是把错误的<br /> 命o发给错误的设备。这些错误都会导致不可预料的事情发生Q而当E序员发Cq些?br /> 怪的事情的时候,再来调试E序查找错误Q那是非常困难的事情?<br /> 所以在Linux核心中是q样定义一个命令码的组l结构: <br /> ____________________________________<br /> | 讑֤cd | 序列?| 方向 |数据寸|<br /> |----------|--------|------|--------|<br /> | 8 bit | 8 bit |2 bit |8~14 bit|<br /> |----------|--------|------|--------|<br /> <br /> q样一来,<strong>一个命令就变成了一个整数Ş式的命o码。但是命令码非常的不直观Q所?br /> Linux Kernel中提供了一些宏Q这些宏可根据便于理解的字符串生成命令码Q或者是?br /> 命o码得C些用户可以理解的字符串以标明q个命o对应的设备类型、设备序列号、数<br /> 据传送方向和数据传输寸?/strong><br /> <br /> q些宏我׃在这里解释了Q具体的形式误者察看Linux核心源代码中的和Q文仉l?br /> 除了q些宏完整的定义。这里我只多说一个地方,那就?qL"?<br /> qL是一个字母,数据长度也是8Q所以就用一个特定的字母来标明设备类型,q和用一<br /> 个数字是一LQ只是更加利于记忆和理解。就是这P再没有更复杂的了?<br /> 更多的说了也没有Q读者还是看一看源代码吧,推荐各位阅读《Linux 讑֤驱动E序》所<br /> 带源代码中的short一例,因ؓ它比较短,功能比较单,可以看明白ioctl的功能和l?br /> 节?<br /> <br /> 四?cmd参数如何得出 <br /> q里实要说一_cmd参数在用L序端׃些宏Ҏ讑֤cd、序列号、传送方向?br /> 数据寸{生成,q个整数通过pȝ调用传递到内核中的驱动E序Q再由驱动程序用解<br /> 码宏从这个整C得到讑֤的类型、序列号、传送方向、数据尺寸等信息Q然后通过<br /> switch{case}l构q行相应的操作?<br /> 要透彻理解Q只能是通过阅读源代码,我这文章实际上只是一个引子。Cmd参数的组l?br /> q是比较复杂的,我认搞熟它还是得׃时间的Q但是这是值得的,驱动E序中最<br /> 隄是对中断的理解?<br /> <br /> 五?结 <br /> ioctl其实没有什么很隄东西需要理解,关键是理解cmd命o码是怎么在用L序里生成<br /> q在驱动E序里解析的Q程序员最主要的工作量在switch{case}l构中,因ؓ对设备的<br /> I/O控制都是通过q一部分的代码实现的?<br /> <br /> 参考资料: <br /> 1Q《Linux 讑֤驱动E序》,鲁宾DQ中国电力出版社?<br /> 2Q《write的奥U》,colyQ真情流?202.204.7.235)->电脑技?>Linux技术? <img src ="http://m.tkk7.com/lihao336/aggbug/345548.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2011-03-03 00:28 <a href="http://m.tkk7.com/lihao336/archive/2011/03/03/345548.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]ZFrameBuffer的直接写?/title><link>http://m.tkk7.com/lihao336/archive/2011/03/03/345547.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Wed, 02 Mar 2011 16:26:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2011/03/03/345547.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/345547.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2011/03/03/345547.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/345547.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/345547.html</trackback:ping><description><![CDATA[<br /> 1.FrameBuffer配置?00x600x16色的昄模式<br /> ?boot/grub/menu.lst中的kernel加入vga=0x314<br /> //test.c<br /> <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">unistd.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">types.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">stat.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">fcntl.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> argc,</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">**</span><span style="color: #000000;">argv){<br />  </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> fb_fd</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />  </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">fbdev</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">/dev/fb0</span><span style="color: #000000;">"</span><span style="color: #000000;">;<br />  </span><span style="color: #0000ff;">if</span><span style="color: #000000;">((fd_fd</span><span style="color: #000000;">=</span><span style="color: #000000;">open(fbdev,O_RDWR))</span><span style="color: #000000;"><</span><span style="color: #000000;">0</span><span style="color: #000000;">){<br />   printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">open FrameBuffer device failed.</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">  </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />  }<br />  printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">open FrameBuffer device successfully!</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> close(fb_fd);<br /> }</span></div> <br /> ~译后执行一下,看看当前内核是否支持FrameBuffer机制.<br /> 讑֤打开成功后要获取相当的参敎ͼ使用ioctlQ会填充以下l构体,<br /> 在linux/fb.h中定义的<br /> struct fb_fix_screeninfo<br /> struct fb_var_screeninfo<br /> struct fb_cmap<br /> 从fs.h中可看出<br /> <br /> #define FBIOGET_VSCREENINFO 0x4600<br /> #define FBIOGET_FSCREENINFO 0x4602<br /> <br /> 我们qq两条命令获取相当的参数信息<br /> //test.c<br /> <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">unistd.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">types.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">stat.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">fcntl.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">linux</span><span style="color: #000000;">/</span><span style="color: #000000;">fb.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> argc,</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">**</span><span style="color: #000000;">argv){<br />  </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> fb_fd</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />  </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">env</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">/dev/fb0</span><span style="color: #000000;">"</span><span style="color: #000000;">;<br />  </span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> fb_fix_screeninfo fb_fixinfo;<br />  </span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> fb_var_screeninfo fb_varinfo;<br />  </span><span style="color: #0000ff;">if</span><span style="color: #000000;">((fb_fd</span><span style="color: #000000;">=</span><span style="color: #000000;">open(env,O_RDWR))</span><span style="color: #000000;"><</span><span style="color: #000000;">0</span><span style="color: #000000;">){<br />   printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Error:open FrameBuffer device:%s</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,env);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">  </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />  }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br />   printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">OK:open FrameBuffer device:%s</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,env);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> }<br />  </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(ioctl(fb_fd,FBIOGET_FSCREENINFO,</span><span style="color: #000000;">&</span><span style="color: #000000;">fb_fixinfo)</span><span style="color: #000000;">==-</span><span style="color: #000000;">1</span><span style="color: #000000;">){<br />   printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Error:FBIOGET_FSCREENINFO</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">  </span><span style="color: #0000ff;">goto</span><span style="color: #000000;"> fail;<br />  }<br />  printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ioctl FBIOGET_FSCREENINFO ok</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">id=%s</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.id);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">smem_start=%#x</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.smem_start);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">mem_len=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.smem_len);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">type=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.type);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">type_aux=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.type_aux);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">visual=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.visual);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">xpanstep=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.xpanstep);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ypanstep=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.ypanstep);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ywrapstep=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.ywrapstep);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">line_length=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.line_length);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">mmio_start=%#x</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.mmio_start);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">mmio_len=%#x</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.mmio_len);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">accel=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.accel);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[0]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.reserved[0]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[1]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.reserved[1]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[2]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_fixinfo.reserved[2]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(ioctl(fb_fd,FBIOGET_VSCREENINFO,</span><span style="color: #000000;">&</span><span style="color: #000000;">fb_varinfo)</span><span style="color: #000000;">==-</span><span style="color: #000000;">1</span><span style="color: #000000;">){<br />   printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Error:ioctl:FBIOGET_VSCREENINFO</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">  </span><span style="color: #0000ff;">goto</span><span style="color: #000000;"> fail;<br />  }<br />  printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ioctl FBIOGET_VSCREENINFO ok</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">xres=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.xres);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">yres=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.yres);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">xres_virtual=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.xres_virtual);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">yres_virtual=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.yres_virtual);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">xoffset=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.xoffset);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">yoffset=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.yoffset);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">bits_per_pixel=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.bits_per_pixel);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">grayscale=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.grayscale);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">red=%#x</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.red);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">green=%#x</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.green);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">blue=%#x</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.blue);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">transp=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.transp);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">nonstd=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.nonstd);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">activate=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.activate);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">height=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.height);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">width=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.width);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">accel_flags=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.accel_flags);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">pixclock=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.pixclock);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">left_margin=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.left_margin);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">right_margin=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.right_margin);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">upper_margin=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.upper_margin);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">lower_margin=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.lower_margin);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">hsync_len=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.hsync_len);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">vsync_len=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.vsync_len);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">sync=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.sync);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">vmode=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.vmode);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">rotate=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.rotate);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[0]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.reserved[0]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[1]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.reserved[1]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[2]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.reserved[2]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[3]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.reserved[3]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">reserved[4]=%d</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">,fb_varinfo.reserved[4]);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;"> <br />  close(fb_fd);<br />  </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br /> fail:<br />  close(fb_fd);<br />  </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br /> }</span></div> <br /> 从输出结果来看xres=800,yres=600,从这里可以看个FrameBuffer的最大gؓ800x600<br /> 得到framebuffer的信息后Q我们开辟一D内存,然后映射framebuffer的内?<br /> q样当向q段内存写入信息Ӟframebuffer中就会写入相同的数据Q也׃有数据表C的囑փ昄在屏q上?br /> 例:在屏q上昄一个渐变窗?br /> <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">unistd.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">types.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">stat.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">fcntl.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">linux</span><span style="color: #000000;">/</span><span style="color: #000000;">fb.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">errno.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">mman.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">stdlib.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> #include </span><span style="color: #000000;"><</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">ioctl.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> flush_screen(</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">buf,</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">framebuf,</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> width,</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> height);<br /> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> argc, </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">argv[])<br /> {<br />         </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> fb_fd</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />         </span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> fb_fix_screeninfo fb_fixinfo;<br />         </span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> fb_var_screeninfo fb_varinfo;<br />     </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">fb_addr;<br />     unsigned </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> fb_size;<br />     </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">buffer;<br />     </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />        </span><span style="color: #0000ff;">if</span><span style="color: #000000;">((fb_fd</span><span style="color: #000000;">=</span><span style="color: #000000;">open(</span><span style="color: #000000;">"</span><span style="color: #000000;">/dev/fb0</span><span style="color: #000000;">"</span><span style="color: #000000;">, O_RDWR))</span><span style="color: #000000;"><</span><span style="color: #000000;">0</span><span style="color: #000000;">){<br />          printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">open framebuffer device failed.</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">         </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />        }<br />     printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">open framebuffer device ok</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">     <br />         </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(ioctl(fb_fd, FBIOGET_FSCREENINFO, </span><span style="color: #000000;">&</span><span style="color: #000000;">fb_fixinfo) </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br />         {<br />                 printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ioctl FBIOGET_FSCREENINFO failed.</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">                </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />         }<br />     printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ioctl FBIOGET_FSCREENINFO ok</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">        </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(ioctl(fb_fd, FBIOGET_VSCREENINFO, </span><span style="color: #000000;">&</span><span style="color: #000000;">fb_varinfo) </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br />         {<br />                 printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ioctl FBIOGET_VSCREENINFO failed.</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">                </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />         }<br />     printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">ioctl FBIOGET_VSCREENINFO ok</span><span style="color: #000000;">"</span><span style="color: #000000;">n</span><span style="color: #000000;">"</span><span style="color: #000000;">);</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">        fb_size </span><span style="color: #000000;">=</span><span style="color: #000000;"> fb_varinfo.yres </span><span style="color: #000000;">*</span><span style="color: #000000;"> fb_fixinfo.line_length;   </span><span style="color: #008000;">//</span><span style="color: #008000;">整个framebuffer的大?/span><span style="color: #008000;"><br /> </span><span style="color: #000000;">        fb_addr </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">)mmap(NULL, fb_size, PROT_READ</span><span style="color: #000000;">|</span><span style="color: #000000;">PROT_WRITE,MAP_SHARED, fb_fd, </span><span style="color: #000000;">0</span><span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">framebuffer的物理地址映射到进E地址I间</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">        buffer</span><span style="color: #000000;">=</span><span style="color: #000000;">(</span><span style="color: #0000ff;">char</span><span style="color: #000000;">*</span><span style="color: #000000;">)malloc(fb_varinfo.yres </span><span style="color: #000000;">*</span><span style="color: #000000;"> fb_fixinfo.line_length); </span><span style="color: #008000;">//</span><span style="color: #008000;">甌一个缓冲区Q采用双~冲方式</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;">(i</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;i</span><span style="color: #000000;"><=</span><span style="color: #000000;">0xff</span><span style="color: #000000;">;i</span><span style="color: #000000;">+=</span><span style="color: #000000;">0x0f</span><span style="color: #000000;">){<br />           memset(buffer,i,fb_varinfo.yres </span><span style="color: #000000;">*</span><span style="color: #000000;"> fb_fixinfo.line_length);<br />           flush_screen(buffer,fb_addr,fb_varinfo.xres,fb_varinfo.yres);<br />       sleep(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />     }<br />         </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">fb_addr)<br />                 exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />         free(buffer);<br />         </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br /> }<br /> <br /> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> flush_screen(</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">buf,</span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">framebuf,</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> width,</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> height)<br /> {<br />                 </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">t_data </span><span style="color: #000000;">=</span><span style="color: #000000;"> buf;<br />                 </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">t_fb_addr </span><span style="color: #000000;">=</span><span style="color: #000000;"> framebuf;<br />                 </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> bytew</span><span style="color: #000000;">=</span><span style="color: #000000;"> width</span><span style="color: #000000;"><<</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />                 </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(</span><span style="color: #000000;">--</span><span style="color: #000000;">height </span><span style="color: #000000;">>=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">)<br />                 {<br />                         memcpy(t_fb_addr,t_data,bytew);<br />                         t_fb_addr </span><span style="color: #000000;">+=</span><span style="color: #000000;"> width;<br />                         t_data </span><span style="color: #000000;">+=</span><span style="color: #000000;"> width;<br />                 }<br /> }</span></div> <br /> ~译后,q行看一下结果,量在字W模式下q行<br /> vi /etc/inittab运行别改?<br /> 重启后,q行一下看看结果?br /> <br /> 参考链接:<br /> <strong><a href="">http://m.tkk7.com/lihao336/admin/EditPosts.aspx?postid=345547</a></strong><br /> <img src ="http://m.tkk7.com/lihao336/aggbug/345547.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2011-03-03 00:26 <a href="http://m.tkk7.com/lihao336/archive/2011/03/03/345547.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]Linux的~冲讑֤(Framebuffer)?/title><link>http://m.tkk7.com/lihao336/archive/2011/03/03/345544.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Wed, 02 Mar 2011 16:19:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2011/03/03/345544.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/345544.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2011/03/03/345544.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/345544.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/345544.html</trackback:ping><description><![CDATA[Linux的~冲讑֤(Framebuffer)?br /> <br /> ?~冲QframebufferQ是Linux为显C备提供的一个接口,把显存抽象后的一U设备,他允怸层应用程序在囑Ş模式下直接对昄~冲行读 写操作。这U操作是抽象的,l一的。用户不必关心物理显存的位置、换|制等{具体细节。这些都是由Framebuffer讑֤驱动来完成的?br /> 帧缓冲驱动的应用q泛Q在linux的桌面系l中QXwindow服务器就是利用~冲q行H口的绘制。尤其是通过帧缓冲可昄汉字炚wQ成为Linux汉化的唯一可行Ҏ? <br />     Linux FrameBuffer 本质上只是提供了对图形设备的g抽象Q在开发者看来,FrameBuffer 是一块显C缓存,往昄~存中写入特定格式的数据意味着向屏q输出内宏V所以说FrameBuffer是一块白ѝ例如对于初始化?6 位色的FrameBuffer 来说Q?FrameBuffer中的两个字节代表屏幕上一个点Q从上到下,从左臛_Q屏q位|与内存地址是顺序的U性关pR?br />     帧缓存可以在pȝ存储?内存)的Q意位|,视频控制器通过讉K帧缓存来h屏幕?帧缓存也叫刷新缓?Frame buffer ?refresh buffer, q里的(frame)是指整个屏幕范围? <br />     帧缓存有个地址Q是在内存里。我们通过不停的向frame buffer中写入数据, 昄控制器就自动的从frame buffer中取数据q显C出来。全部的囑Ş都共享内存中同一个~存?br />     CPU指定昄控制器工作,则显C控制器ҎCPU的控制到指定的地方去取数??指oQ?目前的数据一般是从显存里取, 如果昑֭里存不下Q则从内存里取, 内存也放不下Q则从硬盘里取,当然也不是内存放不下Q而是Z节省内存的话Q可以放在硬盘里Q然后通过 指o控制昄控制器去取。~存 Frame BufferQ里面存储的东西是一帧一帧的Q?昑֍会不停的hFrame Buffer, q每一帧如果不捕获的话Q?则会被丢弃,也就是说是实时的。这每一帧不是保存在内存还是显存里Q?都是一个显性的信息Q这每一帧假设是800x600的分辨率Q?则保存的?00x600个像素点Q和颜色倹{?br />     昄器可以显C无限种颜色Q目前普通电脑的昑֍可以昄32位真彩?4位真彩?6位增?56艌Ӏ除256色外Q大家可以根据自q需要在昑֍的允许范围之内随意选择。很多用h一U错误概念,认ؓ256色是最高的选项Q而实际上正好相反?56色是最低的选项Q它已不能满_色图像的昄需要?6位不?6U颜Ԍ而是2?6ơ^?256×256)U颜Ԍ?56色就?56(2?ơ^?U颜艌Ӏ所?6位色要比256色丰富得多?<br />     帧缓冲设备对应的讑֤文g?/dev/fb*Q如果系l有多个昄卡,Linux下还可支持多个~冲讑֤Q最多可?2 个,分别?dev/fb0?dev/fb31Q?dev/fb则ؓ当前~省的~冲讑֤Q通常指向/dev/fb0。当然在嵌入式系l中支持一个显 C备就够了。~冲讑֤为标准字W设备,主设备号?9Q次讑֤号则??1。分别对?dev/fb0-/dev/fb31。通过/dev/fbQ?应用E序的操作主要有q几U:  <br /> 1Q??写(read/writeQ?dev/fbQ相当于?写屏q缓冲区。例如用 cp /dev/fb0 tmp命o可将当前屏幕的内Ҏ贝到一个文件中Q而命令cp tmp > /dev/fb0 则将囑Ş文gtmp昄在屏q上?<br /> 2Q映(mapQ操作:<strong><span style="color: #ff0000;">׃Linux工作在保护模式,每个应用E序都有自己的虚拟地址I间Q在应用E序中是不能直接讉K物理~冲区地址的。ؓ此, Linux在文件操?file_operationsl构中提供了mmap函数Q可文件的内容映射到用L间。对于~冲讑֤Q则可通过映射操作Q可屏q缓冲区的物理地址 映射到用L间的一D虚拟地址中,之后用户可以通过dq段虚拟地址讉K屏幕~冲区,在屏q上l图?/span></strong>。实际上Q用~冲讑֤的应用程序都是通过映射操作来显C图形的。由于映操作都是由内核来完成,下面我们看刎ͼ帧缓冲驱动留l开发h员的工作q不多?br /> 3Q?I/O控制Q对于~冲讑֤Q对讑֤文g的ioctl操作可读?讄昄讑֤及屏q的参数Q如分L率,昄颜色敎ͼ屏幕大小{等。ioctl的操作是由底层的驱动E序来完成的? <br /> 在应用程序中Q操?dev/fb的一般步骤如下:<br />   <br /> <strong>1Q?打开/dev/fb讑֤文g? <br /> 2Q?用ioctrl操作取得当前昄屏幕的参敎ͼ如屏q分辨率Q每个像素点的比Ҏ。根据屏q参数可计算屏幕~冲区的大小? <br /> 3Q?屏q缓冲区映射到用L间? <br /> 4Q?映射后就可以直接d屏幕~冲区,q行l图和图片显CZ?</strong><br />  <br /> 典型E序D如下:  <br /> <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><span style="color: #008080;"> 1</span> <span style="color: #000000;">#include<br /> </span><span style="color: #008080;"> 2</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> main()<br /> </span><span style="color: #008080;"> 3</span> <span style="color: #000000;">{<br /> </span><span style="color: #008080;"> 4</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> fbfd </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br /> </span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">struct</span><span style="color: #000000;"> fb_var_screeninfo vinfo;<br /> </span><span style="color: #008080;"> 6</span> <span style="color: #0000ff;">struct</span><span style="color: #000000;"> fb_fix_screeninfo finfo;<br /> </span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> screensize </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br /> </span><span style="color: #008080;"> 8</span> <span style="color: #008000;">/*</span><span style="color: #008000;">打开讑֤文g</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /> </span><span style="color: #008080;"> 9</span> <span style="color: #000000;">fbfd </span><span style="color: #000000;">=</span><span style="color: #000000;"> open(</span><span style="color: #000000;">"</span><span style="color: #000000;">/dev/fb0</span><span style="color: #000000;">"</span><span style="color: #000000;">, O_RDWR);<br /> </span><span style="color: #008080;">10</span> <span style="color: #008000;">/*</span><span style="color: #008000;">取得屏幕相关参数</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /> </span><span style="color: #008080;">11</span> <span style="color: #000000;">ioctl(fbfd, FBIOGET_FSCREENINFO, </span><span style="color: #000000;">&</span><span style="color: #000000;">finfo);<br /> </span><span style="color: #008080;">12</span> <span style="color: #000000;">ioctl(fbfd, FBIOGET_VSCREENINFO, </span><span style="color: #000000;">&</span><span style="color: #000000;">vinfo);<br /> </span><span style="color: #008080;">13</span> <span style="color: #008000;">/*</span><span style="color: #008000;">计算屏幕~冲区大?/span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /> </span><span style="color: #008080;">14</span> <span style="color: #000000;">screensize </span><span style="color: #000000;">=</span><span style="color: #000000;"> vinfo.xres </span><span style="color: #000000;">*</span><span style="color: #000000;"> vinfo.yres </span><span style="color: #000000;">*</span><span style="color: #000000;"> vinfo.bits_per_pixel </span><span style="color: #000000;">/</span><span style="color: #000000;"> </span><span style="color: #000000;">8</span><span style="color: #000000;">;<br /> </span><span style="color: #008080;">15</span> <span style="color: #008000;">/*</span><span style="color: #008000;">映射屏幕~冲区到用户地址I间</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /> </span><span style="color: #008080;">16</span> <span style="color: #000000;">fbp</span><span style="color: #000000;">=</span><span style="color: #000000;">(</span><span style="color: #0000ff;">char</span><span style="color: #000000;">*</span><span style="color: #000000;">)mmap(</span><span style="color: #000000;">0</span><span style="color: #000000;">,screensize,PROT_READ</span><span style="color: #000000;">|</span><span style="color: #000000;">PROT_WRITE,MAP_SHARED, fbfd, </span><span style="color: #000000;">0</span><span style="color: #000000;">);<br /> </span><span style="color: #008080;">17</span> <span style="color: #008000;">/*</span><span style="color: #008000;">下面可通过fbp指针d~冲?/span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /> </span><span style="color: #008080;">18</span> <span style="color: #000000;">}</span></div> <br /> <img src ="http://m.tkk7.com/lihao336/aggbug/345544.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2011-03-03 00:19 <a href="http://m.tkk7.com/lihao336/archive/2011/03/03/345544.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用mutt发送邮?/title><link>http://m.tkk7.com/lihao336/archive/2011/01/25/343466.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Mon, 24 Jan 2011 18:14:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2011/01/25/343466.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/343466.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2011/01/25/343466.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/343466.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/343466.html</trackback:ping><description><![CDATA[1.安装msmtp<br /> 配置~/.msmtprc<br /> account default<br /> host smtp.yourprovider.example<br /> from you@yourprovider.example<br /> <br /> auth login<br /> user JoeExample<br /> password Secret<br /> <br /> 可用msmtp --host=smtp.yourprovider.example --serverinfo 来查看server的信?br /> <br /> 2.安装mutt<br /> 配置?.muttrc<br /> <br /> set sendmail="/usr/bin/msmtp"<br /> set from=you@yourprovider.example<br /> set editor=vim<br /> <br /> <img src ="http://m.tkk7.com/lihao336/aggbug/343466.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2011-01-25 02:14 <a href="http://m.tkk7.com/lihao336/archive/2011/01/25/343466.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Shell History (快速用Linux命o)http://m.tkk7.com/lihao336/archive/2010/10/11/334367.htmlcalvincalvinMon, 11 Oct 2010 07:44:00 GMThttp://m.tkk7.com/lihao336/archive/2010/10/11/334367.htmlhttp://m.tkk7.com/lihao336/comments/334367.htmlhttp://m.tkk7.com/lihao336/archive/2010/10/11/334367.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/334367.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/334367.html阅读全文

calvin 2010-10-11 15:44 发表评论
]]>
使用linnm为emacsd行号http://m.tkk7.com/lihao336/archive/2010/10/08/333953.htmlcalvincalvinFri, 08 Oct 2010 01:35:00 GMThttp://m.tkk7.com/lihao336/archive/2010/10/08/333953.htmlhttp://m.tkk7.com/lihao336/comments/333953.htmlhttp://m.tkk7.com/lihao336/archive/2010/10/08/333953.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/333953.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/333953.html阅读全文

calvin 2010-10-08 09:35 发表评论
]]>
BASH 中的字符串处?/title><link>http://m.tkk7.com/lihao336/archive/2010/09/24/332773.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Fri, 24 Sep 2010 13:21:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2010/09/24/332773.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/332773.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2010/09/24/332773.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/332773.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/332773.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://m.tkk7.com/lihao336/archive/2010/09/24/332773.html'>阅读全文</a><img src ="http://m.tkk7.com/lihao336/aggbug/332773.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2010-09-24 21:21 <a href="http://m.tkk7.com/lihao336/archive/2010/09/24/332773.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell /bin/bash^M: bad interpreter错误解决http://m.tkk7.com/lihao336/archive/2010/06/30/324872.htmlcalvincalvinWed, 30 Jun 2010 05:26:00 GMThttp://m.tkk7.com/lihao336/archive/2010/06/30/324872.htmlhttp://m.tkk7.com/lihao336/comments/324872.htmlhttp://m.tkk7.com/lihao336/archive/2010/06/30/324872.html#Feedback1http://m.tkk7.com/lihao336/comments/commentRss/324872.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/324872.html阅读全文

calvin 2010-06-30 13:26 发表评论
]]>
僉|QZombieQ进E?/title><link>http://m.tkk7.com/lihao336/archive/2010/06/27/324594.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 27 Jun 2010 02:53:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2010/06/27/324594.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/324594.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2010/06/27/324594.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/324594.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/324594.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://m.tkk7.com/lihao336/archive/2010/06/27/324594.html'>阅读全文</a><img src ="http://m.tkk7.com/lihao336/aggbug/324594.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2010-06-27 10:53 <a href="http://m.tkk7.com/lihao336/archive/2010/06/27/324594.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu|络配置相关http://m.tkk7.com/lihao336/archive/2010/06/24/324355.htmlcalvincalvinThu, 24 Jun 2010 12:24:00 GMThttp://m.tkk7.com/lihao336/archive/2010/06/24/324355.htmlhttp://m.tkk7.com/lihao336/comments/324355.htmlhttp://m.tkk7.com/lihao336/archive/2010/06/24/324355.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/324355.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/324355.html阅读全文

calvin 2010-06-24 20:24 发表评论
]]>
文g与目录权?/title><link>http://m.tkk7.com/lihao336/archive/2010/06/18/323760.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Thu, 17 Jun 2010 16:23:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2010/06/18/323760.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/323760.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2010/06/18/323760.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/323760.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/323760.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://m.tkk7.com/lihao336/archive/2010/06/18/323760.html'>阅读全文</a><img src ="http://m.tkk7.com/lihao336/aggbug/323760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2010-06-18 00:23 <a href="http://m.tkk7.com/lihao336/archive/2010/06/18/323760.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell 快捷?/title><link>http://m.tkk7.com/lihao336/archive/2010/06/17/323758.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Thu, 17 Jun 2010 14:48:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2010/06/17/323758.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/323758.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2010/06/17/323758.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/323758.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/323758.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://m.tkk7.com/lihao336/archive/2010/06/17/323758.html'>阅读全文</a><img src ="http://m.tkk7.com/lihao336/aggbug/323758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2010-06-17 22:48 <a href="http://m.tkk7.com/lihao336/archive/2010/06/17/323758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>卸蝲KDEhttp://m.tkk7.com/lihao336/archive/2010/05/29/322240.htmlcalvincalvinSat, 29 May 2010 12:54:00 GMThttp://m.tkk7.com/lihao336/archive/2010/05/29/322240.htmlhttp://m.tkk7.com/lihao336/comments/322240.htmlhttp://m.tkk7.com/lihao336/archive/2010/05/29/322240.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/322240.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/322240.html阅读全文

calvin 2010-05-29 20:54 发表评论
]]>
调整Close/Maximize/Minimize 按钮的位|?/title><link>http://m.tkk7.com/lihao336/archive/2010/05/19/321412.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Wed, 19 May 2010 12:52:00 GMT</pubDate><guid>http://m.tkk7.com/lihao336/archive/2010/05/19/321412.html</guid><wfw:comment>http://m.tkk7.com/lihao336/comments/321412.html</wfw:comment><comments>http://m.tkk7.com/lihao336/archive/2010/05/19/321412.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/lihao336/comments/commentRss/321412.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/lihao336/services/trackbacks/321412.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://m.tkk7.com/lihao336/archive/2010/05/19/321412.html'>阅读全文</a><img src ="http://m.tkk7.com/lihao336/aggbug/321412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/lihao336/" target="_blank">calvin</a> 2010-05-19 20:52 <a href="http://m.tkk7.com/lihao336/archive/2010/05/19/321412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>恢复q程会话--screen工具http://m.tkk7.com/lihao336/archive/2010/05/19/321380.htmlcalvincalvinWed, 19 May 2010 07:10:00 GMThttp://m.tkk7.com/lihao336/archive/2010/05/19/321380.htmlhttp://m.tkk7.com/lihao336/comments/321380.htmlhttp://m.tkk7.com/lihao336/archive/2010/05/19/321380.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/321380.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/321380.html阅读全文

calvin 2010-05-19 15:10 发表评论
]]>
Linux下C语言~译器gcc不认识boolcdhttp://m.tkk7.com/lihao336/archive/2010/05/12/320735.htmlcalvincalvinWed, 12 May 2010 10:28:00 GMThttp://m.tkk7.com/lihao336/archive/2010/05/12/320735.htmlhttp://m.tkk7.com/lihao336/comments/320735.htmlhttp://m.tkk7.com/lihao336/archive/2010/05/12/320735.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/320735.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/320735.html阅读全文

calvin 2010-05-12 18:28 发表评论
]]>
umount 时出?Device is busy"的解?[转]http://m.tkk7.com/lihao336/archive/2010/05/11/320536.htmlcalvincalvinMon, 10 May 2010 16:06:00 GMThttp://m.tkk7.com/lihao336/archive/2010/05/11/320536.htmlhttp://m.tkk7.com/lihao336/comments/320536.htmlhttp://m.tkk7.com/lihao336/archive/2010/05/11/320536.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/320536.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/320536.html阅读全文

calvin 2010-05-11 00:06 发表评论
]]>
在emacs下进入shell环境http://m.tkk7.com/lihao336/archive/2010/05/09/320419.htmlcalvincalvinSun, 09 May 2010 13:45:00 GMThttp://m.tkk7.com/lihao336/archive/2010/05/09/320419.htmlhttp://m.tkk7.com/lihao336/comments/320419.htmlhttp://m.tkk7.com/lihao336/archive/2010/05/09/320419.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/320419.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/320419.html阅读全文

calvin 2010-05-09 21:45 发表评论
]]>
Ubuntu 10.04 中文字体问题http://m.tkk7.com/lihao336/archive/2010/05/03/319977.htmlcalvincalvinMon, 03 May 2010 14:57:00 GMThttp://m.tkk7.com/lihao336/archive/2010/05/03/319977.htmlhttp://m.tkk7.com/lihao336/comments/319977.htmlhttp://m.tkk7.com/lihao336/archive/2010/05/03/319977.html#Feedback0http://m.tkk7.com/lihao336/comments/commentRss/319977.htmlhttp://m.tkk7.com/lihao336/services/trackbacks/319977.html阅读全文

calvin 2010-05-03 22:57 发表评论
]]>
վ֩ģ壺 һɫݳѾƷվ| պëƬ߹ۿ| ޶Ƶ| ɫWWWƷƵ| Ƭ߹ۿ| ޹Ʒþþ| ѵҰսƵ| AVѹۿ| ޼Ļ| Ƶ| 9ֻоƷ| ޲Ļ| պƷһҳһ| av߿վ | 7777þĻ| ѹۿɫƬ| Ұ߹ۿƵ| ˾þ¶ۺ| պ| Ƶ88| պӰ߹ۿվ| av÷ۺ| ޾ƷŮ߹ۿ| þþ޾Ʒ| ݺݾþѹۿ| Ļ| һѾƷƵ| ˳ۺվ7777㽶| AV | һ| þþƷž޾Ʒ| ƷƵһ| hƵ߹ۿ| japaneseɫ߿| ˳ŷĻ| ɫվ| A޾VƷ| ȫëƬ| aƬav| ŮƵƵȫƵ | ձѵӰһ|