Discussion:
mmap(): Invalid argument
Jernej Perdan
2005-12-19 12:24:40 UTC
Permalink
Hi!

I've found similar problem, but it haven't helped me to solve mine, so I'm posting new message.
I'm trying to run an application on my PXA255 module. When I run it from NFS mounted root filesystem it works.
The problem ocours when the aplicaton is run from root filesystem which is burned to flash (jffs2). I get folowing error: Invalid argument
I found out this is due to mmap call when I try to mmap txt file to SDRAM.
The errno returned number is 22 -> EINVAL: we don't like start or length or offset. (they're too large or not aligned on a PAGESIZE boundary)

o my printfs:
mbaza_size = 626
Num of bytes in a page: 4096
error = 22
Mapiranje datoteke spodletelo!
: Invalid argument

o code:
baza::baza(const char *baza_kje):mbaza(NULL)
{
struct stat statbuf;
memset(&statbuf,0,sizeof(statbuf));

baza_dat = new char[strlen(baza_kje)];
strcpy(baza_dat,baza_kje);
// odpremo datoteko z bazo
fd = open(baza_dat, O_RDWR|O_CREAT);
if (fd < 0)
{
die("Ne morem odpreti baze!\n");
exit(1);
}
chmod(baza_dat,0644);

// doloèimo velikost datoteke
if (fstat(fd,&statbuf) != 0)
{
die("Ne morem brati informacij o datoteki!\n");
exit(1);
}
mbaza_size = statbuf.st_size;
// se ukvarjamo s prazno datoteko?
if (mbaza_size == 0)
{
mbaza = NULL;
return;
}

printf("mbaza_size = %d\n", mbaza_size);
int sz = getpagesize();
printf("Num of bytes in a page: %d\n", sz);

// mapiramo datoteko v pomnilnik
mbaza = mmap(NULL,mbaza_size, PROT_READ|PROT_EXEC|PROT_WRITE, MAP_SHARED, fd, 0);
if (mbaza == MAP_FAILED)
{
printf("error = %d\n", errno);
die("Mapiranje datoteke spodletelo!\n");
exit(1);
}
}


Printfs I get when usinf NFS mounted root filesystem:
mbaza_size = 486
Num of bytes in a page: 4096

I'm new to embedded systems so i don't know which values should I try instead of used ones or where else to look.
Maybe is this failure due to other (mis)configuration(s)?

Any ideas?

Jernej





-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette: http://www.arm.linux.org.uk/mailinglists/etiquette.php
Russell King - ARM Linux
2005-12-19 12:58:52 UTC
Permalink
Post by Jernej Perdan
Hi!
I've found similar problem, but it haven't helped me to solve mine, so I'm posting new message.
I'm trying to run an application on my PXA255 module. When I run it from NFS mounted root filesystem it works.
The problem ocours when the aplicaton is run from root filesystem which is burned to flash (jffs2). I get folowing error: Invalid argument
I found out this is due to mmap call when I try to mmap txt file to SDRAM.
The errno returned number is 22 -> EINVAL: we don't like start or length or offset. (they're too large or not aligned on a PAGESIZE boundary)
mbaza_size = 626
Num of bytes in a page: 4096
error = 22
Mapiranje datoteke spodletelo!
: Invalid argument
baza::baza(const char *baza_kje):mbaza(NULL)
{
struct stat statbuf;
memset(&statbuf,0,sizeof(statbuf));
baza_dat = new char[strlen(baza_kje)];
strcpy(baza_dat,baza_kje);
// odpremo datoteko z bazo
fd = open(baza_dat, O_RDWR|O_CREAT);
Opening file for read/write with create. If the file does not exist,
it will be created and will be zero length. Note that if you use
O_CREAT, you must supply the third argument (the file mode).
Post by Jernej Perdan
if (fd < 0)
{
die("Ne morem odpreti baze!\n");
exit(1);
}
chmod(baza_dat,0644);
Fixing your open call will remove the need for this.
Post by Jernej Perdan
// dolo????imo velikost datoteke
if (fstat(fd,&statbuf) != 0)
{
die("Ne morem brati informacij o datoteki!\n");
exit(1);
}
mbaza_size = statbuf.st_size;
// se ukvarjamo s prazno datoteko?
if (mbaza_size == 0)
{
mbaza = NULL;
return;
}
printf("mbaza_size = %d\n", mbaza_size);
int sz = getpagesize();
printf("Num of bytes in a page: %d\n", sz);
// mapiramo datoteko v pomnilnik
mbaza = mmap(NULL,mbaza_size, PROT_READ|PROT_EXEC|PROT_WRITE, MAP_SHARED, fd, 0);
You're asking for execute permission for a file without, which is
incorrect. However, that's not the problem. jffs2 does not
support writable shared mappings, and if you try to set one up, it
will return EINVAL.

Hence, you might as well open the file read-only and only supply
PROT_READ.

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette: http://www.arm.linux.org.uk/mailinglists/etiquette.php
Carlo Agrusti
2005-12-19 12:53:54 UTC
Permalink
Post by Jernej Perdan
Hi!
I've found similar problem, but it haven't helped me to solve mine, so I'm posting new message.
I'm trying to run an application on my PXA255 module. When I run it from NFS mounted root filesystem it works.
The problem ocours when the aplicaton is run from root filesystem which is burned to flash (jffs2). I get folowing error: Invalid argument
I found out this is due to mmap call when I try to mmap txt file to SDRAM.
This issue has been already discussed in ML; the point is that jffs2
does not support shared access, so, you have to map on ram based files.
First possible solution is to run the entire file system on ramdisk or
either to mount a part of it (eg only /var) on a little one.

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette: http://www.arm.linux.org.uk/mailinglists/etiquette.php
Loading...