I want to map a file stored in ramdisk to a fixed address, but mmap fails. What mistake I am doing? Is there any other method to do this?
int fd = open("/mnt/tmpfs/hello.txt",
(O_RDONLY),
(S_IRWXU | S_IRWXG | S_IRWXO) );
if ( fd < 0 )
perror("open() error");
struct stat buf;
fstat(fd, &buf);
void * address = aligned_alloc(PGSIZE, buf.st_size)
void *new_address = mmap(address,
buf.st_size,
PROT_READ,
(MAP_SHARED|MAP_FIXED),
fd,
0);
if (new_address != address) {
perror("mmap failed!")
}