Dear folks,

When we were trying to make a userland FS application we have
encountered "Invalid Argument" when doing mmap() over an open descriptor
to a disk device.  The program goes here:


============================
#include        <sys/types.h>
#include        <sys/stat.h>
#include        <sys/mman.h>    /* mmap() */
#include        <fcntl.h>
#include        <errno.h>
#include        <assert.h>

int
main(int argc, char *argv[])
{
        int                     fd;
        char            *src, *dst;
        struct stat     statbuf;

        dst = strdup("abcdefghijklmn");
        if (dst == NULL) {
                printf("Can not allocate memory\n");
                exit(-1);
        }

        if ((fd = open("/dev/da2s1", O_RDWR | O_DIRECT)) < 0)
                printf("can't open for read/write");

        if ((src = mmap(0, 10, PROT_WRITE | PROT_READ,
                            MAP_SHARED, fd, 0)) == (caddr_t) -1) {
                perror("mmap error for input");
                return -1;
        }

        memcpy(dst, src, 10);   /* does the file copy */

        exit(0);
}
============================

Do we need some special prerequisite before doing mmap()?  According to
the vm_mmap.c it seems that we should map a DTYPE_VNODE object, which
looks somewhat confusing...

Thanks in advance!

Cheers,
-- 
Xin LI <delphij delphij net>  http://www.delphij.net/

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to