mmap(): enodev

Pietro Paolini P.Paolini at Genexis.eu
Sun May 25 15:10:06 EDT 2014


Hello,

thanks a lot, Sunday is never a good day for working, what a mistake :-) !
___________
From: Pawan Prakash Sharma [pawanprakash101 at gmail.com]
Sent: 25 May 2014 15:19
To: Pietro Paolini
Cc: kernelnewbies at kernelnewbies.org
Subject: Re: mmap(): enodev

Hi Pietro,

Following line is buggy one

if ((fd = open(FILENAME, O_RDWR) == -1)) <--- here fd will have
Boolean value only

it should be

if ((fd = open(FILENAME, O_RDWR)) == -1)

Check the operator precedence for more clarification. Also I hope the
file you are opening already exists.

Regards,
-Pawan

On Sun, May 25, 2014 at 6:16 PM, Pietro Paolini <P.Paolini at genexis.eu> wrote:
> Hello everyone,
> in order to try to use mmap() to perform IPC I am writing a test program like this :
>
> int main(char **argv, int argn)
> {
>         char *addr;
>         int fd;
>
>         if ((fd = open(FILENAME, O_RDWR) == -1)) {
>                 perror("open:");
>                 exit(1);
>         }
>         addr = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
>         if (addr == MAP_FAILED) {
>                 printf("mmap() : %p %s", addr, strerror(errno));
>                 exit(1);
>         }
>         close(fd);
> ....
>
>
> I am running under
> Linux crunchbang 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
>
> My problem is that everytime I have got an "No such device" error which I don't fully get, could a problem of my platoform
> or am I simply doing something wrong ?
>
> Thanks all,
> Pietro
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



More information about the Kernelnewbies mailing list