source: rtems/doc/new_chapters/files.t @ bc950e87

4.104.114.84.95
Last change on this file since bc950e87 was bc950e87, checked in by Joel Sherrill <joel.sherrill@…>, on 11/19/98 at 16:02:06

Applied updates from remote work while doing class.

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