Exclusive access (was Re: [vox-tech] Tar, MySQL, and cron-ed backups)

Jeff Newmiller vox-tech@lists.lugod.org
Fri, 5 Dec 2003 18:24:49 -0800 (PST)


On Fri, 5 Dec 2003, Mark K. Kim wrote:

> On Fri, 5 Dec 2003, Mitch Patenaude wrote:
> 
> > > * some combination of these?
> >
> > yes. if it was half-way through reading the file.. then the first half
> > is the old file, and the second half is the new files.  If more than
> > one change was made, then more than one file is there.
> 
> Hooooooooold on...  are you *sure*?  As I recall, once a file is opened,
> it is guaranteed to stay in that form until you close it.

Presumably, you mean _open for read_, because otherwise you could never
write to the file.

As it is, shared access to files is presumed in Unix, as is the privilege
of processes with write permission to change those files.  File locking
strategies are a fundamental subject in Unix programming, and are
non-trivial. [1]

A transaction-based filesystem that guaranteed both the ability to see a
consistent file content and still allow writes is probably some computer
scientist's holy grail.

Apple programmers apparently had to take a step "backwards" when OSX was
introduced, having to give up automatic exclusive write access to be
consistent with BSD semantics. [2]

[1] http://www.erlenstar.demon.co.uk/unix/faq_3.html#SEC35
[2] http://developer.apple.com/technotes/tn/tn2037.html

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------