source: rtems-docs/posix_users/input_and_output.rst @ d389819

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

  • Property mode set to 100644
File size: 21.4 KB
Line 
1Input and Output Primitives Manager
2###################################
3
4Introduction
5============
6
7The input and output primitives manager is ...
8
9The directives provided by the input and output primitives manager are:
10
11- ``pipe`` - Create an Inter-Process Channel
12
13- ``dup`` - Duplicates an open file descriptor
14
15- ``dup2`` - Duplicates an open file descriptor
16
17- ``close`` - Closes a file
18
19- ``read`` - Reads from a file
20
21- ``write`` - Writes to a file
22
23- ``fcntl`` - Manipulates an open file descriptor
24
25- ``lseek`` - Reposition read/write file offset
26
27- ``fsync`` - Synchronize file complete in-core state with that on disk
28
29- ``fdatasync`` - Synchronize file in-core data with that on disk
30
31- ``sync`` - Schedule file system updates
32
33- ``mount`` - Mount a file system
34
35- ``unmount`` - Unmount file systems
36
37- ``readv`` - Vectored read from a file
38
39- ``writev`` - Vectored write to a file
40
41- ``aio_read`` - Asynchronous Read
42
43- ``aio_write`` - Asynchronous Write
44
45- ``lio_listio`` - List Directed I/O
46
47- ``aio_error`` - Retrieve Error Status of Asynchronous I/O Operation
48
49- ``aio_return`` - Retrieve Return Status Asynchronous I/O Operation
50
51- ``aio_cancel`` - Cancel Asynchronous I/O Request
52
53- ``aio_suspend`` - Wait for Asynchronous I/O Request
54
55- ``aio_fsync`` - Asynchronous File Synchronization
56
57Background
58==========
59
60There is currently no text in this section.
61
62Operations
63==========
64
65There is currently no text in this section.
66
67Directives
68==========
69
70This section details the input and output primitives manager's directives.
71A subsection is dedicated to each of this manager's directives
72and describes the calling sequence, related constants, usage,
73and status codes.
74
75pipe - Create an Inter-Process Channel
76--------------------------------------
77.. index:: pipe
78.. index:: create an inter
79
80**CALLING SEQUENCE:**
81
82.. code:: c
83
84    int pipe(
85    );
86
87**STATUS CODES:**
88
89*E*
90    The
91
92**DESCRIPTION:**
93
94**NOTES:**
95
96This routine is not currently supported by RTEMS but could be
97in a future version.
98
99dup - Duplicates an open file descriptor
100----------------------------------------
101.. index:: dup
102.. index:: duplicates an open file descriptor
103
104**CALLING SEQUENCE:**
105
106.. code:: c
107
108    #include <unistd.h>
109    int dup(
110    int fildes
111    );
112
113**STATUS CODES:**
114
115*EBADF*
116    Invalid file descriptor.
117
118*EINTR*
119    Function was interrupted by a signal.
120
121*EMFILE*
122    The process already has the maximum number of file descriptors open
123    and tried to open a new one.
124
125**DESCRIPTION:**
126
127The ``dup`` function returns the lowest numbered available file
128descriptor. This new desciptor refers to the same open file as the
129original descriptor and shares any locks.
130
131**NOTES:**
132
133NONE
134
135dup2 - Duplicates an open file descriptor
136-----------------------------------------
137.. index:: dup2
138.. index:: duplicates an open file descriptor
139
140**CALLING SEQUENCE:**
141
142.. code:: c
143
144    #include <unistd.h>
145    int dup2(
146    int fildes,
147    int fildes2
148    );
149
150**STATUS CODES:**
151
152*EBADF*
153    Invalid file descriptor.
154
155*EINTR*
156    Function was interrupted by a signal.
157
158*EMFILE*
159    The process already has the maximum number of file descriptors open
160    and tried to open a new one.
161
162**DESCRIPTION:**
163
164``dup2`` creates a copy of the file descriptor ``oldfd``.
165
166The old and new descriptors may be used interchangeably. They share locks, file
167position pointers and flags; for example, if the file position is modified by using``lseek`` on one of the descriptors, the position is also changed for the other.
168
169**NOTES:**
170
171NONE
172
173close - Closes a file
174---------------------
175.. index:: close
176.. index:: closes a file.
177
178**CALLING SEQUENCE:**
179
180.. code:: c
181
182    #include <unistd.h>
183    int close(
184    int fildes
185    );
186
187**STATUS CODES:**
188
189*EBADF*
190    Invalid file descriptor
191
192*EINTR*
193    Function was interrupted by a signal.
194
195**DESCRIPTION:**
196
197The ``close()`` function deallocates the file descriptor named by``fildes`` and makes it available for reuse. All outstanding
198record locks owned by this process for the file are unlocked.
199
200**NOTES:**
201
202A signal can interrupt the ``close()`` function. In that case,``close()`` returns -1 with ``errno`` set to EINTR. The file
203may or may not be closed.
204
205read - Reads from a file
206------------------------
207.. index:: read
208.. index:: reads from a file
209
210**CALLING SEQUENCE:**
211
212.. code:: c
213
214    #include <unistd.h>
215    int read(
216    int           fildes,
217    void         \*buf,
218    unsigned int  nbyte
219    );
220
221**STATUS CODES:**
222
223On error, this routine returns -1 and sets ``errno`` to one of
224the following:
225
226*EAGAIN*
227    The O_NONBLOCK flag is set for a file descriptor and the process
228    would be delayed in the I/O operation.
229
230*EBADF*
231    Invalid file descriptor
232
233*EINTR*
234    Function was interrupted by a signal.
235
236*EIO*
237    Input or output error
238
239*EINVAL*
240    Bad buffer pointer
241
242**DESCRIPTION:**
243
244The ``read()`` function reads ``nbyte`` bytes from the file
245associated with ``fildes`` into the buffer pointed to by ``buf``.
246
247The ``read()`` function returns the number of bytes actually read
248and placed in the buffer. This will be less than ``nbyte`` if:
249
250- The number of bytes left in the file is less than ``nbyte``.
251
252- The ``read()`` request was interrupted by a signal.
253
254- The file is a pipe or FIFO or special file with less than ``nbytes``
255  immediately available for reading.
256
257When attempting to read from any empty pipe or FIFO:
258
259- If no process has the pipe open for writing, zero is returned to
260  indicate end-of-file.
261
262- If some process has the pipe open for writing and O_NONBLOCK is set,
263  -1 is returned and ``errno`` is set to EAGAIN.
264
265- If some process has the pipe open for writing and O_NONBLOCK is clear,``read()`` waits for some data to be written or the pipe to be closed.
266
267When attempting to read from a file other than a pipe or FIFO and no data
268is available.
269
270- If O_NONBLOCK is set, -1 is returned and ``errno`` is set to EAGAIN.
271
272- If O_NONBLOCK is clear, ``read()`` waits for some data to become
273  available.
274
275- The O_NONBLOCK flag is ignored if data is available.
276
277**NOTES:**
278
279NONE
280
281write - Writes to a file
282------------------------
283.. index:: write
284.. index:: writes to a file
285
286**CALLING SEQUENCE:**
287
288.. code:: c
289
290    #include <unistd.h>
291    int write(
292    int           fildes,
293    const void   \*buf,
294    unsigned int  nbytes
295    );
296
297**STATUS CODES:**
298
299*EAGAIN*
300    The O_NONBLOCK flag is set for a file descriptor and the process
301    would be delayed in the I/O operation.
302
303*EBADF*
304    Invalid file descriptor
305
306*EFBIG*
307    An attempt was made to write to a file that exceeds the maximum file
308    size
309
310*EINTR*
311    The function was interrupted by a signal.
312
313*EIO*
314    Input or output error.
315
316*ENOSPC*
317    No space left on disk.
318
319*EPIPE*
320    Attempt to write to a pope or FIFO with no reader.
321
322*EINVAL*
323    Bad buffer pointer
324
325**DESCRIPTION:**
326
327The ``write()`` function writes ``nbyte`` from the array pointed
328to by ``buf`` into the file associated with ``fildes``.
329
330If ``nybte`` is zero and the file is a regular file, the ``write()``
331function returns zero and has no other effect. If ``nbyte`` is zero
332and the file is a special file, te results are not portable.
333
334The ``write()`` function returns the number of bytes written. This
335number will be less than ``nbytes`` if there is an error. It will never
336be greater than ``nbytes``.
337
338**NOTES:**
339
340NONE
341
342fcntl - Manipulates an open file descriptor
343-------------------------------------------
344.. index:: fcntl
345.. index:: manipulates an open file descriptor
346
347**CALLING SEQUENCE:**
348
349.. code:: c
350
351    #include <sys/types.h>
352    #include <fcntl.h>
353    #include <unistd.h>
354    int fcntl(
355    int fildes,
356    int cmd
357    );
358
359**STATUS CODES:**
360
361*EACCESS*
362    Search permission is denied for a direcotry in a file's path
363    prefix.
364
365*EAGAIN*
366    The O_NONBLOCK flag is set for a file descriptor and the process
367    would be delayed in the I/O operation.
368
369*EBADF*
370    Invalid file descriptor
371
372*EDEADLK*
373    An ``fcntl`` with function F_SETLKW would cause a deadlock.
374
375*EINTR*
376    The functioin was interrupted by a signal.
377
378*EINVAL*
379    Invalid argument
380
381*EMFILE*
382    Too many file descriptor or in use by the process.
383
384*ENOLCK*
385    No locks available
386
387**DESCRIPTION:**
388
389``fcntl()`` performs one of various miscellaneous operations on``fd``. The operation in question is determined by ``cmd``:
390
391*F_DUPFD*
392    Makes ``arg`` be a copy of ``fd``, closing ``fd`` first if necessary.
393    The same functionality can be more easily achieved by using ``dup2()``.
394    The old and new descriptors may be used interchangeably. They share locks,
395    file position pointers and flags; for example, if the file position is
396    modified by using ``lseek()`` on one of the descriptors, the position is
397    also changed for the other.
398    The two descriptors do not share the close-on-exec flag, however. The
399    close-on-exec flag of the copy is off, meaning that it will be closed on
400    exec.
401    On success, the new descriptor is returned.
402
403*F_GETFD*
404    Read the close-on-exec flag. If the low-order bit is 0, the file will
405    remain open across exec, otherwise it will be closed.
406
407*F_SETFD*
408    Set the close-on-exec flag to the value specified by ``arg`` (only the least
409    significant bit is used).
410
411*F_GETFL*
412    Read the descriptor's flags (all flags (as set by open()) are returned).
413
414*F_SETFL*
415    Set the descriptor's flags to the value specified by ``arg``. Only``O_APPEND`` and ``O_NONBLOCK`` may be set.
416    The flags are shared between copies (made with ``dup()`` etc.) of the same
417    file descriptor.
418    The flags and their semantics are described in ``open()``.
419
420*F_GETLK, F_SETLK and F_SETLKW*
421    Manage discretionary file locks. The third argument ``arg`` is a pointer to a
422    struct flock (that may be overwritten by this call).
423
424*F_GETLK*
425    Return the flock structure that prevents us from obtaining the lock, or set the``l_type`` field of the lock to ``F_UNLCK`` if there is no obstruction.
426
427*F_SETLK*
428    The lock is set (when ``l_type`` is ``F_RDLCK`` or ``F_WRLCK``) or
429    cleared (when it is ``F_UNLCK``. If lock is held by someone else, this
430    call returns -1 and sets ``errno`` to EACCES or EAGAIN.
431
432*F_SETLKW*
433    Like ``F_SETLK``, but instead of returning an error we wait for the lock to
434    be released.
435
436*F_GETOWN*
437    Get the process ID (or process group) of the owner of a socket.
438    Process groups are returned as negative values.
439
440*F_SETOWN*
441    Set the process or process group that owns a socket.
442    For these commands, ownership means receiving ``SIGIO`` or ``SIGURG``
443    signals.
444    Process groups are specified using negative values.
445
446**NOTES:**
447
448The errors returned by ``dup2`` are different from those returned by``F_DUPFD``.
449
450lseek - Reposition read/write file offset
451-----------------------------------------
452.. index:: lseek
453.. index:: reposition read/write file offset
454
455**CALLING SEQUENCE:**
456
457.. code:: c
458
459    #include <sys/types.h>
460    #include <unistd.h>
461    int lseek(
462    int    fildes,
463    off_t  offset,
464    int    whence
465    );
466
467**STATUS CODES:**
468
469*EBADF*
470    ``fildes`` is not an open file descriptor.
471
472*ESPIPE*
473    ``fildes`` is associated with a pipe, socket or FIFO.
474
475*EINVAL*
476    ``whence`` is not a proper value.
477
478**DESCRIPTION:**
479
480The ``lseek`` function repositions the offset of the file descriptor``fildes`` to the argument offset according to the directive whence.
481The argument ``fildes`` must be an open file descriptor. ``Lseek``
482repositions the file pointer fildes as follows:
483
484- If ``whence`` is SEEK_SET, the offset is set to ``offset`` bytes.
485
486- If ``whence`` is SEEK_CUR, the offset is set to its current location
487  plus offset bytes.
488
489- If ``whence`` is SEEK_END, the offset is set to the size of the
490  file plus ``offset`` bytes.
491
492The ``lseek`` function allows the file offset to be set beyond the end
493of the existing end-of-file of the file. If data is later written at this
494point, subsequent reads of the data in the gap return bytes of zeros
495(until data is actually written into the gap).
496
497Some devices are incapable of seeking. The value of the pointer associated
498with such a device is undefined.
499
500**NOTES:**
501
502NONE
503
504fsync - Synchronize file complete in-core state with that on disk
505-----------------------------------------------------------------
506.. index:: fsync
507.. index:: synchronize file complete in
508
509**CALLING SEQUENCE:**
510
511.. code:: c
512
513    int fsync(
514    int fd
515    );
516
517**STATUS CODES:**
518
519On success, zero is returned. On error, -1 is returned, and ``errno``
520is set appropriately.
521
522*EBADF*
523    ``fd`` is not a valid descriptor open for writing
524
525*EINVAL*
526    ``fd`` is bound to a special file which does not support support synchronization
527
528*EROFS*
529    ``fd`` is bound to a special file which does not support support synchronization
530
531*EIO*
532    An error occurred during synchronization
533
534**DESCRIPTION:**
535
536``fsync`` copies all in-core parts of a file to disk.
537
538**NOTES:**
539
540NONE
541
542fdatasync - Synchronize file in-core data with that on disk
543-----------------------------------------------------------
544.. index:: fdatasync
545.. index:: synchronize file in
546
547**CALLING SEQUENCE:**
548
549.. code:: c
550
551    int fdatasync(
552    int fd
553    );
554
555**STATUS CODES:**
556
557On success, zero is returned. On error, -1 is returned, and ``errno`` is
558set appropriately.
559
560*EBADF*
561    ``fd`` is not a valid file descriptor open for writing.
562
563*EINVAL*
564    ``fd`` is bound to a special file which does not support synchronization.
565
566*EIO*
567    An error occurred during synchronization.
568
569*EROFS*
570    ``fd`` is bound to a special file which dows not support synchronization.
571
572**DESCRIPTION:**
573
574``fdatasync`` flushes all data buffers of a file to disk (before the system call
575returns). It resembles ``fsync`` but is not required to update the metadata such
576as access time.
577
578Applications that access databases or log files often write a tiny data fragment
579(e.g., one line in a log file) and then call ``fsync`` immediately in order to
580ensure that the written data is physically stored on the harddisk. Unfortunately,
581fsync will always initiate two write operations: one for the newly written data and
582another one in order to update the modification time stored in the inode. If the
583modification time is not a part of the transaction concept ``fdatasync`` can be
584used to avoid unnecessary inode disk write operations.
585
586**NOTES:**
587
588NONE
589
590sync - Schedule file system updates
591-----------------------------------
592.. index:: sync
593.. index:: synchronize file systems
594
595**CALLING SEQUENCE:**
596
597.. code:: c
598
599    void sync(void);
600
601**STATUS CODES:**
602
603NONE
604
605**DESCRIPTION:**
606
607The ``sync`` service causes all information in memory that updates
608file systems to be scheduled for writing out to all file systems.
609
610**NOTES:**
611
612The writing of data to the file systems is only guaranteed to be
613scheduled upon return.  It is not necessarily complete upon return
614from ``sync``.
615
616mount - Mount a file system
617---------------------------
618.. index:: mount
619.. index:: mount a file system
620
621**CALLING SEQUENCE:**
622
623.. code:: c
624
625    #include <libio.h>
626    int mount(
627    rtems_filesystem_mount_table_entry_t \**mt_entry,
628    rtems_filesystem_operations_table    \*fs_ops,
629    rtems_filesystem_options_t            fsoptions,
630    char                                 \*device,
631    char                                 \*mount_point
632    );
633
634**STATUS CODES:**
635
636*EXXX*
637
638**DESCRIPTION:**
639
640The ``mount`` routines mounts the filesystem class
641which uses the filesystem operations specified by ``fs_ops``
642and ``fsoptions``.  The filesystem is mounted at the directory``mount_point`` and the mode of the mounted filesystem is
643specified by ``fsoptions``.  If this filesystem class requires
644a device, then the name of the device must be specified by ``device``.
645
646If this operation succeeds, the mount table entry for the mounted
647filesystem is returned in ``mt_entry``.
648
649**NOTES:**
650
651NONE
652
653unmount - Unmount file systems
654------------------------------
655.. index:: unmount
656.. index:: unmount file systems
657
658**CALLING SEQUENCE:**
659
660.. code:: c
661
662    #include <libio.h>
663    int unmount(
664    const char \*mount_path
665    );
666
667**STATUS CODES:**
668
669*EXXX*
670
671**DESCRIPTION:**
672
673The ``unmount`` routine removes the attachment of the filesystem specified
674by ``mount_path``.
675
676**NOTES:**
677
678NONE
679
680readv - Vectored read from a file
681---------------------------------
682.. index:: readv
683.. index:: vectored read from a file
684
685**CALLING SEQUENCE:**
686
687.. code:: c
688
689    #include <sys/uio.h>
690    ssize_t readv(
691    int                 fd,
692    const struct iovec \*iov,
693    int                 iovcnt
694    );
695
696**STATUS CODES:**
697
698In addition to the errors detected by``Input and Output Primitives Manager read - Reads from a file, read()``,
699this routine may return -1 and sets ``errno`` based upon the following
700errors:
701
702*EINVAL*
703    The sum of the ``iov_len`` values in the iov array overflowed an``ssize_t``.
704
705*EINVAL*
706    The ``iovcnt`` argument was less than or equal to 0, or greater
707    than ``IOV_MAX``.
708
709**DESCRIPTION:**
710
711The ``readv()`` function is equivalent to ``read()``
712except as described here. The ``readv()`` function shall place
713the input data into the ``iovcnt`` buffers specified by the
714members of the ``iov`` array: ``iov[0], iov[1], ..., iov[iovcnt-1]``.
715
716Each ``iovec`` entry specifies the base address and length of an area
717in memory where data should be placed. The ``readv()`` function
718always fills an area completely before proceeding to the next.
719
720**NOTES:**
721
722NONE
723
724writev - Vectored write to a file
725---------------------------------
726.. index:: writev
727.. index:: vectored write to a file
728
729**CALLING SEQUENCE:**
730
731.. code:: c
732
733    #include <sys/uio.h>
734    ssize_t writev(
735    int                 fd,
736    const struct iovec \*iov,
737    int                 iovcnt
738    );
739
740**STATUS CODES:**
741
742In addition to the errors detected by``Input and Output Primitives Manager write - Write to a file, write()``,
743this routine may return -1 and sets ``errno`` based upon the following
744errors:
745
746*EINVAL*
747    The sum of the ``iov_len`` values in the iov array overflowed an``ssize_t``.
748
749*EINVAL*
750    The ``iovcnt`` argument was less than or equal to 0, or greater
751    than ``IOV_MAX``.
752
753**DESCRIPTION:**
754
755The ``writev()`` function is equivalent to ``write()``,
756except as noted here. The ``writev()`` function gathers output
757data from the ``iovcnt`` buffers specified by the members of
758the ``iov array``: ``iov[0], iov[1], ..., iov[iovcnt-1]``.
759The ``iovcnt`` argument is valid if greater than 0 and less
760than or equal to ``IOV_MAX``.
761
762Each ``iovec`` entry specifies the base address and length of
763an area in memory from which data should be written. The ``writev()``
764function always writes a complete area before proceeding to the next.
765
766If ``fd`` refers to a regular file and all of the ``iov_len``
767members in the array pointed to by ``iov`` are 0, ``writev()``
768returns 0 and has no other effect. For other file types, the behavior
769is unspecified by POSIX.
770
771**NOTES:**
772
773NONE
774
775aio_read - Asynchronous Read
776----------------------------
777.. index:: aio_read
778.. index:: asynchronous read
779
780**CALLING SEQUENCE:**
781
782.. code:: c
783
784    int aio_read(
785    );
786
787**STATUS CODES:**
788
789*E*
790    The
791
792**DESCRIPTION:**
793
794**NOTES:**
795
796This routine is not currently supported by RTEMS but could be
797in a future version.
798
799aio_write - Asynchronous Write
800------------------------------
801.. index:: aio_write
802.. index:: asynchronous write
803
804**CALLING SEQUENCE:**
805
806.. code:: c
807
808    int aio_write(
809    );
810
811**STATUS CODES:**
812
813*E*
814    The
815
816**DESCRIPTION:**
817
818**NOTES:**
819
820This routine is not currently supported by RTEMS but could be
821in a future version.
822
823lio_listio - List Directed I/O
824------------------------------
825.. index:: lio_listio
826.. index:: list directed i/o
827
828**CALLING SEQUENCE:**
829
830.. code:: c
831
832    int lio_listio(
833    );
834
835**STATUS CODES:**
836
837*E*
838    The
839
840**DESCRIPTION:**
841
842**NOTES:**
843
844This routine is not currently supported by RTEMS but could be
845in a future version.
846
847aio_error - Retrieve Error Status of Asynchronous I/O Operation
848---------------------------------------------------------------
849.. index:: aio_error
850.. index:: retrieve error status of asynchronous i/o operation
851
852**CALLING SEQUENCE:**
853
854.. code:: c
855
856    int aio_error(
857    );
858
859**STATUS CODES:**
860
861*E*
862    The
863
864**DESCRIPTION:**
865
866**NOTES:**
867
868This routine is not currently supported by RTEMS but could be
869in a future version.
870
871aio_return - Retrieve Return Status Asynchronous I/O Operation
872--------------------------------------------------------------
873.. index:: aio_return
874.. index:: retrieve return status asynchronous i/o operation
875
876**CALLING SEQUENCE:**
877
878.. code:: c
879
880    int aio_return(
881    );
882
883**STATUS CODES:**
884
885*E*
886    The
887
888**DESCRIPTION:**
889
890**NOTES:**
891
892This routine is not currently supported by RTEMS but could be
893in a future version.
894
895aio_cancel - Cancel Asynchronous I/O Request
896--------------------------------------------
897.. index:: aio_cancel
898.. index:: cancel asynchronous i/o request
899
900**CALLING SEQUENCE:**
901
902.. code:: c
903
904    int aio_cancel(
905    );
906
907**STATUS CODES:**
908
909*E*
910    The
911
912**DESCRIPTION:**
913
914**NOTES:**
915
916This routine is not currently supported by RTEMS but could be
917in a future version.
918
919aio_suspend - Wait for Asynchronous I/O Request
920-----------------------------------------------
921.. index:: aio_suspend
922.. index:: wait for asynchronous i/o request
923
924**CALLING SEQUENCE:**
925
926.. code:: c
927
928    int aio_suspend(
929    );
930
931**STATUS CODES:**
932
933*E*
934    The
935
936**DESCRIPTION:**
937
938**NOTES:**
939
940This routine is not currently supported by RTEMS but could be
941in a future version.
942
943aio_fsync - Asynchronous File Synchronization
944---------------------------------------------
945.. index:: aio_fsync
946.. index:: asynchronous file synchronization
947
948**CALLING SEQUENCE:**
949
950.. code:: c
951
952    int aio_fsync(
953    );
954
955**STATUS CODES:**
956
957*E*
958    The
959
960**DESCRIPTION:**
961
962**NOTES:**
963
964This routine is not currently supported by RTEMS but could be
965in a future version.
966
967.. COMMENT: COPYRIGHT (c) 1988-2002.
968
969.. COMMENT: On-Line Applications Research Corporation (OAR).
970
971.. COMMENT: All rights reserved.
972
Note: See TracBrowser for help on using the repository browser.