xref: /netbsd-src/lib/libc/sys/intro.2 (revision ce63d6c20fc4ec8ddc95c84bb229e3c4ecf82b69)
1.\" Copyright (c) 1980,1983,1986,1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)intro.2	6.13 (Berkeley) 7/23/91
33.\"
34.Dd July 23, 1991
35.Dt INTRO 2
36.Os BSD 4
37.Sh NAME
38.Nm intro
39.Nd introduction to system calls and error numbers
40.Sh SYNOPSIS
41.Fd #include <sys/errno.h>
42.Sh DESCRIPTION
43This section provides an overview of the system calls,
44their error returns, and other common definitions and concepts.
45.\".Pp
46.\".Sy System call restart
47.\".Pp
48.\"<more later...>
49.Sh DIAGNOSTICS
50Nearly all of the system calls provide an error number in the external
51variable
52.Va errno ,
53which is defined as:
54.Pp
55.Dl extern int errno
56.Pp
57When a system call detects an error,
58it returns an integer value
59indicating failure (usually -1)
60and sets the variable
61.Va errno
62accordingly.
63<This allows interpretation of the failure on receiving
64a -1 and to take action accordingly.>
65Successful calls never set
66.Va errno ;
67once set, it remains until another error occurs.
68It should only be examined after an error.
69Note that a number of system calls overload the meanings of these
70error numbers, and that the meanings must be interpreted according
71to the type and circumstances of the call.
72.Pp
73The following is a complete list of the errors and their
74names as given in
75.Aq Pa sys/errno.h .
76.Bl -hang -width Ds
77.It Er 0 Em "Error 0" .
78Not used.
79.It Er 1 EPERM Em "Operation not permitted .
80An attempt was made to perform an operation limited to processes
81with appropriate privileges or to the owner of a file or other
82resources.
83.It Er 2 ENOENT Em "No such file or directory" .
84A component of a specified pathname did not exist, or the
85pathname was an empty string.
86.It Er 3 ESRCH Em "No such process" .
87No process could be found corresponding to that specified by the given
88process ID.
89.It Er 4 EINTR Em "Interrupted function call" .
90An asynchronous signal (such as
91.Dv SIGINT
92or
93.Dv SIGQUIT )
94was caught by the process during the execution of an interruptible
95function. If the signal handler performs a normal return, the
96interupted function call will seem to have returned the error condition.
97.It Er 5 EIO Em "Input/output error" .
98Some physical input or output error occurred.
99This error not be reported until a subsequent operation on the same file
100descriptor and may be lost (over written) by any subsequent errors.
101.It Er 6 ENXIO Em "\&No such device or address" .
102Input or output on a special file referred to a device that did not
103exist, or
104made a request beyond the limits of the device.
105This error may also occur when, for example,
106a tape drive is not online or no disk pack is
107is loaded on a drive.
108.It Er 7 E2BIG Em "Arg list too long" .
109The number of bytes used for the argument and environment
110list of the new process exceeded the current limit
111of 20480 bytes
112.Pf ( Dv NCARGS
113in
114.Aq Pa sys/param.h ) .
115.It Er 8 ENOEXEC Em "Exec format error" .
116A request was made to execute a file
117that, although it has the appropriate permissions,
118was not in the format required for an
119executable file.
120.It Er 9 EBADF Em "Bad file descriptor" .
121A file descriptor argument was out of range, referred to no open file,
122or a read (write) request was made to a file that was only open for
123writing (reading).
124.It Er 10 ECHILD Em "\&No child processes" .
125A
126.Xr wait
127or
128.Xr waitpid
129function was executed by a process that had no existing or unwaited-for
130child processes.
131.It Er 11 EDEADLK Em "Resource deadlock avoided" .
132An attempt was made to lock a system resource that
133would have resulted in a deadlock situation.
134.It Er 12 ENOMEM Em "Cannnot allocate memory" .
135The new process image required more memory than was allowed by the hardware
136or by system-imposed memory management constraints.
137A lack of swap space is normally temporary; however,
138a lack of core is not.
139Soft limits may be increased to their corresponding hard limits.
140.It Er 13 EACCES Em "Permission denied" .
141An attempt was made to access a file in a way forbidden
142by its file access permissions.
143.It Er 14 EFAULT Em "Bad address" .
144The system detected an invalid address in attempting to
145use an argument of a call.
146.It Er 15 ENOTBLK Em "Not a block device" .
147A block device operation was attempted on a non-block device or file.
148.It Er 16 EBUSY Em "Resource busy" .
149An attempt to use a system resource which was in use at the time
150in a manner which would have conflicted with the request.
151.It Er 17 EEXIST Em "File exists" .
152An existing file was mentioned in an inappropriate context,
153for instance, as the new link name in a
154.Xr link
155function.
156.It Er 18 EXDEV Em "Improper link" .
157A hard link to a file on another file system
158was attempted.
159.It Er 19 ENODEV Em "Operation not supported by device" .
160An attempt was made to apply an inappropriate
161function to a device,
162for example,
163trying to read a write-only device such as a printer.
164.It Er 20 ENOTDIR Em "Not a directory" .
165A component of the specified pathname existed, but it was
166not a directory, when a directory was expected.
167.It Er 21 EISDIR Em "Is a directory" .
168An attempt was made to open a directory with write mode specified.
169.It Er 22 EINVAL Em "Invalid argument" .
170Some invalid argument was supplied. (For example,
171specifying an undefined signal to a
172.Xr signal
173or
174.Xr kill
175function).
176.It Er 23 ENFILE Em "Too many open files in system" .
177Maximum number of file descriptors allowable on the system
178has been reached and a requests for an open cannot be satisfied
179until at least one has been closed.
180.It Er 24 EMFILE Em "Too many open files" .
181<As released, the limit on the number of
182open files per process is 64.>
183.Xr Getdtablesize 2
184will obtain the current limit.
185.It Er 25 ENOTTY Em "Inappropriate ioctl for device" .
186A control function (see
187.Xr ioctl 2 )
188was attempted for a file or
189special device for which the operation was inappropriate.
190.It Er 26 ETXTBSY Em "Text file busy" .
191The new process was a pure procedure (shared text) file
192which was open for writing by another process, or
193the pure procedure file was being executed an
194.Xr open
195call requested write access.
196.It Er 27 EFBIG Em "File too large" .
197The size of a file exceeded the maximum (about
198.if t 2\u\s-231\s+2\d
199.if n 2.1E9
200bytes).
201.It Er 28 ENOSPC Em "Device out of space" .
202A
203.Xr write
204to an ordinary file, the creation of a
205directory or symbolic link, or the creation of a directory
206entry failed because no more disk blocks are available
207on the file system, or the allocation of an inode for a newly
208created file failed because no more inodes are available
209on the file system.
210.It Er 29 ESPIPE Em "Illegal seek" .
211An
212.Xr lseek
213function was issued on a socket, pipe or
214.Tn FIFO .
215.It Er 30 EROFS Em "Read-only file system" .
216An attempt was made to modify a file or directory
217was made
218on a file system that was read-only at the time.
219.It Er 31 EMLINK Em "Too many links" .
220Maximum allowable hard links to a single file has been exceeded (limit
221of 32767 hard links per file).
222.It Er 32 EPIPE Em "Broken pipe" .
223A write on a pipe, socket or
224.Tn FIFO
225for which there is no process
226to read the data.
227.It Er 33 EDOM Em "Numerical argument out of domain" .
228A numerical input argument was outside the defined domain of the mathematical
229function.
230.It Er 34 ERANGE Em "Numerical result out of range" .
231A numerical result of the function was to large to fit in the
232available space (perhaps exceeded precision).
233.It Er 35 EAGAIN Em "Resource temporarily unavailable" .
234This is a temporary condition and later calls to the
235same routine may complete normally.
236.It Er 36 EINPROGRESS Em "Operation now in progress" .
237An operation that takes a long time to complete (such as
238a
239.Xr connect 2 )
240was attempted on a non-blocking object (see
241.Xr fcntl 2 ) .
242.It Er 37 EALREADY Em "Operation already in progress" .
243An operation was attempted on a non-blocking object that already
244had an operation in progress.
245.It Er 38 ENOTSOCK Em "Socket operation on non-socket" .
246Self-explanatory.
247.It Er 39 EDESTADDRREQ Em "Destination address required" .
248A required address was omitted from an operation on a socket.
249.It Er 40 EMSGSIZE Em "Message too long" .
250A message sent on a socket was larger than the internal message buffer
251or some other network limit.
252.It Er 41 EPROTOTYPE Em "Protocol wrong type for socket" .
253A protocol was specified that does not support the semantics of the
254socket type requested. For example, you cannot use the
255.Tn ARPA
256Internet
257.Tn UDP
258protocol with type
259.Dv SOCK_STREAM .
260.It Er 42 ENOPROTOOPT Em "Protocol not available" .
261A bad option or level was specified in a
262.Xr getsockopt 2
263or
264.Xr setsockopt 2
265call.
266.It Er 43 EPROTONOSUPPORT Em "Protocol not supported" .
267The protocol has not been configured into the
268system or no implementation for it exists.
269.It Er 44 ESOCKTNOSUPPORT Em "Socket type not supported" .
270The support for the socket type has not been configured into the
271system or no implementation for it exists.
272.It Er 45 EOPNOTSUPP Em "Operation not supported" .
273The attempted operation is not supported for the type of object referenced.
274Usually this occurs when a file descriptor refers to a file or socket
275that cannot support this operation,
276for example, trying to
277.Em accept
278a connection on a datagram socket.
279.It Er 46 EPFNOSUPPORT Em "Protocol family not supported" .
280The protocol family has not been configured into the
281system or no implementation for it exists.
282.It Er 47 EAFNOSUPPORT Em "Address family not supported by protocol family" .
283An address incompatible with the requested protocol was used.
284For example, you shouldn't necessarily expect to be able to use
285.Tn NS
286addresses with
287.Tn ARPA
288Internet protocols.
289.It Er 48 EADDRINUSE Em "Address already in use" .
290Only one usage of each address is normally permitted.
291.It Er 49 EADDRNOTAVAIL Em "Cannot assign requested address" .
292Normally results from an attempt to create a socket with an
293address not on this machine.
294.It Er 50 ENETDOWN Em "Network is down" .
295A socket operation encountered a dead network.
296.It Er 51 ENETUNREACH Em "Network is unreachable" .
297A socket operation was attempted to an unreachable network.
298.It Er 52 ENETRESET Em "Network dropped connection on reset" .
299The host you were connected to crashed and rebooted.
300.It Er 53 ECONNABORTED Em "Software caused connection abort" .
301A connection abort was caused internal to your host machine.
302.It Er 54 ECONNRESET Em "Connection reset by peer" .
303A connection was forcibly closed by a peer.  This normally
304results from a loss of the connection on the remote socket
305due to a timeout or a reboot.
306.It Er 55 ENOBUFS Em "\&No buffer space available" .
307An operation on a socket or pipe was not performed because
308the system lacked sufficient buffer space or because a queue was full.
309.It Er 56 EISCONN Em "Socket is already connected" .
310A
311.Xr connect
312request was made on an already connected socket; or,
313a
314.Xr sendto
315or
316.Xr sendmsg
317request on a connected socket specified a destination
318when already connected.
319.It Er 57 ENOTCONN Em "Socket is not connected" .
320An request to send or receive data was disallowed because
321the socket is not connected and (when sending on a  datagram socket)
322no address was supplied.
323.It Er 58 ESHUTDOWN Em "Cannot send after socket shutdown" .
324A request to send data was disallowed because the socket
325had already been shut down with a previous
326.Xr shutdown 2
327call.
328.It Er 60 ETIMEDOUT Em "Connection timed out" .
329A
330.Xr connect
331or
332.Xr send
333request failed because the connected party did not
334properly respond after a period of time.  (The timeout
335period is dependent on the communication protocol.)
336.It Er 61 ECONNREFUSED Em "Connection refused" .
337No connection could be made because the target machine actively
338refused it.  This usually results from trying to connect
339to a service that is inactive on the foreign host.
340.It Er 62 ELOOP Em "Too many levels of symbolic links" .
341A path name lookup involved more than 8 symbolic links.
342.It Er 63 ENAMETOOLONG Em "File name too long" .
343A component of a path name exceeded 255
344.Pq Dv MAXNAMELEN
345characters, or an entire
346path name exceeded 1023
347.Pq Dv MAXPATHLEN Ns -1
348characters.
349.It Er 64 EHOSTDOWN Em "Host is down" .
350A socket operation failed because the destination host was down.
351.It Er 65 EHOSTUNREACH Em "No route to host" .
352A socket operation was attempted to an unreachable host.
353.It Er 66 ENOTEMPTY Em "Directory not empty" .
354A directory with entries other than
355.Ql \&.
356and
357.Ql \&..
358was supplied to a remove directory or rename call.
359.It Er 67 EPROCLIM Em "Too many processes" .
360.It Er 68 EUSERS Em "Too many users" .
361The quota system ran out of table entries.
362.It Er 69 EDQUOT Em "Disc quota exceeded" .
363A
364.Xr write
365to an ordinary file, the creation of a
366directory or symbolic link, or the creation of a directory
367entry failed because the user's quota of disk blocks was
368exhausted, or the allocation of an inode for a newly
369created file failed because the user's quota of inodes
370was exhausted.
371.It Er 70 ESTALE Em "Stale NFS file handle" .
372An attempt was made to access an open file (on an
373.Tn NFS
374filesystem)
375which is now unavailable as referenced by the file descriptor.
376This may indicate the file was deleted on the
377.Tn NFS
378server or some
379other catastrophic event occured.
380.It Er 72 EBADRPC Em "RPC struct is bad" .
381Exchange of
382.Tn RPC
383information was unsuccessful.
384.It Er 73 ERPCMISMATCH Em "RPC version wrong" .
385The version of
386.Tn RPC
387on the remote peer is not compatible with
388the local version.
389.It Er 74 EPROGUNAVAIL Em "RPC prog. not avail" .
390The requested program is not registered on the remote host.
391.It Er 75 EPROGMISMATCH Em "Program version wrong" .
392The requested version of the program is not available
393on the remote host
394.Pq Tn RPC .
395.It Er 76 EPROCUNAVAIL Em "Bad procedure for program" .
396An
397.Tn RPC
398call was attempted for a procedure which doesn't exist
399in the remote program.
400.It Er 77 ENOLCK Em "No locks available" .
401A system-imposed limit on the number of simultaneous file
402locks was reached.
403.It Er 78 ENOSYS Em "Function not implemented" .
404Attempted a system call that is not available on this
405system.
406.Sh DEFINITIONS
407.Bl -tag -width Ds
408.It  Process ID .
409Each active process in the system is uniquely identified by a non-negative
410integer called a process ID.  The range of this ID is from 0 to 30000.
411.It  Parent process ID
412A new process is created by a currently active process; (see
413.Xr fork 2 ) .
414The parent process ID of a process is the process ID of its creator.
415.It  Process Group ID
416Each active process is a member of a process group that is identified by
417a non-negative integer called the process group ID.  This is the process
418ID of the group leader.  This grouping permits the signaling of related
419processes (see
420.Xr killpg 2 )
421and the job control mechanisms of
422.Xr csh 1 .
423.It  Tty Group ID
424Each active process can be a member of a terminal group that is identified
425by a non-negative integer called the tty group ID.  This grouping is used
426to arbitrate between multiple jobs contending for the same terminal;
427(see
428.Xr csh 1
429and
430.Xr tty 4 ) .
431.It "Real User ID and Real Group ID"
432Each user on the system is identified by a positive integer
433termed the real user ID.
434.Pp
435Each user is also a member of one or more groups.
436One of these groups is distinguished from others and
437used in implementing accounting facilities.  The positive
438integer corresponding to this distinguished group is termed
439the real group ID.
440.Pp
441All processes have a real user ID and real group ID.
442These are initialized from the equivalent attributes
443of the process that created it.
444.It "Effective User Id, Effective Group Id, and Access Groups"
445Access to system resources is governed by three values:
446the effective user ID, the effective group ID, and the
447group access list.
448.Pp
449The effective user ID and effective group ID are initially the
450process's real user ID and real group ID respectively.  Either
451may be modified through execution of a set-user-ID or set-group-ID
452file (possibly by one its ancestors) (see
453.Xr execve 2 ) .
454.Pp
455The group access list is an additional set of group ID's
456used only in determining resource accessibility.  Access checks
457are performed as described below in ``File Access Permissions''.
458.It  Super-user
459A process is recognized as a
460.Em super-user
461process and is granted special privileges if its effective user ID is 0.
462.It  Special Processes
463The processes with a process ID's of 0, 1, and 2 are special.
464Process 0 is the scheduler.  Process 1 is the initialization process
465.Xr init ,
466and is the ancestor of every other process in the system.
467It is used to control the process structure.
468Process 2 is the paging daemon.
469.It  Descriptor
470An integer assigned by the system when a file is referenced
471by
472.Xr open 2
473or
474.Xr dup 2 ,
475or when a socket is created by
476.Xr pipe 2 ,
477.Xr socket 2
478or
479.Xr socketpair 2 ,
480which uniquely identifies an access path to that file or socket from
481a given process or any of its children.
482.It  File Name
483Names consisting of up to 255
484.Pq Dv MAXNAMELEN
485characters may be used to name
486an ordinary file, special file, or directory.
487.Pp
488These characters may be selected from the set of all
489.Tn ASCII
490character
491excluding 0 (NUL) and the
492.Tn ASCII
493code for
494.Ql \&/
495(slash).  (The parity bit,
496bit 7, must be 0.)
497.Pp
498Note that it is generally unwise to use
499.Ql \&* ,
500.Ql \&? ,
501.Ql \&[
502or
503.Ql \&]
504as part of
505file names because of the special meaning attached to these characters
506by the shell.
507.It  Path Name
508A path name is a
509.Tn NUL Ns -terminated
510character string starting with an
511optional slash
512.Ql \&/ ,
513followed by zero or more directory names separated
514by slashes, optionally followed by a file name.
515The total length of a path name must be less than 1024
516.Pq Dv MAXPATHLEN
517characters.
518.Pp
519If a path name begins with a slash, the path search begins at the
520.Em root
521directory.
522Otherwise, the search begins from the current working directory.
523A slash by itself names the root directory.  An empty
524pathname refers to the current directory.
525.It  Directory
526A directory is a special type of file that contains entries
527that are references to other files.
528Directory entries are called links.  By convention, a directory
529contains at least two links,
530.Ql \&.
531and
532.Ql \&.. ,
533referred to as
534.Em dot
535and
536.Em dot-dot
537respectively.  Dot refers to the directory itself and
538dot-dot refers to its parent directory.
539.It "Root Directory and Current Working Directory"
540Each process has associated with it a concept of a root directory
541and a current working directory for the purpose of resolving path
542name searches.  A process's root directory need not be the root
543directory of the root file system.
544.It  File Access Permissions
545Every file in the file system has a set of access permissions.
546These permissions are used in determining whether a process
547may perform a requested operation on the file (such as opening
548a file for writing).  Access permissions are established at the
549time a file is created.  They may be changed at some later time
550through the
551.Xr chmod 2
552call.
553.Pp
554File access is broken down according to whether a file may be: read,
555written, or executed.  Directory files use the execute
556permission to control if the directory may be searched.
557.Pp
558File access permissions are interpreted by the system as
559they apply to three different classes of users: the owner
560of the file, those users in the file's group, anyone else.
561Every file has an independent set of access permissions for
562each of these classes.  When an access check is made, the system
563decides if permission should be granted by checking the access
564information applicable to the caller.
565.Pp
566Read, write, and execute/search permissions on
567a file are granted to a process if:
568.Pp
569The process's effective user ID is that of the super-user. (Note:
570even the super-user cannot execute a non-executable file.)
571.Pp
572The process's effective user ID matches the user ID of the owner
573of the file and the owner permissions allow the access.
574.Pp
575The process's effective user ID does not match the user ID of the
576owner of the file, and either the process's effective
577group ID matches the group ID
578of the file, or the group ID of the file is in
579the process's group access list,
580and the group permissions allow the access.
581.Pp
582Neither the effective user ID nor effective group ID
583and group access list of the process
584match the corresponding user ID and group ID of the file,
585but the permissions for ``other users'' allow access.
586.Pp
587Otherwise, permission is denied.
588.It  Sockets and Address Families
589.Pp
590A socket is an endpoint for communication between processes.
591Each socket has queues for sending and receiving data.
592.Pp
593Sockets are typed according to their communications properties.
594These properties include whether messages sent and received
595at a socket require the name of the partner, whether communication
596is reliable, the format used in naming message recipients, etc.
597.Pp
598Each instance of the system supports some
599collection of socket types; consult
600.Xr socket 2
601for more information about the types available and
602their properties.
603.Pp
604Each instance of the system supports some number of sets of
605communications protocols.  Each protocol set supports addresses
606of a certain format.  An Address Family is the set of addresses
607for a specific group of protocols.  Each socket has an address
608chosen from the address family in which the socket was created.
609.Sh SEE ALSO
610intro(3), perror(3)
611.Sh HISTORY
612An
613.Nm intro
614appeared in
615.At v6 .
616