免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1534 | 回复: 0

项目笔记20110904-08 [复制链接]

论坛徽章:
0
发表于 2011-12-23 02:39 |显示全部楼层
1、inode 的定义中,为什么会使用取消字节对齐?<div>原因可能有2:1是inode结构体中都是4个或8个字节的类型,无需对齐便可从偶数地址开始读取数据,而且inode中有3个4字节的数据类型,那么编译器会在inode结尾多分配4字节的空间以达到整个数据结构的8字节对齐,取消字节对齐可以节省4字节的空间。2是存储到磁盘中以后可能会对磁盘结构造成影响。</div><div><br></div><div>2、柔性数组结构成员:</div><div><span class="Apple-style-span" style="line-height: normal; border-collapse: collapse; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><table id="src_table_0" style="border-collapse: collapse; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: 12px; "><tbody style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><tr id="sl_svn133_36" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="kwd" style="color: rgb(0, 0, 136); ">struct</span><span class="pln" style="color: rgb(0, 0, 0); "> log_header </span><span class="pun" style="color: rgb(102, 102, 0); ">{</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_37" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; int32_t version</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_38" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; int64_t header_checksum</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_39" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; int64_t data_checksum</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_40" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; uint32_t log_size</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_41" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; uint64_t ctime</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "> &nbsp; &nbsp; &nbsp; </span><span class="com" style="color: rgb(136, 0, 0); ">/* create time */</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_42" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; uint64_t start_db_no</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "> </span><span class="com" style="color: rgb(136, 0, 0); ">/* log first db no*/</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_43" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; uint32_t db_num</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "> &nbsp; &nbsp; &nbsp;</span><span class="com" style="color: rgb(136, 0, 0); ">/* db amounts */</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_44" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; uint32_t ib_num</span><span class="pun" style="color: rgb(102, 102, 0); ">;</span><span class="pln" style="color: rgb(0, 0, 0); "> &nbsp; &nbsp; &nbsp;</span><span class="com" style="color: rgb(136, 0, 0); ">/* ib amount */</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_45" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pln" style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; </span><span class="kwd" style="color: rgb(0, 0, 136); ">char</span><span class="pln" style="color: rgb(0, 0, 0); "> data</span><span class="pun" style="color: rgb(102, 102, 0); ">[</span><span class="lit" style="color: rgb(0, 102, 102); ">0</span><span class="pun" style="color: rgb(102, 102, 0); ">];</span><span class="pln" style="color: rgb(0, 0, 0); "><br></span></td></tr><tr id="sl_svn133_46" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; white-space: pre-wrap; vertical-align: top; "><span class="pun" style="color: rgb(102, 102, 0); ">}</span><span class="pln" style="color: rgb(0, 0, 0); ">__attribute__</span><span class="pun" style="color: rgb(102, 102, 0); ">((</span><span class="pln" style="color: rgb(0, 0, 0); ">packed</span><span class="pun" style="color: rgb(102, 102, 0); ">));</span><span class="pln" style="color: rgb(0, 0, 0); "> <br></span></td></tr><tr id="sl_svn133_47" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "></tr></tbody></table><font class="Apple-style-span" size="2">该结构体中包含</font></span><font class="Apple-style-span" size="2">柔性数组结构成员char data[0],其作用是在分配结构体空间的时候可以改变分配空间的大小。如:</font></div><div><font class="Apple-style-span" size="2">struct log_header *p = (struct log_header *) malloc(sizeof(struct log_header)+100*sizeof(int));</font></div><div><font class="Apple-style-span" size="2"><br></font></div><div><font class="Apple-style-span" size="2">3、glibc中的g_message函数格式如下:</font></div><div><font class="Apple-style-span" size="2">void g_message(gchar *format,......);</font></div><div><font class="Apple-style-span" size="2">师哥的代码</font></div><div><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="line-height: normal; font-size: 12px; border-collapse: collapse; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span class="pln" style="color: rgb(0, 0, 0); ">g_message</span><span class="pun" style="color: rgb(102, 102, 0); ">(</span><span class="pln" style="color: rgb(0, 0, 0); ">G_LOG_HLFS_DOMAIN</span><span class="pun" style="color: rgb(102, 102, 0); ">,</span><span class="str" style="color: rgb(0, 136, 0); ">"local [fs:%s] [path%s]\n"</span><span class="pun" style="color: rgb(102, 102, 0); ">,</span><span class="pln" style="color: rgb(0, 0, 0); ">fs_name</span><span class="pun" style="color: rgb(102, 102, 0); ">,</span><span class="pln" style="color: rgb(0, 0, 0); ">fs_path</span><span class="pun" style="color: rgb(102, 102, 0); ">);</span></span></font></div><div><span class="Apple-style-span" style="line-height: normal; font-size: small; border-collapse: collapse; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">是否可行?</span></div><div><font class="Apple-style-span" face="Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace" size="2"><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">自己编写了如下代码进行测试:</span></font></div><div><font class="Apple-style-span" face="Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace" size="2"><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;1 #include &lt;glib.h&gt;</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;2&nbsp;</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;3 main()</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;4 {</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;5 &nbsp; &nbsp; char a[]="adaksfsdafasdfsdfasdf";</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;6 &nbsp; &nbsp; g_message("HLFS", ":bucuo%s", a);</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&nbsp;&nbsp;7 }</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">打印结果:</div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">** Message: HLFS</span>
</div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">应该是不可以的。</span></div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">4、NBD安装和使用的问题:</span></div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">在Ubuntu10.10下使用命令<br>
sudo apt-get install nbd-server nbd-client<br>
安装nbd时遇到下面的警告:<br>
** Message: No configured exports; quitting.<br>
&nbsp;nbd-server.<br>
之后在使用命令<br>
sudo nbd-server 1234 /var/tmp/nbd-disk <br>
启动nbd-server时又出现了下面的警告:<br>
** (process:14752): WARNING **: Specifying an export on the command line is deprecated.<br>
** (process:14752): WARNING **: Please use a configuration file instead.<br>
</span></div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">根据提示问题应该是没有nbd-server的配置文件。然后查阅man手册页:</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><a href="http://linux.die.net/man/5/nbd-server" target="_blank" target="_blank">http://linux.die.net/man/5/nbd-server</a></div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">根据NBD-SERVER的编写规则编写了如下配置文件:</div><div style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br></div><div><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">  1 [generic]
  2 [export1]
  3     exportname = /var/tmp/nbd-disk
  4     port = 12345</span><span class="Apple-style-span" style="border-collapse: collapse; line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">
</span></div><div>问题轻松解决。</div></font></div>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP