need help about get errno [ENXIO] for mmap

from mmap manpage I get it's errors discription:
[ENXIO] The addresses specified by the range [off, off + len) are invalid
for filedes.

How could I trigger a ENXIO ? anyone can input the code?

Lei

Assuming: mmap() call with MAP_FIXED. Probably for a character special file. You did not specify.

ENXIO: Now you are trying to reference something outside the bounds of the memory you mapped.... the device does not support what you are asking it to do. You can also get ENXIO when the device does not exist any longer.

Ex: you can mmap() a character special device but you cannot expect the driver to keep everything displayed on the device in memory.

Since you did not post your code - this is a guess on my part. Post code and we will help you. We need the mmap call, and the line(s) of code that generated ENXIO.

thanks for the replay

[lyang0@pek-lpgbuild7 mmap]$ cat 18-1_test.c

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

int main(void)

{
  int fd = -1;
  void *pa = NULL;
  void *addr = NULL;
  addr=0x10000;
  printf("addr is %p\n",addr);
  size_t len = 0;
  int prot = PROT_READ;
  int flag;
  off_t off = 0;
  long page_size = sysconf(_SC_PAGE_SIZE);
  len = 2 * page_size;
  off= (off_t)addr-page_size;

    if((fd = open("/bin/ls",O_RDONLY,0 )) < 0){
        printf("File open failed\n");
    }

  flag = MAP_SHARED;
  pa = mmap (addr, len, prot, flag, fd, off);
  printf("err is %d\n",errno);
  printf("len is %d\n",len);
  printf("off is %d\n",off);
  printf("add is %d\n",addr);
  close(fd);
}

the results is
[lyang0@pek-lpgbuild7 mmap]$ ./test
addr is 0x10000
err is 0
len is 8192
off is 61440
add is 65536

from the mmap discription:

[ENXIO] The addresses specified by the range [off, off + len) are invalid for filedes.

add is in [off, off + len), but I don't got ENXIO

/bin/ls is a regular file, the ENXIO error usually arises on devices like tty's which are character sepcial files. Normally len should be the result of a stat() call, struct stat st_size for /bin/ls in this case, because you are reading a regular file.