|
下面是一个最普通的小程序,我想看看我的USB盘上的文件系统是什么格式(可以看见长文件名),但在属性中看不见是fat16还是32,所以就把引导扇读进来:
#include <stdio.h>
#include <string.h>
int main()
{
FILE *sda,*f;
sda=NULL;
f=NULL;
//你可以读写任意数目的byte
long total=1024*64;
long pointer=0;
//初始化缓冲区
char buff[256];
memset(buff,0,256);
if(NULL==(sda=fopen("/dev/sda","rb")))
{
printf("cant open the sda file\n");
return 1;
}
if(NULL==(f=fopen("/home/test2/mysda.dat","wb")))
{
printf("can't open the mysda.dat file\n");
fclose(f);
return 1;
}
printf("now,both file were opened\n");
printf("the FILE pointer is %d and %d\n",sda,f);
while(pointer<=total)
{
if(256!=fread(buff,1,256,sda))
{
printf("read error...%d..now leaving\n",point);
exit(1);
}
if(256!=fwrite(buff,1,256,f))
{
printf("write error ..%d..now leaving\n",point);
exit(1);
}
pointer+=256;
}
return 0;
}
然后用KHexEdit打开,前面的512个byte,说明是fat16的格式,并且有NTLDR is missing ........ 云云,fat16不支持长文件名,但是我在linux和2000下都可以看见完整的长文件名,估计和95下的fat16有区别.
简单的文件读写还可以用来对付一些版权保护的光盘(可能只能拷贝文件的一部分) |
|