comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada/UNIX(tm) and the NAME function
@ 1989-01-01  0:01 Erland Sommarskog
  0 siblings, 0 replies; 8+ messages in thread
From: Erland Sommarskog @ 1989-01-01  0:01 UTC (permalink / raw)


Dik T. Winter (dik@cwi.nl) writes:
>And note also that getwd (in C terms, getcwd is Fortran I believe) may fail.
>It will do so if the parent directory of one of the directories has
>execute permission only, no read permission.  In that case a file may
>be opened, but it is not possible to get an absolute path name.

I guess this is what happens when you type "pwd" and get something like
"...can't open". This is the occassion when you as VMS-raised person get 
very confused and wonder where you are. Such things just doesn't happen
on that system...
-- 
Erland Sommarskog
ENEA Data, Stockholm              This signature is not to be quoted.
sommar@enea.se

^ permalink raw reply	[flat|nested] 8+ messages in thread
* re: Ada/UNIX(tm) and the NAME function
@ 1988-12-28 16:38 David Emery
  1988-12-30 17:35 ` Barry Margolin
  1989-01-03 20:03 ` John Stafford
  0 siblings, 2 replies; 8+ messages in thread
From: David Emery @ 1988-12-28 16:38 UTC (permalink / raw)


This is not a significant problem on Unix.  First, you should get an
absolute pathname to the file.  This should be interpreted according
to Unix semantics.  My understanding of this is that, for a relative
pathname, the effect is as if current value of the process' working
directory is prepended to the relative pathname, converting it to an
absolute pathname.  This is then used to get the file.  (note that
there are plenty of optimizations here, particularly those that
"cache" the path traversal to get to the working directory).  There is
no requirement for Ada to determine the "best" path to a file, only
the absolute pathname used to open the file.

So, the Ada implementation of Text_IO.OPEN (or whatever) does the same
thing.  If the pathname isn't absolute, call Unix.getcwd, append the
pathname to this string, and associate it with the FILE_TYPE object.
(More specifically, store it inside the private FILE_TYPE object.)
Note that there is NO requirement to walk the directory chain.  If
Unix can open the file, then this is a good filename; if Unix cannot
open the file, then of course there is no reasonable name associated
with the FILE_TYPE object.  (So call Unix.open before 'calculating'
the file name.)

TEXT_IO.NAME then looks like 
	return FILE.FILE_NAME;
and NAME_ERROR is raised if file_type.file_name has no 'legal' value.

Of course, you have the potential problem of losing access to the file
during the execution of the process.  (For instance, someone clobbers
/usr).  This will always be true with Unix, so Ada shouldn't attempt
to fix Unix.

Naturally, Robert Firth's comment about exceptions is right on the
money.  

One of the things on our "agenda" for the Ada Binding to POSIX is to
provide a reasonable POSIX "binding" interpretation of Ada's TEXT_IO
in a POSIX environment (things like the meaning of FORM string, etc.)
We will discuss this issue at our next meeting but I would be very
surprised we came up with any other interpretation.  We will have to
think a bit about what is returned by TEXT_IO.NAME(TEXT_IO.STANDARD_INPUT).  
Furthermore, I suspect that we will in general try to better define
and possibly restrict the exceptions that a conforming POSIX
implementation can raise for TEXT_IO operations (e.g. restrict
TEXT_IO.NAME to raising STATUS_ERROR, and then only when the given
file hasn't been opened.)  

			dave emery
			(Technical Co-Editor, IEEE POSIX Ada Binding)
			mitre
			emery@mitre.org (new style)
			emery@mitre-bedford.arpa (old style)
			
"Advertisment": for more information on the POSIX Ada binding, contact
me.  To get on the Email list discussing the binding, send mail to
	posix-ada-request@grebyn.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Ada/UNIX(tm) and the NAME function
@ 1988-12-20 19:40 John Stafford
  1988-12-21 19:43 ` Robert Firth
  0 siblings, 1 reply; 8+ messages in thread
From: John Stafford @ 1988-12-20 19:40 UTC (permalink / raw)


Ada I/O has a function NAME which

   "Returns a string which uniquely identifies the external file
   currently associated with the given file (and may thus be used in an
   open operation).  If an environment allows alternative specifications
   of the name (for example, abbreviations), the string returned by the
   function should correspond to a full specification of the name."

So the question is, what should NAME do on a UNIX (tm) system?

   The first interpretation that comes to mind is that NAME should
   return "a" fully rooted path to the given file.  The term "a" is used
   because with hard links there is no "the" fully rooted path to the
   given file.  Futher, on systems which support "alternative
   specifications" like symbolic links or hidden files or alternative
   file system universes, such should be "resolved" and made "explicit"
   in the result.  Things like references to .  and ..  (in the file
   name given to the Ada I/O system by the user) are "alternative
   specifications" as well and should be "resolved" and made "explicit"
   in the result as well.

The problems with that interpretation are:

   1.  The name must be determined when the file is opened/created,
   since the user may have specified a relative file name and may change
   working directory after opening the file and before using NAME.  I
   recognize that changing working directory isn't directly supported by
   Ada, but NAME should work even if the user does change working
   directory since it is to return the "full specification of the name".

   2.  Even if the user gives a rooted path, the work still needs to be
   done to resolve any "alternative specifications".

   3.  The Ada I/O system ends up basically having to implement /bin/pwd
   to walk up the directory tree to compute the fully rooted path.  And
   if it uses chdir(2) during the walk, it also needs to first determine
   the current working directory so that it can "get back there" when it
   is done resolving the path to the specified file.  This potentially
   has severe impact on the performance of all Ada open/create
   operations.

   4.  Lack of read or execute permission anywhere in "a" path to the
   file in question (or to the current working directory in the chdir(2)
   case) will cause this process to fail.  Due to problem 1, it would
   seem that the open/create must therefore fail (probably by raising
   NAME_ERROR), even though the user may have permission to access the
   file and will never need the NAME.

   5.  The error cannot be deferred to the actual use of NAME because
   NAME is not defined as being able to raise any exception except
   STATUS_ERROR and it may only do that if the file is not open.

I am interested in alternative interpretations and/or comments on my
interpretation and comments.  I am also interested in information as to
what current compilers do if anyone cares to share it.  I don't claim to
even know what "Ada should do", but if Ada and UNIX are to get along,
somebody probably will need to take the monkey of defining the behavior
of NAME in a UNIX environment (I am not volunteering, I was referring to
some "official" standards type group, like the Ada/POSIX folks).

--
John Stafford
{biggies}!hplabs!hpda!jws

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1989-01-03 20:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-01-01  0:01 Ada/UNIX(tm) and the NAME function Erland Sommarskog
  -- strict thread matches above, loose matches on Subject: below --
1988-12-28 16:38 David Emery
1988-12-30 17:35 ` Barry Margolin
1988-12-30 22:08   ` Dik T. Winter
1989-01-03 20:03 ` John Stafford
1988-12-20 19:40 John Stafford
1988-12-21 19:43 ` Robert Firth
1989-01-03 15:19   ` Stephe Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox