Can you please describe for me a scenario where opening a file fails
and it is not possible to diagnose why?
I believe that in UNIX V6, and perhaps UNIX V7, if open() (yes,
it's a non-standard function used in some implementations to implement
fopen()) failed, you'd get a proper errno. However, if fopen()
failed to allocate an open file slot (This was a fixed-size array
of 20 FILE structures), there wasn't any error return from the
kernel since the error happened at the user-program level. There
wasn't any error code for "Out of FILE array slots": the kernel
controlled the list of error codes. For some reason it wasn't
suitable to use ENOMEM, like no dynamic memory allocation was being
done. This is a case not of being "not possible to diagnose why",
but more of "didn't bother to diagnose why".
There may have been other errors diagnosed at the user level that
didn't have error codes, like fopen(name, "Q"). However, I wouldn't
put it past the code to check for "r" and "a", and if it didn't
find either, assume "w" rather than return an error.
I think this was a rather lame excuse, but at the time of
standardization, there was a large base of existing code, and
probably most of it without a support contract.
There are a number of situations where a file open may fail and it
is *NOT PERMITTED* to tell you why it failed. For example, consider
a situation where the file names may be classified, and at a different
classification than the file contents. Perhaps there's a directory
/home with subdirectories named after the code name of the agent.
If you (with a low security level) get ENOENT for some and EACCES
for others, you can guess the code names of agents even if you can't
list them all. Try to open it, and see which failure you get.
That's not allowed. However, I don't believe that *ALL* reasons
for failure would be classified (e.g. failure to allocate memory,
or disk errors could legitimately be distinguished), so there is
no excuse for having only one error code EFAILED. You could use
ENOENT to include all the cases where you're not allowed to see the
files in question, or make up one like ENOENT_OR_NOACCES.
You're never going to be able to put a complete list of error codes in
the standard. People will always be inventing new hardware with new
failure modes. Someone will stick in an error code for violating the
MPAA content rating. There will be plenty of opportunity for error
codes related to bad credit card number, credit limit exceeded, or
similar payment failure. This, however, means that there's no short
list of error codes that, if they exist, means "file does not exist",
so it can be treated specially (like ask "do you want to create it?").