<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8058632625030346233</id><updated>2024-09-05T22:07:51.005+08:00</updated><category term="makefile"/><category term="linux"/><category term="Programming"/><category term="code"/><category term="signal"/><category term="kernel"/><category term="VIM"/><category term="apache"/><category term="shell_script"/><category term="C"/><category term="GDB"/><category term="IPv6"/><category term="Ldscript"/><category term="Socket Programming"/><category term="andriod"/><category term="camera"/><category term="cmd"/><category term="javascript"/><category term="other"/><category term="php"/><category term="shell"/><category term="u-boot gdb"/><title type='text'>雜記</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>73</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-81608848138297254</id><published>2011-08-11T00:22:00.001+08:00</published><updated>2011-08-11T00:22:45.779+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><title type='text'>kernel- hash list</title><content type='html'>&lt;p&gt;The overall structure of the hash list in kernel is shown as blow.&lt;/p&gt;&lt;p&gt;Here is the data structure.&lt;/p&gt;&lt;pre style=&quot;color: #000020; background: #f6f8ff;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_head &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;first&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;pprev&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/5MTY8rsiaal1pk1Ids2Q9Q?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheKAVvXU-UvvernGWT8PUvCWuabLwfsg4TIuSLxsltYFEA8A9_IF7cBZvBuMF0e9OarPz3GzF3GvrXsR6j6xrAYZitI6JLdrcCqoBAQVORhgBWUG6XtOT-v6O360ZTVa0VfNt2OggaWWQ/s640/all.png&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;197&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Kernel provides some interface to build a whole hash list quickly and they are more useful.&lt;/p&gt;&lt;p&gt;Some figures are illustrated to desrcbie how to use these function calls for the hash list.&amp;nbsp;&lt;/p&gt;&lt;pre style=&quot;color: #000020; background: #f6f8ff;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;inline&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt; hlist_add_head&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_head &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;h&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;first &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; h&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;first&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; first&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;first&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;        first&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    h&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;first &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; n&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;h&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;first&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Insert &amp;nbsp;a node to the head of hash list.&lt;/p&gt;&lt;p&gt;There are 2 case for this operation and please see below.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Case 1:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;no any node exists in the hash list.&lt;br /&gt; &lt;a href=&quot;https://picasaweb.google.com/lh/photo/p00wifAYfEOsaxG8Je52CA?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERs2IFC5KV4frnqZlCdDgGvxuUvb5MuuT0O3Jjj3oujN0-mGZ8JjbnhHAAPS2AANtvcb2TZZIkRdphT56bONTslpnCbVWt3_w7SdvyjZy1LQqBuBJ_e6qwfvFqQ5HZGLdczUPNcLfTs4/s640/hlist_addh1.png&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;507&quot; /&gt;&lt;/a&gt;&lt;br /&gt; Case 2:&lt;/p&gt;&lt;p&gt;Otherwise , there are &amp;nbsp;more than one nodes&amp;nbsp;&amp;nbsp;at least&amp;nbsp;in the list.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/VxycNcNsXbmD6aF-gf2xtQ?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMbDLcjlyxSv5tDh2UBb6wVEpz6HIRkK3nQlfsk4Wm3qbiVNV7bn3gxglWmTj3alHD9GehBwswK4Khy3Jjp9Rw0jH_TCuo5xFhYVK6sNsMascV1jCKG-_CGgDxBe9XTz2Bi0fhOP3mwjc/s640/hlist_addh2.png&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;263&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre style=&quot;color: #000020; background: #f6f8ff;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;inline&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt; hlist_add_before&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;br /&gt;                    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; n&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Add the node &lt;strong&gt;&lt;span style=&quot;color: #993366;&quot;&gt;N&lt;/span&gt;&lt;/strong&gt; before the Node next.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/_XVpLdKY-qzYg_EWa5caDQ?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB7R0nw5OBDU2_N7eOeUu4nIIW8jh-CFcngjCREo2k8h3fX3BDuTDKvmtjYvvWjV4p83R0FcuQC6tepHW103s4ZWfwUCbVNptaX782Qw3fKtSDbnu0v4EVtwSSEJtjdpADgJd1jbsMQ_s/s640/hlist_add_before.png&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;315&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre style=&quot;color: #000020; background: #f6f8ff;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;inline&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt; hlist_add_after&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;br /&gt;                    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;        next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev  &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;next&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Add the node &lt;strong&gt;&lt;span style=&quot;color: #993366;&quot;&gt;Next &lt;/span&gt;&lt;/strong&gt;after node N.&lt;br /&gt; &lt;a href=&quot;https://picasaweb.google.com/lh/photo/Ezi4ZUTPsUPPm5usN-_XEg?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbyS7XUiSPWPk_ABoWj2syRPgYcXlTbETpyGFkxcrh1DjhjLA2yooC92qyFZVQYckrtwfddpYWUaQh5D2le1bHTzSDPSw8baMUhAuO6KrUBxcPrcsNouAZ3nG5ZoW7hgRAFFG0iI4ACUE/s640/hlist_add_after.png&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;315&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre style=&quot;color: #000020; background: #f6f8ff;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;inline&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt; hlist_del&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; hlist_node &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    __hlist_del&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;n&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;next &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; LIST_POISON1&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    n&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;pprev &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; LIST_POISON2&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Remove the node &lt;strong&gt;&lt;span style=&quot;color: #993366;&quot;&gt;N&lt;/span&gt;&lt;/strong&gt; from the list.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://picasaweb.google.com/lh/photo/GyfLiuR99QXqNHD9F_oX4w?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3o4he_hWSBj-KEsne5qLLUx6n-oa-W_xnX6RdGS4e007TvACPBtwkCxLesd8XLvjbLWlJeouN27641BSLlGTEjjyInmMs82-90t2d-CAo_g-dddLE68CioLWEukKvWP5ypzouJSEnXoA/s640/hlist_del.png&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;294&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/81608848138297254/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/08/kernel-hash-list.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/81608848138297254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/81608848138297254'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/08/kernel-hash-list.html' title='kernel- hash list'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheKAVvXU-UvvernGWT8PUvCWuabLwfsg4TIuSLxsltYFEA8A9_IF7cBZvBuMF0e9OarPz3GzF3GvrXsR6j6xrAYZitI6JLdrcCqoBAQVORhgBWUG6XtOT-v6O360ZTVa0VfNt2OggaWWQ/s72-c/all.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-8173336659597926208</id><published>2011-08-09T23:39:00.006+08:00</published><updated>2011-08-10T00:02:27.249+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><title type='text'>Linux kernel - contain_of</title><content type='html'>This marco is mostly used in kernel .&lt;br /&gt;
The figure is&amp;nbsp;illustrated&amp;nbsp;to descible how the marco &quot;contain_of&quot; work.&lt;br /&gt;
&lt;a href=&quot;https://picasaweb.google.com/lh/photo/O5zxgfj9KdSaIlt5WeTWpg?feat=embedwebsite&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;266&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNuAiGJTLjsCkJH2PriLTpndGPEAxQ8cN-7_UiIN1-n44yTGlk_AiOTJsPMIh0M1NS-Wl-2ScQzWu6Poah84eJ1PXjT4L7snGbugdC_i07qHpXTHTI41h3BGmbGjlkXy0I56H1QQadM6o/s640/%2525E7%2525B9%2525AA%2525E5%25259C%2525961.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
The following is the &amp;nbsp;source code using the marco &quot;contain_of&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&#39;color:#000020;background:#f6f8ff;&#39;&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;#&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;include &lt;/span&gt;&lt;span style=&#39;color:#800000; &#39;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#39;color:#40015a; &#39;&gt;stdio.h&lt;/span&gt;&lt;span style=&#39;color:#800000; &#39;&gt;&gt;&lt;/span&gt;

&lt;span style=&#39;color:#004a43; &#39;&gt;#&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;define&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; offsetof&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;TYPE&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; MEMBER&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;size_t&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;TYPE &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;0&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;-&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;&gt;&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;MEMBER&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;
&lt;span style=&#39;color:#004a43; &#39;&gt;#&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;define&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; container_of&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;ptr&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; type&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; member&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;{&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;            \&lt;/span&gt;
&lt;span style=&#39;color:#004a43; &#39;&gt;&amp;#xa0;&amp;#xa0;&amp;#xa0;&amp;#xa0;&amp;#xa0;const typeof&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;type &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;0&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;-&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;&gt;&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;member &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;__mptr &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;=&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;ptr&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;;&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;    \&lt;/span&gt;
&lt;span style=&#39;color:#004a43; &#39;&gt;&amp;#xa0;&amp;#xa0;&amp;#xa0;&amp;#xa0;&amp;#xa0;&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;type &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;char &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;__mptr &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;-&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; offsetof&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;type&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt;member&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#004a43; &#39;&gt; &lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;;&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;}&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;

&lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt;  St_Inner&lt;span style=&#39;color:#406080; &#39;&gt;{&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;int&lt;/span&gt;         dw_a&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
&lt;span style=&#39;color:#406080; &#39;&gt;}&lt;/span&gt;&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;

&lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt; St_Outer &lt;span style=&#39;color:#406080; &#39;&gt;{&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;int&lt;/span&gt;         dw_a&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt; St_Inner    St_b&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;int&lt;/span&gt;         dw_c&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
&lt;span style=&#39;color:#406080; &#39;&gt;}&lt;/span&gt;&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;

     
&lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;int&lt;/span&gt; &lt;span style=&#39;color:#400000; &#39;&gt;main&lt;/span&gt; &lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;
&lt;span style=&#39;color:#406080; &#39;&gt;{&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt; St_Outer  src&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt; St_Outer  &lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;p_dest&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt;  St_Inner &lt;span style=&#39;color:#308080; &#39;&gt;*&lt;/span&gt;p_Inner&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    p_Inner &lt;span style=&#39;color:#308080; &#39;&gt;=&lt;/span&gt; &lt;span style=&#39;color:#308080; &#39;&gt;&amp;amp;&lt;/span&gt;src&lt;span style=&#39;color:#308080; &#39;&gt;.&lt;/span&gt;St_b&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    
    
    p_dest &lt;span style=&#39;color:#308080; &#39;&gt;=&lt;/span&gt; container_of &lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;p_Inner&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;&lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;struct&lt;/span&gt; St_Outer&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt; St_b&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    
    printf &lt;span style=&#39;color:#308080; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#800000; &#39;&gt;&quot;&lt;/span&gt;&lt;span style=&#39;color:#1060b6; &#39;&gt;p_dest &lt;/span&gt;&lt;span style=&#39;color:#0f69ff; &#39;&gt;%x&lt;/span&gt;&lt;span style=&#39;color:#1060b6; &#39;&gt; == src &lt;/span&gt;&lt;span style=&#39;color:#0f69ff; &#39;&gt;%x&lt;/span&gt;&lt;span style=&#39;color:#0f69ff; &#39;&gt;\n&lt;/span&gt;&lt;span style=&#39;color:#800000; &#39;&gt;&quot;&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;p_dest&lt;span style=&#39;color:#308080; &#39;&gt;,&lt;/span&gt;&lt;span style=&#39;color:#308080; &#39;&gt;&amp;amp;&lt;/span&gt;src&lt;span style=&#39;color:#308080; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
    &lt;span style=&#39;color:#200080; font-weight:bold; &#39;&gt;return&lt;/span&gt; &lt;span style=&#39;color:#008c00; &#39;&gt;0&lt;/span&gt;&lt;span style=&#39;color:#406080; &#39;&gt;;&lt;/span&gt;
&lt;span style=&#39;color:#406080; &#39;&gt;}&lt;/span&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/8173336659597926208/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/08/linux-kernel-containof.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/8173336659597926208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/8173336659597926208'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/08/linux-kernel-containof.html' title='Linux kernel - contain_of'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNuAiGJTLjsCkJH2PriLTpndGPEAxQ8cN-7_UiIN1-n44yTGlk_AiOTJsPMIh0M1NS-Wl-2ScQzWu6Poah84eJ1PXjT4L7snGbugdC_i07qHpXTHTI41h3BGmbGjlkXy0I56H1QQadM6o/s72-c/%2525E7%2525B9%2525AA%2525E5%25259C%2525961.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-2418417004249981546</id><published>2011-07-20T00:12:00.001+08:00</published><updated>2011-07-20T00:12:59.678+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>Interesting callback function</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;typedef&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;fp_t &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020; font-family: monospace; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #406080;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; color: #000020; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;fp_t&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;fp&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span style=&quot;color: #406080;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
It is easy to understand to expand it shown as the following.&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;fp&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;
Here is an example to show &amp;nbsp;where this callback function can be used.&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #004a43;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #004a43;&quot;&gt;include &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #40015a;&quot;&gt;stdio.h&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;typedef&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;fp_t &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;

&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  spi_read&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
printf &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;spi_read&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  spi_write&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
printf &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;spi_write&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  nand_read&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
printf &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;nand_read&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  nand_write&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
printf &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;nand_write&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;spi_fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;nand_fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #400000;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
 
    fp_t&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    spi_fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; spi_read&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;    
    spi_fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; spi_write&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;    
    nand_fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; nand_read&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;    
    nand_fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; nand_write&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;    
    
    fp &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;spi_fp&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
        &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;fp&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/2418417004249981546/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/07/interesting-callback-function.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2418417004249981546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2418417004249981546'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/07/interesting-callback-function.html' title='Interesting callback function'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-324015857988068323</id><published>2011-06-14T11:22:00.003+08:00</published><updated>2011-07-20T12:30:40.612+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>LD_DEBUG and LD_LIBRARY_PATH</title><content type='html'>It is useful to find out which library are loaded when running the program.&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;LD_DEBUG &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; help &lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/a.out&lt;/span&gt;&lt;/pre&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Vaild option for LD_DEBUG&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;libs&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display library search paths&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;reloc&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display relocation processing&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;files&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display progress for input file&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;symbols&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display symbol table processing&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;bindings&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display information about symbol binding&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;versions&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display version dependencies&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;all&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;all previous options combined&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;statistics&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display relocation statistic&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;unused&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;determined unused DSOs&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;color: black;&quot;&gt;help&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;color: #888888;&quot;&gt;display this help message and exit&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;LD_DEBUG&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;libs &lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;a&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;out&lt;/pre&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;    find library&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;libc&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;so&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; searching
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;     &lt;span style=&quot;color: red;&quot;&gt;search cache=/etc/ld.so.cache&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;      trying file&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;lib&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;tls&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;i686&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;cmov&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;libc&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;so&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;6&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;    calling init&lt;span style=&quot;color: #406080;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;lib&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;tls&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;i686&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;cmov&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;libc&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;so&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;6&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;    initialize program&lt;span style=&quot;color: #406080;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;a&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;out
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;    transferring control&lt;span style=&quot;color: #406080;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;a&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;out
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;    calling fini&lt;span style=&quot;color: #406080;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;a&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;out &lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;    calling fini&lt;span style=&quot;color: #406080;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;lib&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;tls&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;i686&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;cmov&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;libc&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;so&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;
&lt;span style=&quot;color: #008c00;&quot;&gt;17315&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;:&lt;/span&gt;&lt;/pre&gt;
From above result, it will find the file &quot;ld.so.conf&quot; to know where the standard library is located.&lt;br /&gt;
In this case, the library I only use is glibc. So it is a simple code.&lt;br /&gt;
But it is handy tool if your program is very complex and you want to know which library is linked.&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;gcc &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;share b&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;c &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;o libb&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;so
gcc &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;o a&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;c&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;lb &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;L&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;/pre&gt;
Then you should export libary PATH &quot;LD_LIBRARY_PATH&quot;&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;export&lt;/span&gt; LD_LIBRARY_PATH&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;$LD_LIBRARY_PATH;./&lt;/pre&gt;
The program will be executed successfully.&lt;br /&gt;
You can try LD_DEBUG again and the loader will search additional path &quot;./&quot; you assigned &amp;nbsp;and load the specific library to memory.</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/324015857988068323/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/06/it-is-useful-to-find-out-which-library.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/324015857988068323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/324015857988068323'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/06/it-is-useful-to-find-out-which-library.html' title='LD_DEBUG and LD_LIBRARY_PATH'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-2306459537325677547</id><published>2011-06-07T23:27:00.002+08:00</published><updated>2011-07-20T12:31:23.925+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ldscript"/><title type='text'>Overlay attribute in LDScript</title><content type='html'>&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;For each section within the&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;code&gt;OVERLAY&lt;/code&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;, the linker automatically defines two symbols. The symbol&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;code&gt;__load_start_&lt;var&gt;secname&lt;/var&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;is defined as the starting load address of the section. The symbol&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;code&gt;__load_stop_&lt;var&gt;secname&lt;/var&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;is defined as the final load address of the section.&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;OVERLAY &lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x1000&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; AT &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x4000&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #308080;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;text0 &lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt; o1&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;text1 &lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt; o2&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080; font-weight: bold;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #308080;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;
This will define both&amp;nbsp;&lt;samp&gt;`.text0&#39;&lt;/samp&gt;&amp;nbsp;and&amp;nbsp;&lt;samp&gt;`.text1&#39;&lt;/samp&gt;&amp;nbsp;to start at address 0x1000.&amp;nbsp;&lt;samp&gt;`.text0&#39;&lt;/samp&gt;&amp;nbsp;will be loaded at address 0x4000, and&amp;nbsp;&lt;samp&gt;`.text1&#39;&lt;/samp&gt;&amp;nbsp;will be loaded immediately after&amp;nbsp;&lt;samp&gt;`.text0&#39;&lt;/samp&gt;. The following symbols will be defined:&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;&lt;code&gt;__load_start_text0&lt;/code&gt;&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;&lt;code&gt;__load_stop_text0&lt;/code&gt;&lt;/span&gt;,&lt;span style=&quot;color: blue;&quot;&gt;&lt;code&gt;__load_start_text1&lt;/code&gt;&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;&lt;code&gt;__load_stop_text1&lt;/code&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;
C code to copy overlay&amp;nbsp;&lt;code&gt;.text1&lt;/code&gt;&amp;nbsp;into the overlay area might look like the following.&lt;/div&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;extern&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt; __load_start_text1&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; __load_stop_text1&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
memcpy &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;0x1000&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;__load_start_text1&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;
          &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;__load_stop_text1 &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;&amp;amp;&lt;/span&gt;__load_start_text1&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;
