linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Nazarewicz <mina86@tlen.pl>
To: darshan.ghumare@gmail.com
Cc: linux-c-programming@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Msync Invalid Arg
Date: Tue, 29 Dec 2009 15:30:24 +0100	[thread overview]
Message-ID: <87vdfphmyn.fsf@erwin.mina86.com> (raw)
In-Reply-To: <22791256.21262087525518.JavaMail.root@wombat> (darshan ghumare's message of "Tue, 29 Dec 2009 06:52:05 -0500")

[-- 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 --]

      reply	other threads:[~2009-12-29 14:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-29 11:52 Msync Invalid Arg darshan.ghumare
2009-12-29 14:30 ` Michal Nazarewicz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vdfphmyn.fsf@erwin.mina86.com \
    --to=mina86@tlen.pl \
    --cc=darshan.ghumare@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).