lkml.org 
[lkml]   [2009]   [Dec]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: Msync Invalid Arg
    Date
    darshan.ghumare@gmail.com writes:

    > Whne I try to execute following code I get "Invalid Argumemt" error
    > message in msync.

    /* Code rewritten to be shorter */

    > #include <fcntl.h>
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <string.h>
    > #include <sys/mman.h>
    > #include <unistd.h>
    >
    > #define DIE_IF(cnd, msg) do{ if (cnd) { perror(msg); return 1; } }while(0)
    >
    > int main(void)
    > {
    > char data[20];
    > void *addr;
    > int fd, ret;
    >
    > fd = open("/dev/mem", O_RDWR | O_SYNC);
    > DIE_IF(fd < 0, "open");
    >
    > addr = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    > DIE_IF(addr == MAP_FAILED, "mmap");
    >
    > strcpy(data, "Test Msg");
    > ret = write(fd, data, strlen(data));
    > DIE_IF(ret < 0, "write");
    >
    > ret = msync(addr, 4096, MS_SYNC);
    > DIE_IF(ret < 0, "msync");
    >
    > ret = lseek(fd, 0, SEEK_SET);
    > DIE_IF(ret < 0, "lseek");
    >
    > memset(data, 0, sizeof data);
    > ret = read(fd, data, sizeof data);
    > DIE_IF(ret < 0, "read");
    > printf("Read: %s.\n", data);
    >
    > return 0;
    > }


    The msync(2) fails because /dev/mem driver (drivers/char/mem.c) does not
    implement fsync file operation which is used by msync(2) system call.

    This sort of makes sense since there is no need to sync the /dev/mem
    file -- there is no backing storage on hard drive or anywhere, when you
    write data there you write directly to the memory and same goes for
    reading.

    Anyhow, I'm Ccing this to linux-kernel as maybe we need a dummy fsync
    operation for /dev/mem which would do nothing and return zero?

    --
    Best regards, _ _
    .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
    ..o | Computer Science, Michal "mina86" Nazarewicz (o o)
    ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
    [unhandled content-type:application/pgp-signature]
    \
     
     \ /
      Last update: 2009-12-29 15:33    [W:4.244 / U:0.416 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site