针对海思平台system命令占用资源较大的问题,因此程序中与系统调用相关的就只能用函数实现了。

demo

mount.c:

#include <sys/mount.h>

int main(void)
{
    int ret = 0;
    ret = mount("/dev/mmcblk0p1","/mnt/sd_card","vfat",MS_SYNCHRONOUS,"iocharset=utf8");
    if(ret == 0)
	printf("mount success!\n");
    else
	printf("mount failed!\n");
    return 0;
}
umount.c

#include <sys/mount.h>

int main(void)
{
    int ret = 0;
    ret = umount("/mnt/sd_card");
    if(ret == 0)
	printf("umount success!\n");
    else
	printf("umount failed!\n");
    return 0;
}
几个格式化分区的命令

mksdcard.sh

#!/bin/sh
#创建分区,参数为fdisk.param 
fdisk /dev/mmcblk0 < /mnt/victa/fdisk.param 
#格式化分区
mkfs.vfat /dev/mmcblk0p1
#挂载分区
mount -t vfat /dev/mmcblk0p1 /mnt/mmc/
fdisk.param
d
1
d
2
d
3
d
4
n
p
1


w







Logo

更多推荐