problem with mmap

N

Neal Becker

On linux, I don't understand why:

f = open ('/dev/eos', 'rw')
m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE,
flags=mmap.MAP_SHARED)

gives 'permission denied', but this c++ code works:

#include <sys/mman.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>

int main() {
int fd = open ("/dev/eos", O_RDWR);
void* m = mmap (NULL, 1000000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
std::cout << m << '\n';
}
 
C

Carl Banks

On linux, I don't understand why:

f = open ('/dev/eos', 'rw')
m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE,
flags=mmap.MAP_SHARED)

gives 'permission denied',

Try

f = open('/dev/eos', 'r+')


Carl Banks
 
H

hdante

Try

f = open('/dev/eos', 'r+')

Carl Banks

The equivalent code in python should be:

import os, mmap
f = os.open('/dev/eos', os.O_RDWR)
m = mmap.mmap(f, 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE,
flags=mmap.MAP_SHARED)

That should work like the C++ code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top