* Re: File/Record locking in Ada
1997-02-28 0:00 ` Keith Allan Shillington
@ 1997-03-01 0:00 ` Keith Thompson
1997-03-03 0:00 ` David Emery
1997-03-05 0:00 ` David Emery
2 siblings, 0 replies; 6+ messages in thread
From: Keith Thompson @ 1997-03-01 0:00 UTC (permalink / raw)
In <01bc259a$a035e850$fc00af88@godiva> "Keith Allan Shillington" <keith@sd.aonix.com> writes:
> Hmmm. That would be a protected type.
I don't think so. A protected type can protect access to a resource
within a single (possibly multi-tasking) program, but not between
different programs running independently on the same system. Since files
are shared across multiple independent programs, protected types won't
work for file locking.
What you really want is something like the POSIX_File_Locking package.
If you don't have a working implementation of that, you may be able
to interface to fcntl(). According to IEEE 1003.5, the Get_Lock,
Set_Lock, and Wait_To_Set_Lock routines correspond to fcntl(F_GETLK),
fcntl(F_SETLK), and fcntl(F_SETLKW), respectively.
--
Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
"Humor is such a subjective thing." -- Cartagia
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: File/Record locking in Ada
1997-02-28 0:00 ` Keith Allan Shillington
1997-03-01 0:00 ` Keith Thompson
@ 1997-03-03 0:00 ` David Emery
1997-03-03 0:00 ` Larry Kilgallen
1997-03-05 0:00 ` David Emery
2 siblings, 1 reply; 6+ messages in thread
From: David Emery @ 1997-03-03 0:00 UTC (permalink / raw)
Just remember that in POSIX, file locks are advisory. This means that
if one process locks the file using Posix_File_Locking, and another
process does -not- use Posix_File_Locking (or the C fcntl() equivalent), the
second (ill-behaved) process will get access to the file.
There's no way that I know of to get "guaranteed locking" of files against
processes that do not use POSIX_File_Locking or some other protocol
(see below).
THe other "traditional" approach to file locking is to take advantage of
the fact that the link() operation is atomic, and create a lockfile for
the file named "foo" by calling
POSIX_Files.Link
(Old_Pathname => "foo", New_Pathname => "foo.LOCK");
This will fail if New_Pathname exists (POSIX_Error, error code File_Exists), or
will atomically create the new link.
Note that POSIX doesn't know anything about NFS, so the behavior of file
locking or hard links on an NFS-mounted file system is not defined by POSIX.
dave
--
Note: if email to me bounces, use 'emery@grebyn.com'
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: File/Record locking in Ada
1997-03-03 0:00 ` David Emery
@ 1997-03-03 0:00 ` Larry Kilgallen
0 siblings, 0 replies; 6+ messages in thread
From: Larry Kilgallen @ 1997-03-03 0:00 UTC (permalink / raw)
In article <c4ohd0ncig.fsf@hc17031.hcsd.ca>, demer@hc17031.hcsd.ca (David Emery) writes:
> Just remember that in POSIX, file locks are advisory.
Good point.
In fact, any "locking" scheme voluntarily added to an Ada program
presumes that all other accessors will play be the same rules.
The only way to _guarantee_ that locks are respected is to have
a mechanism which is tied into the record access method, which
means an end to free-form data access which might be present in
an existing Ada program. Only if that record access method
can be guaranteed to always be used (such as by interaction
with operating system inner modes) is a file or record lock
guaranteed.
Larry Kilgallen
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: File/Record locking in Ada
1997-02-28 0:00 ` Keith Allan Shillington
1997-03-01 0:00 ` Keith Thompson
1997-03-03 0:00 ` David Emery
@ 1997-03-05 0:00 ` David Emery
2 siblings, 0 replies; 6+ messages in thread
From: David Emery @ 1997-03-05 0:00 UTC (permalink / raw)
File locking can be done simply, but record locking will require a
lot more support.
For many (but not all) applications, file-level locking is sufficient.
dave
--
Note: if email to me bounces, use 'emery@grebyn.com'
^ permalink raw reply [flat|nested] 6+ messages in thread