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