LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: swordhui

求助: 一个获取文件信息的C语言程序.

[复制链接]
 楼主| 发表于 2009-10-9 21:02:38 | 显示全部楼层
深空兄的建议很有建设性.
最好的办法是, 工具默认只支持md5, 以后可以通过参数扩展, 允许支持多种校验方式.

看看Gentoo的夸张之处:
DIST apertium-3.1.0.tar.gz 636733 RMD160 7ef44def6fbfd6a7b0967e8777a17fadd02c78c3 SHA1 0969c2f23ab251505a14f82fb24800c5d0587db4 SHA256 ce0efd0f72a02973c2f3ba4d07f5e7d6b064b97a5758e585aa8432a5faf2adae
回复 支持 反对

使用道具 举报

发表于 2009-10-9 22:17:50 | 显示全部楼层
自己用用,简单就好,参数扩展,支持多种校验是指在原程序中留几个空口?还是通过设置的main()的argv参数来实现?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-10-12 00:33:45 | 显示全部楼层
用main的argc, argv实现, 可以参考一些简单命令的源码, 如core-utils里的/bin/false.

参数打开后, 文件信息再多加一列内容: 如 SHA265:xxxxxxxxxxxxxxxxx

校验时, 如果发现SHA256开始的列, 就进行SHA256校验.
回复 支持 反对

使用道具 举报

发表于 2009-10-12 08:50:11 | 显示全部楼层
Post by swordhui;2035505
用main的argc, argv实现, 可以参考一些简单命令的源码, 如core-utils里的/bin/false.

参数打开后, 文件信息再多加一列内容: 如 SHA265:xxxxxxxxxxxxxxxxx

校验时, 如果发现SHA256开始的列, 就进行SHA256校验.


知道了,那就从argc/argv实现吧,内部我自己进行处理。。。
这两天有点忙,上面登记房子,可能要过几天才有空写了
回复 支持 反对

使用道具 举报

发表于 2009-10-19 00:02:34 | 显示全部楼层
破事折腾完毕,继续看md5校验,争取下周出货
回复 支持 反对

使用道具 举报

发表于 2009-10-22 11:16:23 | 显示全部楼层
初步看完md5的rfc文档,感觉比翻译的要准确,决定采用4gl或rfc的md5代码,在主程序里直接调用既可。
回复 支持 反对

使用道具 举报

发表于 2009-10-25 13:09:35 | 显示全部楼层
初步看懂md5的非数学部分实现,可以对程序进行包装了,收获果实的时候到了,计划最近两天完成包装和调试
回复 支持 反对

使用道具 举报

发表于 2009-11-1 21:47:45 | 显示全部楼层
要出几天差 暂时搞不成了  等 出差回来继续搞  swordhui也不来看看  莫非也出差了
回复 支持 反对

使用道具 举报

发表于 2009-11-8 14:11:05 | 显示全部楼层

程序已经初步出炉,等swori看了后再进行最后包装和功能补齐

程序主要功能已经写出来了,支持文件信息获取和md5校验(md5校验代码直接采用的rfc文档示例程序,通过与网上的一般的md5校验程序进行过比较,写得代码质量好很多,效率也不差,故直接用之),带-cm参数为选用信息获取+md5校验,不带参数为信息获取.该程序目前只是"能用"而已,还有很多已知的缺陷和性能问题要解决,有以下几个:
1. 程序没有容错处理和多级、超深目录测试
2. 没有进行广范围、严格性测试
3. 批量文件处理暂时没有加上,以后视需求决定是否加上
4. 大文件(>512M)用md5进行校验,主要是读写块太小,仅1000,将 视需要扩展读取块的大小。目前机器的内存都比较大了,可以用空间换时间
5. 输出方式目前为stdout,没有写入到文件,视需求采用合适的输出方式
6. 获得到权限码,没有转换成文件属主名字

本机测试效果:

lfs_pack]$gcc  md5.c mddriver.c file_info.c -o file_info

lfs_pack]$./file_info md5.c
file name is :md5.c
file mode is:664
the file size is :10423
the last modified time count is  :1257677773
the last modified time is :Sun Nov  8 10:56:13 2009
the file type is :F

lfs_pack]$./file_info -cm  md5.c
file name is :md5.c
file mode is:664
the file size is :10423
the last modified time count is  :1257677773
the last modified time is :Sun Nov  8 10:56:13 2009
the file type is :F
MD5 (md5.c) = 716a5f0b9fde5409b2e2b291608e8c96

lfs_pack]$ls -l md5.c
-rw-rw-r-- 1   [][] 10423 Nov  8 10:56 md5.c

校验时间测试:
lfs_pack]$ls ~/music -l --block-size=MB
total 1528MB
-rw-rw-r-- 1 [][] 1280MB Oct 18 17:29 chen_zh_to.mpg
-rw-rw-r-- 1 [][] 676MB Oct 18 19:37 phoix.mpg
-rw-rw-r-- 1 [][]   6MB Mar 15  2009 红色记忆_年赛演唱版_OUTPUT.mp3
-rw-rw-r-- 1 [][]  17MB Oct 18 23:49 叶振棠 - 万里长城永不倒.ape

time ./file_info -cm ~/music/chen_zh_to.mpg
file name is :chen_zh_to.mpg
file mode is:664
the file size is :1279173730
the last modified time count is  :1255886986
the last modified time is :Sun Oct 18 17:29:46 2009
the file type is :F

MD5 (chen_zh_to.mpg) = 497d74912f1f438730798a7435c78ba2

real    0m23.835s
user    0m23.091s
sys     0m0.731s


lfs_pack]$time ./file_info -cm ~/music/phoix.mpg
file name is :phoix.mpg
file mode is:664
the file size is :675976044
the last modified time count is  :1255894642
the last modified time is :Sun Oct 18 19:37:22 2009
the file type is :F
MD5 (phoix.mpg) = 3c326de91c91999682580d54563ea288

real    0m12.581s
user    0m12.153s
sys     0m0.426s


k lfs_pack]$ls ~/games/rom -l --block-size=MB
total 82MB
-rw-r--r-- 1 [][] 82MB May 20 21:48 kof2000.zip


lfs_pack]$time ./file_info -cm ~/games/rom/kof2000.zip
file name is :kof2000.zip
file mode is:644
the file size is :81588914
the last modified time count is  :1242856116
the last modified time is :Wed May 20 21:48:36 2009
the file type is :F
MD5 (kof2000.zip) = 543f0bbf80260268c9f57f3ccaf2f79a
real    0m1.526s
user    0m1.469s
sys     0m0.057s

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2009-11-8 14:27:03 | 显示全部楼层
用md5sum试了一下,差了个数量级,深受打击了。。。。。看来需要看看md5sum的代码了,用它的肯定快
$time md5sum  chen_zh_to.mpg
497d74912f1f438730798a7435c78ba2  chen_zh_to.mpg

real    0m3.556s
user    0m2.855s
sys     0m0.623s

time md5sum phoix.mpg
3c326de91c91999682580d54563ea288  phoix.mpg

real    0m1.878s
user    0m1.498s
sys     0m0.378s

真搞不懂,这家伙怎么做到这么快的,就算按100MB/S的磁盘读取速度,也要10s吧,况且硬盘还不一定达得到这个速度
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表