Can you guarantee integrity of an mmap'd file under SVR4?

George Ross gdmr at lfcs.edinburgh.ac.uk
Thu Mar 28 07:35:00 AEST 1991


In article <2023 at brchh104.bnr.ca> you write:
> My application would like to mmap an NFS-mounted file read-only and be
> guaranteed of the integrity of its data; that is, if someone overwrites
> the file, I'd like my application to keep seeing the original data.  This
> is for SunOS or SVR4.

I can't help you directly, as I didn't ever get round to trying a UNIX
implementation (I have a working VMS version, if that's any good 8-)), but
you could try something like this:

	Each "virtual file" comes in two parts.  There's a static part,
	which is only ever updated as a result of a policy decision, and
	a "differential" part which contains some book-keeping information
	and copies of any changed pages.

	When the virtual file is opened those pages in the static part which
	aren't in the differential part are mapped read-only into your VM,
	while the differential part is mapped read-write.

	If you write to the differential part that's fine.  If you try to
	write to the static part you'll get a signal.  You field the signal,
	allocate a new differential page (update the book-keeping
	information), copy the data and map the differential version
	read-write in place of the static version.  Then return from the
	signal handler to resume the instruction which caused the signal.

You can implement proper transactions using this scheme (that's what we
originally used it for) by mapping the differential part read-only in the
first instance and allocating new pages when you try to write to it in the
same manner as you do for the static part.  You can arrange that your
transaction is committed by writing one single page of header information,
or abandoned by not writing the new header information.

Of course, your virtual file can be the static part for some other virtual
file, and so on.

There's more in my 1983 PhD thesis "Virtual Files: a Framework for
Experimental Design".  Send mail to dam at cs.ed.ac.uk if you're interested.
It's CST-26-83.  I believe there's a real-money charge, but I don't know
how much.

TFS does something similar, so far as I can see.

George D M Ross, Department of Computer Science, University of Edinburgh
031-650 5147   Janet: gdmr at uk.ac.ed.cs   Internet: gdmr at cs.ed.ac.uk



More information about the Comp.sys.sun mailing list