使用u盘,把相应的应用程序,比如:myapp文件拷到linux系统下。插入u盘,开机后,主动监测u盘中是否有相应的应用程序myapp,如果有,就拷贝到相应的路径下,代替掉原来的应用程序文件,重启后,就是启用新的应用程序文件。
代码如下所示 :
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int u_disk_update()
{
int fd=1;
unsigned char DEV[64]; //u盘等磁盘设备的设备文件路径
unsigned char PATH[64]; //Update文件的路径
unsigned char cmd[64]; //系统调用的命令
char chOrder[50];//="mount -t vfat /dev/uba1 /mnt/nfs";
char chOrder1[50];//="cp -f /mnt/nfs/images/* /mnt/jffs2/";
int i=0;
int j=0;
unsigned char ch[8]={'a','b','c','d','e','f','g','h'}; //sda,sdb,sdc
for(j=0;j<4;j++)//最多支持4个分区
{
for(i=0;i<8;i++)//最多8个硬盘
{
sprintf(PATH,"/dev/sd%c%d",ch[i],j); //"/dev/sda1/update","/dev/sda2/update"...
sprintf(DEV,"/dev/sd%c%d",ch[i],j); //对应的设备文件路径"/dev/sda1","/d