home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!auspex-gw!guy
- From: guy@Auspex.COM (Guy Harris)
- Newsgroups: comp.unix.wizards
- Subject: Re: flock(2) emulation?
- Message-ID: <14071@auspex-gw.auspex.com>
- Date: 15 Aug 92 00:06:21 GMT
- References: <BsrzAp.7KD@ef2007.efhd.ford.com> <19480@fritz.filenet.com> <1992Aug14.171020.20534@krfiny.uucp>
- Sender: news@auspex-gw.auspex.com
- Organization: Auspex Systems, Santa Clara
- Lines: 71
- Nntp-Posting-Host: bootme.auspex.com
-
- >If I recall the history correctly:
-
- Not completely.
-
- >first was lockf(3) - a library that provided advisory record locking.
- >Then it was rolled into the OS
-
- (Presumably meaning "rolled into the kernel"; the kernel isn't all there
- is to the OS....)
-
- Actually, the original "lockf()" *was* in the kernel.
-
- > as flock(2),
-
- "flock()" was a *separate* locking mechanism, which showed up in 4.2BSD
- (maybe earlier; I don't know if Berkeley invented it or not).
-
- >and lockf(3) became simply calls to flock.
-
- It sounds as if you're thinking of System V-style locking with
- "fcntl()"; AT&T put that in some SVR2-vintage release, and made
- "lockf()" a library routine wrapped around it.
-
- >This enabled manditory record locking
- >(write(2) returns EAGAIN or blocks if it would overwrite a locked
- >region of the file).
-
- The "lockf()" implementation by John Bass (which was, I think, the first
- one; published in an issue of ";login:", as I remember) had mandatory
- record locking - it was, I think, the *only* kind of locking it had.
- Other byte-span locking implementations may have done only advisory
- locking, or have done both (the AT&T "fcntl()" locking did both).
-
- >As mentioned in this newsgroup, the library probably kept a file
- >containing
- >- the file being locked (by major number/minor number/inode)
- >- the region locked and the PID
- >that way, all processes can access the global file and
- >inspect each other's locks.
-
- Nope. The original implementation kept such a database, but it kept it
- in the kernel, rather than in a file.
-
- >The problem with advisory record locking is that a 'rude'
- >program that doesn't respect the locking can destroy the file.
- >Manditory record locking (having a file with the "get GID bit" set)
- >enforces the lock by blocking writes on locked portions.
-
- The problem with mandatory record locking is that a "rude" program can
- lock a file and never unlock it; for example, it could stick a read lock
- on, say, "/etc/passwd" and hang onto it forever. That's why it's not
- the default....
-
- Many OSes offer, from what I can tell, only advisory locking;
- admittedly, they're OSes not used much for commercial data processing,
- such as IBM's MVS and VMS. :-)
-
- In other words, the lack of mandatory record locking isn't necessarily
- crippling; OS/360 and successors seem to have gotten along without it.
- Of course, in those OSes, those files that require locks are generally
- accessed through a library that does the locking for you, so you
- probably have to do a lot more work to write such a rude program.
-
- Frankly, if there's some UNIX programmer who can't manage to get locking
- right, I wouldn't trust them to access such a file *except* through e.g.
- some ISAM package; said package would, presumably, not only manage the
- index, etc., better than said programmer's code could, it would also
- manage locks better than their code could.
-
- As I remember, AT&T's documentation recommends *against* using mandatory
- locking....
-