linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: darshan.ghumare@gmail.com
To: linux-c-programming@vger.kernel.org
Subject: Msync Invalid Arg
Date: Tue, 29 Dec 2009 06:52:05 -0500	[thread overview]
Message-ID: <22791256.21262087525518.JavaMail.root@wombat> (raw)

Whne I try to execute following code then  get an erro message that "Invalid Argumemt" in msync. 


#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include <linux/types.h>

int main()
{
	int fd;
	char data[20];
	__u8 *start_addr,*end_addr;
	int PageSize;

	if ( (PageSize = sysconf(_SC_PAGE_SIZE)) < 0) {
	    perror("sysconf() Error=");
		    return -1;
	}
	printf("PageSize = %d\n",PageSize);

	if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
	{ 
		printf("Error opening /dev/mem\n");
		return -1;
	}

	start_addr = mmap(0, PageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
										0);
	if(start_addr == MAP_FAILED)
	{
		printf("enc_status map failed %s\n", strerror(errno));
		return -1;
	}

	end_addr = start_addr + (4096 - 1);
	strcpy(data, "Test Msg");
	printf("\n%s:Writing NVRAM.......\n", __FUNCTION__);
	if(write(fd, data, strlen(data)) <= 0)
	{
		printf("%s: Not able to write on NVRAM. %s.\n", __FUNCTION__,
				strerror(errno));
		return -1;
	}
	printf("\n%s:Synching NVRAM.......\n", __FUNCTION__);
	if(msync(start_addr, PageSize, MS_SYNC) <= 0)
	{
		printf("%s: Not able to sync to NVRAM. %s.\n", __FUNCTION__,
				strerror(errno));
		return -1;
	}
	printf("\n%s:reading NVRAM.......\n", __FUNCTION__);
	strcpy(data, "");
	if(read(fd, data, sizeof(data)) <= 0)
	{
		printf("%s: Not able to read on NVRAM. %s.\n", __FUNCTION__,
				strerror(errno));
		return -1;
	}
	printf("%s: data  %s.\n", __FUNCTION__, data);
	return 0;
}


--
This message was sent on behalf of darshan.ghumare@gmail.com at openSubscriber.com
http://www.opensubscriber.com/messages/linux-c-programming@vger.kernel.org/topic.html

             reply	other threads:[~2009-12-29 11:52 UTC|newest]

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

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=22791256.21262087525518.JavaMail.root@wombat \
    --to=darshan.ghumare@gmail.com \
    --cc=linux-c-programming@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).