Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ open(2) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod

close

creat

dup

fcntl

lockf

lseek

mknod

read, readx

umask

write, writex

stat.h

open

Purpose

     Opens a file for reading or writing.

Syntax

     #include <fcntl.h>

     int open (path, oflag [, mode|)
     char *path;
     int oflag, mode;

Description

     The open system call opens a file descriptor for the file
     named by the path  parameter.  If Distributed Services is
     installed  on  your  system,  this path  can  cross  into
     another node.

     Note:  Distributed Services does not support remote pipes
     or special files.

     The file status  flags are set according to  the value of
     the oflag parameter.  The oflag parameter values are con-
     structed  by logically  OR-ing flags  from the  following
     list:

     Note:  Do not use O_RDONLY, O_WRONLY, or O_RDWR together.

     O_RDONLY    Open for reading only.

     O_WRONLY    Open for writing only.

     O_RDWR      Open for reading and writing.

     O_NDELAY    Open  with no  delay.  This  flag may  affect
                 subsequent reads and writes.

                 When opening a FIFO with O_RDONLY or O_WRONLY
                 set:

                 o   If O_NDELAY is set,  an open for reading-
                     only returns without  delay.  An open for
                     writing-only  returns  an   error  if  no
                     process currently  has the file  open for
                     reading.

                 o   If  O_NDELAY   is  clear,  an   open  for
                     reading-only blocks until a process opens
                     the  file  for   writing.   An  open  for
                     writing-only blocks until a process opens
                     the file for reading.

                 When opening a file  associated with a commu-
                 nication line:

                 o   If  O_NDELAY  is  set, the  open  returns
                     without waiting for carrier.

                 o   If  O_NDELAY is  clear,  the open  blocks
                     until carrier is present.

                 When  opening a  regular  file that  supports
                 enforced record locks:

                 o   If O_NDELAY is set, then reads and writes
                     to portions  of the file that  are locked
                     by other processes return an error.

                 o   If  O_NDELAY  is  clear, then  reads  and
                     writes to  portions of the file  that are
                     locked  by other  processes blocks  until
                     the locks are released.

     O_APPEND    If set, the file pointer is set to the end of
                 the file prior to each write.

     O_CREAT     If the file exists,  this flag has no effect.
                 If the  file does not exist,  then the file's
                 owner ID  is set  to the  process's effective
                 user ID,  the file's group  ID is set  to the
                 process's  effective group  ID, and  the low-
                 order 12 bits of the file mode are set to the
                 value  of  the  mode  parameter  modified  as
                 follows:

                 o   All bits  set in the process's  file mode
                     creation mask are cleared.  (For informa-
                     tion   about  the   creation  mask,   see
                     "umask.")

                 o   The S_ISVTX bit of  the mode, which saves
                     the  text   image  after   execution,  is
                     cleared.

                 For information  about file modes and  a list
                 of   the  mode   values,   see  "chmod"   and
                 "stat.h.")

     O_TRUNC     If the file exists,  then its length is trun-
                 cated  to  0,  and  the mode  and  owner  are
                 unchanged.  If  the file has  any outstanding
                 record locks,  then open  fails and  the file
                 remains unchanged.

     O_EXCL      If O_EXCL and O_CREAT  are set, open fails if
                 the file exists.

     The file pointer used to mark the current position within
     the file is set to the beginning of the file.

     The new file descriptor is set to remain open across exec
     system calls (see "fcntl").

     No process can  have more than 200  file descriptors open
     simultaneously.

Return Value

     Upon successful  completion, the file descriptor,  a non-
     negative integer, is returned.  If open fails, a value of
     -1 is returned and errno is set to indicate the error.

Diagnostics

     The open  system call  fails, and the  named file  is not
     opened if one or more of the following are true:

     ENOTDIR    A component of the path prefix is not a direc-
                tory.

     ENOENT     O_CREAT is not set and the named file does not
                exist.

     EACCES     A component  of the path prefix  denies search
                permission.

     EACCES     The  type of  access  specified  by the  oflag
                parameter is denied for the named file.

     EISDIR     The named  file is  a directory and  the oflag
                parameter is write or read/write.

     EROFS      The  named file  resides on  a read-only  file
                system  and the  oflag parameter  is write  or
                read/write.

     EMFILE     Two  hundred (200)  file descriptors  are cur-
                rently open.

     ENXIO      The named file is a character special or block
                special file,  and the device  associated with
                this special file does not exist.

     ENXIO      The named  file is a multiplexed  special file
                and either  the channel  number is  outside of
                the  valid  range,  or no  more  channels  are
                available.

     ENXIO      The special  file or  named pipe resides  in a
                remote node.

     ETXTBSY    The  file is  a pure  procedure (shared  text)
                file  that is  being  executed  and the  oflag
                parameter is write or read/write.

     EFAULT     The path parameter &pointsout..

     EEXIST     O_CREAT and O_EXCL are set, and the named file
                exists.

     ENXIO      O_NDELAY  is set,  the named  file is  a FIFO,
                O_WRONLY is  set, and no process  has the file
                open for reading.

     EAGAIN     O_TRUNC is set, and  the named file contains a
                record  lock owned  by  another process.   See
                "lockf" for information about record locks.

     EINTR      A  signal was  caught during  the open  system
                call.

     ENFILE     The system file table is full.

     ENOSPC     The directory that would  contain the new file
                cannot be extended.

     ESTALE     The  process's root  or  current directory  is
                located in a virtual file system that has been
                unmounted.

     If Distributed Services is installed on your system, open
     can also fail if one or more of the following are true:

     EINVAL        The path parameter identifies a remote file
                   that is  neither a directory nor  a regular
                   file.

     EDIST         The   server   has  blocked   new   inbound
                   requests.

     EDIST         Outbound requests are currently blocked.

     EDIST         The server has a  release level of Distrib-
                   uted Services that  cannot communicate with
                   this node.

     EAGAIN        The  server  is  too  busy  to  accept  the
                   request.

     ESTALE        The file  descriptor for a remote  file has
                   become obsolete.

     EPERM         The translate tables of  the server did not
                   contain any entry  for either the effective
                   user  ID  or  effective  group  ID  of  the
                   calling process.

     ENODEV        The named file is  a remote file located on
                   a  device that  has been  unmounted at  the
                   server.

     ENOMEM        Either  this node  or the  server does  not
                   have enough memory available to service the
                   request.

     ENOCONNECT    An attempt to establish  a new network con-
                   nection with a remote node failed.

     EBADCONNECT   An attempt to use  an existing network con-
                   nection with a remote node failed.

Related Information

     In  this  book:   "chmod,"   "close,"   "creat,"  "dup,"
     "fcntl,"   "lockf,"  "lseek,"  "mknod,"   "read,  readx,"
     "umask," "write, writex," and "stat.h."

     Device Driver Development Guide.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026