NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/38531: mmap(2) on ntfs should return MAP_FAILED but doesn't



I took some time to find out the function which returns errno 22
in the error trace of /bin/cp:

 615      1 cp       RET   write -1 errno 22 Invalid argument

With a debug kernel or i386cd.iso (netbsd-5), I get two console
messages with errno=22 from ubc_uiomove.

ubc_uiomove is defind in src/sys/uvm/uvm_bio.c and handels buffered
i/o mapping. For files less than 8 MiB in size mmap is called in src/bin/cp/utils.c and a look at the same file in FreeBSD shows
that mmap is only used if VM_AND_BUFFER_CACHE_SYNCHRONIZED is
defined. This might be a hint that indeed a missing synchronization
is triggering this error.

The relevant parts of the FreeBSD code:

#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
                if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
                    fs->st_size <= 8 * 1024 * 1024 &&
                    (p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
                    MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) {

NetBSD, utils.c, rev. 1.34:

if (fs->st_size <= 8 * 1048576) {
                        size_t fsize = (size_t)fs->st_size;
                        p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED,
                            from_fd, (off_t)0);
                        if (p == MAP_FAILED) {
                                goto mmap_failed;


I dont have enough insight into UVM to figure out a solution. So some
of the experts should take a look, please.

Kai-Uwe Eckhardt




Home | Main Index | Thread Index | Old Index