首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

ZedBoard学习(三)U盘读写

ZedBoard学习(三)U盘读写

今天在Linux下操作U盘时才发现,以前对Linux的理解太浅了,对ARM Linux的理解有太浅了,因为需要进行数据的存储,最初的想法移植停留在怎么写U盘的驱动,其实Linux里U盘的驱动都已经写好了,那么U盘就更PC上的存储器是一样的,直接进行文件的读写就可以了。写一段简单的读写文件的代码,进行测试,从file1中拷贝内容到file2。 #include <stdio.h>int main(int argc, char **argv){    FILE* sourceFile;    FILE* destFile;    char buf[50];    int numBytes;    sourceFile = fopen("/mnt/file1", "rb");    destFile = fopen("/mnt/file2", "wb");     if(sourceFile==NULL)    {        printf("Could not open source file\n");        return 2;    }    if(destFile==NULL)    {        printf("Could not open destination file\n");        return 3;    }     while(numBytes=fread(buf, 1, 50, sourceFile))    {        fwrite(buf, 1, numBytes, destFile);    }}交叉编译环境编译 arm-xilinx-linux-gnueabi-gcc USB.c连上网线进行FTP传输,挂载U盘,mount /dev/sda /mnt,这个时候U盘已经挂在了/mnt文件夹下通过超级终端执行程序 ./a.out查看file2中的内容,就会发现拷贝已经完成。cat /mnt/file2[[wysiwyg_imageupload:777:]]              文章来源:http://blog.csdn.net/renshengrumenglibing/article/details/8245607
记录学习中的点点滴滴,让每一天过的更加有意义!
返回列表