mmap msync munmap close
来源:互联网 发布:知乎在国外开中餐厅 编辑:程序博客网 时间:2024/05/30 20:07
转自:http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201082753446602/
open 打开文件后——>使用mmap建设文件映射;建立文件映射后,可以对映射到的空间进行操作。用msync同步到文件中。
问:close后对映射空间的操作能够同步到文件中吗?
答:可以,只要文件映射存在,就可以向你映射空间的内容写入文件,实现空间和文件的同步。
实例代码::
以下是Camera mmap的一个例子:
* V4L interface- mmap function
* @param file structure file *
* @param vma structure vm_area_struct*
* @return status 0 Success, EINTR busy lock error, ENOBUFS remap_page error
*/
static int mxc_mmap(struct file*file, struct vm_area_struct*vma)
{
struct video_device *dev = video_devdata(file);
unsigned long size;
int res = 0;
cam_data *cam = video_get_drvdata(dev);
pr_err( "=============================camera mmap\n" );
pr_err( "In MVC:mxc_mmap\n" );
pr_err( " pgoff=0x%lx, start=0x%lx, end=0x%lx\n" ,
vma->vm_pgoff, vma->vm_start, vma->vm_end);
/* make this _really_ smp-safe */
if (down_interruptible(&cam->busy_lock))
return -EINTR;
size = vma->vm_end- vma->vm_start;
vma->vm_page_prot= pgprot_writecombine(vma->vm_page_prot);
if (remap_pfn_range(vma, vma->vm_start,
vma->vm_pgoff, size, vma->vm_page_prot)) {
pr_err( "ERROR: v4l2 capture: mxc_mmap: "
"remap_pfn_range failed\n" );
res = -ENOBUFS;
goto mxc_mmap_exit;
}
vma->vm_flags&=~VM_IO; /* using shared anonymous pages */
mxc_mmap_exit:
up(&cam->busy_lock);
return res;
}- * V4L interface - mmap function
* @param file structure file *
* @param vma structure vm_area_struct *
* @return status 0 Success, EINTR busy lock error, ENOBUFS remap_page error
*/
static int mxc_mmap(struct file*file, struct vm_area_struct*vma)
{
struct video_device *dev = video_devdata(file);
unsigned long size;
int res = 0;
cam_data *cam = video_get_drvdata(dev);
pr_err( "=============================camera mmap\n" );
pr_err( "In MVC:mxc_mmap\n" );
pr_err( " pgoff=0x%lx, start=0x%lx, end=0x%lx\n" ,
vma->vm_pgoff, vma->vm_start, vma->vm_end);
/* make this _really_ smp-safe */
if (down_interruptible(&cam->busy_lock))
return -EINTR;
size = vma->vm_end- vma->vm_start;
vma->vm_page_prot= pgprot_writecombine(vma->vm_page_prot);
if (remap_pfn_range(vma, vma->vm_start,
vma->vm_pgoff, size, vma->vm_page_prot)) {
pr_err( "ERROR: v4l2 capture: mxc_mmap: "
"remap_pfn_range failed\n" );
res = -ENOBUFS;
goto mxc_mmap_exit;
}
vma->vm_flags&=~VM_IO; /* using shared anonymous pages */
mxc_mmap_exit:
up(&cam->busy_lock);
return res;
}
/*!
* V4L interface - mmap function
* @param file structure file *
* @param vma structure vm_area_struct *
* @return status 0 Success, EINTR busy lock error, ENOBUFS remap_page error
*/
static int mxc_mmap(struct file*file,struct vm_area_struct*vma)
{
struct video_device *dev = video_devdata(file);
unsigned long size;
int res = 0;
cam_data *cam = video_get_drvdata(dev);
pr_err("=============================camera mmap\n");
pr_err("In MVC:mxc_mmap\n");
pr_err(" pgoff=0x%lx, start=0x%lx, end=0x%lx\n",
vma->vm_pgoff, vma->vm_start, vma->vm_end);
/* make this _really_ smp-safe */
if (down_interruptible(&cam->busy_lock))
return -EINTR;
size = vma->vm_end- vma->vm_start;
vma->vm_page_prot= pgprot_writecombine(vma->vm_page_prot);
if (remap_pfn_range(vma, vma->vm_start,
vma->vm_pgoff, size, vma->vm_page_prot)) {
pr_err("ERROR: v4l2 capture: mxc_mmap: "
"remap_pfn_range failed\n");
res = -ENOBUFS;
goto mxc_mmap_exit;
}
vma->vm_flags&=~VM_IO;/* using shared anonymous pages */
mxc_mmap_exit:
up(&cam->busy_lock);
return res;
}
========================================
用户层调用:
mmap (NULL, mCaptureBuffers[i].length,PROT_READ | PROT_WRITE, MAP_SHARED, fd_v4l, mCaptureBuffers[i].phy_offset);
以下是抓取的Log:
[ 46.355719]=============================camera mmap
[ 46.360704] In MVC:mxc_mmap
[ 46.363635] pgoff=0x93900, start=0x40c0f000, end=0x40cbf000
[ 46.459041]=============================camera mmap
[ 46.464109] In MVC:mxc_mmap
[ 46.466908] pgoff=0x93a00, start=0x40dbf000, end=0x40e6f000
[ 46.569979]=============================camera mmap
[ 46.575116] In MVC:mxc_mmap
[ 46.577927] pgoff=0x93b00, start=0x42692000, end=0x42742000
[ 46.631274]=============================camera mmap
[ 46.636332] In MVC:mxc_mmap
[ 46.639130] pgoff=0x93c00, start=0x42842000, end=0x428f2000
[ 46.673606]=============================camera mmap
[ 46.678661] In MVC:mxc_mmap
[ 46.681459] pgoff=0x93d00, start=0x429f2000, end=0x42aa2000
拍照:
[ 1072.567111]=============================camera mmap
[ 1072.572256] In MVC:mxc_mmap
[ 1072.575093] pgoff=0x92c00, start=0x42692000, end=0x42952000
[ 1072.591292]=============================camera mmap
[ 1072.596321] In MVC:mxc_mmap
[ 1072.599119] pgoff=0x91000, start=0x42952000, end=0x42c12000
[ 1072.612007]=============================camera mmap
[ 1072.616990] In MVC:mxc_mmap
[ 1072.619852] pgoff=0x91400, start=0x42f25000, end=0x431e5000
返回preview:
[ 1074.351975]=============================camera mmap
[ 1074.357060] In MVC:mxc_mmap
[ 1074.359895] pgoff=0x91700, start=0x40c0a000, end=0x40cba000
[ 1074.369823]=============================camera mmap
[ 1074.374837] In MVC:mxc_mmap
[ 1074.377635] pgoff=0x93900, start=0x40cc5000, end=0x40d75000
[ 1074.385910]=============================camera mmap
[ 1074.390883] In MVC:mxc_mmap
[ 1074.393713] pgoff=0x93e00, start=0x40d75000, end=0x40e25000
[ 1074.402028]=============================camera mmap
[ 1074.407004] In MVC:mxc_mmap
[ 1074.409808] pgoff=0x92b00, start=0x40e25000, end=0x40ed5000
[ 1074.417813]=============================camera mmap
[ 1074.422813] In MVC:mxc_mmap
[ 1074.425610] pgoff=0x91600, start=0x42692000, end=0x42742000
切换到录像:
[ 1148.276637]=============================camera mmap
[ 1148.281664] In MVC:mxc_mmap
[ 1148.284470] pgoff=0x92b00, start=0x40e00000, end=0x40e98000
[ 1148.293967]=============================camera mmap
[ 1148.298943] In MVC:mxc_mmap
[ 1148.301780] pgoff=0x93900, start=0x42323000, end=0x423bb000
[ 1148.311097]=============================camera mmap
[ 1148.316121] In MVC:mxc_mmap
[ 1148.318920] pgoff=0x93e00, start=0x423bb000, end=0x42453000
[ 1148.328422]=============================camera mmap
[ 1148.333448] In MVC:mxc_mmap
[ 1148.336246] pgoff=0x93c00, start=0x42453000, end=0x424eb000
[ 1148.346153]=============================camera mmap
[ 1148.351130] In MVC:mxc_mmap
[ 1148.353981] pgoff=0x93d00, start=0x424eb000, end=0x42583000
==================================================================
- mmap msync munmap close
- mmap msync munmap close
- mmap msync munmap close
- 文件映射mmap、msync、munmap(open后建立文件映射,close后文件映射依然存在,msync依然可以实现同步)
- 文件映射IO:mmap-mprotect-msync-munmap函数族
- 文件映射IO:mmap-mprotect-msync-munmap函数族
- 文件映射IO(mmap-mprotect-msync-munmap)函数
- 文件映射IO:mmap-mprotect-msync-munmap函数族
- mmap/munmap函数详解
- mmap/munmap函数详解
- mmap VS munmap mkstemp
- mmap和munmap函数
- C++ mmap/munmap
- 关于mmap/munmap系统调用
- mmap函数和munmap函数
- mmap和munmap函数详解
- linux内存映射 mmap munmap
- mmap()、munmap()的用法、例子
- 一个c语言题目
- linux系统时间修改及同步
- 浅谈Java线程启动与Thread.join()
- hdu 1257 最少拦截系统(DP)
- php同时作为server端和client端(soapclient)的超时时间设置小结
- mmap msync munmap close
- 用eclipse新建JSP
- erlang:猜数字
- Ubuntu下配置Samba服务
- c语言计算几何系列题、
- 如何让你的 Android 显示gif格式的图片
- 老鸟学习python
- 关于typedef的用法总结
- erlang:简单函数重载