libing64

ZedBoard学习(3)U盘读写

2012-12-01 08:14  libing64  阅读(362)  评论(0编辑  收藏  举报

今天在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

 

 

分类:

技术点:

相关文章:

  • 2021-11-03
  • 2021-12-06
  • 2022-12-23
  • 2021-10-17
  • 2021-11-11
  • 2021-11-19
  • 2021-08-18
  • 2021-11-27
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2021-08-15
  • 2021-07-01
  • 2021-04-08
  • 2021-12-24
相关资源
相似解决方案