mmap for device file problem?
Hi,all
In my embedded MIPS platform with kernel-2.4.25, the root filesystem is jffs2 format its size is 2048k of /dev/mtdblock1, Now , I want to write whole root filesystem via the same size as jffs2 file.it's my steps as below:
1.open device file->/dev/mtdblock1 and get file length 2048k <open/lseek>
2.map device file into virtual memory,the size is 2048k <mmap>
3.open new jffs2 root file(only file) , read its content very time with getpagesize(64k),
4.write new jffs2 content into map memory address,add one byte sizeof(char) step by step:
*pvirtualaddr++ = *pnewjffs2++;
5.munmap ,write back into file and close all resource.
sometimes,it works well and finishes re-write content,But sometimes it will write bad jffs2 inode leading not to mount root file system ,why ? and other method does this ?
Thank you .
advan
|