Note that the&amp;nbsp;&lt;code&gt;OVERLAY&lt;/code&gt;&amp;nbsp;command is just&lt;em&gt; syntactic sugar&lt;/em&gt;, since everything it does can be done using the more basic commands. The above example could have been written identically as follows.&lt;/div&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;text0 &lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x1000&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; AT &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x4000&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; o1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;__load_start_text0&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; LOADADDR &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt;text0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;__load_stop_text0&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; LOADADDR &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt;text0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; SIZEOF &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt;text0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt;text1 &lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x1000&lt;/span&gt;&lt;span style=&quot;color: #e34adc;&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; AT &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x4000&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; SIZEOF &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;text0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; o2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;__load_start_text1&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; LOADADDR &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt;text1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;__load_stop_text1&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; LOADADDR &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt;text1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt; SIZEOF &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #007997;&quot;&gt;text1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0x1000&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; MAX &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;SIZEOF &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;text0&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt; SIZEOF &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #074726;&quot;&gt;text1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; font-weight: bold; white-space: normal;&quot;&gt;Reference from The GNU linker.&lt;/span&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/2306459537325677547/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/06/overlay-attribute-in-ldscript.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2306459537325677547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2306459537325677547'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/06/overlay-attribute-in-ldscript.html' title='Overlay attribute in LDScript'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-6570124111989042787</id><published>2011-06-04T01:50:00.001+08:00</published><updated>2011-07-20T12:30:57.843+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>Weak function</title><content type='html'>From gnu gcc document:&lt;br /&gt;
The&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;code&gt;weak&lt;/code&gt;&amp;nbsp;&lt;/span&gt;attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;libweak.c&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #004a43;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #004a43;&quot;&gt;include &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: maroon;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #40015a;&quot;&gt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; weakfunc&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; __attribute__&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;weak&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; weakfunc&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
    printf &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;default weak function&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;main.c&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f1f0f0; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #004a43;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #004a43;&quot;&gt;include &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #40015a;&quot;&gt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #400000; font-weight: bold;&quot;&gt;void&lt;/span&gt; weakfunc&lt;span style=&quot;color: #806030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #806030;&quot;&gt;{&lt;/span&gt;
    printf &lt;span style=&quot;color: #806030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #e60000;&quot;&gt;weak function from main&lt;/span&gt;&lt;span style=&quot;color: #0f6900;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;;&lt;/span&gt;    
&lt;span style=&quot;color: #806030;&quot;&gt;}&lt;/span&gt;

&lt;span style=&quot;color: #400000; font-weight: bold;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;main&lt;/span&gt; &lt;span style=&quot;color: #806030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #806030;&quot;&gt;{&lt;/span&gt;
    weakfunc&lt;span style=&quot;color: #806030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #400000; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #c00000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #806030;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #806030;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
Compile the library and main function.&lt;br /&gt;
&lt;pre style=&quot;background: #f1f0f0; color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;#gcc -shared -o libweak.so weakfunc.c&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;#gcc &amp;nbsp;-o weakfunc{,.c} -lweak -L.&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;#LD_LIBRARY_PATH=. ./main&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #674ea7;&quot;&gt;weak function from main &lt;/span&gt;
&lt;/pre&gt;
From above, it is very clear that the weak function of the library is replaced.&lt;br /&gt;
&lt;pre style=&quot;background: #f1f0f0; color: black;&quot;&gt;#objdump -t &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #660000;&quot;&gt;libweak.so&lt;/span&gt; |grep weakfunc
0000046c &amp;nbsp;w &amp;nbsp; &amp;nbsp;F .text&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;00000014 &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;weakfunc&lt;/span&gt;
&lt;/pre&gt;
In the library, this function has weak attribute.&lt;br /&gt;
&lt;pre style=&quot;background: #f1f0f0; color: black;&quot;&gt;#objdump -t &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;main &lt;/span&gt;|grep weakfunc
080484e4 &amp;nbsp;g &amp;nbsp; &amp;nbsp;F .text&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;00000014 &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;weakfunc&lt;/span&gt;
&lt;/pre&gt;
However, this function is presented as &amp;nbsp;global attribute.</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/6570124111989042787/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/06/weak-function.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/6570124111989042787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/6570124111989042787'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/06/weak-function.html' title='Weak function'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-2386781940761644494</id><published>2011-06-02T12:36:00.000+08:00</published><updated>2011-06-02T12:36:06.815+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="andriod"/><title type='text'>Andriod 專有名詞整理</title><content type='html'>&lt;div style=&quot;background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span id=&quot;internal-source-marker_0.5470876048784703&quot; style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;最近研究了Andriod，整理了一些專有名詞如&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;IPL (InitialProgramLoader):&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Initialize the hardware setting, such as memory, cpu clock , flash, about the development board.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;It is similar with the bootloader in the embedded system, like u-boot.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;SPL (Second Program Loader):&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;The main goal is to load system OS to memory.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;In addition, some features is provided as the below list.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(1) check hardware, like LCD, led.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(2) search the active partion and load it to memory.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(3) connection with PC and recieve commands from PC host.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;HBoot: &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;This is &amp;nbsp;HTC’s SPL&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;fastboot: &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Fastboot is protocol used to update the flash filesystem in Android devices from a host over USB.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;The command &quot;fastboot.exe&quot; you can run on your host after fastboot has been started on a device connected via USB.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;e.g.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;$ fastboot erase boot&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Andriod Recovery:&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;The recovey of &amp;nbsp;the mainstream andriod can provide some options to recovery your systems or factory-to-default, even&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;though it can load official ROM in the zip file of SD card and recovey the system.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;ClockworkMod recovery&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; is one of the widely used custom andriod recovery and it provide more options to recovery unofficial or official &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;ROM from the zip file of SD card.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/2386781940761644494/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2011/06/andriod.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2386781940761644494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2386781940761644494'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2011/06/andriod.html' title='Andriod 專有名詞整理'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-8581599423682743552</id><published>2009-10-26T10:03:00.005+08:00</published><updated>2011-06-02T23:59:38.240+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>CGI debug</title><content type='html'>Web server will redirect STDIN, STDOUT and STDERR to CGI interface so the following function is used to print out debug messages from C code.&lt;br /&gt;
&lt;br /&gt;
Function 1:&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; debug_printf&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;degmsg&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
 &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; old &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; dup&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;STDOUT&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; ttyfd &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; ret&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     va_list ap&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     &lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; msg&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;512&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     
     ttyfd &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; open&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;/dev/ttyS0&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; O_RDWR&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     va_start&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;ap&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;degmsg&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     ret &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; vsprintf&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;msg&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;degmsg&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;ap&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     va_end&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;ap&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     dup2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;ttyfd&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; STDOUT&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     close&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;ttyfd&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     printf&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;%s&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;msg&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  
     dup2&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;old&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; STDOUT&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
Function 2:&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f6f8ff; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #406080;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;void&lt;/span&gt; debug_printf&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;degmsg&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;  
     va_list ap&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt; ret&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     &lt;span style=&quot;color: #003060;&quot;&gt;FILE&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;*&lt;/span&gt;con_ptr&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;char&lt;/span&gt; msg&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;512&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     
     va_start&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;ap&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;degmsg&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     ret &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; vsprintf&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;msg&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;degmsg&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;ap&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     va_end&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;ap&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     con_ptr &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; fopen&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;/dev/ttyS1&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;w+&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;      
     &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;!&lt;/span&gt;con_ptr&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;  
         perror&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;fopen&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;  
     fprintf&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;con_ptr&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0f69ff;&quot;&gt;%s&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;msg&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     fflush&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;con_ptr&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
     fclose&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;con_ptr&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;  
 &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/8581599423682743552/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/10/cgi-debug.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/8581599423682743552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/8581599423682743552'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/10/cgi-debug.html' title='CGI debug'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-2949982238528844509</id><published>2009-10-01T01:38:00.002+08:00</published><updated>2009-10-01T01:40:49.772+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>How to mount JFFS2 image</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #4c1130; font-family: tahoma, arial, sans-serif;&quot;&gt;Use memory to emulate the MTD device&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: tahoma, arial, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana;&quot;&gt;mknod /tmp/mtdblock0 b 31 0&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: tahoma, arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;modprobe mtdblock&lt;br /&gt;
