* Re: Msync Invalid Arg
[not found] <22791256.21262087525518.JavaMail.root@wombat>
@ 2009-12-29 14:30 ` Michal Nazarewicz
0 siblings, 0 replies; only message in thread
From: Michal Nazarewicz @ 2009-12-29 14:30 UTC (permalink / raw)
To: darshan.ghumare; +Cc: linux-c-programming, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1838 bytes --]
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--
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-12-29 14:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <22791256.21262087525518.JavaMail.root@wombat>
2009-12-29 14:30 ` Msync Invalid Arg Michal Nazarewicz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox