Hi tech@,

(I post it here as this is a low level tech question. Any extended talk should be moved to misc@..)

Any way I try to mmap /dev/rsd0c , I get EINVAL (22).

Neither http://man.openbsd.org/mmap nor http://man.openbsd.org/sd gives any hint.

"ls -l /dev/rsd0c; ls -l /dev/sd0c" shows that sd0c is a block device and rsd0c is a character device, and mmap's man page says that "character special files" are OK.

read() speed on /dev/rsd0c is way higher than on /dev/sd0c (in the ballpark of >>100% faster), that's why I was interested in this in the first place.

Is it possible to do any way?

Thanks,
Tinker


Example trymap.c below:

# gcc -o trymap trymap.c
# ./trymap /dev/sd0c
Opened /dev/sd0c with handle 3.
mmap succeeded.
# ./trymap /dev/rsd0c
Opened /dev/rsd0c with handle 3.
mmap failed, errno 22: Invalid argument.

Changing to O_RDWR and PROT_READ | PROT_WRITE changes nothing.

Changing flags to MAP_FILE | MAP_SHARED also changes nothing.


trymap.c:

#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>

int main(int argc, char *argv[]) {
  if (argc != 2) { printf("Use: trymap filename\n"); return 0; }
  char* filename = argv[1];
  int f = open(filename,O_RDONLY);
  if (f == -1) {
    printf("Failed to open file %s!\n",filename);
    return -1;
  }
  printf("Opened %s with handle %i.\n",filename,f);
void* mmaparea = mmap(NULL, /* addr - we don't provide any suggestion. */
                        1 * 1024 * 1024 * 1024, // 1GB
                        PROT_READ,
                        0, /* flags - MAP_FILE implied */
                        f,
                        0 // offset
                        );
  if (mmaparea == MAP_FAILED) {
    printf("mmap failed, errno %i: %s.\n",errno,strerror(errno));
    return -1;
  }
  printf("mmap succeeded.\n");
  return 0;
}

Reply via email to