免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3759 | 回复: 3
打印 上一主题 下一主题

如何在ucLinux使用mmap() ? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-29 15:21 |只看该作者 |倒序浏览
如下代码在 ucLinux下没法执行通过,请赐教。
mmap( NULL,
stStat.st_size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
iFd,
0);
the mmap() return -1; with "invalidate argument"

the filesystem is RAMFS too.

按理说,不应出现这样的问题。如果是ROMFS倒也说得过去。
thank you at first.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-07-29 15:36 |只看该作者

如何在ucLinux使用mmap() ?

MAP_SHARED|MAP_FILE 实验 一下.MAP_FILE 保证兼容性的.

ps: 只是猜测.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2005-07-29 15:46 |只看该作者

如何在ucLinux使用mmap() ?

>;>ROT_READ | PROT_WRITE

另外 如果这样指定mmap的 参数.那么你的iFd 在open的时候也要O_RDWR打开.

论坛徽章:
0
4 [报告]
发表于 2005-07-29 19:23 |只看该作者

如何在ucLinux使用mmap() ?

uClinux: 2.4.22, CPU: ARM9-based 32-bit RISC CPU, 166MHz

now I write a single programe which open() & mmap() a regular file, read and modify it.
but after the programe have finished, the file's content has not changed.
the code likes below:

/*--------------------------------------------------------------------------------

int main( int argc, char **argv)
{
    char *p_str;
    struct stat stStat;

    iFd = open( "/tmp/aa.txt", O_RDWR | O_NONBLOCK);
    if( iFd == -1)
    {
        fprintf( stderr, "%s.%d \n", __FILE__, __LINE__);
        perror( "open faild :";
        abort();
    }          

    iRetSts = fstat( iFd, &stStat);
    if( iRetSts == -1)
    {
        fprintf( stderr, "%s.%d \n", __FILE__, __LINE__);
        perror( "fstat error:";
        return -1;
    }

    p_str = mmap( NULL,
                  stStat.st_size,
                  PROT_READ ,
                  MAP_SHARED,
                  iFd,
                  0);
    if( p_str == (char *)-1)       
    {
        fprintf( stderr, "%s.%d \n", __FILE__, __LINE__);
        perror( "mmap failed ;";
        abort();
    }          
   
    printf( "p_str[0] = %c \n", p_str[0]);
    p_str[0] = 'A';

    return 0;
}

/*--------------------------------------------------------------------------------------

If call mmap() with PROT_WRITE, the mmap() will return -1, with "invalidate argument".
If call mmap() without PROT_WRITE, the mmap() will work correctly, but after the programe
terminated , the content of the /tmp/aa.txt has not changed.

the /tmp is RAMFS filesystem.

please help me. thank you very much.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP