PDA

View Full Version : QFileDevice::map() returns "Access is denied" after file resize



Jansemon
5th November 2013, 16:19
Hello everyone,

I'm using a memory mapped file through a QFile object and its map() method. Works like a charm so far -- until I'm doing a resize() of the file. After that, map() always results in "Access is denied".

Maybe I'm doing something wrong, but I've tried every conceivable combination of unmap(), close(), open(), resize(), flush() I could think of. I know that the resize works, since size() reports the correct size after the resize and its size on disk is also correct. unmap() returns true. open() returns true. resize() returns true. But as soon as I want to map() the whole file (we're talking 128kB here), I get an error. I can, however, map() to the original file size... Cache problem or something?! No idea what I'm doing wrong.

Heres the method with which I try to extend the mmap'd file:



void xxx::Extend()
{
file.unmap(mmap);

file.resize( file.size() + PAGESIZE );

// Doesn't seem to be necessary
file.close();
file.open(QIODevice::ReadWrite);

// After this, mmap == nullptr, except parm size of map() is <= original file size
mmap = file.map(0, file.size());

// This prints "Access is denied"
qDebug() << file.errorString();
}



Thanks a lot in advance and best regards!


Edit: OS is Windows 7 64bit, Qt 5.1.1 and MinGW 4.8.0

anda_skoa
5th November 2013, 16:35
Have you tried mapping the old size again? I.e. maybe the new size is beyond some kind of limit?

Alternatively try to open+map using a local QFile instance, to check if some kind of internal state of "file" could be at fault.

Cheers,
_

Jansemon
5th November 2013, 16:55
Thanks for your reply.

As stated, that is exactly what works - I can map the old size (64kB), but not oldsize + 1 (after resizing it to 128kB)... I'll try creating a new instance of QFile and try it again.

Added after 15 minutes:

Hm... ok, when I delete the previous QFile object and create a new one (after I resized the old one) it works. Is this by design or a bug? Because if it's the former, maybe some notice in the docs would be nice. ;)

anda_skoa
5th November 2013, 19:48
Sounds like a bug to me.

Cheers,
_