modprobe mtdram total_size=65536 erase_size=256&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span style=&quot;font-family: tahoma, arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;modprobe jffs2&lt;br /&gt;
&lt;br /&gt;
dd if=image.jffs2 of=/tmp/mtdblock0&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: tahoma, arial, sans-serif;&quot;&gt;mkdir /mnt/jffs2&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: tahoma, arial, sans-serif;&quot;&gt;mount -t jffs2 /tmp/mtdblock0 /mnt/jffs2&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/2949982238528844509/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/10/how-to-mount-jffs2-image.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2949982238528844509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2949982238528844509'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/10/how-to-mount-jffs2-image.html' title='How to mount JFFS2 image'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-397633813103671332</id><published>2009-07-03T10:45:00.001+08:00</published><updated>2009-07-03T10:52:04.170+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="IPv6"/><title type='text'>IPV6 DHCPV6 Configuration</title><content type='html'>&lt;b&gt;Router Advertisement Daemon (radvd)&lt;br&gt;/etc/radvd.conf&lt;/b&gt;&lt;br&gt;&lt;div&gt;&lt;table id=&quot;eani&quot; width=&quot;400&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#9fc5e8&quot; bgcolor=&quot;#9fc5e8&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;100%&quot;&gt;&lt;b&gt;interface eth0 {&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;AdvSendAdvert on;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;MinRtrAdvInterval 3;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;MaxRtrAdvInterval 10;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;prefix 2001:0db8:0100:f101::/64 {&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; AdvOnLink on;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;#Disable Stateless Address Autoconfiguration&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;#AdvAutonomous on;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;AdvRouterAddr on;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;};&amp;nbsp;&lt;br&gt;};&lt;/b&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;b&gt;Wide-DHCPv6 &lt;br&gt;Server configuration: dhcp6s.conf &lt;/b&gt;&lt;br&gt;&lt;div&gt;&lt;table id=&quot;i1n.&quot; width=&quot;400&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#9fc5e8&quot; bgcolor=&quot;#9fc5e8&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;100%&quot;&gt;&lt;b&gt;option domain-name-servers 2001:470:1f01:2191::1 2001:470:1f01:2191::2;&amp;nbsp;&lt;br&gt;option domain-name &quot;dean.net&quot;;&amp;nbsp;&lt;br&gt;interface eth0{&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;address-pool pool1 3600;&amp;nbsp;&lt;br&gt;};&amp;nbsp;&lt;br&gt;pool pool1 {&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;range 2001:5c0:1101:b700::1000 to 2001:5c0:1101:b700::2000 ;&amp;nbsp;&lt;br&gt;};&amp;nbsp;&lt;br&gt;host host0 {&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;duid 00:00:00:00:a0:a0;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;prefix 3ffe:ffff:102::120/64 infinity;&amp;nbsp;&lt;br&gt;};&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;b&gt;&lt;font class=&quot;Apple-style-span&quot; color=&quot;#0C343D&quot;&gt;Client configuration &lt;br&gt;DHCPV6 client for the stateful autoconfigutation&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;div&gt;&lt;table id=&quot;hxtr&quot; width=&quot;400&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#9fc5e8&quot; bgcolor=&quot;#9fc5e8&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;100%&quot;&gt;&lt;div&gt;&lt;b&gt;interface eth0 {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; send ia-na 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; request domain-name-servers;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; request domain-name;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; script &quot;/tmp/dean/dhcp6c-script&quot;;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;id-assoc na 0 {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;# non-temporary addresses&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;b&gt;&lt;font size=&quot;2&quot;&gt;DHCPV6 client for the stateless autoconfigutation&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;div&gt;&lt;table id=&quot;s:lk&quot; width=&quot;400&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#9fc5e8&quot; bgcolor=&quot;#9fc5e8&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;100%&quot;&gt;&lt;div&gt;&lt;b&gt;interface eth0&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;{&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;information-only;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;request domain-name-servers;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;request domain-name;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;script &quot;/tmp/dean/dhcp6c-script&quot;;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;b&gt;DHCPV6 script&lt;/b&gt;&lt;div&gt;&lt;font class=&quot;Apple-style-span&quot; size=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;2&quot;&gt;update DNS in resolv.conf&lt;/font&gt;&lt;br&gt;&lt;/b&gt;&lt;/font&gt;&lt;div&gt;&lt;div&gt;&lt;table id=&quot;wzhy&quot; width=&quot;400&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#9fc5e8&quot; bgcolor=&quot;#9fc5e8&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;100%&quot;&gt;&lt;div&gt;&lt;b&gt;#!/bin/sh&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;if [ -n &quot;$new_domain_name&quot; -o -n &quot;$new_domain_name_servers&quot; ]; then&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;new_resolv_conf=/tmp/resolv.conf.dhcp6c-new&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;rm -f $new_resolv_conf&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if [ -n &quot;$new_domain_name&quot; ]; then&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;echo search $new_domain_name &amp;gt;&amp;gt; $new_resolv_conf&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;fi&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if [ -n &quot;$new_domain_name_servers&quot; ]; then&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for nameserver in $new_domain_name_servers; do&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;echo nameserver $nameserver &amp;gt;&amp;gt; $new_resolv_conf&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;done&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;fi&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;# To preserve IPv4 informations...&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;cat /etc/resolv.conf &amp;gt;&amp;gt; $new_resolv_conf&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;mv -f $new_resolv_conf /etc/resolv.conf&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;fi&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;exit 0&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/397633813103671332/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/07/ipv6-dhcpv6-configuration.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/397633813103671332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/397633813103671332'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/07/ipv6-dhcpv6-configuration.html' title='IPV6 DHCPV6 Configuration'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-7683279170919956113</id><published>2009-06-25T14:32:00.002+08:00</published><updated>2011-06-03T00:14:36.571+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="shell_script"/><title type='text'>Shell script tricks</title><content type='html'>&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;1. The array of shell script&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;names&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt; Jennifer Tonya Anna Sadie &lt;span style=&quot;color: #406080;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;for&lt;/span&gt; name &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;${&lt;/span&gt;names&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;do&lt;/span&gt;
   &lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;$name&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;done&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;names&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt; Jennifer Tonya Anna Sadie &lt;span style=&quot;color: #406080;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt; i &lt;span style=&quot;color: #44aadd;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; i &amp;amp;lt&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color: #595979;&quot;&gt;#names[@]} ; i++ ))&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;do&lt;/span&gt;
    &lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;${&lt;/span&gt;names&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;done&lt;/span&gt;
&lt;/pre&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;2. Variable substitution for shell script&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;$DEVICE0&lt;/span&gt;=eth0
&lt;span style=&quot;color: #007d45;&quot;&gt;$echo&lt;/span&gt; &lt;span style=&quot;color: #1060b6;&quot;&gt;&quot;Configure interface &quot;&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;!&lt;/span&gt;DEVICE&lt;span style=&quot;color: #007d45;&quot;&gt;${&lt;/span&gt;i&lt;span style=&quot;color: #007d45;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;$n&lt;/span&gt;=&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;$&lt;/span&gt; &lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;eval&lt;/span&gt; &lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #0f69ff;&quot;&gt;\$&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;$n&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;$&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;&quot;date&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;$&lt;/span&gt; &lt;span style=&quot;color: #7779bb; font-weight: bold;&quot;&gt;echo&lt;/span&gt; $&lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;$n&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;Output :Wed May 21 20:39:00 EEST 2008&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;3. Increment i in the while loop&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;$&lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;$i&lt;/span&gt;+&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #007d45;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-color: #cceeee; background-image: initial; background-origin: initial; color: black;&quot;&gt;`expr i + &lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-color: #cceeee; background-image: initial; background-origin: initial; color: #007d45;&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-color: #cceeee; background-image: initial; background-origin: initial; color: black;&quot;&gt;`&lt;/span&gt;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/7683279170919956113/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/06/shell-script-tricks.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7683279170919956113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7683279170919956113'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/06/shell-script-tricks.html' title='Shell script tricks'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-7648837177469645337</id><published>2009-06-15T16:49:00.002+08:00</published><updated>2011-07-20T12:31:47.843+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>Re-entrant  vs Thread safe</title><content type='html'>&lt;div style=&quot;margin-left: 0px; margin-right: 0px;&quot;&gt;
Both concepts of reentrancy and&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Thread_safety&quot; style=&quot;background-color: initial; background-image: none; background-repeat: initial; color: #002bb8; text-decoration: none;&quot; title=&quot;Thread safety&quot;&gt;thread safety&lt;/a&gt;&amp;nbsp;relate to the way functions handle resources. However, they are not the same. While the concept of reentrancy can affect the external interface of a function, thread safety only concerns the implementation of the function and not its external interface.&lt;/div&gt;
&lt;ul style=&quot;list-style-type: square; margin-left: 1.5em; margin-right: 0px;&quot;&gt;
&lt;li&gt;In most cases, to make a non-reentrant function reentrant, its external interface must be modified such that all data is provided by the caller of the function.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;list-style-type: square; margin-left: 1.5em; margin-right: 0px;&quot;&gt;
&lt;li&gt;To make a thread-unsafe function thread-safe, only the implementation needs to be changed, usually by adding&lt;a href=&quot;http://en.wikipedia.org/wiki/Synchronization_(computer_science)&quot; style=&quot;background-color: initial; background-image: none; background-repeat: initial; color: #002bb8; text-decoration: none;&quot; title=&quot;Synchronization (computer science)&quot;&gt;synchronization&lt;/a&gt;&amp;nbsp;blocks to protect shared resources from concurrent accesses by different threads.&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;margin-left: 0px; margin-right: 0px;&quot;&gt;
Therefore, reentrancy is a more fundamental property than&amp;nbsp;&lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/Thread-safe&quot; style=&quot;background-color: initial; background-image: none; background-repeat: initial; color: #5a3696; text-decoration: none;&quot; title=&quot;Thread-safe&quot;&gt;thread-safety&lt;/a&gt;&amp;nbsp;and by definition, leads to&amp;nbsp;&lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/Thread-safe&quot; style=&quot;background-color: initial; background-image: none; background-repeat: initial; color: #5a3696; text-decoration: none;&quot; title=&quot;Thread-safe&quot;&gt;thread-safety&lt;/a&gt;: Every reentrant function is thread-safe; however, not every thread-safe function is reentrant.&lt;/div&gt;
Reference from&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Reentrant_(subroutine)&quot;&gt;http://en.wikipedia.org/wiki/Reentrant_(subroutine)&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/7648837177469645337/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/06/re-entrant-vs-thread-safe.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7648837177469645337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7648837177469645337'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/06/re-entrant-vs-thread-safe.html' title='Re-entrant  vs Thread safe'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-847956114069767567</id><published>2009-06-09T15:05:00.003+08:00</published><updated>2009-06-09T15:59:08.803+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>How to show the page table entry</title><content type='html'>&lt;div&gt;&lt;br /&gt;&lt;/div&gt;excerpt from arch/arm/mm/fault.c&lt;br /&gt;&lt;pre width=&quot;80&quot;&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;show_pte&quot;&gt;&lt;/a&gt;void show_pte(struct mm_struct *mm, unsigned long addr)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt;       pgd_t *pgd;&lt;br /&gt;&lt;br /&gt;       &lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (!mm)&lt;br /&gt;               mm = &amp;amp;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;init_mm&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       printk(KERN_ALERT &lt;span style=&quot;color:#666666;&quot;&gt;&quot;pgd = %p\n&quot;&lt;/span&gt;, mm-&amp;gt;pgd);&lt;br /&gt;       pgd = &lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;pgd_offset&lt;/span&gt;(mm, addr);&lt;br /&gt;       printk(KERN_ALERT &lt;span style=&quot;color:#666666;&quot;&gt;&quot;[%08lx] *pgd=%08lx&quot;&lt;/span&gt;, addr, pgd_val(*pgd));&lt;br /&gt;&lt;br /&gt;       &lt;span style=&quot;color:#4169E1;&quot;&gt;do&lt;/span&gt; {&lt;br /&gt;               pmd_t *pmd;&lt;br /&gt;               pte_t *pte;&lt;br /&gt;&lt;br /&gt;               &lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (pgd_none(*pgd))&lt;br /&gt;                       &lt;span style=&quot;color:#4169E1;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;               &lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (pgd_bad(*pgd)) {&lt;br /&gt;                       printk(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;(bad)&quot;&lt;/span&gt;);&lt;br /&gt;                       &lt;span style=&quot;color:#4169E1;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;               pmd = &lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;pmd_offset&lt;/span&gt;(pgd, addr);&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#if PTRS_PER_PMD != 1&lt;/span&gt;&lt;br /&gt;               printk(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;, *pmd=%08lx&quot;&lt;/span&gt;, pmd_val(*pmd));&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#endif&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;               &lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (pmd_none(*pmd))&lt;br /&gt;                       &lt;span style=&quot;color:#4169E1;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;               &lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (pmd_bad(*pmd)) {&lt;br /&gt;                       printk(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;(bad)&quot;&lt;/span&gt;);&lt;br /&gt;                       &lt;span style=&quot;color:#4169E1;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#ifndef CONFIG_HIGHMEM&lt;/span&gt;&lt;br /&gt;               &lt;span style=&quot;color:#B22222;&quot;&gt;/* We must not map this if we have highmem enabled */&lt;/span&gt;&lt;br /&gt;               pte = &lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;pte_offset_map&lt;/span&gt;(pmd, addr);&lt;br /&gt;               printk(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;, *pte=%08lx&quot;&lt;/span&gt;, pte_val(*pte));&lt;br /&gt;               printk(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;, *ppte=%08lx&quot;&lt;/span&gt;, pte_val(pte[-PTRS_PER_PTE]));&lt;br /&gt;               &lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;pte_unmap&lt;/span&gt;(pte);&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#endif&lt;/span&gt;&lt;br /&gt;       } &lt;span style=&quot;color:#4169E1;&quot;&gt;while&lt;/span&gt;(0);&lt;br /&gt;&lt;br /&gt;       printk(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;\n&quot;&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/847956114069767567/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/06/how-to-show-page-table-entry.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/847956114069767567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/847956114069767567'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/06/how-to-show-page-table-entry.html' title='How to show the page table entry'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-564824323736411023</id><published>2009-06-09T13:31:00.001+08:00</published><updated>2009-06-18T14:15:45.620+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>crontab</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;font size=&quot;5&quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;Arial&quot;&gt;Crontab command&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;#export to the file&lt;/div&gt;&lt;div&gt;crontab -l &amp;gt; filename&lt;/div&gt;&lt;div&gt;# import from the file&lt;/div&gt;&lt;div&gt;crontab filename&amp;nbsp;&lt;/div&gt;&lt;div&gt;# import from the file for the specific user&lt;/div&gt;&lt;div&gt;crontab -u user filename&amp;nbsp;&lt;/div&gt;&lt;div&gt;# edit&lt;/div&gt;&lt;div&gt;crontab -e&amp;nbsp;&lt;/div&gt;&lt;div&gt;# delete all&lt;/div&gt;&lt;div&gt;crontab -r&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h1&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;Arial&quot;&gt;C&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;Arial&quot;&gt;rontab special usage&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/h1&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;font class=&quot;Apple-style-span&quot; color=&quot;#222222&quot; face=&quot;georgia&quot; size=&quot;4&quot;&gt;&lt;span style=&quot;font-family: -webkit-sans-serif&quot;&gt;&lt;table class=&quot;wikitable zeroBorder&quot; style=&quot; color: black; background-color: rgb(249, 249, 249); margin-right: 1em; margin-left: 0px; background-image: initial; background-repeat: initial&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot; background-image: initial; background-repeat: initial; background-color: rgb(242, 242, 242); text-align: center&quot;&gt;Entry&lt;/th&gt;&lt;th style=&quot; background-image: initial; background-repeat: initial; background-color: rgb(242, 242, 242); text-align: center&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot; background-image: initial; background-repeat: initial; background-color: rgb(242, 242, 242); text-align: center&quot;&gt;Equivalent To&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@reboot&lt;/td&gt;&lt;td&gt;Run once, at startup.&lt;/td&gt;&lt;td&gt;&lt;i&gt;None&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@yearly&lt;/td&gt;&lt;td&gt;Run once a year&lt;/td&gt;&lt;td&gt;0 0 1 1 *&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@annually&lt;/td&gt;&lt;td&gt;(same as @yearly)&lt;/td&gt;&lt;td&gt;0 0 1 1 *&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@monthly&lt;/td&gt;&lt;td&gt;Run once a month&lt;/td&gt;&lt;td&gt;0 0 1 * *&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@weekly&lt;/td&gt;&lt;td&gt;Run once a week&lt;/td&gt;&lt;td&gt;0 0 * * 0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@daily&lt;/td&gt;&lt;td&gt;Run once a day&lt;/td&gt;&lt;td&gt;0 0 * * *&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@midnight&lt;/td&gt;&lt;td&gt;(same as @daily)&lt;/td&gt;&lt;td&gt;0 0 * * *&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;@hourly&lt;/td&gt;&lt;td&gt;Run once an hour&lt;/td&gt;&lt;td&gt;0 * * * *&lt;br&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font class=&quot;Apple-style-span&quot; color=&quot;#222222&quot; face=&quot;georgia&quot; size=&quot;4&quot;&gt;&lt;font size=&quot;3&quot;&gt;reference from&amp;nbsp;&lt;/font&gt;&lt;span style=&quot;color: rgb(0, 0, 0); font-family: Verdana&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Cron&quot;&gt;http://en.wikipedia.org/wiki/Cron&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;font-family: &#39;times new roman&#39;&quot;&gt;&lt;h1&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;Arial&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Crontab Example&lt;/span&gt;&lt;/font&gt;&lt;/h1&gt;&lt;div&gt;&lt;div&gt;&lt;table id=&quot;un6v&quot; width=&quot;75%&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#000000&quot; bgcolor=&quot;#999999&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;100%&quot;&gt;&lt;span style=&quot;font-family: -webkit-sans-serif&quot;&gt;&lt;pre style=&quot; color: black; background-color: rgb(249, 249, 249)&quot;&gt;# .---------------- minute (0 - 59) &lt;br /&gt;# |  .------------- hour (0 - 23)&lt;br /&gt;# |  |  .---------- day of month (1 - 31)&lt;br /&gt;# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... &lt;br /&gt;# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat &lt;br /&gt;# |  |  |  |  |&lt;br /&gt;# *  *  *  *  *  command to be executed&lt;/pre&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: &#39;times new roman&#39;&quot;&gt;&lt;br&gt;&lt;div&gt;&lt;table border=&quot;1&quot; width=&quot;75%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;&quot; height=&quot;75&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;8%&quot; align=&quot;center&quot; bgcolor=&quot;#808080&quot; height=&quot;13&quot;&gt;&lt;font color=&quot;#FFFFFF&quot; face=&quot;Verdana&quot; size=&quot;1&quot;&gt;min&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#808080&quot; height=&quot;13&quot;&gt;&lt;font color=&quot;#FFFFFF&quot; face=&quot;Verdana&quot; size=&quot;1&quot;&gt;hour&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#808080&quot; height=&quot;13&quot;&gt;&lt;font color=&quot;#FFFFFF&quot; face=&quot;Verdana&quot; size=&quot;1&quot;&gt;day/month&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;13%&quot; align=&quot;center&quot; bgcolor=&quot;#808080&quot; height=&quot;13&quot;&gt;&lt;font color=&quot;#FFFFFF&quot; face=&quot;Verdana&quot; size=&quot;1&quot;&gt;month&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#808080&quot; height=&quot;13&quot;&gt;&lt;font color=&quot;#FFFFFF&quot; face=&quot;Verdana&quot; size=&quot;1&quot;&gt;day/week&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;66%&quot; align=&quot;left&quot; valign=&quot;top&quot; bgcolor=&quot;#808080&quot; height=&quot;13&quot;&gt;&lt;font color=&quot;#FFFFFF&quot; face=&quot;Verdana&quot; size=&quot;1&quot;&gt;&amp;nbsp;Execution time&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;8%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;30&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;0&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;1&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;13%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;1,6,12&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;*&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;66%&quot; align=&quot;left&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font face=&quot;Verdana&quot; size=&quot;1&quot;&gt;-- 00:30 Hrs&amp;nbsp; on 1st of Jan, June &amp;amp; Dec.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;114%&quot; align=&quot;center&quot; bgcolor=&quot;#DBDBDB&quot; colspan=&quot;6&quot; height=&quot;1&quot;&gt;&lt;p align=&quot;left&quot;&gt;&lt;font size=&quot;1&quot; face=&quot;Verdana&quot; color=&quot;#DBDBDB&quot;&gt;:&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;8%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;0&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;20&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;*&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;13%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;10&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;1-5&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;66%&quot; align=&quot;left&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;--8.00 PM every weekday (Mon-Fri) only in Oct.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;114%&quot; align=&quot;center&quot; bgcolor=&quot;#DBDBDB&quot; colspan=&quot;6&quot; height=&quot;2&quot;&gt;&lt;p align=&quot;left&quot;&gt;&lt;font size=&quot;1&quot; face=&quot;Verdana&quot; color=&quot;#DBDBDB&quot;&gt;:&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;8%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;0&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;0&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;1,10,15&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;13%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;*&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;*&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;66%&quot; align=&quot;left&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;-- midnight on 1st ,10th &amp;amp; 15th of month&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;114%&quot; align=&quot;center&quot; bgcolor=&quot;#DBDBDB&quot; colspan=&quot;6&quot; height=&quot;2&quot;&gt;&lt;p align=&quot;left&quot;&gt;&lt;font size=&quot;1&quot; face=&quot;Verdana&quot; color=&quot;#DBDBDB&quot;&gt;:&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;8%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;5,10&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;0&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;10&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;13%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;*&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;9%&quot; align=&quot;center&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;1&lt;/font&gt;&lt;/td&gt;&lt;td width=&quot;66%&quot; align=&quot;left&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot; height=&quot;38&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Times New Roman&quot;&gt;-- At 12.05,12.10 every Monday &amp;amp; on 10th of every month&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=&quot;114%&quot; bgcolor=&quot;#DBDBDB&quot; colspan=&quot;6&quot; height=&quot;1&quot;&gt;&lt;font size=&quot;1&quot; face=&quot;Verdana&quot; color=&quot;#DBDBDB&quot;&gt;:&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;div&gt;&lt;table id=&quot;cgu4&quot; width=&quot;75%&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;zeroBorder&quot; bordercolor=&quot;#000000&quot; bgcolor=&quot;#cccccc&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width=&quot;50%&quot;&gt;*/8 * * * * root init 6&lt;/td&gt;&lt;td width=&quot;50%&quot;&gt;&amp;nbsp;&amp;nbsp;After 8 minutes , execute &quot;reboot&quot; command&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;ps:&amp;nbsp;&lt;span style=&quot;font-family: -webkit-sans-serif&quot;&gt;&quot;*/8&quot; in the minute time field is equivalent to &quot;0,8,16,24,32,48,56&quot;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/564824323736411023/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/06/crontab.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/564824323736411023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/564824323736411023'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/06/crontab.html' title='crontab'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-3214688718393455021</id><published>2009-06-08T16:19:00.004+08:00</published><updated>2009-06-08T16:35:06.325+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>Linux 2.6 Driver Template</title><content type='html'>&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre width=&quot;80&quot;&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/module.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/config.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/sched.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/kernel.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/init.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/slab.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/ioport.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;asm/io.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/fs.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;linux/cdev.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#A020F0;&quot;&gt;#include &amp;lt;asm/uaccess.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;struct&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt; void **data;&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;struct cdev&lt;/span&gt; *cdev ;&lt;br /&gt;  &lt;br /&gt;}DBG_Dev_Tag;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#228B22;&quot;&gt;#define DBG_MAJOR         111&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#228B22;&quot;&gt;#define DBG_MINOR          1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#228B22;&quot;&gt;#define MAXDEVICENUM 1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#228B22;&quot;&gt;#define DEBUG_IOC_MAGIC &#39;D&#39;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#228B22;&quot;&gt;#define DEBUG_IOCSHOWDEB    _IOR(DEBUG_IOC_MAGIC,   1, int)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;DBG_Dev_Tag *DBG_devices;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int dbg_major = DBG_MAJOR;&lt;br /&gt;int dbg_minor;&lt;br /&gt;&lt;br /&gt;static &lt;span style=&quot;color:#4169E1;&quot;&gt;struct file_operations&lt;/span&gt; DBG_fops =&lt;br /&gt;{&lt;br /&gt;.ioctl   = DBG_ioctl,&lt;br /&gt;.read    = DBG_read,&lt;br /&gt;.write   = DBG_write,&lt;br /&gt;.open    = DBG_open,&lt;br /&gt;.release = DBG_release,&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_ioctl&quot;&gt;&lt;/a&gt;int DBG_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt;     &lt;span style=&quot;color:#4169E1;&quot;&gt;struct net_device&lt;/span&gt; *dev = &amp;amp;_wpcm450_netdevice;&lt;br /&gt;  &lt;br /&gt;     &lt;span style=&quot;color:#4169E1;&quot;&gt;switch&lt;/span&gt; (cmd)&lt;br /&gt;     {&lt;br /&gt;         &lt;span style=&quot;color:#4169E1;&quot;&gt;case&lt;/span&gt; DEBUG_IOCSHOWDEB:&lt;br /&gt;                 //show something&lt;br /&gt;              &lt;br /&gt;                     &lt;span style=&quot;color:#4169E1;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#FF0000;&quot;&gt;                default:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;                     &lt;span style=&quot;color:#4169E1;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;     }&lt;br /&gt;  &lt;br /&gt;     &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_read&quot;&gt;&lt;/a&gt;ssize_t DBG_read (struct file *filp, char *buf, size_t count, loff_t *offset)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_write&quot;&gt;&lt;/a&gt;ssize_t DBG_write (struct file *file, const char *buf, size_t count, loff_t *offset)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_open&quot;&gt;&lt;/a&gt;static int DBG_open(struct inode *inode, struct file *filp)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt;     DBG_Dev_Tag *dev;&lt;br /&gt;  &lt;br /&gt;     dev = container_of (inode-&amp;gt;i_cdev,DBG_Dev_Tag,cdev);&lt;br /&gt;  &lt;br /&gt;     filp-&amp;gt; private_data = dev;&lt;br /&gt;&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_release&quot;&gt;&lt;/a&gt;static int DBG_release(struct inode *inode, struct file *filp)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;dbg_setup_cdev&quot;&gt;&lt;/a&gt;static void dbg_setup_cdev(DBG_Dev_Tag *dev,int index)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt;      int err;&lt;br /&gt;      int dev_id = MKDEV(dbg_major,dbg_minor + index );&lt;br /&gt;   &lt;br /&gt;      cdev_init(dev-&amp;gt;cdev,&amp;amp;DBG_fops);&lt;br /&gt;   &lt;br /&gt;      dev-&amp;gt;cdev-&amp;gt;owner = THIS_MODULE;&lt;br /&gt;   &lt;br /&gt;      dev-&amp;gt;cdev-&amp;gt;ops = &amp;amp;DBG_fops;&lt;br /&gt;   &lt;br /&gt;      err = cdev_add(dev-&amp;gt;cdev,dev_id,1);&lt;br /&gt;   &lt;br /&gt;      &lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (err)&lt;br /&gt;              printk (&lt;span style=&quot;color:#666666;&quot;&gt;&quot;error %x adding dbg%x\n&quot;&lt;/span&gt;,err,index);&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_init&quot;&gt;&lt;/a&gt;static int __init DBG_init(void)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt;int result;&lt;br /&gt;dev_t dev_id;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DBG_devices = kmalloc (&lt;span style=&quot;color:#4169E1;&quot;&gt;sizeof&lt;/span&gt; (DBG_Dev_Tag) * MAXDEVICENUM ,GFP_KERNEL);&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (DBG_devices == NULL)&lt;br /&gt;{&lt;br /&gt;          result = -ENOMEM;&lt;br /&gt;          &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; result;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;memset(DBG_devices, 0, MAXDEVICENUM * &lt;span style=&quot;color:#4169E1;&quot;&gt;sizeof&lt;/span&gt;(DBG_Dev_Tag));&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (dbg_major)&lt;br /&gt;{&lt;br /&gt;             dev_id = MKDEV(dbg_major,dbg_minor);&lt;br /&gt;          &lt;br /&gt;             result = register_chrdev_region(dev_id, 1, &lt;span style=&quot;color:#666666;&quot;&gt;&quot;debug&quot;&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;             result = alloc_chrdev_region(&amp;amp;dev_id,DBG_MINOR,1,&lt;span style=&quot;color:#666666;&quot;&gt;&quot;dbg&quot;&lt;/span&gt;);&lt;br /&gt;                   dbg_major = MAJOR(dev_id);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;if&lt;/span&gt; (result &amp;lt; 0 )&lt;br /&gt;{&lt;br /&gt;             printk (&lt;span style=&quot;color:#666666;&quot;&gt;&quot;can&#39;t get major %d\n&quot;&lt;/span&gt;,dbg_major);&lt;br /&gt;             &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; result;&lt;br /&gt;}&lt;br /&gt;  &lt;br /&gt;DBG_devices-&amp;gt;cdev = cdev_alloc();&lt;br /&gt;&lt;br /&gt;dbg_setup_cdev(DBG_devices,1);&lt;br /&gt;&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt; 0;     &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;&lt;a name=&quot;DBG_exit&quot;&gt;&lt;/a&gt;static void __exit DBG_exit(void)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;{&lt;br /&gt; dev_t dev_id;&lt;br /&gt;&lt;br /&gt; kfree(DBG_devices);&lt;br /&gt;&lt;br /&gt; cdev_del(DBG_devices -&amp;gt;cdev);&lt;br /&gt;&lt;br /&gt; dev_id = MKDEV(dbg_major,dbg_minor);&lt;br /&gt; unregister_chrdev_region(dev_id,1);&lt;br /&gt; &lt;span style=&quot;color:#4169E1;&quot;&gt;return&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;MODULE_AUTHOR(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;XXXXXXXXXX&quot;&lt;/span&gt;);&lt;br /&gt;MODULE_DESCRIPTION(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;Debug driver&quot;&lt;/span&gt;);&lt;br /&gt;MODULE_LICENSE(&lt;span style=&quot;color:#666666;&quot;&gt;&quot;GPL&quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;module_init(DBG_init)&lt;/span&gt;&lt;/strong&gt;;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#4169E1;&quot;&gt;module_exit(DBG_exit)&lt;/span&gt;&lt;/strong&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;//**************************Makefile *******************************&lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;KERNELDIR =   obj-m := test_drv.o&lt;br /&gt;&lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;#combine two drivers into the one.&lt;/span&gt; &lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#FF0000;&quot;&gt;#test_drv-objs := testA_drv.o testB_drv.o&lt;/span&gt;  &lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;ifneq ($(KERNELRELEASE),)  &lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;CFLAGS +=  -D__KERNEL__ -DMODULE  -Wall -DEXPORT_SYMTAB -O2  &lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;else  &lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;all:  &lt;/pre&gt;&lt;pre width=&quot;80&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;$(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules endif &lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/3214688718393455021/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/06/linux-26-driver-template.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/3214688718393455021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/3214688718393455021'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/06/linux-26-driver-template.html' title='Linux 2.6 Driver Template'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-4320087749092397999</id><published>2009-06-05T10:32:00.003+08:00</published><updated>2009-06-05T10:44:41.660+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Socket Programming"/><title type='text'>TCP keepalive under linux</title><content type='html'>&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(53, 28, 117); &quot;&gt;TCP keepalive During TCP connection idle&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;Main goal:&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;ul&gt;&lt;li&gt;Checking for dead peers&lt;/li&gt;&lt;li&gt;Preventing disconnection due to network inactivity- TCP connections through NATs or proxy but they keep limited memory resources (mantain a few TCP connections, discard old connections)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;  &lt;span style=&quot;color:#351c75;&quot;&gt;How to use TCP keepalive under Linux&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#6AA84F;&quot;&gt;tcp_keepalive_time&lt;/span&gt; - the interval between the last data packet sent (simple ACKs are not considered data) and the first keepalive probe; after the connection is marked to need keepalive&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#6AA84F;&quot;&gt;tcp_keepalive_intvl&lt;/span&gt; - the interval between subsequential keepalive probes, regardless of what the connection has exchanged in the meantime&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#6AA84F;&quot;&gt;tcp_keepalive_probes&lt;/span&gt; - the number of unacknowledged probes to send before considering the connection dead and notifying the application layer&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;  &lt;span style=&quot;color:#0b5394;&quot;&gt;        procfs interface&lt;/span&gt;&lt;br /&gt;&lt;table bgcolor=&quot;#999999&quot; border=&quot;0&quot; bordercolor=&quot;#000000&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; class=&quot;zeroBorder&quot; id=&quot;g141&quot; width=&quot;50%&quot;&gt;&lt;tbody&gt;    &lt;/tbody&gt;&lt;tbody&gt;    &lt;tr&gt;      &lt;td width=&quot;100%&quot;&gt;&lt;br /&gt;      echo 20 &amp;gt; /proc/sys/net/ipv4/tcp_keepalive_probes&lt;br /&gt;&lt;br /&gt;      echo 600 &amp;gt; /proc/sys/net/ipv4/tcp_keepalive_time&lt;br /&gt;&lt;br /&gt;      echo 60 &amp;gt; /proc/sys/net/ipv4/tcp_keepalive_intvl&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;  &lt;span style=&quot;color:#0b5394;&quot;&gt;        sysctl interface&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;table bgcolor=&quot;#999999&quot; border=&quot;0&quot; bordercolor=&quot;#000000&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; class=&quot;zeroBorder&quot; id=&quot;n:e.&quot; width=&quot;50%&quot;&gt;&lt;tbody&gt;    &lt;/tbody&gt;&lt;tbody&gt;    &lt;tr&gt;      &lt;td&gt;&lt;br /&gt;      sysctl -w \&lt;br /&gt;&lt;br /&gt;      &amp;gt; net.ipv4.tcp_keepalive_time=600 \&lt;br /&gt;&lt;br /&gt;      &amp;gt; net.ipv4.tcp_keepalive_intvl=60 \&lt;br /&gt;&lt;br /&gt;      &amp;gt; net.ipv4.tcp_keepalive_probes=20&lt;br /&gt;    &lt;/td&gt;    &lt;/tr&gt;    &lt;/tbody&gt;&lt;tbody&gt;  &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#351C75;&quot;&gt;How to program network applications with TCP keepalive&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;ul&gt;&lt;li&gt;System call :setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &amp;amp;optval, optlen)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;ul&gt;&lt;li&gt;Other three socket options for the current socket overide system-wide variables as the follwoing&lt;/li&gt;&lt;/ul&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Georgia;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;TCP_KEEPCNT&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: overrides &lt;/span&gt;&lt;/span&gt;&lt;tt class=&quot;varname&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;tcp_keepalive_probes&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;tt class=&quot;varname&quot;&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;TCP_KEEPIDLE&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: overrides &lt;/span&gt;&lt;/span&gt;&lt;tt class=&quot;varname&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;tcp_keepalive_time&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/tt&gt;&lt;/div&gt;&lt;div style=&quot;TEXT-ALIGN:left&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;   style=&quot;font-family:-webkit-monospace;font-size:100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:16px;&quot;&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;TCP_KEEPINTVL&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: overrides &lt;/span&gt;&lt;/span&gt;&lt;tt class=&quot;varname&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;tcp_keepalive_intvl&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  reference from &lt;a href=&quot;http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/#whatis&quot; id=&quot;e7sx&quot; title=&quot;http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/#whatis&quot;&gt;http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/#whatis&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/4320087749092397999/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2009/06/tcp-keepalive-during-tcp-connection_05.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/4320087749092397999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/4320087749092397999'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2009/06/tcp-keepalive-during-tcp-connection_05.html' title='TCP keepalive under linux'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-7043987913884809600</id><published>2008-10-09T11:18:00.002+08:00</published><updated>2009-06-08T10:00:33.644+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GDB"/><title type='text'>GDB Script file</title><content type='html'>&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#6600CC;&quot;&gt;For Linux Applications&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;set solib-absolute-prefix /home/dean/rootfs/&lt;br /&gt;&lt;br /&gt;set  solib-search-path /home/dean/rootfs/lib/&lt;br /&gt;&lt;br /&gt;target remote 192.168.38.38:1234&lt;br /&gt;&lt;br /&gt;handle SIG32 nostop&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#6600CC;&quot;&gt;&lt;b&gt;For bootloader &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Use JTAG (J-link)  to debug bootloader ;take a example for u-boot&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;#&lt;/div&gt;&lt;div&gt;# J-LINK GDB SERVER initialization&lt;/div&gt;&lt;div&gt;#&lt;/div&gt;&lt;div&gt;# This connects to a GDB Server listening&lt;/div&gt;&lt;div&gt;# for commands on localhost at tcp port 2331&lt;/div&gt;&lt;div&gt;target remote 192.168.42.42:2331&lt;/div&gt;&lt;div&gt;# Set JTAG speed to 30 kHz&lt;/div&gt;&lt;div&gt;monitor speed 30&lt;/div&gt;&lt;div&gt;# Set GDBServer to big endian&lt;/div&gt;&lt;div&gt;monitor endian little&lt;/div&gt;&lt;div&gt;# Reset the chip to get to a known state.&lt;/div&gt;&lt;div&gt;monitor reset 1&lt;/div&gt;&lt;div&gt;#monitor WaitHalt 2000&lt;/div&gt;&lt;div&gt;#&lt;/div&gt;&lt;div&gt;# CPU core initialization (to be done by user)&lt;/div&gt;&lt;div&gt;#&lt;/div&gt;&lt;div&gt;# Set the processor mode&lt;/div&gt;&lt;div&gt;monitor reg cpsr = 0xd3&lt;/div&gt;&lt;div&gt;# Set auto JTAG speed&lt;/div&gt;&lt;div&gt;monitor speed auto&lt;/div&gt;&lt;div&gt;# Setup GDB FOR FASTER DOWNLOADS&lt;/div&gt;&lt;div&gt;set remote memory-write-packet-size 1024&lt;/div&gt;&lt;div&gt;set remote memory-write-packet-size fixed&lt;/div&gt;&lt;div&gt;# Load the program executable called &quot;image.elf&quot;&lt;/div&gt;&lt;div&gt;load /home/dean/u-boot-1.2.0/u-boot &lt;/div&gt;&lt;div&gt;#assign PC conter to the start of the program (address 0x01400004) saved in the flash&lt;br /&gt;&lt;/div&gt;&lt;div&gt;monitor reg pc = 0x01400004&lt;/div&gt;&lt;div&gt;#add symbol file to this flash start address (0x01400000)  ;this context is the useless data &lt;/div&gt;&lt;div&gt;#for identification &lt;/div&gt;&lt;div&gt;add-symbol-file u-boot-1.2.0/u-boot 0x01400000&lt;/div&gt;&lt;div&gt;#set hardware breakpoint &lt;/div&gt;&lt;div&gt;monitor setBP   0x01400058&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/7043987913884809600/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/10/gdb-script-file.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7043987913884809600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7043987913884809600'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/10/gdb-script-file.html' title='GDB Script file'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-2832302964434773123</id><published>2008-03-24T00:18:00.002+08:00</published><updated>2009-06-08T16:14:01.423+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="u-boot gdb"/><title type='text'>Compile GDB for arm and U-boot相關資料</title><content type='html'>&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;            compile ARM gdb and insigh&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#6633FF;&quot;&gt;t&lt;/span&gt;&lt;br /&gt;  Environment&lt;br /&gt;  ubuntu 7.10&lt;br /&gt;  arm linux kernel 2.6.15.7&lt;br /&gt;  ARM  gcc-3.4.2 and glibc-2.3.3&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#333399;&quot;&gt;compile GDB and GDBServer&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;ul&gt;&lt;li&gt;compile GDB&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 80px;&quot;&gt;    get termcap and build arm termcap library&lt;br /&gt;  moidfy Makefile&lt;br /&gt;  assign&lt;br /&gt;  CC=arm-linux-gcc&lt;br /&gt;  LD=arm-linux-ld&lt;br /&gt;  AR=arm-linux-ar&lt;br /&gt;  make;&lt;br /&gt;  copy libtermcap.a into the library of the toolchains and termcap.h into the include path of the toolchain&lt;br /&gt;  build GDB&lt;br /&gt;  ./configure  --host= i686-pc-linux-gnu --target=arm-linux ;make &lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;ul&gt;&lt;li&gt;compile GDBServer&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;    CC=arm-linux-gcc AR= arm-linux-ar LD=arm-linux-ld ./configure --host= i686-pc-linux-gnu --target=arm-linux;make&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;compile Insight&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 80px;&quot;&gt;    ./configure  --host= i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/insight ;make;make install&lt;/div&gt;&lt;ul&gt;&lt;li&gt;燒Kernel的過程&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;boot# &lt;span style=&quot;color:#9900ff;&quot;&gt;tftp 41000000 uImage&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;Using faradaynic#0 device&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;TFTP from server 192.168.42.50; our IP address is 192.168.42.51&lt;br /&gt;Filename &#39;uImage&#39;.&lt;br /&gt;Load address: 0x41000000&lt;br /&gt;Loading: #################################################################         &lt;br /&gt;done&lt;br /&gt;Bytes transferred = 1090003 (10a1d3 hex)&lt;br /&gt;boot# &lt;span style=&quot;color:#9900ff;&quot;&gt;erase 14080000 141fffff&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;........................ done&lt;br /&gt;Erased 24 sectors&lt;br /&gt;&lt;br /&gt;boot# &lt;span style=&quot;color:#9900ff;&quot;&gt;cp.b 41000000 14080000 10a1d3(image size)&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;環境變數的設定&lt;/b&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;color:#9900ff;&quot;&gt;setenv bootargs mem=36M console=ttyS1&lt;br /&gt;root=/dev/nfs rw nfsroot=192.168.42.50:/home/dean/MyTMP/0.18/aspeed/rootfs ip=192.168.42.45:192.168.42.50:192.168.42.1.255.255.0.0:::eth0:off&lt;/span&gt;&lt;br /&gt;格式如下:&lt;br /&gt;ip=ipaddr:tftp_serverip:gatewayip:netmask:::網卡名稱:off&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;Add netconsole parameters as the below:&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap; &quot;&gt;&lt;a href=&quot;file:///Y:/Note/netconsole=@192.168.42.45/eth0,@192.168.42.46/&quot; style=&quot;color: rgb(52, 101, 164); &quot;&gt;netconsole=@192.168.42.45/eth0,@192.168.42.46/&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;The kernel will throw the data of console to the remote pc&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Please execute the command in the remote PC and show the console data &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#CC33CC;&quot;&gt;netcat -u -l -p 6666 -v&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;u-boot之mkimage的使用方式&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;[root@localhost tftpboot]#mkimage -A arm -O linux -T kernel -C none -a 0x30000 -e 0x30008000 -d zImage zImage.img&lt;br /&gt;&lt;br /&gt;參數的意義：&lt;br /&gt;      -A :set architecture&lt;br /&gt;      -O :set OS&lt;br /&gt;      -T :set image type&lt;br /&gt;      -C :set compression type&lt;br /&gt;      -a :set load address&lt;br /&gt;      -e :set entry point&lt;br /&gt;      -n :set image name&lt;br /&gt;      -d :use image data&lt;br /&gt;      -x :set XIP (execute in place)&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/2832302964434773123/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/03/compile-arm-gdb-and-insight-environment.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2832302964434773123'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2832302964434773123'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/03/compile-arm-gdb-and-insight-environment.html' title='Compile GDB for arm and U-boot相關資料'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-6956307534253677785</id><published>2008-03-24T00:15:00.000+08:00</published><updated>2008-04-16T01:50:42.034+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VIM"/><title type='text'>VIM的指令</title><content type='html'>            &lt;font id=&quot;qcq:&quot; size=&quot;3&quot;&gt;&lt;span id=&quot;b33:&quot; style=&quot;font-family: Verdana;&quot;&gt;&lt;b id=&quot;fu45&quot;&gt;            [VIM DIFF]&lt;/b&gt;&lt;/span&gt;&lt;br id=&quot;mq0h&quot; style=&quot;font-family: Verdana;&quot;&gt;&lt;/font&gt;&lt;br id=&quot;d2v8&quot; style=&quot;font-family: Verdana;&quot;&gt;&lt;pre id=&quot;oj.b&quot; style=&quot;font-family: Verdana;&quot; class=&quot;section&quot;&gt;]c 跳到下一個差異點&lt;br id=&quot;gc9a&quot;&gt;[c 跳到上一個差異點&lt;br id=&quot;d1ji&quot;&gt;&lt;br id=&quot;vbxa&quot;&gt;dp （diff &quot;put&quot;）把當前文件的內容複製到另一個文件&lt;br id=&quot;b1z8&quot;&gt;do  (diff &quot;get&quot;) 把另一個文件的內容複製到當前行中&lt;br id=&quot;hadb&quot;&gt;&lt;br id=&quot;ose_&quot;&gt;diffupdate 重新刷新比較結果&lt;br id=&quot;bym9&quot;&gt;wqa （write, then quit all）儲存全部文件，然后離開&lt;br id=&quot;je2r&quot;&gt;set diffopt=context:3 預設是會把不同之處上下各 6 行的顯示出來&lt;br id=&quot;kk_w&quot;&gt;&lt;br id=&quot;xh1d&quot;&gt;zo （folding open）&lt;br id=&quot;tb43&quot;&gt;zc （folding close）&lt;br id=&quot;nn7:&quot;&gt;&lt;br id=&quot;xuzn&quot;&gt;&lt;br id=&quot;qei1&quot;&gt;&lt;font id=&quot;uusj&quot; size=&quot;3&quot;&gt;&lt;b id=&quot;c3yj&quot;&gt;[VIM]&lt;/b&gt;&lt;/font&gt;&lt;br id=&quot;hvad&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;b id=&quot;f737&quot;&gt;&lt;b id=&quot;m_ek&quot;&gt;VIM Registers 0 : For Yank operation&lt;/b&gt;&lt;/b&gt;&lt;br id=&quot;hrpc&quot;&gt;最近一次做 yank 動作所存進去的東西&lt;br id=&quot;rj5_&quot;&gt;&lt;br id=&quot;l0yc&quot;&gt;&lt;b id=&quot;h:.x&quot;&gt;VIM Registers [1-9] : for delete operation&lt;/b&gt;&lt;br id=&quot;ura-&quot;&gt;di:顯示&lt;b id=&quot;dag2&quot;&gt;&lt;b id=&quot;evm7&quot;&gt;Registers 的內容&lt;/b&gt;&lt;/b&gt;&lt;br id=&quot;u_n2&quot;&gt;&quot;Np N=1~9 會把Register的內容貼上&lt;br id=&quot;bglo&quot;&gt;按一下.會依序貼上Register的內容&lt;br id=&quot;qn1k&quot;&gt;&lt;br id=&quot;e3vd&quot;&gt;&lt;b id=&quot;llwf&quot;&gt;VIM &lt;/b&gt;&lt;b id=&quot;tg9e&quot;&gt;Registers&lt;/b&gt;&lt;b id=&quot;w6dk&quot;&gt; [a-z A-Z]:&lt;/b&gt;&lt;br id=&quot;crwx&quot;&gt;使用者指定才會用到的東西&lt;br id=&quot;vano&quot;&gt;PS:小寫的[a-z]表示覆蓋 大寫的[A-Z]表示附加&lt;br id=&quot;xi6y&quot;&gt;ex:%s/pattern/y a =&amp;gt;%s/pattern/y A&lt;br id=&quot;y.5y&quot;&gt;&lt;br id=&quot;tykf&quot;&gt;&quot;*p 把OS剪貼簿上的東西來取代選取的區域&lt;br id=&quot;k07:&quot;&gt;&lt;br id=&quot;gq8v&quot;&gt;&lt;font id=&quot;my.y&quot; size=&quot;3&quot;&gt;&lt;b&gt;[多行註解]&lt;/b&gt;&lt;/font&gt;&lt;br id=&quot;lc3r&quot;&gt;Ctrl+v進入Visual Block模式&lt;br id=&quot;q4jx&quot;&gt;選取要註解的那幾行(j向下、k向上)。&lt;br id=&quot;gwvz&quot;&gt;按下大寫I(d or x為刪除)，會進入編輯模式，輸入註解符號。&lt;br id=&quot;v1e5&quot;&gt;然後按下Esc，這時候剛才有選取的那幾行都會加上剛才輸入的字串&lt;/pre&gt;&lt;pre id=&quot;oj.b&quot; style=&quot;font-family: Verdana;&quot; class=&quot;section&quot;&gt;&lt;br id=&quot;js69&quot;&gt;&lt;br id=&quot;ru60&quot;&gt;&lt;br id=&quot;o1dq&quot;&gt;&lt;br id=&quot;vbpj&quot;&gt;&lt;br id=&quot;hbfh&quot;&gt;&lt;br id=&quot;z9ms&quot;&gt;&lt;br id=&quot;p5hn&quot;&gt;&lt;br id=&quot;e355&quot;&gt; &lt;br id=&quot;mkt5&quot;&gt;&lt;br id=&quot;czo1&quot;&gt;&lt;br id=&quot;hp3v&quot;&gt;&lt;br id=&quot;v.ps&quot;&gt;&lt;br id=&quot;kxtx&quot;&gt;&lt;br id=&quot;exky&quot;&gt; &lt;br id=&quot;euks&quot;&gt;&lt;/pre&gt;&lt;br id=&quot;w3ho&quot; style=&quot;font-family: Verdana;&quot;&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/6956307534253677785/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/03/vim-diff-c-c-dp-diff-put-do-diff-get.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/6956307534253677785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/6956307534253677785'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/03/vim-diff-c-c-dp-diff-put-do-diff-get.html' title='VIM的指令'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-604620928634429283</id><published>2008-03-01T15:35:00.000+08:00</published><updated>2008-03-01T15:38:02.960+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>FIND的使用方式</title><content type='html'>&lt;span style=&quot;font-family:新細明體;&quot;&gt;一、&lt;/span&gt;find &lt;span style=&quot;font-family:新細明體;&quot;&gt;命令格式&lt;/span&gt;&lt;br /&gt;1&lt;span style=&quot;font-family:新細明體;&quot;&gt;、&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的一般形式為；&lt;/span&gt;&lt;br /&gt;find pathname -options [-print -exec -ok ...]&lt;br /&gt;2&lt;span style=&quot;font-family:新細明體;&quot;&gt;、&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的參數；&lt;/span&gt;&lt;br /&gt;pathname: find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令所查找的目錄路徑。例如用&lt;/span&gt;.&lt;span style=&quot;font-family:新細明體;&quot;&gt;來表示當前目錄，用&lt;/span&gt;/&lt;span style=&quot;font-family:新細明體;&quot;&gt;來表示系統根目錄。&lt;/span&gt;&lt;br /&gt;-print&lt;span style=&quot;font-family:新細明體;&quot;&gt;： &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令將匹配的文件輸出到標準輸出。&lt;/span&gt;&lt;br /&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;： &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令對匹配的文件執行該參數所給出的&lt;/span&gt;shell&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令。相應命令的形式為&lt;/span&gt;&#39;command&#39; { } ;&lt;span style=&quot;font-family:新細明體;&quot;&gt;，注意&lt;/span&gt;{ }&lt;span style=&quot;font-family:新細明體;&quot;&gt;和&lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;；之間的空格。&lt;/span&gt;&lt;br /&gt;-ok&lt;span style=&quot;font-family:新細明體;&quot;&gt;： 和&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;的作用相同，只不過以一種更為安全的模式來執行該參數所給出的&lt;/span&gt;shell&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令，在執行每一個命令之前，都會給出提示，讓用戶來確定是否執行。&lt;/span&gt;&lt;br /&gt;3&lt;span style=&quot;font-family:新細明體;&quot;&gt;、&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令選項&lt;/span&gt;&lt;br /&gt;-name&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按照文件名查找文件。&lt;/span&gt;&lt;br /&gt;-perm&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按照文件權限來查找文件。&lt;/span&gt;&lt;br /&gt;-prune&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;使用這一選項可以使&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令不在當前指定的目錄中查找，如果同時使用&lt;/span&gt;-depth&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項，那麼&lt;/span&gt;-prune&lt;span style=&quot;font-family:新細明體;&quot;&gt;將被&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令忽略。&lt;/span&gt;&lt;br /&gt;-user&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按照文件屬主來查找文件。&lt;/span&gt;&lt;br /&gt;-group&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按照文件所屬的組來查找文件。&lt;/span&gt;&lt;br /&gt;-mtime -n +n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按照文件的更改時間來查找文件， &lt;/span&gt;- n&lt;span style=&quot;font-family:新細明體;&quot;&gt;表示文件更改時間距現在&lt;/span&gt;n&lt;span style=&quot;font-family:新細明體;&quot;&gt;天以內，&lt;/span&gt;+ n&lt;span style=&quot;font-family:新細明體;&quot;&gt;表示文件更改時間距現在&lt;/span&gt;n&lt;span style=&quot;font-family:新細明體;&quot;&gt;天以前。&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令還有&lt;/span&gt;-atime&lt;span style=&quot;font-family:新細明體;&quot;&gt;和&lt;/span&gt;-ctime &lt;span style=&quot;font-family:新細明體;&quot;&gt;選項，但它們都和&lt;/span&gt;-m time&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。&lt;/span&gt;&lt;br /&gt;-nogroup&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找無有效所屬組的文件，即該文件所屬的組在&lt;/span&gt;/etc/groups&lt;span style=&quot;font-family:新細明體;&quot;&gt;中不存在。&lt;/span&gt;&lt;br /&gt;-nouser&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找無有效屬主的文件，即該文件的屬主在&lt;/span&gt;/etc/passwd&lt;span style=&quot;font-family:新細明體;&quot;&gt;中不存在。&lt;/span&gt;&lt;br /&gt;-newer file1 ! file2&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找更改時間比文件&lt;/span&gt;file1&lt;span style=&quot;font-family:新細明體;&quot;&gt;新但比文件&lt;/span&gt;file2&lt;span style=&quot;font-family:新細明體;&quot;&gt;舊的文件。&lt;/span&gt;&lt;br /&gt;-type&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找某一類型的文件，諸如：&lt;/span&gt;&lt;br /&gt;b - &lt;span style=&quot;font-family:新細明體;&quot;&gt;塊設備文件。&lt;/span&gt;&lt;br /&gt;d - &lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄。&lt;/span&gt;&lt;br /&gt;c - &lt;span style=&quot;font-family:新細明體;&quot;&gt;字符設備文件。&lt;/span&gt;&lt;br /&gt;p - &lt;span style=&quot;font-family:新細明體;&quot;&gt;管道文件。&lt;/span&gt;&lt;br /&gt;l - &lt;span style=&quot;font-family:新細明體;&quot;&gt;符號鏈接文件。&lt;/span&gt;&lt;br /&gt;f - &lt;span style=&quot;font-family:新細明體;&quot;&gt;普通文件。&lt;/span&gt;&lt;br /&gt;-size n&lt;span style=&quot;font-family:新細明體;&quot;&gt;：&lt;/span&gt;[c] &lt;span style=&quot;font-family:新細明體;&quot;&gt;查找文件長度為&lt;/span&gt;n&lt;span style=&quot;font-family:新細明體;&quot;&gt;塊的文件，帶有&lt;/span&gt;c&lt;span style=&quot;font-family:新細明體;&quot;&gt;時表示文件長度以字節計。&lt;/span&gt;&lt;br /&gt;-depth&lt;span style=&quot;font-family:新細明體;&quot;&gt;：在查找文件時，首先查找當前目錄中的文件，然後再在其子目錄中查找。&lt;/span&gt;&lt;br /&gt;-fstype&lt;span style=&quot;font-family:新細明體;&quot;&gt;：查找位於某一類型文件系統中的文件，這些文件系統類型通常可以在配置文件&lt;/span&gt;/etc/fstab&lt;span style=&quot;font-family:新細明體;&quot;&gt;中找到，該配置文件中包含了本系統中有關文件系統的信息。&lt;/span&gt;&lt;br /&gt;-mount&lt;span style=&quot;font-family:新細明體;&quot;&gt;：在查找文件時不跨越文件系統&lt;/span&gt;mount&lt;span style=&quot;font-family:新細明體;&quot;&gt;點。&lt;/span&gt;&lt;br /&gt;-follow&lt;span style=&quot;font-family:新細明體;&quot;&gt;：如果&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令遇到符號鏈接文件，就跟蹤至鏈接所指向的文件。&lt;/span&gt;&lt;br /&gt;-cpio&lt;span style=&quot;font-family:新細明體;&quot;&gt;：對匹配的文件使用&lt;/span&gt;cpio&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令，將這些文件備份到磁帶設備中。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;另外&lt;/span&gt;,&lt;span style=&quot;font-family:新細明體;&quot;&gt;下面三個的區別&lt;/span&gt;:&lt;br /&gt;-amin n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;　　查找系統中最後&lt;/span&gt;N&lt;span style=&quot;font-family:新細明體;&quot;&gt;分鐘訪問的文件&lt;/span&gt;&lt;br /&gt;　　-atime n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;　　查找系統中最後&lt;/span&gt;n*24&lt;span style=&quot;font-family:新細明體;&quot;&gt;小時訪問的文件&lt;/span&gt;&lt;br /&gt;　　-cmin n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;　　查找系統中最後&lt;/span&gt;N&lt;span style=&quot;font-family:新細明體;&quot;&gt;分鐘被改變文件狀態的文件&lt;/span&gt;&lt;br /&gt;　　-ctime n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;　　查找系統中最後&lt;/span&gt;n*24&lt;span style=&quot;font-family:新細明體;&quot;&gt;小時被改變文件狀態的文件&lt;/span&gt;&lt;br /&gt;　-mmin n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;　　查找系統中最後&lt;/span&gt;N&lt;span style=&quot;font-family:新細明體;&quot;&gt;分鐘被改變文件數據的文件&lt;/span&gt;&lt;br /&gt;　　-mtime n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;　　查找系統中最後&lt;/span&gt;n*24&lt;span style=&quot;font-family:新細明體;&quot;&gt;小時被改變文件數據的文件&lt;/span&gt;&lt;br /&gt;4&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;或&lt;/span&gt;ok&lt;span style=&quot;font-family:新細明體;&quot;&gt;來執行&lt;/span&gt;shell&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;使用&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;時，只要把想要的操作寫在一個文件裡，就可以用&lt;/span&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;來配合&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找，很方便的&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在有些操作系統中只允許&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項執行諸如&lt;/span&gt;l s&lt;span style=&quot;font-family:新細明體;&quot;&gt;或&lt;/span&gt;ls -l&lt;span style=&quot;font-family:新細明體;&quot;&gt;這樣的命令。大多數用戶使用這一選項是為了查找舊文件並刪除它們。建議在真正執行&lt;/span&gt;rm&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令刪除文件之前，最好先用&lt;/span&gt;ls&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令看一下，確認它們是所要刪除的文件。&lt;/span&gt;&lt;br /&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項後面跟隨著所要執行的命令或腳本，然後是一對兒&lt;/span&gt;{ }&lt;span style=&quot;font-family:新細明體;&quot;&gt;，一個空格和一個&lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;，最後是一個分號。為了使用&lt;/span&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項，必須要同時使用&lt;/span&gt;print&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。如果驗證一下&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令，會發現該命令只輸出從當前路徑起的相對路徑及文件名。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;例如：為了用&lt;/span&gt;ls -l&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令列出所匹配到的文件，可以把&lt;/span&gt;ls -l&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令放在&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項中&lt;/span&gt;&lt;br /&gt;# find . -type f -exec ls -l { }  \;&lt;br /&gt;-rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf&lt;br /&gt;-rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic&lt;br /&gt;-rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;上面的例子中，&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令匹配到了當前目錄下的所有普通文件，並在&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項中使用&lt;/span&gt;ls -l&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令將它們列出。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;/logs&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄中查找更改時間在&lt;/span&gt;5&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以前的文件並刪除它們：&lt;/span&gt;&lt;br /&gt;$ find logs -type f -mtime +5 -exec rm { }  \;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;記住：在&lt;/span&gt;shell&lt;span style=&quot;font-family:新細明體;&quot;&gt;中用任何方式刪除文件之前，應當先查看相應的文件，一定要小心！當使用諸如&lt;/span&gt;mv&lt;span style=&quot;font-family:新細明體;&quot;&gt;或&lt;/span&gt;rm&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令時，可以使用&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項的安全模式。它將在對每個匹配到的文件進行操作之前提示你。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在下面的例子中， &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令在當前目錄中查找所有文件名以&lt;/span&gt;.LOG&lt;span style=&quot;font-family:新細明體;&quot;&gt;結尾、更改時間在&lt;/span&gt;5&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以上的文件，並刪除它們，只不過在刪除之前先給出提示。&lt;/span&gt;&lt;br /&gt;$ find . -name &quot;*.conf&quot; -mtime +5 -ok rm { }  \;&lt;br /&gt;&amp;lt; rm ... ./conf/httpd.conf &amp;gt; ? n&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按&lt;/span&gt;y&lt;span style=&quot;font-family:新細明體;&quot;&gt;鍵刪除文件，按&lt;/span&gt;n&lt;span style=&quot;font-family:新細明體;&quot;&gt;鍵不刪除。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;任何形式的命令都可以在&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項中使用。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在下面的例子中我們使用&lt;/span&gt;grep&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令。&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令首先匹配所有文件名為「 &lt;/span&gt;passwd*&lt;span style=&quot;font-family:新細明體;&quot;&gt;」的文件，例如&lt;/span&gt;passwd&lt;span style=&quot;font-family:新細明體;&quot;&gt;、&lt;/span&gt;passwd.old&lt;span style=&quot;font-family:新細明體;&quot;&gt;、&lt;/span&gt;passwd.bak&lt;span style=&quot;font-family:新細明體;&quot;&gt;，然後執行&lt;/span&gt;grep&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令看看在這些文件中是否存在一個&lt;/span&gt;sam&lt;span style=&quot;font-family:新細明體;&quot;&gt;用戶。&lt;/span&gt;&lt;br /&gt;# find /etc -name &quot;passwd*&quot; -exec grep &quot;sam&quot; { }  \;&lt;br /&gt;sam:x:501:501::/usr/sam:/bin/bash&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;二、&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的例子；&lt;/span&gt;&lt;br /&gt;1&lt;span style=&quot;font-family:新細明體;&quot;&gt;、查找當前用戶主目錄下的所有文件：&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;下面兩種方法都可以使用&lt;/span&gt;&lt;br /&gt;$ find $HOME -print&lt;br /&gt;$ find ~ -print&lt;br /&gt;2&lt;span style=&quot;font-family:新細明體;&quot;&gt;、讓當前目錄中文件屬主具有讀、寫權限，並且文件所屬組的用戶和其他用戶具有讀權限的文件；&lt;/span&gt;&lt;br /&gt;$ find . -type f -perm 644 -exec ls -l { }  \;&lt;br /&gt;3&lt;span style=&quot;font-family:新細明體;&quot;&gt;、為了查找系統中所有文件長度為&lt;/span&gt;0&lt;span style=&quot;font-family:新細明體;&quot;&gt;的普通文件，並列出它們的完整路徑；&lt;/span&gt;&lt;br /&gt;$ find / -type f -size 0 -exec ls -l { }  \;&lt;br /&gt;4&lt;span style=&quot;font-family:新細明體;&quot;&gt;、查找&lt;/span&gt;/var/logs&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄中更改時間在&lt;/span&gt;7&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以前的普通文件，並在刪除之前詢問它們；&lt;/span&gt;&lt;br /&gt;$ find /var/logs -type f -mtime +7 -ok rm { }  \;&lt;br /&gt;5&lt;span style=&quot;font-family:新細明體;&quot;&gt;、為了查找系統中所有屬於&lt;/span&gt;root&lt;span style=&quot;font-family:新細明體;&quot;&gt;組的文件；&lt;/span&gt;&lt;br /&gt;$find . -group root -exec ls -l { }  \;&lt;br /&gt;-rw-r--r-- 1 root root 595 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:09 ./fie1&lt;br /&gt;6&lt;span style=&quot;font-family:新細明體;&quot;&gt;、&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令將刪除當目錄中訪問時間在&lt;/span&gt;7&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以來、含有數字後綴的&lt;/span&gt;admin.log&lt;span style=&quot;font-family:新細明體;&quot;&gt;文件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;該命令只檢查三位數字，所以相應文件的後綴不要超過&lt;/span&gt;999&lt;span style=&quot;font-family:新細明體;&quot;&gt;。先建幾個&lt;/span&gt;admin.log*&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件 ，才能使用下面這個命令&lt;/span&gt;&lt;br /&gt;$ find . -name &quot;admin.log[0-9][0-9][0-9]&quot; -atime -7 -ok&lt;br /&gt;rm { } ;&lt;br /&gt;&amp;lt; rm ... ./admin.log001 &amp;gt; ? n&lt;br /&gt;&amp;lt; rm ... ./admin.log002 &amp;gt; ? n&lt;br /&gt;&amp;lt; rm ... ./admin.log042 &amp;gt; ? n&lt;br /&gt;&amp;lt; rm ... ./admin.log942 &amp;gt; ? n&lt;br /&gt;7&lt;span style=&quot;font-family:新細明體;&quot;&gt;、為了查找當前文件系統中的所有目錄並排序；&lt;/span&gt;&lt;br /&gt;$ find . -type d sort&lt;br /&gt;8&lt;span style=&quot;font-family:新細明體;&quot;&gt;、為了查找系統中所有的&lt;/span&gt;rmt&lt;span style=&quot;font-family:新細明體;&quot;&gt;磁帶設備；&lt;/span&gt;&lt;br /&gt;$ find /dev/rmt -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;三、&lt;/span&gt;xargs&lt;br /&gt;xargs - build and execute command lines from standard input&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在使用&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項處理匹配到的文件時， &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令將所有匹配到的文件一起傳遞給&lt;/span&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;執行。但有些系統對能夠傳遞給&lt;/span&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;的命令長度有限制，這樣在&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令運行幾分鐘之後，就會出現溢出錯誤。錯誤信息通常是「參數列太長」或「參數列溢出」。這就是&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的用處所在，特別是與&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令一起使用。&lt;/span&gt;&lt;br /&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令把匹配到的文件傳遞給&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令，而&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令每次只獲取一部分文件而不是全部，不像&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項那樣。這樣它可以先處理最先獲取的一部分文件，然後是下一批，並如此繼續下去。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在有些系統中，使用&lt;/span&gt;-exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項會為處理每一個匹配到的文件而發起一個相應的進程，並非將匹配到的文件全部作為參數一次執行；這樣在有些情況下就會出現進程過多，系統性能下降的問題，因而效率不高；&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;而使用&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令則只有一個進程。另外，在使用&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令時，究竟是一次獲取所有的參數，還是分批取得參數，以及每一次獲取參數的數目都會根據該命令的選項及系統內核中相應的可調參數來確定。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;來看看&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令是如何同&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令一起使用的，並給出一些例子。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;下面的例子查找系統中的每一個普通文件，然後使用&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令來測試它們分別屬於哪類文件&lt;/span&gt;&lt;br /&gt;#find . -type f -print xargs file&lt;br /&gt;./.kde/Autostart/Autorun.desktop: UTF-8 Unicode English text&lt;br /&gt;./.kde/Autostart/.directory: ISO-8859 text&lt;span style=&quot;font-family:新細明體;&quot;&gt;在整個系統中查找內存信息轉儲文件&lt;/span&gt;(core dump) &lt;span style=&quot;font-family:新細明體;&quot;&gt;，然後把結果保存到&lt;/span&gt;/tmp/core.log &lt;span style=&quot;font-family:新細明體;&quot;&gt;文件中：&lt;/span&gt;&lt;br /&gt;$ find / -name &quot;core&quot; -print xargs echo &quot;&quot; &amp;gt;/tmp/core.log&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;上面這個執行太慢，我改成在當前目錄下查找&lt;/span&gt;&lt;br /&gt;#find . -name &quot;file*&quot; -print xargs echo &quot;&quot; &amp;gt; /temp/core.log&lt;br /&gt;# cat /temp/core.log&lt;br /&gt;./file6&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在當前目錄下查找所有用戶具有讀、寫和執行權限的文件，並收回相應的寫權限：&lt;/span&gt;&lt;br /&gt;# ls -l&lt;br /&gt;drwxrwxrwx 2 sam adm 4096 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;30 20:14 file6&lt;br /&gt;-rwxrwxrwx 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 http3.conf&lt;br /&gt;-rwxrwxrwx 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 httpd.conf&lt;br /&gt;# find . -perm -7 -print xargs chmod o-w&lt;br /&gt;# ls -l&lt;br /&gt;drwxrwxr-x 2 sam adm 4096 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;30 20:14 file6&lt;br /&gt;-rwxrwxr-x 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 http3.conf&lt;br /&gt;-rwxrwxr-x 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 httpd.conf&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;用&lt;/span&gt;grep&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令在所有的普通文件中搜索&lt;/span&gt;hostname&lt;span style=&quot;font-family:新細明體;&quot;&gt;這個詞：&lt;/span&gt;&lt;br /&gt;# find . -type f -print xargs grep &quot;hostname&quot;&lt;br /&gt;./httpd1.conf:# different IP addresses or hostnames and have them handled by the&lt;br /&gt;./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames&lt;br /&gt;on your&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;用&lt;/span&gt;grep&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令在當前目錄下的所有普通文件中搜索&lt;/span&gt;hostnames&lt;span style=&quot;font-family:新細明體;&quot;&gt;這個詞：&lt;/span&gt;&lt;br /&gt;# find . -name * -type f -print xargs grep &quot;hostnames&quot;&lt;br /&gt;./httpd1.conf:# different IP addresses or hostnames and have them handled by the&lt;br /&gt;./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames&lt;br /&gt;on your&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;注意，在上面的例子中， &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;用來取消&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令中的&lt;/span&gt;*&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;shell&lt;span style=&quot;font-family:新細明體;&quot;&gt;中的特殊含義。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令配合使用&lt;/span&gt;exec&lt;span style=&quot;font-family:新細明體;&quot;&gt;和&lt;/span&gt;xargs&lt;span style=&quot;font-family:新細明體;&quot;&gt;可以使用戶對所匹配到的文件執行幾乎所有的命令。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;四、&lt;/span&gt;find &lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的參數&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;下面是&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;一些常用參數的例子，有用到的時候查查就行了，像上面前幾個貼子，都用到了其中的的一些參數，也可以用&lt;/span&gt;man&lt;span style=&quot;font-family:新細明體;&quot;&gt;或查看論壇裡其它貼子有&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;的命令手冊&lt;/span&gt;&lt;br /&gt;1&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;name&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;文件名選項是&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令最常用的選項，要麼單獨使用該選項，要麼和其他選項一起使用。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;可以使用某種文件名模式來匹配文件，記住要用引號將文件名模式引起來。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;不管當前路徑是什麼，如果想要在自己的根目錄&lt;/span&gt;$HOME&lt;span style=&quot;font-family:新細明體;&quot;&gt;中查找文件名符合&lt;/span&gt;*.txt&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件，使用&lt;/span&gt;~&lt;span style=&quot;font-family:新細明體;&quot;&gt;作為 &lt;/span&gt;&#39;pathname&#39;&lt;span style=&quot;font-family:新細明體;&quot;&gt;參數，波浪號&lt;/span&gt;~&lt;span style=&quot;font-family:新細明體;&quot;&gt;代表了你的&lt;/span&gt;$HOME&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄。&lt;/span&gt;&lt;br /&gt;$ find ~ -name &quot;*.txt&quot; -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;想要在當前目錄及子目錄中查找所有的『 &lt;/span&gt;*.txt&lt;span style=&quot;font-family:新細明體;&quot;&gt;』文件，可以用：&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;$ find . -name &quot;*.txt&quot; -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;想要的當前目錄及子目錄中查找文件名以一個大寫字母開頭的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find . -name &quot;[A-Z]*&quot; -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;想要在&lt;/span&gt;/etc&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄中查找文件名以&lt;/span&gt;host&lt;span style=&quot;font-family:新細明體;&quot;&gt;開頭的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find /etc -name &quot;host*&quot; -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;想要查找&lt;/span&gt;$HOME&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄中的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find ~ -name &quot;*&quot; -print &lt;span style=&quot;font-family:新細明體;&quot;&gt;或&lt;/span&gt;find . -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;要想讓系統高負荷運行，就從根目錄開始查找所有的文件。&lt;/span&gt;&lt;br /&gt;$ find / -name &quot;*&quot; -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果想在當前目錄查找文件名以兩個小寫字母開頭，跟著是兩個數字，最後是&lt;/span&gt;.txt&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件，下面的命令就能夠返回名為&lt;/span&gt;ax37.txt&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件：&lt;/span&gt;&lt;br /&gt;$find . -name &quot;[a-z][a-z][0--9][0--9].txt&quot; -print&lt;br /&gt;2&lt;span style=&quot;font-family:新細明體;&quot;&gt;、用&lt;/span&gt;perm&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按照文件權限模式用&lt;/span&gt;-perm&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;,&lt;span style=&quot;font-family:新細明體;&quot;&gt;按文件權限模式來查找文件的話。最好使用八進制的權限表示法。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如在當前目錄下查找文件權限位為&lt;/span&gt;755&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件，即文件屬主可以讀、寫、執行，其他用戶可以讀、執行的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find . -perm 755 -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;還有一種表達方法：在八進制數字前面要加一個橫槓&lt;/span&gt;-&lt;span style=&quot;font-family:新細明體;&quot;&gt;，表示都匹配，如&lt;/span&gt;-007&lt;span style=&quot;font-family:新細明體;&quot;&gt;就相當於&lt;/span&gt;777&lt;span style=&quot;font-family:新細明體;&quot;&gt;，&lt;/span&gt;-006&lt;span style=&quot;font-family:新細明體;&quot;&gt;相當於&lt;/span&gt;666&lt;br /&gt;# ls -l&lt;br /&gt;-rwxrwxr-x 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 http3.conf&lt;br /&gt;-rw-rw-rw- 1 sam adm 34890 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 00:57 httpd1.conf&lt;br /&gt;-rwxrwxr-x 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 httpd.conf&lt;br /&gt;drw-rw-rw- 2 gem group 4096 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;26 19:48 sam&lt;br /&gt;-rw-rw-rw- 1 root root 2792 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 20:19 temp&lt;br /&gt;# find . -perm 006&lt;br /&gt;# find . -perm -006&lt;br /&gt;./sam&lt;br /&gt;./httpd1.conf&lt;br /&gt;./temp&lt;br /&gt;-perm mode:&lt;span style=&quot;font-family:新細明體;&quot;&gt;文件許可正好符合&lt;/span&gt;mode&lt;br /&gt;-perm +mode:&lt;span style=&quot;font-family:新細明體;&quot;&gt;文件許可部分符合&lt;/span&gt;mode&lt;br /&gt;-perm -mode: &lt;span style=&quot;font-family:新細明體;&quot;&gt;文件許可完全符合&lt;/span&gt;mode&lt;br /&gt;3&lt;span style=&quot;font-family:新細明體;&quot;&gt;、忽略某個目錄&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果在查找文件時希望忽略某個目錄，因為你知道那個目錄中沒有你所要查找的文件，那麼可以使用&lt;/span&gt;-prune&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項來指出需要忽略的目錄。在使用&lt;/span&gt;-prune&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項時要當心，因為如果你同時使用了&lt;/span&gt;-depth&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項，那麼&lt;/span&gt;-prune&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項就會被&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令忽略。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果希望在&lt;/span&gt;/apps&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找文件，但不希望在&lt;/span&gt;/apps/bin&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找，可以用：&lt;/span&gt;&lt;br /&gt;$ find /apps -path &quot;/apps/bin&quot; -prune -o -print&lt;br /&gt;4&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找文件的時候怎麼避開某個文件目錄&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;比如要在&lt;/span&gt;/usr/sam&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找不在&lt;/span&gt;dir1&lt;span style=&quot;font-family:新細明體;&quot;&gt;子目錄之內的所有文件&lt;/span&gt;&lt;br /&gt;find /usr/sam -path &quot;/usr/sam/dir1&quot; -prune -o -print&lt;br /&gt;find [-path ..] [expression] &lt;span style=&quot;font-family:新細明體;&quot;&gt;在路徑列表的後面的是表達式&lt;/span&gt;&lt;br /&gt;-path &quot;/usr/sam&quot; -prune -o -print &lt;span style=&quot;font-family:新細明體;&quot;&gt;是 &lt;/span&gt;-path &quot;/usr/sam&quot; -a -prune -o&lt;br /&gt;-print &lt;span style=&quot;font-family:新細明體;&quot;&gt;的簡寫表達式按順序求值&lt;/span&gt;, -a &lt;span style=&quot;font-family:新細明體;&quot;&gt;和 &lt;/span&gt;-o &lt;span style=&quot;font-family:新細明體;&quot;&gt;都是短路求值，與 &lt;/span&gt;shell &lt;span style=&quot;font-family:新細明體;&quot;&gt;的 &lt;/span&gt;&amp;amp;&amp;amp; &lt;span style=&quot;font-family:新細明體;&quot;&gt;和 &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;類似如果 &lt;/span&gt;-path &quot;/usr/sam&quot; &lt;span style=&quot;font-family:新細明體;&quot;&gt;為真，則求值 &lt;/span&gt;-prune , -prune &lt;span style=&quot;font-family:新細明體;&quot;&gt;返回真，與邏輯表達式為真；否則不求值 &lt;/span&gt;-prune&lt;span style=&quot;font-family:新細明體;&quot;&gt;，與邏輯表達式為假。如果 &lt;/span&gt;-path &quot;/usr/sam&quot; -a -prune &lt;span style=&quot;font-family:新細明體;&quot;&gt;為假，則求值 &lt;/span&gt;-print &lt;span style=&quot;font-family:新細明體;&quot;&gt;，&lt;/span&gt;-print&lt;span style=&quot;font-family:新細明體;&quot;&gt;返回真，或邏輯表達式為真；否則不求值 &lt;/span&gt;-print&lt;span style=&quot;font-family:新細明體;&quot;&gt;，或邏輯表達式為真。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;這個表達式組合特例可以用偽碼寫為&lt;/span&gt;&lt;br /&gt;if -path &quot;/usr/sam&quot; then&lt;br /&gt;-prune&lt;br /&gt;else&lt;br /&gt;-print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;避開多個文件夾&lt;/span&gt;&lt;br /&gt;find /usr/sam ( -path /usr/sam/dir1 -o -path /usr/sam/file1 ) -prune -o -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;圓括號表示表達式的結合。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;表示引用，即指示 &lt;/span&gt;shell &lt;span style=&quot;font-family:新細明體;&quot;&gt;不對後面的字符作特殊解釋，而留給 &lt;/span&gt;find &lt;span style=&quot;font-family:新細明體;&quot;&gt;命令去解釋其意義。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找某一確定文件，&lt;/span&gt;-name&lt;span style=&quot;font-family:新細明體;&quot;&gt;等選項加在&lt;/span&gt;-o &lt;span style=&quot;font-family:新細明體;&quot;&gt;之後&lt;/span&gt;&lt;br /&gt;#find /usr/sam (-path /usr/sam/dir1 -o -path /usr/sam/file1 ) -prune -o -name &quot;temp&quot; -print&lt;br /&gt;5&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;user&lt;span style=&quot;font-family:新細明體;&quot;&gt;和&lt;/span&gt;nouser&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;按文件屬主查找文件，如在&lt;/span&gt;$HOME&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄中查找文件屬主為&lt;/span&gt;sam&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find ~ -user sam -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;/etc&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找文件屬主為&lt;/span&gt;uucp&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件：&lt;/span&gt;&lt;br /&gt;$ find /etc -user uucp -print&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;為了查找屬主帳戶已經被刪除的文件，可以使用&lt;/span&gt;-nouser&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。這樣就能夠找到那些屬主在&lt;/span&gt;/etc/passwd&lt;span style=&quot;font-family:新細明體;&quot;&gt;文件中沒有有效帳戶的文件。在使用&lt;/span&gt;-nouser&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項時，不必給出用戶名； &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令能夠為你完成相應的工作。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;例如，希望在&lt;/span&gt;/home&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找所有的這類文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find /home -nouser -print&lt;br /&gt;6&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;group&lt;span style=&quot;font-family:新細明體;&quot;&gt;和&lt;/span&gt;nogroup&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;就像&lt;/span&gt;user&lt;span style=&quot;font-family:新細明體;&quot;&gt;和&lt;/span&gt;nouser&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項一樣，針對文件所屬於的用戶組， &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令也具有同樣的選項，為了在&lt;/span&gt;/apps&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找屬於&lt;/span&gt;gem&lt;span style=&quot;font-family:新細明體;&quot;&gt;用戶組的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find /apps -group gem -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;要查找沒有有效所屬用戶組的所有文件，可以使用&lt;/span&gt;nogroup&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。下面的&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令從文件系統的根目錄處查找這樣的文件&lt;/span&gt;&lt;br /&gt;$ find / -nogroup-print&lt;br /&gt;7&lt;span style=&quot;font-family:新細明體;&quot;&gt;、按照更改時間或訪問時間等查找文件&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果希望按照更改時間來查找文件，可以使用&lt;/span&gt;mtime,atime&lt;span style=&quot;font-family:新細明體;&quot;&gt;或&lt;/span&gt;ctime&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。如果系統突然沒有可用空間了，很有可能某一個文件的長度在此期間增長迅速，這時就可以用&lt;/span&gt;mtime&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項來查找這樣的文件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;用減號&lt;/span&gt;-&lt;span style=&quot;font-family:新細明體;&quot;&gt;來限定更改時間在距今&lt;/span&gt;n&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以內的文件，而用加號&lt;/span&gt;+&lt;span style=&quot;font-family:新細明體;&quot;&gt;來限定更改時間在距今&lt;/span&gt;n&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以前的文件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;希望在系統根目錄下查找更改時間在&lt;/span&gt;5&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以內的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find / -mtime -5 -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;為了在&lt;/span&gt;/var/adm&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找更改時間在&lt;/span&gt;3&lt;span style=&quot;font-family:新細明體;&quot;&gt;日以前的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find /var/adm -mtime +3 -print&lt;br /&gt;8&lt;span style=&quot;font-family:新細明體;&quot;&gt;、查找比某個文件新或舊的文件&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果希望查找更改時間比某個文件新但比另一個文件舊的所有文件，可以使用&lt;/span&gt;-newer&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。它的一般形式為：&lt;/span&gt;&lt;br /&gt;newest_file_name ! oldest_file_name&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;其中，！是邏輯非符號。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找更改時間比文件&lt;/span&gt;sam&lt;span style=&quot;font-family:新細明體;&quot;&gt;新但比文件&lt;/span&gt;temp&lt;span style=&quot;font-family:新細明體;&quot;&gt;舊的文件：&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;例：有兩個文件&lt;/span&gt;&lt;br /&gt;-rw-r--r-- 1 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:07 fiel&lt;br /&gt;-rw-rw-rw- 1 sam adm 34890 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 00:57 httpd1.conf&lt;br /&gt;-rwxrwxr-x 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 httpd.conf&lt;br /&gt;drw-rw-rw- 2 gem group 4096 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;26 19:48 sam&lt;br /&gt;-rw-rw-rw- 1 root root 2792 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 20:19 temp&lt;br /&gt;# find -newer httpd1.conf ! -newer temp -ls&lt;br /&gt;1077669 0 -rwxrwxr-x 2 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:01 ./httpd.conf&lt;br /&gt;1077671 4 -rw-rw-rw- 1 root root 2792 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 20:19 ./temp&lt;br /&gt;1077673 0 -rw-r--r-- 1 sam adm 0 10&lt;span style=&quot;font-family:新細明體;&quot;&gt;月 &lt;/span&gt;31 01:07 ./fiel&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;查找更改時間在比&lt;/span&gt;temp&lt;span style=&quot;font-family:新細明體;&quot;&gt;文件新的文件：&lt;/span&gt;&lt;br /&gt;$ find . -newer temp -print&lt;br /&gt;9&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;type&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;/etc&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找所有的目錄，可以用：&lt;/span&gt;&lt;br /&gt;$ find /etc -type d -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在當前目錄下查找除目錄以外的所有類型的文件，可以用：&lt;/span&gt;&lt;br /&gt;$ find . ! -type d -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;/etc&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找所有的符號鏈接文件，可以用&lt;/span&gt;&lt;br /&gt;$ find /etc -type l -print&lt;br /&gt;10&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;size&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;可以按照文件長度來查找文件，這裡所指的文件長度既可以用塊（&lt;/span&gt;block&lt;span style=&quot;font-family:新細明體;&quot;&gt;）來計量，也可以用字節來計量。以字節計量文件長度的表達形式為&lt;/span&gt;N c&lt;span style=&quot;font-family:新細明體;&quot;&gt;；以塊計量文件長度只用數字表示即可。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在按照文件長度查找文件時，一般使用這種以字節表示的文件長度，在查看文件系統的大小，因為這時使用塊來計量更容易轉換。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在當前目錄下查找文件長度大於&lt;/span&gt;1 M&lt;span style=&quot;font-family:新細明體;&quot;&gt;字節的文件：&lt;/span&gt;&lt;br /&gt;$ find . -size +1000000c -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;/home/apache&lt;span style=&quot;font-family:新細明體;&quot;&gt;目錄下查找文件長度恰好為&lt;/span&gt;100&lt;span style=&quot;font-family:新細明體;&quot;&gt;字節的文件：&lt;/span&gt;&lt;br /&gt;$ find /home/apache -size 100c -print&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在當前目錄下查找長度超過&lt;/span&gt;10&lt;span style=&quot;font-family:新細明體;&quot;&gt;塊的文件（一塊等於&lt;/span&gt;512&lt;span style=&quot;font-family:新細明體;&quot;&gt;字節）： &lt;/span&gt;&lt;br /&gt;$ find . -size +10 -print&lt;br /&gt;11&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;depth&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在使用&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令時，可能希望先匹配所有的文件，再在子目錄中查找。使用&lt;/span&gt;depth&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項就可以使&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令這樣做。這樣做的一個原因就是，當在使用&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令向磁帶上備份文件系統時，希望首先備份所有的文件，其次再備份子目錄中的文件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在下面的例子中， &lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令從文件系統的根目錄開始，查找一個名為&lt;/span&gt;CON.FILE&lt;span style=&quot;font-family:新細明體;&quot;&gt;的文件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;它將首先匹配所有的文件然後再進入子目錄中查找。&lt;/span&gt;&lt;br /&gt;$ find / -name &quot;CON.FILE&quot; -depth -print&lt;br /&gt;12&lt;span style=&quot;font-family:新細明體;&quot;&gt;、使用&lt;/span&gt;mount&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在當前的文件系統中查找文件（不進入其他文件系統），可以使用&lt;/span&gt;find&lt;span style=&quot;font-family:新細明體;&quot;&gt;命令的&lt;/span&gt;mount&lt;span style=&quot;font-family:新細明體;&quot;&gt;選項。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;從當前目錄開始查找位於本文件系統中文件名以&lt;/span&gt;XC&lt;span style=&quot;font-family:新細明體;&quot;&gt;結尾的文件：&lt;/span&gt;&lt;br /&gt;$ find . -name &quot;*.XC&quot; -mount -print</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/604620928634429283/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/02/find-1-find-find-pathname-options-print_29.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/604620928634429283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/604620928634429283'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/02/find-1-find-find-pathname-options-print_29.html' title='FIND的使用方式'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-201061415788965030</id><published>2008-03-01T12:09:00.000+08:00</published><updated>2008-03-01T13:28:07.794+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="shell"/><title type='text'>[Note]Shell Script變數</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;顯示變數值的全部。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/home/kenny/tmp/test.1.sh &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME##/*/} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;比對變數值開端﹐如果以 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/*/ &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;開頭的話﹐砍掉最長的部份。 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;test.1.sh &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME#/*/} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;比對變數值開端﹐如果以 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/*/ &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;開頭的話﹐砍掉最短的部份。 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;kenny/tmp/test.1.sh &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME%.*} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;比對變數值末端﹐如果以 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;.* &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;結尾的話﹐砍掉最短的部份。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;home/kenny/tmp/test.1 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME%%.*} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;比對變數值末端﹐如果以 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;.* &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;結尾的話﹐砍掉最長的部份。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/home/kenny/tmp/test &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME/sh/bash} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果在變數值中找到 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;sh &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;的話﹐將第一個 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;sh &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;換成 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;bash&lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/home/kenny/tmp/test.1.bash&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;${FNAME//sh/bash} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;如果在變數值中找到 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;sh &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;的話﹐將全部 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;sh &lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;換成 &lt;/span&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;bash&lt;/span&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:Georgia;&quot;&gt;/home/kenny/tmp/test.1.bash&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/201061415788965030/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/02/fname-homekennytmptest.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/201061415788965030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/201061415788965030'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/02/fname-homekennytmptest.html' title='[Note]Shell Script變數'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-7455985566178577130</id><published>2008-03-01T12:06:00.000+08:00</published><updated>2008-03-01T13:27:36.434+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>不定參數的用法</title><content type='html'>&lt;span style=&quot;font-family:細明體;&quot;&gt;printf 的原型： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int printf( const char *format [, argument]... ); &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;在format後面的參數不但不定個數且型態也是不定的。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;這些參數是one bye one 的堆在stack裡面。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;printf這個函式如何正確的取出這些參數？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;秘訣就在 format，函式根據format裡的格式(&quot;%d %f...&quot;) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;依序把堆在stack裡的參數取出。而這取出的動作就是用到 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;va_arg, va_end, va_start這三個macro再加上va_list。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;va_list 事實上是一個 char * 的型態： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;typedef char * va_list; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;其它的三個macro的例子(不同的平台會有不太一樣的macro) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;/* A guess at the proper definitions for other platforms */ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) &amp;amp; ~(sizeof(int) - 1) ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define va_start(ap,v) ( ap = (va_list)&amp;amp;v + _INTSIZEOF(v) ) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define va_end(ap) ( ap = (va_list)0 ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;這三個macro若看得懂，對了解它們的運作會很有幫助；看不太懂也沒關係 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;，看一下下面的說明也差不可以了。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;首先 va_start 把取出的指標(va_list)指到第一個不定參數。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;然後就可以用 va_arg 以指定的型態從va_list取出資料並把va_list &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;指標移到下一個位置(例如取走了一個int 4 bytes 的資料， va_list便會加 4) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;當取完資料後便可使用 va_end 把 va_list 歸零(這個macro應看得懂吧)。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;其實對大部份的應用來說 va_end 做不做是沒太大的關係的。 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;下面是一個不定參數函式的範例(轉載自MSDN)： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int average( int first, ... ) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int count = 0, sum = 0, i = first; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;va_list marker; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;va_start( marker, first ); /* Initialize variable arguments. */ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;while( i != -1 ) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;sum += i; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;count++; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;i = va_arg( marker, int); &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;} &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;va_end( marker ); /* Reset variable arguments. */ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;return( sum ? (sum / count) : 0 ); &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;} &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;註：_INTSIZEOF 是 int size memory alignment，如果你不知那是什麼 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;　　就把　_INTSIZEOF 看成這樣的定義會比較容易理解： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define _INTSIZEOF(n) sizeof(n) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;為什麼不直接用sizeof(n)就好了，使用 macro 是為了跨平台時能保持運 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;作正確。若傳了一個2 bytrs的不定參數(如 short)，但在一個 32 bits的 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;平台推入堆疊就會是4個bytes(32 bits)不是2 bytes，所以參數的取出 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;就要非常的小心。使用_INTSIZEOF 在於保證引數指標移動的正確。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) &amp;amp; ~(sizeof(int) - 1) ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;令N=sizeof(n)+sizeof (int)-1&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;X=sizeof()int&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;若X為2之倍數&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;_INTSIZEOF(n)可簡化為N&amp;amp;~(X-1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;而原式為N-N%X，以下證明&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;N&amp;amp;~(X-1)=N-N%X&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;IF X=1&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;N&amp;amp;~(1-1)=N&amp;amp;~(0xFFFF..F)=N-N%1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;IF X=2&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;N&amp;amp;~(2-1)=N&amp;amp;~(0xFFFF...FE)=N-N%2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;IF X=4&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;N&amp;amp;~(4-1)=N&amp;amp;~(0xFFFF...FC)=N-N%4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;目的為了讓_INTSIZEOF(n)成為X之倍數，也就是sizeof(int)之倍數&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/7455985566178577130/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/02/printf-int-printf-const-char-format.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7455985566178577130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7455985566178577130'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/02/printf-int-printf-const-char-format.html' title='不定參數的用法'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-2333555775178324151</id><published>2008-03-01T12:04:00.000+08:00</published><updated>2008-03-01T13:26:55.015+08:00</updated><title type='text'>Memory Aligment</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;對一個 &lt;/span&gt;16&lt;span style=&quot;font-family:新細明體;&quot;&gt;位元的系統來說，意味著，系統有&lt;/span&gt;16&lt;span style=&quot;font-family:新細明體;&quot;&gt;條&lt;/span&gt;data bus&lt;span style=&quot;font-family:新細明體;&quot;&gt;，各能存取一個 &lt;/span&gt;&lt;br /&gt;bit&lt;span style=&quot;font-family:新細明體;&quot;&gt;資料。 &lt;/span&gt;&lt;br /&gt;16&lt;span style=&quot;font-family:新細明體;&quot;&gt;位元當然就是&lt;/span&gt;2bytes,&lt;span style=&quot;font-family:新細明體;&quot;&gt;正如我們&lt;/span&gt;2&lt;span style=&quot;font-family:新細明體;&quot;&gt;個一數，數數會是&lt;/span&gt;2,4,6,8&lt;span style=&quot;font-family:新細明體;&quot;&gt;一樣，&lt;/span&gt;address&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;也不會&lt;/span&gt;(&lt;span style=&quot;font-family:新細明體;&quot;&gt;也不需要&lt;/span&gt;)&lt;span style=&quot;font-family:新細明體;&quot;&gt;出現奇數位置&lt;/span&gt;1,3,5,7...&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;現在來看看硬體存取一個&lt;/span&gt;byte&lt;span style=&quot;font-family:新細明體;&quot;&gt;在奇偶數地址的情況： &lt;/span&gt;&lt;br /&gt;1.&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;要取偶數位置&lt;/span&gt;E&lt;span style=&quot;font-family:新細明體;&quot;&gt;時，會抓到 &lt;/span&gt;(E,E+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;一個&lt;/span&gt;WORD(&lt;span style=&quot;font-family:新細明體;&quot;&gt;因為&lt;/span&gt;data bus&lt;span style=&quot;font-family:新細明體;&quot;&gt;是&lt;/span&gt;16bits)&lt;span style=&quot;font-family:新細明體;&quot;&gt;， &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;因為&lt;/span&gt;E&lt;span style=&quot;font-family:新細明體;&quot;&gt;是在&lt;/span&gt;Lo Byte &lt;span style=&quot;font-family:新細明體;&quot;&gt;所以硬體只要把 &lt;/span&gt;Hi Bytes &lt;span style=&quot;font-family:新細明體;&quot;&gt;拋棄掉就成了。 &lt;/span&gt;&lt;br /&gt;2.&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;要取奇數位置&lt;/span&gt;O&lt;span style=&quot;font-family:新細明體;&quot;&gt;時，會抓到 &lt;/span&gt;(O-1,O)&lt;span style=&quot;font-family:新細明體;&quot;&gt;一個&lt;/span&gt;WORD(&lt;span style=&quot;font-family:新細明體;&quot;&gt;因為&lt;/span&gt;data bus&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;是&lt;/span&gt;16bits)&lt;span style=&quot;font-family:新細明體;&quot;&gt;， 因為&lt;/span&gt;O&lt;span style=&quot;font-family:新細明體;&quot;&gt;是在&lt;/span&gt;Hi Byte &lt;span style=&quot;font-family:新細明體;&quot;&gt;所以硬體得要把 &lt;/span&gt;Hi Bytes &lt;span style=&quot;font-family:新細明體;&quot;&gt;搬到 &lt;/span&gt;Lo Bytes&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;才能算完成存取。 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;看到奇數地址存取會比偶數地址麻煩了嗎？差一點點而已有什麼關係？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;好吧！我們再來看看硬體存取一個&lt;/span&gt;WORD&lt;span style=&quot;font-family:新細明體;&quot;&gt;在奇偶數地址的情況： &lt;/span&gt;&lt;br /&gt;3.&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;要取偶數位置&lt;/span&gt;(E,E+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;時，會抓到 &lt;/span&gt;(E,E+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;一個&lt;/span&gt;WORD&lt;span style=&quot;font-family:新細明體;&quot;&gt;，這樣就完成 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;存取了。 &lt;/span&gt;&lt;br /&gt;4.&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;要取奇數位置&lt;/span&gt;(O,O+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;時，要先抓到 &lt;/span&gt;(O-1,O)&lt;span style=&quot;font-family:新細明體;&quot;&gt;取得&lt;/span&gt;Lo Byte O&lt;span style=&quot;font-family:新細明體;&quot;&gt;，然後 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;再抓&lt;/span&gt;(O,O+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;得到 &lt;/span&gt;Hi Byte(O+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;，最後合併&lt;/span&gt;(O,O+1)&lt;span style=&quot;font-family:新細明體;&quot;&gt;才算完成一個奇數 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;位址&lt;/span&gt;WORD&lt;span style=&quot;font-family:新細明體;&quot;&gt;的存取。 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;比較一下&lt;/span&gt;3,4&lt;span style=&quot;font-family:新細明體;&quot;&gt;，你就不會說只差一點點了吧！？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;在&lt;/span&gt;32&lt;span style=&quot;font-family:新細明體;&quot;&gt;位元和&lt;/span&gt;64&lt;span style=&quot;font-family:新細明體;&quot;&gt;位元的系統，可以類推。這也是為什麼很多編譯器會預設 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;把變數位置調整在 &lt;/span&gt;2/4/8 &lt;span style=&quot;font-family:新細明體;&quot;&gt;倍數上來得到較佳的存取效率。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;但這樣做會使像結構的資料大小意外的變化，若是某個結構的大小是很重要 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:新細明體;&quot;&gt;的，你就必需找出編譯器相關的設定或&lt;/span&gt;directive(&lt;span style=&quot;font-family:新細明體;&quot;&gt;如&lt;/span&gt;VC&lt;span style=&quot;font-family:新細明體;&quot;&gt;的&lt;/span&gt;pack)&lt;span style=&quot;font-family:新細明體;&quot;&gt;來控制 &lt;/span&gt;&lt;br /&gt;aligment&lt;span style=&quot;font-family:新細明體;&quot;&gt;。&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/2333555775178324151/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/02/16-16-data-bus-bit-16-2bytes-2-2468.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2333555775178324151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/2333555775178324151'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/02/16-16-data-bus-bit-16-2bytes-2-2468.html' title='Memory Aligment'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-7538222147045247684</id><published>2008-03-01T12:03:00.000+08:00</published><updated>2008-03-01T13:26:13.039+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>多維動態陣列</title><content type='html'>&lt;span style=&quot;font-family:細明體;&quot;&gt;多維動態陣列在 C 中 大概只能用 malloc，但這在一維時尚 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;不構成問題，但需要多維陣列時怎麼辦呢？這算是程式論壇 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;最常被問到的問題之一了。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;我把它整理了相關的回覆，都只用二維做說明，更多維的陣列 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;類推即可。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;就從 C 談起吧！ &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;動態產生一個[m][n]陣列 Array 的方法 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;code:------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int i;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int **Array;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;Array= (int **)malloc(m*sizeof(void *));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;for (i=0; i&amp;lt;m; i++)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;Array=(int *)malloc(n*sizeof(int *));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;--------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;這樣你就有一個 int Array[m][n]; 可以用了 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;是C 喔！不是 C++ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;但這不夠好，若你要的是一個較大的mXn陣列，那麼太多的malloc &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;會使記憶體碎片化(memory fragment)！沒關係，窮則變，變則通！ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;問題既出在for loop不斷的 memory allocation，就從那兒下手： &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;code:---------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int i;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int **Array, *pData;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;Array= (int **)malloc(m*sizeof(int *));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;pData= (int *)malloc(m*n*sizeof(int));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;for (i=0; i&amp;lt;m; i++, pData+=n)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;Array[i]=pData;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;---------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;注意到嗎？這次只用了二次的malloc。 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;當要release memory也只要free Array[0] 和 Array 就成了！ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;(注意先free Array[0] 再 free Array) &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;如果嫌兩個alloc/free還是太多，也可簡單併成一個： &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;code:-----------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int i;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int **Array, *pData;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;Array= (int **)malloc(m*sizeof(int *)+m*n*sizeof(int));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;for (i=0,pData= (int *)(Array+m); i&amp;lt;m; i++, pData+=n)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;Array[i]=pData;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;----------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;要 free 時只要 free Array 就行了，帥吧？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;如果用的是C++，那可用的方法就更多了！ &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;《幼幼班》嘗試錯誤的階段 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;?&amp;gt; int Array[][] = new int [10][20];//這樣行ㄇ？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;當然不行！ int Array[][]不是一個指標，而且只能有 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;一維為不定大小。 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;《小班》終於會從1數到100了 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;?&amp;gt; 那... &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;?&amp;gt; int *Array[] = new int [10][20];//這樣行ㄇ？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;有點想法了！但可惜的是 &#39;*&#39; 在 C++的語法是修飾前面的 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;識別字，所以 int *Array[]的意思是 &quot;Array是一個 int 指標 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;的一維陣列！&quot; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;如果能使那個 &#39;*&#39; 以獨立指標型態去宣告Array，就會變成 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&quot;Array是一個指標，指向一維 int 的陣列&quot;，而我們知道指標 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;本身就可以當做一維的陣列，那麼是不是就成了&quot;Array是一個二維 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;的int陣列&quot;？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;對了！這正是我們要的！問題是怎麼讓&#39;*&#39;成為獨立指標型態， &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;不會去修飾前面的int識別字？答案是使用括號： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int (*Array)[20] = new int [10][20];//這是正解！ &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;但問題又來了， new 運算子可以使用 new int [m][n]，但 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;int (*Array)[20] 的 [20]卻沒辦法以 [n] 來取代，所以就 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;沒辦法做到不定大小的宣告了。所以這只能算是小班的答案， &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;要做到不定大小的動態多維宣告，加上 STL 的運用，是不錯 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;的想法。 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;《中班》vector 模板的運用 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;vector&amp;lt;int&amp;gt; *array=new vector&amp;lt;int&amp;gt;[m]; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;for (int i=0; i&amp;lt;n; i++) array[i].reserve(n); &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;嘿嘿...不錯吧！？不定大小的二維陣列，而且每個維度還 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;可以隨時調整大小喔！ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;不過還是有缺點ㄟ！！那行 for loop 看起來有點礙眼，不能 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;拿掉嗎？拿掉的話，基本上Array 還是二維陣列，但第二維 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;並沒有預留空間放東西你可以用push.back等成員函式來增加 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;空間和存放data，但不能在還沒有空間時使用像 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;array[5][3]=3; 這種陣列的存取方式。沒更好的方法了嗎？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;vector 不是有預留空間大小的建構子嗎？像一維的宣告： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;vector&amp;lt;int&amp;gt; *Array= new vector &amp;lt;int&amp;gt;(n); &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;//這不是預留了 n 個元素的陣列了嗎？ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;只可惜，這是一維的宣告，若你嘗試做這樣的宣告： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;vector&amp;lt;int&amp;gt; *Array= new vector &amp;lt;int&amp;gt;[m](n); &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;編譯器會給你無情的嘲諷：陣列不能呼叫帶參數的建構子！ &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;這是很令人失望的！為十麼不行？不是邏輯的問題，或許下 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;一版本的C++會可以這樣宣告吧！但為今之計只能自力救濟 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;了。 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;《大班》使用模板在模版中 &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;仔細觀察下面的宣告： &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; Array(m, vector&amp;lt;int&amp;gt;(n));&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/7538222147045247684/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/02/c-malloc-c-mn-array-code-int-i-int.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7538222147045247684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/7538222147045247684'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/02/c-malloc-c-mn-array-code-int-i-int.html' title='多維動態陣列'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8058632625030346233.post-1020732570578061319</id><published>2008-03-01T12:02:00.000+08:00</published><updated>2008-03-24T00:11:35.158+08:00</updated><title type='text'>Makefile的一些用法</title><content type='html'>            &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;make 內建變數的涵義 &lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;Target:&lt;/font&gt;&lt;/font&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;Prequeite&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;   &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;   &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$@ Target的檔名&lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$% 程式庫成員中的檔名元素&lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$&amp;lt;  第一個prequeite的檔名&lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$?  Timestamp 在Target之後的&lt;/font&gt;&lt;/font&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;Prequeite&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$^  &lt;/font&gt;&lt;/font&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;所有的&lt;/font&gt;&lt;/font&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;Prequeite的檔名 但不包含重複部分&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$+  所有的&lt;/font&gt;&lt;/font&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;Prequeite的檔名&lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$* &lt;/font&gt; &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;Target的主檔名&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$(@D) $(&amp;lt;D)  指的是Target的檔案路徑&lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;    &lt;/div&gt; &lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;$(@F) $(&amp;lt;F)   &lt;/font&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;指的是Target的檔案名稱&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt; &lt;font size=&quot;3&quot;&gt;&lt;br&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;&lt;font size=&quot;3&quot;&gt;OBJS = foo.o bar.o &lt;br&gt;CC = gcc&lt;br&gt;CFLAGS = -Wall -O -g&lt;br&gt;&lt;br&gt;myprog : $(OBJS)&lt;br&gt;$(CC) $^ -o $@&lt;br&gt;&lt;br&gt;foo.o : foo.c foo.h bar.h&lt;br&gt;$(CC) $(CFLAGS) -c $&amp;lt; -o $@&lt;br&gt;bar.o : bar.c bar.h&lt;br&gt;$(CC) $(CFLAGS) -c $&amp;lt; -o $@&lt;br&gt;&lt;/font&gt;&lt;font size=&quot;3&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;font style=&quot;font-family: Verdana;&quot; size=&quot;3&quot;&gt;&lt;br&gt;&lt;/font&gt;&lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt; &lt;/div&gt;&lt;p style=&quot;color: rgb(255, 0, 0); font-family: Verdana; text-align: justify;&quot;&gt;&lt;font color=&quot;#000000&quot; size=&quot;3&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br&gt; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt; &lt;/div&gt;&lt;font style=&quot;font-family: Verdana;&quot; size=&quot;3&quot;&gt;.clean: 　　&lt;br&gt;&lt;/font&gt;&lt;div style=&quot;text-align: justify; font-family: Verdana;&quot;&gt;&lt;font size=&quot;3&quot;&gt;rm edit $(objects)&lt;br&gt;&lt;br&gt;更安全的作法PHONY表示clean為一個偽裝目標，也就是說，不管clean這個目標發生什麼問題，都繼續執行　 &lt;br&gt;.PHONY : clean&lt;br&gt;clean : 　　&lt;br&gt;-rm edit $(objects)&lt;br&gt;&lt;br&gt;patsubst是把第二個參數換成第一個參數中所指定的pattern，而第三個參數則是代表所有要代換的東西 &lt;br&gt;%.o:%.c ${CC} ${CLAGS} -o ${patsubst %.o,%,$@} ${STATIC_LIBS}&lt;br&gt;${CC} ${CLAGS} -o ${@:.o=.cgi} ${STATIC_LIBS}&lt;br&gt;&lt;br&gt;通配符自動在規則中進行。但是在變量賦值的和函數的參數中通配符不會擴展，如果在這些情況下需要通配符擴展，&lt;br&gt;必須使用&#39;wildcard&#39;函數。語法如下： &lt;br&gt;$(wildcard PATTERN...)&lt;br&gt;這個在makefile任何地方出現的字符串，會被匹配任何一個文件名格式的以空格隔開的現有文件列表替換。&lt;br&gt;如果沒有任何文件匹配一個模式，這個模式從&#39;wildcard&#39;的輸出中忽略，注意，這和上述的通配符的處理是不一樣的。 &lt;br&gt;『wildcard&#39;函數的一個功能是找出目錄中所有的&#39;.c&#39;文件： &lt;br&gt;$(wildcard *.c)&lt;br&gt;可以通過替換後綴&#39;.c&#39;為&#39;.o&#39;從C文件列表得到目標文件的列表： &lt;br&gt;$(patsubst %.c,%.o,$(wildcard *.c))&lt;br&gt;這樣，上節中的makefile改寫為： &lt;br&gt;objects := $(patsubst %.c,%.o,$(wildcard *.c))&lt;br&gt;foo : $(objects) cc -o foo $(objects)&lt;br&gt;&lt;br&gt;這個makefile利用了編譯C程序的隱含規則，所以不需要對編譯寫出顯式的規則。&lt;br&gt;（&#39;:=&#39;是&#39;=&#39;的一個變體） 注意：&#39;PATTERN&#39;是大小寫敏感的。&lt;/font&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deanjai.blogspot.com/feeds/1020732570578061319/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://deanjai.blogspot.com/2008/02/objs-foo.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/1020732570578061319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8058632625030346233/posts/default/1020732570578061319'/><link rel='alternate' type='text/html' href='http://deanjai.blogspot.com/2008/02/objs-foo.html' title='Makefile的一些用法'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03699821773195361003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>