1. 程式人生 > >Linux下mount/umount函式應用

Linux下mount/umount函式應用

針對海思平臺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