source: rtems-docs/posix_users/files_and_directory.rst @ 36def91

4.115
Last change on this file since 36def91 was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

  • Property mode set to 100644
File size: 49.0 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2002.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7Files and Directories Manager
8#############################
9
10Introduction
11============
12
13The files and directories manager is ...
14
15The directives provided by the files and directories manager are:
16
17- opendir_ - Open a Directory
18
19- readdir_ - Reads a directory
20
21- rewinddir_ - Resets the ``readdir()`` pointer
22
23- scandir_ - Scan a directory for matching entries
24
25- telldir_ - Return current location in directory stream
26
27- closedir_ - Ends directory read operation
28
29- getdents_ - Get directory entries
30
31- chdir_ - Changes the current working directory
32
33- fchdir_ - Changes the current working directory
34
35- getcwd_ - Gets current working directory
36
37- open_ - Opens a file
38
39- creat_ - Create a new file or rewrite an existing one
40
41- umask_ - Sets a file creation mask
42
43- link_ - Creates a link to a file
44
45- symlink_ - Creates a symbolic link to a file
46
47- readlink_ - Obtain the name of the link destination
48
49- mkdir_ - Makes a directory
50
51- mkfifo_ - Makes a FIFO special file
52
53- unlink_ - Removes a directory entry
54
55- rmdir_ - Delete a directory
56
57- rename_ - Renames a file
58
59- stat_ - Gets information about a file.
60
61- fstat_ - Gets file status
62
63- lstat_ - Gets file status
64
65- access_ - Check permissions for a file.
66
67- chmod_ - Changes file mode
68
69- fchmod_ - Changes permissions of a file
70
71- chown_ - Changes the owner and/ or group of a file
72
73- utime_ - Change access and/or modification times of an inode
74
75- ftruncate_ - Truncate a file to a specified length
76
77- truncate_ - Truncate a file to a specified length
78
79- pathconf_ - Gets configuration values for files
80
81- fpathconf_ - Get configuration values for files
82
83- mknod_ - Create a directory
84
85Background
86==========
87
88Path Name Evaluation
89--------------------
90
91A pathname is a string that consists of no more than ``PATH_MAX`` bytes,
92including the terminating null character. A pathname has an optional beginning
93slash, followed by zero or more filenames separated by slashes.  If the
94pathname refers to a directory, it may also have one or more trailing
95slashes. Multiple successive slahes are considered to be the same as one slash.
96
97POSIX allows a pathname that begins with precisely two successive slashes to be
98interpreted in an implementation-defined manner. RTEMS does not currently
99recognize this as a special condition. Any number of successive slashes is
100treated the same as a single slash. POSIX requires that an implementation treat
101more than two leading slashes as a single slash.
102
103Operations
104==========
105
106There is currently no text in this section.
107
108Directives
109==========
110
111This section details the files and directories manager's directives.  A
112subsection is dedicated to each of this manager's directives and describes the
113calling sequence, related constants, usage, and status codes.
114
115.. _opendir:
116
117opendir - Open a Directory
118--------------------------
119.. index:: opendir
120.. index:: open a directory
121
122**CALLING SEQUENCE:**
123
124.. code-block:: c
125
126    #include <sys/types.h>
127    #include <dirent.h>
128    int opendir(
129        const char *dirname
130    );
131
132**STATUS CODES:**
133
134.. list-table::
135 :class: rtems-table
136
137 * - ``EACCES``
138   - Search permission was denied on a component of the path prefix of
139     ``dirname``, or read permission is denied
140 * - ``EMFILE``
141   - Too many file descriptors in use by process
142 * - ``ENFILE``
143   - Too many files are currently open in the system.
144 * - ``ENOENT``
145   - Directory does not exist, or ``name`` is an empty string.
146 * - ``ENOMEM``
147   - Insufficient memory to complete the operation.
148 * - ``ENOTDIR``
149   - ``name`` is not a directory.
150
151**DESCRIPTION:**
152
153This routine opens a directory stream corresponding to the
154directory specified by the ``dirname`` argument. The
155directory stream is positioned at the first entry.
156
157**NOTES:**
158
159The routine is implemented in Cygnus newlib.
160
161.. _readdir:
162
163readdir - Reads a directory
164---------------------------
165.. index:: readdir
166.. index:: reads a directory
167
168**CALLING SEQUENCE:**
169
170.. code-block:: c
171
172    #include <sys/types.h>
173    #include <dirent.h>
174        int readdir(
175        DIR *dirp
176    );
177
178**STATUS CODES:**
179
180.. list-table::
181 :class: rtems-table
182
183 * - ``EBADF``
184   - Invalid file descriptor
185
186**DESCRIPTION:**
187
188The ``readdir()`` function returns a pointer to a structure ``dirent``
189representing the next directory entry from the directory stream pointed to by
190``dirp``. On end-of-file, ``NULL`` is returned.
191
192The ``readdir()`` function may (or may not) return entries for ``.`` or ``..``
193Your program should tolerate reading dot and dot-dot but not require them.
194
195The data pointed to be ``readdir()`` may be overwritten by another call to
196``readdir()`` for the same directory stream. It will not be overwritten by a
197call for another directory.
198
199**NOTES:**
200
201If ``ptr`` is not a pointer returned by ``malloc()``, ``calloc()``, or
202``realloc()`` or has been deallocated with ``free()`` or ``realloc()``, the
203results are not portable and are probably disastrous.
204
205The routine is implemented in Cygnus newlib.
206
207.. _rewinddir:
208
209rewinddir - Resets the readdir() pointer
210----------------------------------------
211.. index:: rewinddir
212.. index:: resets the readdir() pointer
213
214**CALLING SEQUENCE:**
215
216.. code-block:: c
217
218    #include <sys/types.h>
219    #include <dirent.h>
220    void rewinddir(
221        DIR *dirp
222    );
223
224**STATUS CODES:**
225
226No value is returned.
227
228**DESCRIPTION:**
229
230The ``rewinddir()`` function resets the position associated with the directory
231stream pointed to by ``dirp``. It also causes the directory stream to refer to
232the current state of the directory.
233
234**NOTES:**
235
236NONE
237
238If ``dirp`` is not a pointer by ``opendir()``, the results are undefined.
239
240The routine is implemented in Cygnus newlib.
241
242.. _scandir:
243
244scandir - Scan a directory for matching entries
245-----------------------------------------------
246.. index:: scandir
247.. index:: scan a directory for matching entries
248
249**CALLING SEQUENCE:**
250
251.. code-block:: c
252
253    #include <dirent.h>
254    int scandir(
255        const char       *dir,
256        struct dirent ***namelist,
257        int  (*select)(const struct dirent *),
258        int  (*compar)(const struct dirent **, const struct dirent **)
259    );
260
261**STATUS CODES:**
262
263.. list-table::
264 :class: rtems-table
265
266 * - ``ENOMEM``
267   - Insufficient memory to complete the operation.
268
269**DESCRIPTION:**
270
271The ``scandir()`` function scans the directory ``dir``, calling ``select()`` on
272each directory entry. Entries for which ``select()`` returns non-zero are
273stored in strings allocated via ``malloc()``, sorted using ``qsort()`` with the
274comparison function ``compar()``, and collected in array ``namelist`` which is
275allocated via ``malloc()``.  If ``select`` is ``NULL``, all entries are
276selected.
277
278**NOTES:**
279
280The routine is implemented in Cygnus newlib.
281
282.. _telldir:
283
284telldir - Return current location in directory stream
285-----------------------------------------------------
286.. index:: telldir
287.. index:: return current location in directory stream
288
289**CALLING SEQUENCE:**
290
291.. code-block:: c
292
293    #include <dirent.h>
294    off_t telldir(
295        DIR *dir
296    );
297
298**STATUS CODES:**
299
300.. list-table::
301 :class: rtems-table
302
303 * - ``EBADF``
304   - Invalid directory stream descriptor ``dir``.
305
306**DESCRIPTION:**
307
308The ``telldir()`` function returns the current location associated with the
309directory stream ``dir``.
310
311**NOTES:**
312
313The routine is implemented in Cygnus newlib.
314
315.. _closedir:
316
317closedir - Ends directory read operation
318----------------------------------------
319.. index:: closedir
320.. index:: ends directory read operation
321
322**CALLING SEQUENCE:**
323
324.. code-block:: c
325
326    #include <sys/types.h>
327    #include <dirent.h>
328    int closedir(
329        DIR *dirp
330    );
331
332**STATUS CODES:**
333
334.. list-table::
335 :class: rtems-table
336
337 * - ``EBADF``
338   - Invalid file descriptor
339
340**DESCRIPTION:**
341
342The directory stream associated with ``dirp`` is closed.  The value in ``dirp``
343may not be usable after a call to ``closedir()``.
344
345**NOTES:**
346
347NONE
348
349The argument to ``closedir()`` must be a pointer returned by ``opendir()``. If
350it is not, the results are not portable and most likely unpleasant.
351
352The routine is implemented in Cygnus newlib.
353
354.. _chdir:
355
356chdir - Changes the current working directory
357---------------------------------------------
358.. index:: chdir
359.. index:: changes the current working directory
360
361**CALLING SEQUENCE:**
362
363.. code-block:: c
364
365    #include <unistd.h>
366    int chdir(
367        const char *path
368    );
369
370**STATUS CODES:**
371
372On error, this routine returns -1 and sets ``errno`` to one of the following:
373
374.. list-table::
375 :class: rtems-table
376
377 * - ``EACCES``
378   - Search permission is denied for a directory in a file's path prefix.
379 * - ``ENAMETOOLONG``
380   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
381     is in effect.
382 * - ``ENOENT``
383   - A file or directory does not exist.
384 * - ``ENOTDIR``
385   - A component of the specified pathname was not a directory when directory
386     was expected.
387
388**DESCRIPTION:**
389
390The ``chdir()`` function causes the directory named by ``path`` to become the
391current working directory; that is, the starting point for searches of
392pathnames not beginning with a slash.
393
394If ``chdir()`` detects an error, the current working directory is not changed.
395
396**NOTES:**
397
398NONE
399
400.. _fchdir:
401
402fchdir - Changes the current working directory
403----------------------------------------------
404.. index:: fchdir
405.. index:: changes the current working directory
406
407**CALLING SEQUENCE:**
408
409.. code-block:: c
410
411    #include <unistd.h>
412    int fchdir(
413        int fd
414    );
415
416**STATUS CODES:**
417
418On error, this routine returns -1 and sets ``errno`` to one of the following:
419
420.. list-table::
421 :class: rtems-table
422
423 * - ``EACCES``
424   - Search permission is denied for a directory in a file's path prefix.
425 * - ``ENAMETOOLONG``
426   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
427     is in effect.
428 * - ``ENOENT``
429   - A file or directory does not exist.
430 * - ``ENOTDIR``
431   - A component of the specified pathname was not a directory when directory
432     was expected.
433
434**DESCRIPTION:**
435
436The ``fchdir()`` function causes the directory named by ``fd`` to become the
437current working directory; that is, the starting point for searches of
438pathnames not beginning with a slash.
439
440If ``fchdir()`` detects an error, the current working directory is not changed.
441
442**NOTES:**
443
444NONE
445
446.. _getcwd:
447
448getcwd - Gets current working directory
449---------------------------------------
450.. index:: getcwd
451.. index:: gets current working directory
452
453**CALLING SEQUENCE:**
454
455.. code-block:: c
456
457    #include <unistd.h>
458    int getcwd( void );
459
460**STATUS CODES:**
461
462.. list-table::
463 :class: rtems-table
464
465 * - ``EINVAL``
466   - Invalid argument
467 * - ``ERANGE``
468   - Result is too large
469 * - ``EACCES``
470   - Search permission is denied for a directory in a file's path prefix.
471
472**DESCRIPTION:**
473
474The ``getcwd()`` function copies the absolute pathname of the current working
475directory to the character array pointed to by ``buf``. The ``size`` argument
476is the number of bytes available in ``buf``
477
478**NOTES:**
479
480There is no way to determine the maximum string length that ``fetcwd()`` may
481need to return. Applications should tolerate getting ``ERANGE`` and allocate a
482larger buffer.
483
484It is possible for ``getcwd()`` to return EACCES if, say, ``login`` puts the
485process into a directory without read access.
486
487The 1988 standard uses ``int`` instead of ``size_t`` for the second parameter.
488
489.. _open:
490
491open - Opens a file
492-------------------
493.. index:: open
494.. index:: opens a file
495
496**CALLING SEQUENCE:**
497
498.. code-block:: c
499
500    #include <sys/types.h>
501    #include <sys/stat.h>
502    #include <fcntl.h>
503    int open(
504        const char *path,
505        int         oflag,
506        mode_t      mode
507    );
508
509**STATUS CODES:**
510
511.. list-table::
512 :class: rtems-table
513
514 * - ``EACCES``
515   - Search permission is denied for a directory in a file's path prefix.
516 * - ``EEXIST``
517   - The named file already exists.
518 * - ``EINTR``
519   - Function was interrupted by a signal.
520 * - ``EISDIR``
521   - Attempt to open a directory for writing or to rename a file to be a
522     directory.
523 * - ``EMFILE``
524   - Too many file descriptors are in use by this process.
525 * - ``ENAMETOOLONG``
526   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
527     is in effect.
528 * - ``ENFILE``
529   - Too many files are currently open in the system.
530 * - ``ENOENT``
531   - A file or directory does not exist.
532 * - ``ENOSPC``
533   - No space left on disk.
534 * - ``ENOTDIR``
535   - A component of the specified pathname was not a directory when a directory
536     was expected.
537 * - ``ENXIO``
538   - No such device. This error may also occur when a device is not ready, for
539     example, a tape drive is off-line.
540 * - ``EROFS``
541   - Read-only file system.
542
543**DESCRIPTION:**
544
545The ``open`` function establishes a connection between a file and a file
546descriptor. The file descriptor is a small integer that is used by I/O
547functions to reference the file. The ``path`` argument points to the pathname
548for the file.
549
550The ``oflag`` argument is the bitwise inclusive OR of the values of symbolic
551constants. The programmer must specify exactly one of the following three
552symbols:
553
554.. list-table::
555 :class: rtems-table
556
557 * - ``O_RDONLY``
558   - Open for reading only.
559 * - ``O_WRONLY``
560   - Open for writing only.
561 * - ``O_RDWR``
562   - Open for reading and writing.
563
564Any combination of the following symbols may also be used.
565
566.. list-table::
567 :class: rtems-table
568
569 * - ``O_APPEND``
570   - Set the file offset to the end-of-file prior to each write.
571 * - ``O_CREAT``
572   - If the file does not exist, allow it to be created. This flag indicates
573     that the ``mode`` argument is present in the call to ``open``.
574 * - ``O_EXCL``
575   - This flag may be used only if ``O_CREAT`` is also set. It causes the call
576     to ``open`` to fail if the file already exists.
577 * - ``O_NOCTTY``
578   - Do not assign controlling terminal.
579 * - ``O_NONBLOCK``
580   - Do no wait for the device or file to be ready or available. After the file
581     is open, the ``read`` and ``write`` calls return immediately. If the
582     process would be delayed in the read or write opermation, -1 is returned
583     and``errno`` is set to ``EAGAIN`` instead of blocking the caller.
584 * - ``O_TRUNC``
585   - This flag should be used only on ordinary files opened for writing. It
586     causes the file to be tuncated to zero length..
587
588Upon successful completion, ``open`` returns a non-negative file descriptor.
589
590**NOTES:**
591
592NONE
593
594.. _creat:
595
596creat - Create a new file or rewrite an existing one
597----------------------------------------------------
598.. index:: creat
599.. index:: create a new file or rewrite an existing one
600
601**CALLING SEQUENCE:**
602
603.. code-block:: c
604
605    #include <sys/types.h>
606    #include <sys/stat.h>
607    #include <fcntl.h>
608    int creat(
609        const char *path,
610        mode_t      mode
611    );
612
613**STATUS CODES:**
614
615.. list-table::
616 :class: rtems-table
617
618 * - ``EEXIST``
619   - ``path`` already exists and ``O_CREAT`` and ``O_EXCL`` were used.
620 * - ``EISDIR``
621   - ``path`` refers to a directory and the access requested involved writing
622 * - ``ETXTBSY``
623   - ``path`` refers to an executable image which is currently being executed
624     and write access was requested
625 * - ``EFAULT``
626   - ``path`` points outside your accessible address space
627 * - ``EACCES``
628   - The requested access to the file is not allowed, or one of the directories
629     in ``path`` did not allow search (execute) permission.
630 * - ``ENAMETOOLONG``
631   - ``path`` was too long.
632 * - ``ENOENT``
633   - A directory component in ``path`` does not exist or is a dangling symbolic
634     link.
635 * - ``ENOTDIR``
636   - A component used as a directory in ``path`` is not, in fact, a directory.
637 * - ``EMFILE``
638   - The process alreadyh has the maximum number of files open.
639 * - ``ENFILE``
640   - The limit on the total number of files open on the system has been
641     reached.
642 * - ``ENOMEM``
643   - Insufficient kernel memory was available.
644 * - ``EROFS``
645   - ``path`` refers to a file on a read-only filesystem and write access was
646     requested
647
648**DESCRIPTION:**
649
650``creat`` attempts to create a file and return a file descriptor for use in
651read, write, etc.
652
653**NOTES:**
654
655NONE
656
657The routine is implemented in Cygnus newlib.
658
659.. _umask:
660
661umask - Sets a file creation mask.
662----------------------------------
663.. index:: umask
664.. index:: sets a file creation mask.
665
666**CALLING SEQUENCE:**
667
668.. code-block:: c
669
670    #include <sys/types.h>
671    #include <sys/stat.h>
672    mode_t umask(
673        mode_t cmask
674    );
675
676**STATUS CODES:**
677
678**DESCRIPTION:**
679
680The ``umask()`` function sets the process file creation mask to ``cmask``.  The
681file creation mask is used during ``open()``, ``creat()``, ``mkdir()``,
682``mkfifo()`` calls to turn off permission bits in the ``mode`` argument.  Bit
683positions that are set in ``cmask`` are cleared in the mode of the created
684file.
685
686**NOTES:**
687
688NONE
689
690The ``cmask`` argument should have only permission bits set. All other bits
691should be zero.
692
693In a system which supports multiple processes, the file creation mask is
694inherited across ``fork()`` and ``exec()`` calls. This makes it possible to
695alter the default permission bits of created files. RTEMS does not support
696multiple processes so this behavior is not possible.
697
698.. _link:
699
700link - Creates a link to a file
701-------------------------------
702.. index:: link
703.. index:: creates a link to a file
704
705**CALLING SEQUENCE:**
706
707.. code-block:: c
708
709    #include <unistd.h>
710    int link(
711        const char *existing,
712        const char *new
713    );
714
715**STATUS CODES:**
716
717.. list-table::
718 :class: rtems-table
719
720 * - ``EACCES``
721   - Search permission is denied for a directory in a file's path prefix
722 * - ``EEXIST``
723   - The named file already exists.
724 * - ``EMLINK``
725   - The number of links would exceed ``LINK_MAX``.
726 * - ``ENAMETOOLONG``
727   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
728     is in effect.
729 * - ``ENOENT``
730   - A file or directory does not exist.
731 * - ``ENOSPC``
732   - No space left on disk.
733 * - ``ENOTDIR``
734   - A component of the specified pathname was not a directory when a directory
735     was expected.
736 * - ``EPERM``
737   - Operation is not permitted. Process does not have the appropriate
738     priviledges or permissions to perform the requested operations.
739 * - ``EROFS``
740   - Read-only file system.
741 * - ``EXDEV``
742   - Attempt to link a file to another file system.
743
744**DESCRIPTION:**
745
746The ``link()`` function atomically creates a new link for an existing file and
747increments the link count for the file.
748
749If the ``link()`` function fails, no directories are modified.
750
751The ``existing`` argument should not be a directory.
752
753The caller may (or may not) need permission to access the existing file.
754
755**NOTES:**
756
757NONE
758
759.. _symlink:
760
761symlink - Creates a symbolic link to a file
762-------------------------------------------
763.. index:: symlink
764.. index:: creates a symbolic link to a file
765
766**CALLING SEQUENCE:**
767
768.. code-block:: c
769
770    #include <unistd.h>
771    int symlink(
772        const char *topath,
773        const char *frompath
774    );
775
776**STATUS CODES:**
777
778.. list-table::
779 :class: rtems-table
780
781 * - ``EACCES``
782   - Search permission is denied for a directory in a file's path prefix
783 * - ``EEXIST``
784   - The named file already exists.
785 * - ``ENAMETOOLONG``
786   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
787     is in effect.
788 * - ``ENOENT``
789   - A file or directory does not exist.
790 * - ``ENOSPC``
791   - No space left on disk.
792 * - ``ENOTDIR``
793   - A component of the specified pathname was not a directory when a directory
794     was expected.
795 * - ``EPERM``
796   - Operation is not permitted. Process does not have the appropriate
797     priviledges or permissions to perform the requested operations.
798 * - ``EROFS``
799   - Read-only file system.
800
801**DESCRIPTION:**
802
803The ``symlink()`` function creates a symbolic link from the frombath to the
804topath. The symbolic link will be interpreted at run-time.
805
806If the ``symlink()`` function fails, no directories are modified.
807
808The caller may (or may not) need permission to access the existing file.
809
810**NOTES:**
811
812NONE
813
814.. _readlink:
815
816readlink - Obtain the name of a symbolic link destination
817---------------------------------------------------------
818.. index:: readlink
819.. index:: obtain the name of a symbolic link destination
820
821**CALLING SEQUENCE:**
822
823.. code-block:: c
824
825    #include <unistd.h>
826    int readlink(
827        const char *path,
828        char       *buf,
829        size_t      bufsize
830    );
831
832**STATUS CODES:**
833
834.. list-table::
835 :class: rtems-table
836
837 * - ``EACCES``
838   - Search permission is denied for a directory in a file's path prefix
839 * - ``ENAMETOOLONG``
840   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
841     is in effect.
842 * - ``ENOENT``
843   - A file or directory does not exist.
844 * - ``ENOTDIR``
845   - A component of the prefix pathname was not a directory when a directory
846     was expected.
847 * - ``ELOOP``
848   - Too many symbolic links were encountered in the pathname.
849 * - ``EINVAL``
850   - The pathname does not refer to a symbolic link
851 * - ``EFAULT``
852   - An invalid pointer was passed into the ``readlink()`` routine.
853
854**DESCRIPTION:**
855
856The ``readlink()`` function places the symbolic link destination into ``buf``
857argument and returns the number of characters copied.
858
859If the symbolic link destination is longer than bufsize characters the name
860will be truncated.
861
862**NOTES:**
863
864NONE
865
866.. _mkdir:
867
868mkdir - Makes a directory
869-------------------------
870.. index:: mkdir
871.. index:: makes a directory
872
873**CALLING SEQUENCE:**
874
875.. code-block:: c
876
877    #include <sys/types.h>
878    #include <sys/stat.h>
879    int mkdir(
880        const char *path,
881        mode_t      mode
882    );
883
884**STATUS CODES:**
885
886.. list-table::
887 :class: rtems-table
888
889 * - ``EACCES``
890   - Search permission is denied for a directory in a file's path prefix
891 * - ``EEXIST``
892   - The name file already exist.
893 * - ``EMLINK``
894   - The number of links would exceed ``LINK_MAX``
895 * - ``ENAMETOOLONG``
896   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
897     is in effect.
898 * - ``ENOENT``
899   - A file or directory does not exist.
900 * - ``ENOSPC``
901   - No space left on disk.
902 * - ``ENOTDIR``
903   - A component of the specified pathname was not a directory when a directory
904     was expected.
905 * - ``EROFS``
906   - Read-only file system.
907
908**DESCRIPTION:**
909
910The ``mkdir()`` function creates a new diectory named ``path``. The permission
911bits (modified by the file creation mask) are set from ``mode``.  The owner and
912group IDs for the directory are set from the effective user ID and group ID.
913
914The new directory may (or may not) contain entries for ``.`` and ``..`` but is
915otherwise empty.
916
917**NOTES:**
918
919NONE
920
921.. _mkfifo:
922
923mkfifo - Makes a FIFO special file
924----------------------------------
925.. index:: mkfifo
926.. index:: makes a fifo special file
927
928**CALLING SEQUENCE:**
929
930.. code-block:: c
931
932    #include <sys/types.h>
933    #include <sys/stat.h>
934    int mkfifo(
935        const char *path,
936        mode_t      mode
937    );
938
939**STATUS CODES:**
940
941.. list-table::
942 :class: rtems-table
943
944 * - ``EACCES``
945   - Search permission is denied for a directory in a file's path prefix
946 * - ``EEXIST``
947   - The named file already exists.
948 * - ``ENOENT``
949   - A file or directory does not exist.
950 * - ``ENOSPC``
951   - No space left on disk.
952 * - ``ENOTDIR``
953   - A component of the specified ``path`` was not a directory when a directory
954     was expected.
955 * - ``EROFS``
956   - Read-only file system.
957
958**DESCRIPTION:**
959
960The ``mkfifo()`` function creates a new FIFO special file named ``path``.  The
961permission bits (modified by the file creation mask) are set from ``mode``. The
962owner and group IDs for the FIFO are set from the efective user ID and
963group ID.
964
965**NOTES:**
966
967NONE
968
969.. _unlink:
970
971unlink - Removes a directory entry
972----------------------------------
973.. index:: unlink
974.. index:: removes a directory entry
975
976**CALLING SEQUENCE:**
977
978.. code-block:: c
979
980    #include <unistd.h>
981    int unlink(
982        const char path
983    );
984
985**STATUS CODES:**
986
987.. list-table::
988 :class: rtems-table
989
990 * - ``EACCES``
991   - Search permission is denied for a directory in a file's path prefix
992 * - ``EBUSY``
993   - The directory is in use.
994 * - ``ENAMETOOLONG``
995   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
996     is in effect.
997 * - ``ENOENT``
998   - A file or directory does not exist.
999 * - ``ENOTDIR``
1000   - A component of the specified ``path`` was not a directory when a directory
1001     was expected.
1002 * - ``EPERM``
1003   - Operation is not permitted. Process does not have the appropriate
1004     priviledges or permissions to perform the requested operations.
1005 * - ``EROFS``
1006   - Read-only file system.
1007
1008**DESCRIPTION:**
1009
1010The ``unlink`` function removes the link named by ``path`` and decrements the
1011link count of the file referenced by the link. When the link count goes to zero
1012and no process has the file open, the space occupied by the file is freed and
1013the file is no longer accessible.
1014
1015**NOTES:**
1016
1017NONE
1018
1019.. _rmdir:
1020
1021rmdir - Delete a directory
1022--------------------------
1023.. index:: rmdir
1024.. index:: delete a directory
1025
1026**CALLING SEQUENCE:**
1027
1028.. code-block:: c
1029
1030    #include <unistd.h>
1031    int rmdir(
1032        const char *pathname
1033    );
1034
1035**STATUS CODES:**
1036
1037.. list-table::
1038 :class: rtems-table
1039
1040 * - ``EPERM``
1041   - The filesystem containing ``pathname`` does not support the removal of
1042     directories.
1043 * - ``EFAULT``
1044   - ``pathname`` points ouside your accessible address space.
1045 * - ``EACCES``
1046   - Write access to the directory containing ``pathname`` was not allowed for
1047     the process's effective uid, or one of the directories in``pathname`` did
1048     not allow search (execute) permission.
1049 * - ``EPERM``
1050   - The directory containing ``pathname`` has the stickybit (S_ISVTX) set and
1051     the process's effective uid is neither the uid of the file to be delected
1052     nor that of the director containing it.
1053 * - ``ENAMETOOLONG``
1054   - ``pathname`` was too long.
1055 * - ``ENOENT``
1056   - A dirctory component in ``pathname`` does not exist or is a dangling
1057     symbolic link.
1058 * - ``ENOTDIR``
1059   - ``pathname``, or a component used as a directory in ``pathname``, is not,
1060     in fact, a directory.
1061 * - ``ENOTEMPTY``
1062   - ``pathname`` contains entries other than . and .. .
1063 * - ``EBUSY``
1064   - ``pathname`` is the current working directory or root directory of some
1065     process
1066 * - ``EBUSY``
1067   - ``pathname`` is the current directory or root directory of some process.
1068 * - ``ENOMEM``
1069   - Insufficient kernel memory was available
1070 * - ``EROGS``
1071   - ``pathname`` refers to a file on a read-only filesystem.
1072 * - ``ELOOP``
1073   - ``pathname`` contains a reference to a circular symbolic link
1074
1075**DESCRIPTION:**
1076
1077``rmdir`` deletes a directory, which must be empty
1078
1079**NOTES:**
1080
1081NONE
1082
1083.. _rename:
1084
1085rename - Renames a file
1086-----------------------
1087.. index:: rename
1088.. index:: renames a file
1089
1090**CALLING SEQUENCE:**
1091
1092.. code-block:: c
1093
1094    #include <unistd.h>
1095    int rename(
1096        const char *old,
1097        const char *new
1098    );
1099
1100**STATUS CODES:**
1101
1102.. list-table::
1103 :class: rtems-table
1104
1105 * - ``EACCES``
1106   - Search permission is denied for a directory in a file's path prefix.
1107 * - ``EBUSY``
1108   - The directory is in use.
1109 * - ``EEXIST``
1110   - The named file already exists.
1111 * - ``EINVAL``
1112   - Invalid argument.
1113 * - ``EISDIR``
1114   - Attempt to open a directory for writing or to rename a file to be a
1115     directory.
1116 * - ``EMLINK``
1117   - The number of links would exceed ``LINK_MAX``.
1118 * - ``ENAMETOOLONG``
1119   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1120     is in effect.
1121 * - ``ENOENT``
1122   - A file or directory does no exist.
1123 * - ``ENOSPC``
1124   - No space left on disk.
1125 * - ``ENOTDIR``
1126   - A component of the specified pathname was not a directory when a directory
1127     was expected.
1128 * - ``ENOTEMPTY``
1129   - Attempt to delete or rename a non-empty directory.
1130 * - ``EROFS``
1131   - Read-only file system
1132 * - ``EXDEV``
1133   - Attempt to link a file to another file system.
1134
1135**DESCRIPTION:**
1136
1137The ``rename()`` function causes the file known bo ``old`` to now be known as
1138``new``.
1139
1140Ordinary files may be renamed to ordinary files, and directories may be renamed
1141to directories; however, files cannot be converted using ``rename()``. The
1142``new`` pathname may not contain a path prefix of ``old``.
1143
1144**NOTES:**
1145
1146If a file already exists by the name ``new``, it is removed. The ``rename()``
1147function is atomic. If the ``rename()`` detects an error, no files are
1148removed. This guarantees that the ``rename("x", "x")`` does not remove ``x``.
1149
1150You may not rename dot or dot-dot.
1151
1152The routine is implemented in Cygnus newlib using ``link()`` and ``unlink()``.
1153
1154.. _stat:
1155
1156stat - Gets information about a file
1157------------------------------------
1158.. index:: stat
1159.. index:: gets information about a file
1160
1161**CALLING SEQUENCE:**
1162
1163.. code-block:: c
1164
1165    #include <sys/types.h>
1166    #include <sys/stat.h>
1167    int stat(
1168        const char  *path,
1169        struct stat *buf
1170    );
1171
1172**STATUS CODES:**
1173
1174.. list-table::
1175 :class: rtems-table
1176
1177 * - ``EACCES``
1178   - Search permission is denied for a directory in a file's path prefix.
1179 * - ``EBADF``
1180   - Invalid file descriptor.
1181 * - ``ENAMETOOLONG``
1182   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1183     is in effect.
1184 * - ``ENOENT``
1185   - A file or directory does not exist.
1186 * - ``ENOTDIR``
1187   - A component of the specified pathname was not a directory when a directory
1188     was expected.
1189
1190**DESCRIPTION:**
1191
1192The ``path`` argument points to a pathname for a file. Read, write, or execute
1193permission for the file is not required, but all directories listed in ``path``
1194must be searchable. The ``stat()`` function obtains information about the named
1195file and writes it to the area pointed to by ``buf``.
1196
1197**NOTES:**
1198
1199NONE
1200
1201.. _fstat:
1202
1203fstat - Gets file status
1204------------------------
1205.. index:: fstat
1206.. index:: gets file status
1207
1208**CALLING SEQUENCE:**
1209
1210.. code-block:: c
1211
1212    #include <sys/types.h>
1213    #include <sys/stat.h>
1214    int fstat(
1215        int          fildes,
1216        struct stat *buf
1217    );
1218
1219**STATUS CODES:**
1220
1221.. list-table::
1222 :class: rtems-table
1223
1224 * - ``EBADF``
1225   - Invalid file descriptor
1226
1227**DESCRIPTION:**
1228
1229The ``fstat()`` function obtains information about the file associated with
1230``fildes`` and writes it to the area pointed to by the ``buf`` argument.
1231
1232**NOTES:**
1233
1234If the filesystem object referred to by ``fildes`` is a link, then the
1235information returned in ``buf`` refers to the destination of that link.  This
1236is in contrast to ``lstat()`` which does not follow the link.
1237
1238.. _lstat:
1239
1240lstat - Gets file status
1241------------------------
1242.. index:: lstat
1243.. index:: gets file status
1244
1245**CALLING SEQUENCE:**
1246
1247.. code-block:: c
1248
1249    #include <sys/types.h>
1250    #include <sys/stat.h>
1251    int lstat(
1252        int          fildes,
1253        struct stat *buf
1254    );
1255
1256**STATUS CODES:**
1257
1258.. list-table::
1259 :class: rtems-table
1260
1261 * - ``EBADF``
1262   - Invalid file descriptor
1263
1264**DESCRIPTION:**
1265
1266The ``lstat()`` function obtains information about the file associated with
1267``fildes`` and writes it to the area pointed to by the ``buf`` argument.
1268
1269**NOTES:**
1270
1271If the filesystem object referred to by ``fildes`` is a link, then the
1272information returned in ``buf`` refers to the link itself.  This is in contrast
1273to ``fstat()`` which follows the link.
1274
1275The ``lstat()`` routine is defined by BSD 4.3 and SVR4 and not included in
1276POSIX 1003.1b-1996.
1277
1278.. _access:
1279
1280access - Check permissions for a file
1281-------------------------------------
1282.. index:: access
1283.. index:: check permissions for a file
1284
1285**CALLING SEQUENCE:**
1286
1287.. code-block:: c
1288
1289    #include <unistd.h>
1290    int access(
1291        const char *pathname,
1292        int         mode
1293    );
1294
1295**STATUS CODES:**
1296
1297.. list-table::
1298 :class: rtems-table
1299
1300 * - ``EACCES``
1301   - The requested access would be denied, either to the file itself or one of
1302     the directories in ``pathname``.
1303 * - ``EFAULT``
1304   - ``pathname`` points outside your accessible address space.
1305 * - ``EINVAL``
1306   - ``Mode`` was incorrectly specified.
1307 * - ``ENAMETOOLONG``
1308   - ``pathname`` is too long.
1309 * - ``ENOENT``
1310   - A directory component in ``pathname`` would have been accessible but does
1311     not exist or was a dangling symbolic link.
1312 * - ``ENOTDIR``
1313   - A component used as a directory in ``pathname`` is not, in fact, a
1314     directory.
1315 * - ``ENOMEM``
1316   - Insufficient kernel memory was available.
1317
1318**DESCRIPTION:**
1319
1320``Access`` checks whether the process would be allowed to read, write or test
1321for existence of the file (or other file system object) whose name is
1322``pathname``. If ``pathname`` is a symbolic link permissions of the file
1323referred by this symbolic link are tested.
1324
1325``Mode`` is a mask consisting of one or more of ``R_OK``, ``W_OK``, ``X_OK``
1326and ``F_OK``.
1327
1328**NOTES:**
1329
1330NONE
1331
1332.. _chmod:
1333
1334chmod - Changes file mode.
1335--------------------------
1336.. index:: chmod
1337.. index:: changes file mode.
1338
1339**CALLING SEQUENCE:**
1340
1341.. code-block:: c
1342
1343    #include <sys/types.h>
1344    #include <sys/stat.h>
1345    int chmod(
1346        const char *path,
1347        mode_t      mode
1348    );
1349
1350**STATUS CODES:**
1351
1352.. list-table::
1353 :class: rtems-table
1354
1355 * - ``EACCES``
1356   - Search permission is denied for a directory in a file's path prefix
1357 * - ``ENAMETOOLONG``
1358   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1359     is in effect.
1360 * - ``ENOENT``
1361   - A file or directory does not exist.
1362 * - ``ENOTDIR``
1363   - A component of the specified pathname was not a directory when a directory
1364     was expected.
1365 * - ``EPERM``
1366   - Operation is not permitted. Process does not have the appropriate
1367     priviledges or permissions to perform the requested operations.
1368 * - ``EROFS``
1369   - Read-only file system.
1370
1371**DESCRIPTION:**
1372
1373Set the file permission bits, the set user ID bit, and the set group ID bit for
1374the file named by ``path`` to ``mode``. If the effective user ID does not match
1375the owner of the file and the calling process does not have the appropriate
1376privileges, ``chmod()`` returns -1 and sets ``errno`` to ``EPERM``.
1377
1378**NOTES:**
1379
1380NONE
1381
1382.. _fchmod:
1383
1384fchmod - Changes permissions of a file
1385--------------------------------------
1386.. index:: fchmod
1387.. index:: changes permissions of a file
1388
1389**CALLING SEQUENCE:**
1390
1391.. code-block:: c
1392
1393    #include <sys/types.h>
1394    #include <sys/stat.h>
1395    int fchmod(
1396        int    fildes,
1397        mode_t mode
1398    );
1399
1400**STATUS CODES:**
1401
1402.. list-table::
1403 :class: rtems-table
1404
1405 * - ``EACCES``
1406   - Search permission is denied for a directory in a file's path prefix.
1407 * - ``EBADF``
1408   - The descriptor is not valid.
1409 * - ``EFAULT``
1410   - ``path`` points outside your accessible address space.
1411 * - ``EIO``
1412   - A low-level I/o error occurred while modifying the inode.
1413 * - ``ELOOP``
1414   - ``path`` contains a circular reference
1415 * - ``ENAMETOOLONG``
1416   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1417     is in effect.
1418 * - ``ENOENT``
1419   - A file or directory does no exist.
1420 * - ``ENOMEM``
1421   - Insufficient kernel memory was avaliable.
1422 * - ``ENOTDIR``
1423   - A component of the specified pathname was not a directory when a directory
1424     was expected.
1425 * - ``EPERM``
1426   - The effective UID does not match the owner of the file, and is not zero
1427 * - ``EROFS``
1428   - Read-only file system
1429
1430**DESCRIPTION:**
1431
1432The mode of the file given by ``path`` or referenced by ``filedes`` is changed.
1433
1434**NOTES:**
1435
1436NONE
1437
1438.. _getdents:
1439
1440getdents - Get directory entries
1441--------------------------------
1442.. index:: getdents
1443.. index:: get directory entries
1444
1445**CALLING SEQUENCE:**
1446
1447.. code-block:: c
1448
1449    #include <unistd.h>
1450    #include <linux/dirent.h>
1451    #include <linux/unistd.h>
1452    long getdents(
1453        int   dd_fd,
1454        char *dd_buf,
1455        int   dd_len
1456    );
1457
1458**STATUS CODES:**
1459
1460A successful call to ``getdents`` returns th the number of bytes read.  On end
1461of directory, 0 is returned. When an error occurs, -1 is returned, and
1462``errno`` is set appropriately.
1463
1464.. list-table::
1465 :class: rtems-table
1466
1467 * - ``EBADF``
1468   - Invalid file descriptor ``fd``.
1469 * - ``EFAULT``
1470   - Argument points outside the calling process's address space.
1471 * - ``EINVAL``
1472   - Result buffer is too small.
1473 * - ``ENOENT``
1474   - No such directory.
1475 * - ``ENOTDIR``
1476   - File descriptor does not refer to a directory.
1477
1478**DESCRIPTION:**
1479
1480``getdents`` reads several ``dirent`` structures from the directory pointed by
1481``fd`` into the memory area pointed to by ``dirp``. The parameter ``count`` is
1482the size of the memory area.
1483
1484**NOTES:**
1485
1486NONE
1487
1488.. _chown:
1489
1490chown - Changes the owner and/or group of a file.
1491-------------------------------------------------
1492.. index:: chown
1493.. index:: changes the owner and/or group of a file.
1494
1495**CALLING SEQUENCE:**
1496
1497.. code-block:: c
1498
1499    #include <sys/types.h>
1500    #include <unistd.h>
1501    int chown(
1502        const char *path,
1503        uid_t       owner,
1504        gid_t       group
1505    );
1506
1507**STATUS CODES:**
1508
1509.. list-table::
1510 :class: rtems-table
1511
1512 * - ``EACCES``
1513   - Search permission is denied for a directory in a file's path prefix
1514 * - ``EINVAL``
1515   - Invalid argument
1516 * - ``ENAMETOOLONG``
1517   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1518     is in effect.
1519 * - ``ENOENT``
1520   - A file or directory does not exist.
1521 * - ``ENOTDIR``
1522   - A component of the specified pathname was not a directory when a directory
1523     was expected.
1524 * - ``EPERM``
1525   - Operation is not permitted. Process does not have the appropriate
1526     priviledges or permissions to perform the requested operations.
1527 * - ``EROFS``
1528   - Read-only file system.
1529
1530**DESCRIPTION:**
1531
1532The user ID and group ID of the file named by ``path`` are set to ``owner`` and
1533``path``, respectively.
1534
1535For regular files, the set group ID (``S_ISGID``) and set user ID (``S_ISUID``)
1536bits are cleared.
1537
1538Some systems consider it a security violation to allow the owner of a file to
1539be changed, If users are billed for disk space usage, loaning a file to another
1540user could result in incorrect billing. The ``chown()`` function may be
1541restricted to privileged users for some or all files. The group ID can still be
1542changed to one of the supplementary group IDs.
1543
1544**NOTES:**
1545
1546This function may be restricted for some file. The ``pathconf`` function can be
1547used to test the ``_PC_CHOWN_RESTRICTED`` flag.
1548
1549.. _utime:
1550
1551utime - Change access and/or modification times of an inode
1552-----------------------------------------------------------
1553.. index:: utime
1554.. index:: change access and/or modification times of an inode
1555
1556**CALLING SEQUENCE:**
1557
1558.. code-block:: c
1559
1560    #include <sys/types.h>
1561    int utime(
1562        const char     *filename,
1563        struct utimbuf *buf
1564    );
1565
1566**STATUS CODES:**
1567
1568.. list-table::
1569 :class: rtems-table
1570
1571 * - ``EACCES``
1572   - Permission to write the file is denied
1573 * - ``ENOENT``
1574   - ``Filename`` does not exist
1575
1576**DESCRIPTION:**
1577
1578``Utime`` changes the access and modification times of the inode specified by
1579``filename`` to the ``actime`` and ``modtime`` fields of ``buf``
1580respectively. If ``buf`` is ``NULL``, then the access and modification times of the
1581file are set to the current time.
1582
1583**NOTES:**
1584
1585NONE
1586
1587.. _ftruncate:
1588
1589ftruncate - truncate a file to a specified length
1590-------------------------------------------------
1591.. index:: ftruncate
1592.. index:: truncate a file to a specified length
1593
1594**CALLING SEQUENCE:**
1595
1596.. code-block:: c
1597
1598    #include <unistd.h>
1599    int ftrunctate(
1600        int    fd,
1601        size_t length
1602    );
1603
1604**STATUS CODES:**
1605
1606.. list-table::
1607 :class: rtems-table
1608
1609 * - ``ENOTDIR``
1610   - A component of the path prefix is not a directory.
1611 * - ``EINVAL``
1612   - The pathname contains a character with the high-order bit set.
1613 * - ``ENAMETOOLONG``
1614   - The length of the specified pathname exceeds ``PATH_MAX`` bytes, or the length
1615     of a component of the pathname exceeds ``NAME_MAX`` bytes.
1616 * - ``ENOENT``
1617   - The named file does not exist.
1618 * - ``EACCES``
1619   - The named file is not writable by the user.
1620 * - ``EACCES``
1621   - Search permission is denied for a component of the path prefix.
1622 * - ``ELOOP``
1623   - Too many symbolic links were encountered in translating the pathname
1624 * - ``EISDIR``
1625   - The named file is a directory.
1626 * - ``EROFS``
1627   - The named file resides on a read-only file system
1628 * - ``ETXTBSY``
1629   - The file is a pure procedure (shared text) file that is being executed
1630 * - ``EIO``
1631   - An I/O error occurred updating the inode.
1632 * - ``EFAULT``
1633   - ``Path`` points outside the process's allocated address space.
1634 * - ``EBADF``
1635   - The ``fd`` is not a valid descriptor.
1636
1637**DESCRIPTION:**
1638
1639``truncate()`` causes the file named by ``path`` or referenced by ``fd`` to be
1640truncated to at most ``length`` bytes in size. If the file previously was
1641larger than this size, the extra data is lost. With ``ftruncate()``, the file
1642must be open for writing.
1643
1644**NOTES:**
1645
1646NONE
1647
1648.. _truncate:
1649
1650truncate - truncate a file to a specified length
1651------------------------------------------------
1652.. index:: truncate
1653.. index:: truncate a file to a specified length
1654
1655**CALLING SEQUENCE:**
1656
1657.. code-block:: c
1658
1659    #include <unistd.h>
1660    int trunctate(
1661        const char *path,
1662        size_t      length
1663    );
1664
1665**STATUS CODES:**
1666
1667.. list-table::
1668 :class: rtems-table
1669
1670 * - ``ENOTDIR``
1671   - A component of the path prefix is not a directory.
1672 * - ``EINVAL``
1673   - The pathname contains a character with the high-order bit set.
1674 * - ``ENAMETOOLONG``
1675   - The length of the specified pathname exceeds ``PATH_MAX`` bytes, or the length
1676     of a component of the pathname exceeds ``NAME_MAX`` bytes.
1677 * - ``ENOENT``
1678   - The named file does not exist.
1679 * - ``EACCES``
1680   - The named file is not writable by the user.
1681 * - ``EACCES``
1682   - Search permission is denied for a component of the path prefix.
1683 * - ``ELOOP``
1684   - Too many symbolic links were encountered in translating the pathname
1685 * - ``EISDIR``
1686   - The named file is a directory.
1687 * - ``EROFS``
1688   - The named file resides on a read-only file system
1689 * - ``ETXTBSY``
1690   - The file is a pure procedure (shared text) file that is being executed
1691 * - ``EIO``
1692   - An I/O error occurred updating the inode.
1693 * - ``EFAULT``
1694   - ``Path`` points outside the process's allocated address space.
1695 * - ``EBADF``
1696   - The ``fd`` is not a valid descriptor.
1697
1698**DESCRIPTION:**
1699
1700``truncate()`` causes the file named by ``path`` or referenced by``fd`` to be
1701truncated to at most ``length`` bytes in size. If the file previously was
1702larger than this size, the extra data is lost. With ``ftruncate()``, the file
1703must be open for writing.
1704
1705**NOTES:**
1706
1707NONE
1708
1709.. _pathconf:
1710
1711pathconf - Gets configuration values for files
1712----------------------------------------------
1713.. index:: pathconf
1714.. index:: gets configuration values for files
1715
1716**CALLING SEQUENCE:**
1717
1718.. code-block:: c
1719
1720    #include <unistd.h>
1721    int pathconf(
1722        const char *path,
1723        int         name
1724    );
1725
1726**STATUS CODES:**
1727
1728.. list-table::
1729 :class: rtems-table
1730
1731 * - ``EINVAL``
1732   - Invalid argument
1733 * - ``EACCES``
1734   - Permission to write the file is denied
1735 * - ``ENAMETOOLONG``
1736   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1737     is in effect.
1738 * - ``ENOENT``
1739   - A file or directory does not exist
1740 * - ``ENOTDIR``
1741   - A component of the specified ``path`` was not a directory whan a directory
1742     was expected.
1743
1744**DESCRIPTION:**
1745
1746``pathconf()`` gets a value for the configuration option ``name`` for the open
1747file descriptor ``filedes``.
1748
1749The possible values for ``name`` are:
1750
1751.. list-table::
1752 :class: rtems-table
1753
1754 * - ``_PC_LINK_MAX``
1755   - Returns the maximum number of links to the file. If ``filedes`` or``path``
1756     refer to a directory, then the value applies to the whole directory. The
1757     corresponding macro is ``_POSIX_LINK_MAX``.
1758 * - ``_PC_MAX_CANON``
1759   - Returns the maximum length of a formatted input line, where ``filedes`` or
1760     ``path`` must refer to a terminal. The corresponding macro is
1761     ``_POSIX_MAX_CANON``.
1762 * - ``_PC_MAX_INPUT``
1763   - Returns the maximum length of an input line, where ``filedes`` or ``path``
1764     must refer to a terminal. The corresponding macro is``_POSIX_MAX_INPUT``.
1765 * - ``_PC_NAME_MAX``
1766   - Returns the maximum length of a filename in the directory ``path`` or
1767     ``filedes``. The process is allowed to create. The corresponding macro is
1768     ``_POSIX_NAME_MAX``.
1769 * - ``_PC_PATH_MAX``
1770   - returns the maximum length of a relative pathname when ``path``
1771     or``filedes`` is the current working directory. The corresponding macro is
1772     ``_POSIX_PATH_MAX``.
1773 * - ``_PC_PIPE_BUF``
1774   - returns the size of the pipe buffer, where ``filedes`` must refer to a
1775     pipe or FIFO and ``path`` must refer to a FIFO. The corresponding macro is
1776     ``_POSIX_PIPE_BUF``.
1777 * - ``_PC_CHOWN_RESTRICTED``
1778   - Returns nonzero if the ``chown(2)`` call may not be used on this
1779     file. If``filedes`` or ``path`` refer to a directory, then this applies to
1780     all files in that directory. The corresponding macro is
1781     ``_POSIX_CHOWN_RESTRICTED``.
1782
1783**NOTES:**
1784
1785Files with name lengths longer than the value returned for ``name`` equal
1786``_PC_NAME_MAX`` may exist in the given directory.
1787
1788.. _fpathconf:
1789
1790fpathconf - Gets configuration values for files
1791-----------------------------------------------
1792.. index:: fpathconf
1793.. index:: gets configuration values for files
1794
1795**CALLING SEQUENCE:**
1796
1797.. code-block:: c
1798
1799    #include <unistd.h>
1800    int fpathconf(
1801        int filedes,
1802        int name
1803    );
1804
1805**STATUS CODES:**
1806
1807.. list-table::
1808 :class: rtems-table
1809
1810 * - ``EINVAL``
1811   - Invalid argument
1812 * - ``EACCES``
1813   - Permission to write the file is denied
1814 * - ``ENAMETOOLONG``
1815   - Length of a filename string exceeds ``PATH_MAX`` and ``_POSIX_NO_TRUNC``
1816     is in effect.
1817 * - ``ENOENT``
1818   - A file or directory does not exist
1819 * - ``ENOTDIR``
1820   - A component of the specified ``path`` was not a directory whan a directory
1821     was expected.
1822
1823**DESCRIPTION:**
1824
1825``pathconf()`` gets a value for the configuration option ``name`` for the open
1826file descriptor ``filedes``.
1827
1828The possible values for name are:
1829
1830.. list-table::
1831 :class: rtems-table
1832
1833 * - ``_PC_LINK_MAX``
1834   - Returns the maximum number of links to the file. If ``filedes`` or
1835     ``path`` refer to a directory, then the value applies to the whole
1836     directory. The corresponding macro is ``_POSIX_LINK_MAX``.
1837 * - ``_PC_MAX_CANON``
1838   - returns the maximum length of a formatted input line, where ``filedes`` or
1839     ``path`` must refer to a terminal. The corresponding macro is
1840     ``_POSIX_MAX_CANON``.
1841 * - ``_PC_MAX_INPUT``
1842   - Returns the maximum length of an input line, where ``filedes`` or ``path``
1843     must refer to a terminal. The corresponding macro is ``_POSIX_MAX_INPUT``.
1844 * - ``_PC_NAME_MAX``
1845   - Returns the maximum length of a filename in the directory ``path`` or
1846     ``filedes``. The process is allowed to create. The corresponding macro is
1847     ``_POSIX_NAME_MAX``.
1848 * - ``_PC_PATH_MAX``
1849   - Returns the maximum length of a relative pathname when ``path`` or
1850     ``filedes`` is the current working directory. The corresponding macro is
1851     ``_POSIX_PATH_MAX``.
1852 * - ``_PC_PIPE_BUF``
1853   - Returns the size of the pipe buffer, where ``filedes`` must refer to a
1854     pipe or FIFO and ``path`` must refer to a FIFO. The corresponding macro is
1855     ``_POSIX_PIPE_BUF``.
1856 * - ``_PC_CHOWN_RESTRICTED``
1857   - Returns nonzero if the ``chown()`` call may not be used on this file. If
1858     ``filedes`` or ``path`` refer to a directory, then this applies to all
1859     files in that directory. The corresponding macro is
1860     ``_POSIX_CHOWN_RESTRICTED``.
1861
1862**NOTES:**
1863
1864NONE
1865
1866.. _mknod:
1867
1868mknod - create a directory
1869--------------------------
1870.. index:: mknod
1871.. index:: create a directory
1872
1873**CALLING SEQUENCE:**
1874
1875.. code-block:: c
1876
1877    #include <unistd.h>
1878    #include <fcntl.h>
1879    #include <sys/types.h>
1880    #include <sys/stat.h>
1881    long mknod(
1882        const char *pathname,
1883        mode_t      mode,
1884        dev_t       dev
1885    );
1886
1887**STATUS CODES:**
1888
1889``mknod`` returns zero on success, or -1 if an error occurred (in which case,
1890errno is set appropriately).
1891
1892.. list-table::
1893 :class: rtems-table
1894
1895 * - ``ENAMETOOLONG``
1896   - ``pathname`` was too long.
1897 * - ``ENOENT``
1898   - A directory component in ``pathname`` does not exist or is a dangling
1899     symbolic link.
1900 * - ``ENOTDIR``
1901   - A component used in the directory ``pathname`` is not, in fact, a
1902     directory.
1903 * - ``ENOMEM``
1904   - Insufficient kernel memory was available
1905 * - ``EROFS``
1906   - ``pathname`` refers to a file on a read-only filesystem.
1907 * - ``ELOOP``
1908   - ``pathname`` contains a reference to a circular symbolic link, ie a
1909     symbolic link whose expansion contains a reference to itself.
1910 * - ``ENOSPC``
1911   - The device containing ``pathname`` has no room for the new node.
1912
1913**DESCRIPTION:**
1914
1915``mknod`` attempts to create a filesystem node (file, device special file or
1916named pipe) named ``pathname``, specified by ``mode`` and ``dev``.
1917
1918``mode`` specifies both the permissions to use and the type of node to be created.
1919
1920It should be a combination (using bitwise OR) of one of the file types listed
1921below and the permissions for the new node.
1922
1923The permissions are modified by the process's ``umask`` in the usual way: the
1924permissions of the created node are ``(mode & ~umask)``.
1925
1926The file type should be one of ``S_IFREG``, ``S_IFCHR``, ``S_IFBLK`` and
1927``S_IFIFO`` to specify a normal file (which will be created empty), character
1928special file, block special file or FIFO (named pipe), respectively, or zero,
1929which will create a normal file.
1930
1931If the file type is ``S_IFCHR`` or ``S_IFBLK`` then ``dev`` specifies the major
1932and minor numbers of the newly created device special file; otherwise it is
1933ignored.
1934
1935The newly created node will be owned by the effective uid of the process. If
1936the directory containing the node has the set group id bit set, or if the
1937filesystem is mounted with BSD group semantics, the new node will inherit the
1938group ownership from its parent directory; otherwise it will be owned by the
1939effective gid of the process.
1940
1941**NOTES:**
1942
1943NONE
Note: See TracBrowser for help on using the repository browser.