2215 lines
64 KiB
HTML
2215 lines
64 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>open()--Open File</title>
|
|
<!-- Begin Header Records ========================================== -->
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Change History: -->
|
|
<!-- YYMMDD USERID Change description -->
|
|
<!-- Unix2 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<!-- Change History: -->
|
|
<!-- 010313 RIES Change due to O_SYNC etc, V5R2, DCR 98686 -->
|
|
<!-- 010314 JTROUS Change due to S_ISGID change, V5R2, DCR 98686 -->
|
|
<!-- and other PASE changes for 98391 -->
|
|
<!-- 010320 JTROUS Include Journal ERRNOs, should have in V5R1 -->
|
|
<!-- 010603 JTROUS Add dev/zero, V5R2, DCR 98686 -->
|
|
<!-- 011022 JTROUS Changes from API Review 1, V5R2 -->
|
|
<!-- 020313 JTROUS Changes for scan processing, V5R3, DCR 98680 -->
|
|
<!-- 020618 EMIG: updated for NFS threadsafety, V5R3 -->
|
|
<!-- 020624 RTHEIS: Add fclear() and fclear64(), V5R3 -->
|
|
<!-- 0206?? This file has undergone html cleanup June 2002 by JET -->
|
|
<!-- 020718 MFENLON: updated for QFileSvr.400 threadsafety, V5R3 -->
|
|
<!-- 020924 VONBERGE: Fix QSYS.LIB auth table entries P9A09413 -->
|
|
<!-- 021105 JTROUS Fix formatting on change flags in auth table -->
|
|
<!-- 021111 JTROUS Fix CCSID information, v5r3a -->
|
|
<!-- 030505 VONBERGE Remove QSYS.LIB mbr creation restrictions -->
|
|
<!-- 030701 JTROUS Add EDEADLK errno (due to scan mutex), v5r3a -->
|
|
<!-- 040302 JTROUS Add O_FORCE_SCAN, v5r4 -->
|
|
<!-- 040721 JTROUS: fix OS/400 reference, no change flag, V5R4 -->
|
|
<!-- 041006 JTROUS Add Usage note on 2 step create, v5r4 -->
|
|
<!-- 050404 JTROUS: fix enums, no change flag, V5R4 -->
|
|
<!-- End Header Records -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<!-- Java sync-link -->
|
|
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
|
|
</script>
|
|
|
|
<a name="Top_Of_Page"></a>
|
|
|
|
<h2>open()--Open File</h2>
|
|
|
|
<div class="box" style="width: 70%;">
|
|
<br>
|
|
Syntax<br>
|
|
|
|
|
|
<pre>
|
|
#include <fcntl.h>
|
|
|
|
int open(const char <em>*path</em>, int <em>oflag</em>, . . .);
|
|
|
|
</pre>
|
|
|
|
Service Program Name: QP0LLIB1<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Conditional; see <a href="#HDROPENUSG">Usage
|
|
Notes</a>.<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>open()</strong> function opens a file and returns a number
|
|
called a <strong>file descriptor</strong>. You can use this file descriptor to
|
|
refer to the file in subsequent I/O operations such as <strong>read()</strong>
|
|
or <strong>write()</strong>. In these subsequent operations, the file
|
|
descriptor is commonly identified by the argument <em>fildes</em> or <em>
|
|
descriptor</em>. Each file opened by a job gets a new file descriptor.</p>
|
|
|
|
<p>If the last element of the <em>path</em> is a symbolic link, the <strong>
|
|
open()</strong> function resolves the contents of the symbolic link.</p>
|
|
|
|
<p><strong>open()</strong> positions the <strong>file offset</strong> (an
|
|
indicator showing where the next read or write will take place in the file) at
|
|
the beginning of the file. However, there are options that can change the
|
|
position.</p>
|
|
|
|
<p><strong>open()</strong> clears the FD_CLOEXEC file descriptor flag for the
|
|
new file descriptor. Refer to <a href="fcntl.htm">fcntl()--Perform File Control
|
|
Command</a> for additional information about the FD_CLOEXEC flag.</p>
|
|
|
|
<p>The <strong>open()</strong> function also can be used to open a directory.
|
|
The resulting file descriptor can be used in some functions that have a <em>
|
|
fildes</em> parameter.</p>
|
|
|
|
<p>If the file being opened has been saved and its storage freed, the file is
|
|
restored during this <strong>open()</strong> function. The storage extension
|
|
exit program registered against the QIBM_QTA_STOR_EX400 exit point is called to
|
|
restore the object. (See the <a href="XTASX400.htm">Storage Extension</a> Exit
|
|
Program for details). If the file cannot successfully be restored, <strong>
|
|
open()</strong> fails with the EOFFLINE error number.</p>
|
|
|
|
<p>For information about the
|
|
exit point which can be associated with <strong>open()</strong>, see <a href=
|
|
"ifsopenexit.htm">Integrated File System Scan on Open Exit Programs</a>. </p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong><em>path</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to the null-terminated path name of the file to be
|
|
opened.
|
|
|
|
<p>This parameter is assumed to be represented in the CCSID (coded character
|
|
set identifier) currently in effect for the job. If the CCSID of the job is
|
|
65535, this parameter is assumed to be represented in the default CCSID of the
|
|
job.</p>
|
|
|
|
<p>When a new file is created, the new file name is assumed to be represented
|
|
in the language and country currently in effect for the job.</p>
|
|
|
|
<p>See <a href="openu.htm">QlgOpen()--Open a File (using NLS-enabled path
|
|
name)</a> for a description and an example of supplying the <em>path</em> in
|
|
any CCSID.</p>
|
|
</dd>
|
|
|
|
<dt><strong><em>oflag</em></strong></dt>
|
|
|
|
<dd>(Input) The file status flags and file access modes of the file to be
|
|
opened. See <a href="#HDROPNFLAG">Using the oflag Parameter</a>.
|
|
|
|
<p><strong>Note:</strong> The <strong>open64()</strong> API sets the
|
|
O_LARGEFILE flag internally.</p>
|
|
</dd>
|
|
|
|
<dt><strong><em>mode</em></strong></dt>
|
|
|
|
<dd>(Input) An optional third parameter of type <samp>mode_t</samp> that is
|
|
required if the O_CREAT flag is set. It specifies the file permission bits to
|
|
be used when a file is created. For a description of the permission bits, see
|
|
<a href="chmod.htm">chmod()--Change File Authorizations</a>.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>conversion ID</em></strong></dt>
|
|
|
|
<dd>(Input) An optional fourth parameter of type <samp>unsigned int</samp> that
|
|
is required if the O_CCSID or O_CODEPAGE flag is set.
|
|
|
|
<p>If the O_CCSID flag is set, this parameter specifies a CCSID. If the
|
|
O_CODEPAGE flag is set, this parameter specifies a code page used to derive a
|
|
CCSID.</p>
|
|
|
|
<p>The specified or derived CCSID is assumed to be the CCSID of the data in the
|
|
file, when a new file is created. This CCSID is associated with the file during
|
|
file creation.</p>
|
|
|
|
<p>When the O_TEXT_CREAT flag and its prerequisite flags are not set, the
|
|
specified or derived CCSID is the CCSID in which data is to be returned (when
|
|
reading from a file), or the CCSID in which data is being supplied (when
|
|
writing to a file).</p>
|
|
|
|
<p>See <a href="#HDRIFSCCSD">Using CCSIDs and code pages</a> for more
|
|
details.</p>
|
|
</dd>
|
|
|
|
<dt><strong><em>text file creation conversion ID</em></strong></dt>
|
|
|
|
<dd>(Input) An optional fifth parameter of type <samp>unsigned int</samp> that
|
|
is required if the O_TEXT_CREAT flag, along with prerequisite flags O_TEXTDATA,
|
|
O_CREAT, and either O_CCSID or O_CODEPAGE, is set. Note: because O_EXCL is not
|
|
required, this parameter may apply to files that already exist.
|
|
|
|
<p>When O_CCSID flag is set, this parameter specifies a CCSID. If the
|
|
O_CODEPAGE flag is set, this parameter specifies a code page used to derive a
|
|
CCSID.</p>
|
|
|
|
<p>The specified or derived CCSID will be used as the CCSID of this open
|
|
instance. Therefore, this will be the CCSID in which data is to be returned
|
|
(when reading from a file), or the CCSID in which data is being supplied (when
|
|
writing to a file). Data will be stored in the CCSID associated with the open
|
|
file. Note: if the file was not created by this open operation, the file's
|
|
CCSID may be different than the CCSID associated with the <em>conversion
|
|
ID</em> parameter.</p>
|
|
|
|
<p>See <a href="#HDRIFSCCSD">Using CCSIDs and code pages</a> for more
|
|
details.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
|
|
|
|
<h3><a name="HDROPNFLAG">Using the oflag Parameter</a></h3>
|
|
|
|
<p>One of the following values <em>must</em> be specified in <em>
|
|
oflag</em>:</p>
|
|
|
|
<dl compact>
|
|
<dt><em>O_RDONLY</em></dt>
|
|
|
|
<dd>Open for reading only.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_WRONLY</em></dt>
|
|
|
|
<dd>Open for writing only.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_RDWR</em></dt>
|
|
|
|
<dd>Open for both reading and writing.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
|
|
|
|
<p>One or more of the following also can be specified in <em>oflag</em>:</p>
|
|
|
|
<dl>
|
|
<dt><em>O_APPEND</em></dt>
|
|
|
|
<dd>Position the file offset at the end of the file before each write
|
|
operation.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_CREAT</em></dt>
|
|
|
|
<dd>The call to <strong>open()</strong> has a <em>mode</em> argument.
|
|
|
|
<p>If the file being opened already exists, O_CREAT has no effect, except when
|
|
O_EXCL is also specified (see the following description of O_EXCL.</p>
|
|
|
|
<p>If the file being opened does not exist, it is created
|
|
<img src="delta.gif" alt="Start of change">and then opened.
|
|
Since the create and open operations occur as separate steps,
|
|
error [EBUSY] could be received if another user opened the object
|
|
with a conflicting file sharing mode
|
|
after the create step, but before the open step.
|
|
<img src="deltaend.gif" alt="End of change">
|
|
The user ID (uid) of
|
|
the file is set to the effective uid of the job. If the object is being created
|
|
in the "root" (/), QOpenSys, and user-defined file systems, the following
|
|
applies. If the S_ISGID bit of the parent directory is off, the group ID (GID)
|
|
is set to the effective GID of the thread creating the object. If the S_ISGID
|
|
bit of the parent directory is on, the group ID (GID) of the new object is set
|
|
to the GID of the parent directory. For all other file systems, the group ID
|
|
(GID) of the file is set to the GID of the directory in which the file is
|
|
created. File permission bits are set according to <em>mode</em>, except for
|
|
those set in the file mode creation mask of the job. The S_ISUID (set-user-ID)
|
|
and S_ISGID (set-group-ID) bits are also set according to <em>mode</em>. The
|
|
file type bits in <em>mode</em> are ignored. All other bits in <em>mode</em>
|
|
must be cleared (not set) or a [EINVAL] error is returned.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_EXCL</em></dt>
|
|
|
|
<dd>Ignored if O_CREAT is not set. If both O_EXCL and O_CREAT are specified,
|
|
<strong>open()</strong> fails if the file already exists. If both O_EXCL and
|
|
O_CREAT are specified, and <em>path</em> names a symbolic link, <strong>
|
|
open()</strong> fails regardless of the contents of the symbolic link.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_LARGEFILE</em></dt>
|
|
|
|
<dd>Open a large file. The descriptor returned can be used with the other APIs
|
|
to operate on files larger than 2GB (GB = 1073741824) minus 1 byte. The file
|
|
systems that do not support large files will just ignore the O_LARGEFILE open
|
|
flag if it is set. The O_LARGEFILE flag is ignored by the file systems when
|
|
<strong>open()</strong> is used to open a directory.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_TRUNC</em></dt>
|
|
|
|
<dd>Truncate the file to zero length if the file exists and it is a "regular
|
|
file" (a stream file that can support positioning the file offset). The mode
|
|
and owner of the file are not changed. O_TRUNC applies only to regular files.
|
|
O_TRUNC has no effect on FIFO special files. The O_TRUNC behavior applies only
|
|
when the file is successfully opened with O_RDWR or O_WRONLY.
|
|
|
|
<p>Truncation of the file will return the [EOVERFLOW] error if the file is
|
|
larger than 2 GB minus 1 byte and if the O_LARGEFILE oflag is not also
|
|
specified on the <strong>open()</strong> call. (Note that <strong>
|
|
open64()</strong> sets the O_LARGEFILE oflag automatically.)</p>
|
|
|
|
<p>If the file exists and it is a regular file, the S_ISUID (set-user-ID) and
|
|
S_ISGID (set-group-ID) bits of the file mode are cleared.</p>
|
|
|
|
<p>If the file has a digital signature, <strong>open()</strong> with
|
|
the O_TRUNC oflag causes the signature to be deleted.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_TEXTDATA</em></dt>
|
|
|
|
<dd>Determines how the data is processed when a file is opened.<br>
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
<li>If O_TEXTDATA is specified, the data is processed as text.
|
|
|
|
<p>The data is read from the file and written to the file assuming it is in
|
|
textual form. When the data is read from the file, it is converted from the
|
|
CCSID of the file to the CCSID of the job or the CCSID specified by the
|
|
application receiving the data. When data is written to the file, it is
|
|
converted to the CCSID of the file from the CCSID of the job or the CCSID
|
|
specified by the application.</p>
|
|
|
|
<p>For true stream files, any line-formatting characters (such as carriage
|
|
return, tab, and end-of-file) are just converted from one CCSID to another.</p>
|
|
|
|
<p>When reading from a record file that is being used as a stream file,
|
|
end-of-line characters are added to the end of the data in each record. When
|
|
writing to the record file:</p>
|
|
|
|
<ul>
|
|
<li>End-of-line characters are removed.<br>
|
|
</li>
|
|
|
|
<li>Records are padded with blanks (for a source physical file member) or nulls
|
|
(for a data physical file member).<br>
|
|
</li>
|
|
|
|
<li>Tab characters are replaced by the appropriate number of blanks to the next
|
|
tab position.</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</li>
|
|
|
|
<li>If O_TEXTDATA is not specified, the data is processed as binary. The data
|
|
is read from the file and written to the file without any conversion. The
|
|
application is responsible for handling the data.</li>
|
|
</ul>
|
|
|
|
<p>See <a href="#HDRIFSCCSD">Using CCSIDs and code pages</a> for more details
|
|
on text conversions.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_CCSID</em></dt>
|
|
|
|
<dd>The call to open has a fourth argument (<em>conversion ID</em>), which is
|
|
to be interpreted as a CCSID. Text conversions between any two CCSIDs supported
|
|
by the <strong>iconv()</strong> API can be performed.
|
|
|
|
<p>This flag cannot be specified with the O_CODEPAGE flag.</p>
|
|
|
|
<p>See <a href="#HDRIFSCCSD">Using CCSIDs and code pages</a> for more
|
|
details.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_CODEPAGE</em></dt>
|
|
|
|
<dd>The call to open has a fourth argument (<em>conversion ID</em>), which is
|
|
to be interpreted as a code page. Only single-byte-to-single-byte or
|
|
double-byte-to-double-byte text conversions are allowed.
|
|
|
|
<p>This flag cannot be specified with the O_CCSID flag.</p>
|
|
|
|
<p>See <a href="#HDRIFSCCSD">Using CCSIDs and code pages</a> for more
|
|
details.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_TEXT_CREAT</em></dt>
|
|
|
|
<dd>The call to open has a fifth argument (<em>text file creation conversion
|
|
ID</em>), which is to be interpreted as either a code page or CCSID, depending
|
|
on whether the O_CODEPAGE or O_CCSID was set.
|
|
|
|
<p>If the O_TEXT_CREAT flag is specified, all of the following flags must also
|
|
be specified: O_CREAT, O_TEXTDATA, and either O_CODEPAGE or O_CCSID. If all of
|
|
these prerequisite flags are not specified when O_TEXT_CREAT is specified, then
|
|
the call to open will fail with error condition [EINVAL].</p>
|
|
|
|
<p>This flag indicates that the textual data read from or written to this file
|
|
will be converted between the CCSID specified or derived from the <em>text file
|
|
creation conversion ID</em> and the CCSID of the file. When data is read from
|
|
the file, it is converted from the CCSID of the file to the CCSID specified or
|
|
derived from the <em>text file creation conversion ID</em>. When data is
|
|
written to the file, it is converted to the CCSID of the file from the CCSID
|
|
specified or derived from the <em>text file creation conversion ID</em>.</p>
|
|
|
|
<p>See <a href="#HDRIFSCCSD">Using CCSIDs and code pages</a> for more
|
|
details.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_INHERITMODE</em></dt>
|
|
|
|
<dd>Create the file with the same data authorities as the parent directory that
|
|
the file is created in. Any data authorities passed in the <em>mode</em>
|
|
parameter are ignored. The mode parameter, however, must still be specified
|
|
with a valid mode value. This flag is ignored if the O_CREAT flag is not set.
|
|
|
|
<p>The "root" (/), QOpenSys, QSYS.LIB, independent ASP QSYS.LIB, and QDLS file
|
|
systems support this flag on an <strong>open()</strong> with the O_CREAT flag
|
|
set. The QOPT file system ignores this flag because files in this file system
|
|
do not have data authorities.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_NONBLOCK</em></dt>
|
|
|
|
<dd>Return without delay from certain operations on this open descriptor.
|
|
|
|
<p>If O_NONBLOCK is specified when opening a FIFO:</p>
|
|
|
|
<ul>
|
|
<li>An <strong>open()</strong> for reading only or reading and writing access
|
|
returns without delay.<br>
|
|
</li>
|
|
|
|
<li>An <strong>open()</strong> for writing only returns an error if no job
|
|
currently has the FIFO open for reading. The <em>errno</em> value will be
|
|
ENXIO.</li>
|
|
</ul>
|
|
|
|
<p>If O_NONBLOCK is not specified when opening a FIFO:</p>
|
|
|
|
<ul>
|
|
<li>An <strong>open()</strong> for reading only blocks the calling thread until
|
|
another thread opens the FIFO for writing.<br>
|
|
</li>
|
|
|
|
<li>An <strong>open()</strong> for writing only blocks the calling thread until
|
|
another thread opens the FIFO for reading.<br>
|
|
</li>
|
|
|
|
<li>An <strong>open()</strong> for reading and writing returns without
|
|
delay.</li>
|
|
</ul>
|
|
|
|
<p>The O_NONBLOCK open flag is ignored for all other object types.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_SYNC</em></dt>
|
|
|
|
<dd>Updates to the file will be performed synchronously. All file data and file
|
|
attributes relative to the I/O operation are written to permanent storage
|
|
before the update operation returns. Update operations include, but are not
|
|
limited to, the following: <strong>ftruncate()</strong>, <strong>
|
|
open()</strong> with O_TRUNC, <strong>write()</strong>,
|
|
|
|
and <strong>fclear()</strong>.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_DSYNC</em></dt>
|
|
|
|
<dd>Updates to the file will be performed synchronously, but only the file data
|
|
is written to permanent storage before the update operation returns. Update
|
|
operations include, but are not limited to, the following: <strong>
|
|
ftruncate()</strong>, <strong>open()</strong> with O_TRUNC, <strong>
|
|
write()</strong>,
|
|
|
|
and <strong>fclear()</strong>.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_RSYNC</em></dt>
|
|
|
|
<dd>Read operations to the file will be performed synchronously. Pending update
|
|
requests affecting the data to be read are written to permanent storage. This
|
|
flag is used in combination with O_SYNC or O_DSYNC. When O_RSYNC and O_SYNC are
|
|
set, all file data and file attributes are written to permanent storage before
|
|
the read operation returns. When O_RSYNC and O_DSYNC are set, all file data is
|
|
written to permanent storage before the read operation returns.<br>
|
|
<br></dd>
|
|
|
|
|
|
<dt><img src="delta.gif" alt="Start of change"><em>O_FORCE_SCAN</em></dt>
|
|
|
|
<dd>One or more of the following conditions will be ignored when
|
|
determining whether the integrated file system scan-related exit programs
|
|
will be called:
|
|
<ul>
|
|
<li>The Scan file systems control (QSCANFSCTL) system value specification of
|
|
*FSVRONLY.
|
|
</li>
|
|
<li>The object was marked to not be scanned (e.g. scan attribute is *NO).
|
|
</li>
|
|
<li>The object was marked to be scanned only if the object changed
|
|
(e.g. scan attribute is *CHGONLY).
|
|
</li>
|
|
</ul>
|
|
For example, an object is opened that has a scan attribute of *YES,
|
|
and the open request is not through the file servers when
|
|
*FSVRONLY is specified. If O_FORCE_SCAN is specified on that open
|
|
request, the object will be scanned if all the remaining conditions are met.
|
|
Similarly, if an object that has a scan attribute of *NO or
|
|
*CHGONLY is opened with O_FORCE_SCAN specified,
|
|
the object will be scanned if all the remaining conditions are met.
|
|
For a list of the remaining conditions and more information, see <a href=
|
|
"ifsopenexit.htm">Integrated File System Scan on Open Exit Programs</a> and
|
|
<a href=
|
|
"ifscloseexit.htm">Integrated File System Scan on Close Exit Programs</a>.
|
|
<img src="deltaend.gif" alt="End of change">
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
|
|
|
|
<p>A file sharing mode may also be specified in the <em>oflag</em>. If none are
|
|
specified, a default sharing mode of O_SHARE_RDWR is used. No more than one of
|
|
the following may be specified:</p>
|
|
|
|
<dl>
|
|
<dt><em>O_SHARE_RDONLY</em></dt>
|
|
|
|
<dd>Share with readers only. Open the file only if both of the following are
|
|
true:<br>
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
<li>The file currently is not open for writing.</li>
|
|
|
|
<li>The access intent does not conflict with the sharing mode of another open
|
|
instance of this file.</li>
|
|
</ul>
|
|
|
|
<p>Once opened with this sharing mode, any request to open this file for
|
|
writing fails with the [EBUSY] error.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_SHARE_WRONLY</em></dt>
|
|
|
|
<dd>Share with writers only. Open the file only if both of the following are
|
|
true:<br>
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
<li>The file is not currently open for reading.<br>
|
|
</li>
|
|
|
|
<li>The access intent does not conflict with the sharing mode of another open
|
|
instance of this file.</li>
|
|
</ul>
|
|
|
|
<p>Once opened with this sharing mode, any request to open this file for
|
|
reading fails with the [EBUSY] error.</p>
|
|
</dd>
|
|
|
|
<dt><em>O_SHARE_RDWR</em></dt>
|
|
|
|
<dd>Share with readers and writers. Open the file only if the access intent of
|
|
this open does not conflict with the sharing mode of another open instance of
|
|
this file.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>O_SHARE_NONE</em></dt>
|
|
|
|
<dd>Share with neither readers nor writers. Open the file only if the file is
|
|
not currently open. Once the file is opened with this sharing mode, any request
|
|
to open this file for reading or writing fails with the [EBUSY] error.</dd>
|
|
</dl>
|
|
|
|
<p>All other bits in <em>oflag</em> must be cleared (not set).</p>
|
|
|
|
<p><strong>Notes:</strong></p>
|
|
|
|
<ol>
|
|
<li>If O_WRONLY or O_RDWR is specified and the file is checked out by a user
|
|
profile other than that of the current job, the <strong>open()</strong> fails
|
|
with the [EBUSY] error.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If O_WRONLY or O_RDWR is specified and the file is marked "read-only," the
|
|
<strong>open()</strong> fails with the [EROOBJ] error.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If O_CREAT is specified and the file did not previously exist, a successful
|
|
<strong>open()</strong> sets the access time, change time, modification time,
|
|
and creation time for the new file. It also updates the change time and
|
|
modification time of the directory that contains the new file (the parent
|
|
directory of the new file).
|
|
|
|
<p>If O_TRUNC is specified and the file previously existed, a successful
|
|
<strong>open()</strong> updates the change time and modification time for the
|
|
file.</p>
|
|
</li>
|
|
|
|
<li>Sharing Files
|
|
|
|
<p>If a sharing mode is not specified in the <em>oflag</em> parameter, a
|
|
default sharing mode of O_SHARE_RDWR is used. The <strong>open()</strong> may
|
|
fail with the [EBUSY] error number if the file is already open with a sharing
|
|
mode that conflicts with the access intent of this <strong>open()</strong>
|
|
request.</p>
|
|
|
|
<p>Directories may only be opened with a sharing mode of O_SHARE_RDWR. If any
|
|
other sharing mode is specified, the <strong>open()</strong> fails with error
|
|
number [EINVAL].</p>
|
|
|
|
<p>For *CHRSF files, a sharing mode of O_SHARE_RDWR is used regardless of the
|
|
sharing mode specified in the <em>oflag</em> parameter. The sharing mode
|
|
specified in the <em>oflag</em> parameter is ignored.</p>
|
|
|
|
<p>The following table shows when conflicts will occur:</p>
|
|
|
|
<table border width="100%">
|
|
<!-- cols="20 20 20 20 20" -->
|
|
<tr>
|
|
<th align="left" valign="bottom" colspan="5"><em><a name="TBLDC2">File Sharing
|
|
Conflicts</a></em></th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom" rowspan="2">Access Intent</th>
|
|
<th align="left" valign="bottom" colspan="4">Sharing Mode</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Readers Only</th>
|
|
<th align="left" valign="bottom">Writers Only</th>
|
|
<th align="left" valign="bottom">Readers<br>
|
|
and Writers</th>
|
|
<th align="left" valign="bottom">No Others<br>
|
|
(Exclusive)</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">O_RDONLY</td>
|
|
<td align="left" valign="top">OK</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
<td align="left" valign="top">OK</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">O_WRONLY</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
<td align="left" valign="top">OK</td>
|
|
<td align="left" valign="top">OK</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">O_RDWR</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
<td align="left" valign="top">OK</td>
|
|
<td align="left" valign="top">EBUSY</td>
|
|
</tr>
|
|
</table>
|
|
</li>
|
|
</ol>
|
|
|
|
<br>
|
|
|
|
|
|
<h3><a name="HDRIFSCCSD">Using CCSIDs and code pages</a></h3>
|
|
|
|
<p>If the O_CCSID or O_CODEPAGE flag is specified, but O_CREAT is not, the <em>
|
|
mode</em> parameter must be specified, but its value will be ignored.</p>
|
|
|
|
<p>The value of <em>conversion ID</em> must be less than 65536. The [EINVAL]
|
|
error will be returned if it is not.</p>
|
|
|
|
<p>When a new file is created:</p>
|
|
|
|
<ul>
|
|
<li><em>conversion ID</em> is used to derive a CCSID to be associated with the
|
|
new file (the "file CCSID") and this open instance (the "open CCSID"). If the
|
|
file is to contain textual data, this CCSID is assumed to be the CCSID of the
|
|
data, unless the O_TEXT_CREAT flag and its prerequisite flags were also
|
|
specified.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If neither O_CCSID nor O_CODEPAGE is specified, or if O_CCSID is specified
|
|
and <em>conversion ID</em> is zero (0), the file CCSID is set to the CCSID of
|
|
the job. If the job CCSID is 65535, the file CCSID is set to the default CCSID
|
|
of the job.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For this open instance, if the O_TEXT_CREAT flag and its prerequisite flags
|
|
were not specified, the file CCSID and open CCSID are the same and no text
|
|
conversion will take place on data written to or read from the file, whether
|
|
O_TEXTDATA is specified or not. If you would like to associate the new file
|
|
with the CCSID specified in <em>conversion ID</em>, but you would also like to
|
|
have text conversion occur between the file's CCSID and a different CCSID,
|
|
consider using the O_TEXT_CREAT flag and corresponding <em>text file creation
|
|
conversion ID</em> parameter.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The QSYS.LIB and independent ASP QSYS.LIB file systems cannot associate the
|
|
derived CCSID with the database file member being created. Rather, the CCSID of
|
|
the new member is the CCSID of the database file in which the member is being
|
|
created. Data read or written during this open instance is converted from or to
|
|
the CCSID of the database file.</li>
|
|
</ul>
|
|
|
|
<p>
|
|
When an existing file is opened and O_TEXTDATA is <strong>not</strong> specified:</p>
|
|
<ul>
|
|
<li>The value of <em>conversion ID</em> is ignored.
|
|
</li>
|
|
</ul>
|
|
<p>When an existing file is opened
|
|
and O_TEXTDATA is specified:
|
|
</p>
|
|
|
|
<ul>
|
|
<li><em>conversion ID</em> is used to derive a CCSID to be associated with this
|
|
open instance (the "open CCSID").<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If neither O_CCSID nor O_CODEPAGE is specified, or if O_CCSID is specified
|
|
and <em>conversion ID</em> is zero (0), the open CCSID is set to the CCSID of
|
|
the job. If the job CCSID is 65535, the open CCSID is set to the default CCSID
|
|
of the job.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The system will convert from the file CCSID to
|
|
the open CCSID when reading data from the file, and convert from the open CCSID
|
|
to the file CCSID when writing data to the file.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>
|
|
If O_CCSID is not specified, and the file CCSID and open CCSID are not
|
|
the same, and one of them is not strictly single-byte, <strong>open()</strong>
|
|
will fail with errno set to [ECONVERT].
|
|
</li>
|
|
</ul>
|
|
|
|
<p>See <a href="#examples">Examples</a> for a sample program that creates a new
|
|
file and then opens it for data conversion.</p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3><a name="HDROPENAUT">Authorities</a></h3>
|
|
|
|
<p><strong>Note:</strong> Adopted authority is not used.</p>
|
|
|
|
<table border width="100%">
|
|
<!-- cols="45 25 30" -->
|
|
<tr>
|
|
<th align="left" valign="bottom" colspan="3"><em><a name="TBLAOPEN1">
|
|
Authorization Required for open() (excluding QSYS.LIB, independent ASP
|
|
QSYS.LIB,and QDLS)</a></em></th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Object Referred to</th>
|
|
<th align="center" valign="bottom">Authority<br>
|
|
Required</th>
|
|
<th align="left" valign="bottom">errno</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Each directory in the path name preceding the
|
|
object to be opened</td>
|
|
<td align="center" valign="top">*X</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_RDONLY</td>
|
|
<td align="center" valign="top">*R</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_WRONLY</td>
|
|
<td align="center" valign="top">*W</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_RDWR</td>
|
|
<td align="center" valign="top">*RW</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when O_TRUNC is specified</td>
|
|
<td align="center" valign="top">*W</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Parent directory of object to be created when
|
|
object does not exist and O_CREAT is specified</td>
|
|
<td align="center" valign="top">*WX</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
<br>
|
|
|
|
|
|
<table border width="100%">
|
|
<!-- cols="60 20 20" -->
|
|
<tr>
|
|
<th align="left" valign="bottom" colspan="3"><em><a name="TBLAOPEN2">
|
|
Authorization Required for open() in the QSYS.LIB and independent ASP QSYS.LIB
|
|
File Systems</a></em></th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Object Referred to</th>
|
|
<th align="center" valign="bottom">Authority<br>
|
|
Required</th>
|
|
<th align="left" valign="bottom">errno</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Each directory in the path name preceding the
|
|
object to be opened</td>
|
|
<td align="center" valign="top">*X</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_RDONLY</td>
|
|
<td align="center" valign="top">*R</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_WRONLY</td>
|
|
<td align="center" valign="top">*W</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_RDWR</td>
|
|
<td align="center" valign="top">*RW</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
|
|
Existing object when object is a save file</td>
|
|
<td align="center" valign="top">*RWX</td>
|
|
<td align="left" valign="top">EACCES
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when O_TRUNC is specified</td>
|
|
<td align="center" valign="top">*W</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Parent directory of object to be created when
|
|
object does not exist and O_CREAT is specified</td>
|
|
<td align="center" valign="top">*OBJMGT or<br>
|
|
*OBJALTER</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
Parent directory of object to be created when
|
|
object does not exist and object type is *USRSPC or save file</td>
|
|
<td align="left" valign="top">*RX and *Add</td>
|
|
<td align="left" valign="top">EACCES
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
Parent directory of the parent directory of
|
|
object to be created when object does not exist, O_CREAT is specified, and object being created is a physical file member</td>
|
|
<td align="center" valign="top">*ADD</td>
|
|
<td align="left" valign="top">EACCES
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
<br>
|
|
|
|
|
|
<table border width="100%">
|
|
<!-- cols="60 20 20" -->
|
|
<tr>
|
|
<th align="left" valign="bottom" colspan="3"><em><a name="TBLAOPEN3">
|
|
Authorization Required for open() in the QDLS File System</a></em></th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Object Referred to</th>
|
|
<th align="center" valign="bottom">Authority<br>
|
|
Required</th>
|
|
<th align="left" valign="bottom">errno</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Each directory in the path name preceding the
|
|
object to be opened</td>
|
|
<td align="center" valign="top">*X</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_RDONLY</td>
|
|
<td align="center" valign="top">*R</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_WRONLY</td>
|
|
<td align="center" valign="top">*W</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when access mode is O_RDWR</td>
|
|
<td align="center" valign="top">*RW</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Existing object when O_TRUNC is specified</td>
|
|
<td align="center" valign="top">*W</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">Parent directory of object to be created when
|
|
object does not exist and O_CREAT is specified</td>
|
|
<td align="center" valign="top">*CHANGE</td>
|
|
<td align="left" valign="top">EACCES</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
|
|
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="10 90" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>value</em></td>
|
|
<td align="left" valign="top"><strong>open()</strong> was successful. The value
|
|
returned is the file descriptor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>-1</em></td>
|
|
<td align="left" valign="top"><strong>open()</strong> was not successful. The
|
|
<em>errno</em> global variable is set to indicate the error.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
|
|
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>open()</strong> is not successful, <em>errno</em> usually
|
|
indicates one of the following errors. Under some conditions, <em>errno</em>
|
|
could indicate an error other than those listed here.</p>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="25 75" -->
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Error condition</th>
|
|
<th align="left" valign="bottom">Additional information</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EACCES">EACCES</a>]</em></td>
|
|
|
|
|
|
<td align="left" valign="top">
|
|
<p>If you are accessing a remote file through the Network File System, update
|
|
operations to file permissions at the server are not reflected at the client
|
|
until updates to data that is stored locally by the Network File System take
|
|
place. (Several options on the Add Mounted File System (ADDMFS) command
|
|
determine the time between refresh operations of local data.) Access to a
|
|
remote file may also fail due to different mappings of user IDs (UID) or group
|
|
IDs (GID) on the local and remote systems.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EAGAIN">EAGAIN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EBADFID">EBADFID</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EBADNAME">EBADNAME</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EBUSY">EBUSY</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>The open sharing mode may conflict with another open of this file, or
|
|
O_WRONLY or O_RDWR is specified and the file is checked out by another
|
|
user.</p>
|
|
<p>In the QSYS.LIB and independent ASP QSYS.LIB file systems, if the O_TEXTDATA
|
|
flag was specified, the file may be already open in this job or another job
|
|
where the O_TEXTDATA flag was not specified. Or if the O_TEXTDATA flag was not
|
|
specified, the file may be already open in this job or another job where the
|
|
O_TEXTDATA flag was specified.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ECONVERT">ECONVERT</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EDAMAGE">EDAMAGE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EDEADLK">EDEADLK</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EEXIST">EEXIST</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EFAULT">EFAULT</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EFILECVT">EFILECVT</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EINTR">EINTR</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EINVAL">EINVAL</a>]</em></td>
|
|
|
|
<td align="left" valign="top"><p>For example
|
|
<ul>
|
|
<li>O_RDONLY and O_TRUNC were both specified.</li>
|
|
<li>More than one of O_RDONLY, O_WRONLY, or O_RDWR are set in <em>
|
|
oflag</em>.</li>
|
|
<li>More than one of O_SHARE_RDONLY, O_SHARE_WRONLY, O_SHARE_RDWR, or
|
|
O_SHARE_NONE are set in <em>oflag</em>.</li>
|
|
<li>Unused bits in <em>oflag</em> are set and should be cleared.</li>
|
|
<li>Unused bits in <em>mode</em> are set and should be cleared.</li>
|
|
<li>It is not valid to open this type of object.</li>
|
|
<li>O_CODEPAGE and O_CCSID were both specified.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EIO">EIO</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EISDIR">EISDIR</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>The path name given is a directory. Write access or O_TRUNC has been
|
|
specified and is not valid for a directory.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EJRNDAMAGE">EJRNDAMAGE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EJRNENTTOOLONG">EJRNENTTOOLONG</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EJRNINACTIVE">EJRNINACTIVE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EJRNRCVSPC">EJRNRCVSPC</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ELOOP">ELOOP</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EMFILE">EMFILE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENAMETOOLONG">ENAMETOOLONG</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENEWJRN">ENEWJRN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENEWJRNRCV">ENEWJRNRCV</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENFILE">ENFILE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOENT">ENOENT</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOMEM">ENOMEM</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOSPC">ENOSPC</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOSYS">ENOSYS</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOSYSRSC">ENOSYSRSC</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOTAVAIL">ENOTAVAIL</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOTDIR">ENOTDIR</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENOTSUP">ENOTSUP</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENXIO">ENXIO</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>O_NONBLOCK and O_WRONLY open flags are specified, <em>path</em> refers to a
|
|
FIFO, and no job has the FIFO open for reading.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EOFFLINE">EOFFLINE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EOVERFLOW">EOVERFLOW</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>The size of the specified file cannot be represented correctly in a variable
|
|
of type off_t (the file is larger than 2GB minus 1 byte).</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EPERM">EPERM</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EROOBJ">EROOBJ</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ESCANFAILURE">ESCANFAILURE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ESTALE">ESTALE</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
<p>If you are accessing a remote file through the Network File System, the file
|
|
may have been deleted at the server.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ETXTBSY">ETXTBSY</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EUNKNOWN">EUNKNOWN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
|
|
|
|
<p>Additionally, if interaction with a file server is required to access the
|
|
object, <em>errno</em> could also indicate one of the following errors:</p>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="25 75" -->
|
|
|
|
<tr>
|
|
<th align="left" valign="bottom">Error condition</th>
|
|
<th align="left" valign="bottom">Additional information</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EADDRNOTAVAIL">EADDRNOTAVAIL</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ECONNABORTED">ECONNABORTED</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ECONNREFUSED">ECONNREFUSED</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ECONNRESET">ECONNRESET</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EHOSTDOWN">EHOSTDOWN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EHOSTUNREACH">EHOSTUNREACH</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENETDOWN">ENETDOWN</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENETRESET">ENETRESET</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ENETUNREACH">ENETUNREACH</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#ETIMEDOUT">ETIMEDOUT</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">
|
|
<em>[<a href="unix14.htm#EUNATCH">EUNATCH</a>]</em></td>
|
|
|
|
<td align="left" valign="top">
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Error Messages</h3>
|
|
|
|
<p>The following messages may be sent from this function:</p>
|
|
|
|
<table width="100%" cellpadding="5">
|
|
<!-- cols="15 85" -->
|
|
<tr>
|
|
<th align="left" valign="top" nowrap>Message ID</th>
|
|
<th align="left" valign="top">Error Message Text</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">CPE3418 E</td>
|
|
<td align="left" valign="top">Possible APAR condition or hardware failure.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">CPFA0D4 E</td>
|
|
<td align="left" valign="top">File system error occurred. Error number
|
|
&1.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">CPF3CF2 E</td>
|
|
<td align="left" valign="top">Error(s) occurred during running of &1
|
|
API.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top">CPF9872 E</td>
|
|
<td align="left" valign="top">Program or service program &1 in library
|
|
&2 ended. Reason code &3.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
|
|
|
|
<h3><a name="HDROPENUSG">Usage Notes</a></h3>
|
|
|
|
<ol type="1">
|
|
<li>This function will fail with error number [ENOTSAFE] when all the following
|
|
conditions are true:<br>
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
<li>Where multiple threads exist in the job.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The object on which this function is operating resides in a file system
|
|
that is not threadsafe. Only the following file systems are threadsafe for this
|
|
function:<br>
|
|
<br>
|
|
<ul>
|
|
<li>"Root" (/)</li>
|
|
|
|
<li>QOpenSys</li>
|
|
|
|
<li>User-defined</li>
|
|
|
|
<li>QNTC</li>
|
|
|
|
<li>QSYS.LIB</li>
|
|
|
|
<li>Independent ASP QSYS.LIB</li>
|
|
|
|
<li>QOPT</li>
|
|
|
|
<li>Network File System</li>
|
|
|
|
|
|
<li>QFileSvr.400</li>
|
|
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</li>
|
|
|
|
<li>"Root" (/), QOpenSys, and User-Defined File System Differences
|
|
|
|
<p>The user who creates the file becomes its owner. The S_ISGID bit of the
|
|
directory affects what the group ID (GID) is for objects that are created in
|
|
the directory. If the S_ISGID bit of the parent directory is off, the group ID
|
|
(GID) is set to the effective GID of the thread creating the object. If the
|
|
S_ISGID bit of the parent directory is on, the group ID is copied from the
|
|
parent directory in which the file is created.</p>
|
|
|
|
<p>When you do not specify O_INHERITMODE for the <em>oflag</em> parameter, the
|
|
owner, primary group, and public object authorities (*OBJEXIST, *OBJMGT,
|
|
*OBJALTER, and *OBJREF) are copied from the parent directory's owner, primary
|
|
group, and public object authorities. This occurs even when the new file has a
|
|
different owner than the parent directory. The owner, primary group, and public
|
|
data authorities (*R, *W, and *X) are derived from the permissions specified in
|
|
the mode (except for those permissions that are also set in the file mode
|
|
creation mask). The new file does not have any private authorities or
|
|
authorization list. It only has authorities for the owner, primary group, and
|
|
public.</p>
|
|
|
|
<p>When you specify O_INHERITMODE for the <em>oflag</em> parameter, the owner,
|
|
primary group, and public data and object authorities (*R, *W, *X, *OBJEXIST,
|
|
*OBJMGT, *OBJALTER, and *OBJREF) are copied from the parent directory's owner,
|
|
primary group, and public data and object authorities. In addition, the private
|
|
authorities (if any) and authorization list (if any) are copied from the parent
|
|
directory. If the new file has a different owner than the parent directory and
|
|
the new file's owner has a private authority in the parent directory, that
|
|
private authority is not copied from the parent directory. The authority for
|
|
the owner of the new file is copied from the owner of the parent directory.</p>
|
|
|
|
<p>There are some restrictions when opening a FIFO for text conversion and the
|
|
CCSIDs involved are not strictly single-byte:</p>
|
|
|
|
<ul>
|
|
<li>Opening a FIFO for reading or reading and writing is not allowed. The <em>
|
|
errno</em> global variable is set to [ENOTSUP].<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>Any conversion between CCSIDs that are not strictly single-byte must be
|
|
done by an open instance that has write only access.</li>
|
|
</ul>
|
|
<br>
|
|
</li>
|
|
|
|
<li>QSYS.LIB and Independent ASP QSYS.LIB File System Differences
|
|
|
|
<p>The following object types are allowed to be opened:</p>
|
|
|
|
<ul>
|
|
<li>*MBR (physical file member)<br>
|
|
The only types of physical files supported when specifying the O_TEXTDATA flag
|
|
are program-described physical files that contain a single field and source
|
|
physical files that contain a single text field. Externally described physical
|
|
files are supported for binary access only.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>*LIB (library)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>*FILE (physical file or save file)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>*USRSPC (user space)</li>
|
|
</ul>
|
|
<p>
|
|
When creating a member, the ownership, group profile, and authorities are all derived from the member's parent physical file. The input <em>mode</em> value is ignored.
|
|
</p>
|
|
|
|
<p>The group ID is obtained from the primary user profile, if a group profile exists.</p>
|
|
|
|
<p>The primary group authorities specified in <em>mode</em> are not saved if no
|
|
primary group exists.</p>
|
|
|
|
<p>You cannot open a member in a file that has a mixed data CCSID.</p>
|
|
|
|
<p>The file access time for a database member is updated using the normal rules
|
|
that apply to database files. At most, the access time is updated once per
|
|
day.</p>
|
|
|
|
<p>Due to the restriction that only one job may have a database member open for
|
|
writing at a time, the sharing modes O_SHARE_WRONLY and O_SHARE_RDWR do not
|
|
provide the requested level of sharing.</p>
|
|
|
|
<ul>
|
|
<li>If O_SHARE_WRONLY is specified, the <strong>open()</strong> succeeds.
|
|
However, in all jobs other than the one that performed this <strong>
|
|
open()</strong>, the actual enforced share mode for this file is equivalent to
|
|
O_SHARE_NONE.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If O_SHARE_RDWR is specified, or if no share mode is specified, the
|
|
<strong>open()</strong> succeeds. However, in all jobs other than the one that
|
|
performed this <strong>open()</strong>, the actual enforced share mode is
|
|
equivalent to O_SHARE_RDONLY.</li>
|
|
</ul>
|
|
|
|
<p>The <strong>open()</strong> of a database member fails with an [EBUSY] error
|
|
under any of the following conditions:</p>
|
|
|
|
<ul>
|
|
<li>The O_TEXTDATA flag is specified, but the file is already open in this job
|
|
or another job where the O_TEXTDATA flag is not specified.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The O_TEXTDATA flag is not specified, but the file is already open in this
|
|
job or another job where the O_TEXTDATA flag and write access are
|
|
specified.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The O_TEXTDATA flag is specified and write access is requested, but the
|
|
file is already open in this job or another job where O_TEXTDATA is specified
|
|
and write access is also requested.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The O_CREAT flag is specified, the member already exists, and the QSYS.LIB
|
|
or independent ASP QSYS.LIB file system cannot get exclusive access to the
|
|
member. They must have exclusive access to clear the old member.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The O_TEXTDATA flag is not specified (binary mode) and more than one job
|
|
tries to obtain write access to the member. This condition does not apply to PC
|
|
clients. Because PC clients share the same server job, they can share access to
|
|
the member.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The user attempts to open a member with access intentions that conflict
|
|
with existing object locks on the member.</li>
|
|
</ul>
|
|
|
|
<p>This function will fail with error number [ENOTSAFE] if the object on which
|
|
this function is operating is a save file and multiple threads exist in the
|
|
job.</p>
|
|
|
|
<p>This function will fail with error number [ENOTSUP] if the file specified is a
|
|
save file and the O_RDWR flag is specified. A save file can be opened for
|
|
either reading only or writing only.</p>
|
|
|
|
<p>This function will fail with error number [ENOTSUP] if the file specified is a
|
|
save file and the O_TEXTDATA flag is specified.</p>
|
|
|
|
<p>If a save file containing data is opened for writing, the O_APPEND or
|
|
O_TRUNC flag must be specified. Otherwise, the <strong>open()</strong> will
|
|
fail with error number [ENOTSUP].</p>
|
|
|
|
<p>There are some restrictions on sharing modes when opening a save file.</p>
|
|
|
|
<ol type="a">
|
|
<li>A save file may not have more than one open descriptor per job, regardless
|
|
of the sharing mode specified.<br>
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
<li>A save file currently open for reading only cannot be opened again in the
|
|
same job for reading or writing. The <strong>open()</strong> will fail with
|
|
errno set to [EBUSY].<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>A save file currently open for writing only cannot be opened again in the
|
|
same job for reading or writing. The <strong>open()</strong> will fail with
|
|
errno set to [EBUSY].</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</li>
|
|
|
|
<li>Due to the restriction that only one job may have a save file open when the
|
|
save file is open for writing, the sharing modes O_SHARE_WRONLY and
|
|
O_SHARE_RDWR do not provide the reqested level of sharing.<br>
|
|
<br>
|
|
|
|
|
|
<ul>
|
|
<li>If O_SHARE_WRONLY is specified, the <strong>open()</strong> succeeds.
|
|
However, in all jobs other than the one that performed this <strong>
|
|
open()</strong>, the actual enforced share mode for this file is equivalent to
|
|
O_SHARE_NONE.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If O_SHARE_RDWR is specified and the file is opened for reading only, the
|
|
<strong>open()</strong> succeeds. However, in all jobs other than the one that
|
|
performed this <strong>open()</strong>, the actual enforced share mode is
|
|
equivalent to O_SHARE_RDONLY.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>If O_SHARE_RDWR is specified and the file is opened for writing only, the
|
|
<strong>open()</strong> succeeds. However, in all jobs other than the one that
|
|
performed this <strong>open()</strong>, the actual enforced share mode is
|
|
equivalent to O_SHARE_NONE.</li>
|
|
</ul>
|
|
</li>
|
|
</ol>
|
|
|
|
<p><strong>Note:</strong> Unpredictable results, including loss of data, could
|
|
occur if, in the same job, a user tries to open the same file for writing at
|
|
the same time by using both <strong>open()</strong> API for stream file access
|
|
and a data management open API for record access.</p>
|
|
</li>
|
|
|
|
<li>QDLS File System Differences
|
|
|
|
<p>When O_CREAT is specified and a new file is created:</p>
|
|
|
|
<ul>
|
|
<li>the owner's object authority is set to *OBJMGT + *OBJEXIST + *OBJALTER +
|
|
*OBJREF.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The primary group and public object authority and all other authorities are
|
|
copied from the directory (folder) in which the file is created.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The owner, primary group, and public data authority (including *OBJOPR) are
|
|
derived from the permissions specified in <em>mode</em> (except those
|
|
permissions that are also set in the file mode creation mask).</li>
|
|
</ul>
|
|
|
|
<p>The primary group authorities specified in <em>mode</em> are not saved if no
|
|
primary group exists.</p>
|
|
|
|
<p>QDLS does not store the language ID and country ID with its files. When this
|
|
information is requested (using the readdir() function), QDLS returns the
|
|
language ID and country ID of the system.</p>
|
|
</li>
|
|
|
|
<li>QOPT File System Differences
|
|
|
|
<p>When the volume on which the file is being opened is formatted in Universal
|
|
Disk Format (UDF):</p>
|
|
|
|
<ul>
|
|
<li>The authorization that is checked for the object and preceding directories
|
|
in the path name follows the rules described in <a href="#TBLAOPEN1">
|
|
Authorization Required for open()</a>.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The volume authorization list is checked for *USE when the access mode is
|
|
O_RDONLY. The volume authorization list is checked for *CHANGE when the access
|
|
mode is O_RDWR or O_WRONLY.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The user who creates the file becomes its owner.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The group ID is copied from the parent directory in which the file is
|
|
created.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The owner, primary group, and public data authorities (*R, *W, and *X) are
|
|
derived from the permissions specified in the mode (except those permissions
|
|
that are also set in the file mode creation mask).<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>When O_INHERITMODE is specified for the oflag parameter, the data
|
|
authorities are copied from the parent directory.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The sharing modes O_SHARE_RDONLY, O_SHARE_WRONLY, and O_SHARE_RDWR do not
|
|
provide the requested level of sharing when the access mode is O_RDWR or
|
|
O_WRONLY. When the access mode is O_RDWR or O_WRONLY, the resulting sharing
|
|
mode semantic will be equivalent to O_SHARE_NONE.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For newly created files, the same uppercase and lowercase forms in which
|
|
the names are entered are preserved. No distinction is made between uppercase
|
|
and lowercase when searching for names.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>This function will fail with error number [EINVAL] if the O_SYNC, O_DSYNC, or
|
|
O_RSYNC open flag is specified.</li>
|
|
</ul>
|
|
|
|
<p>When the volume on which the file is being opened is not formatted in
|
|
Universal Disk Format (UDF):</p>
|
|
|
|
<ul>
|
|
<li>No authorization checks are made on the object or preceding directories in
|
|
the path name.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The volume authorization list is checked for *USE when the access mode is
|
|
O_RDONLY. The volume authorization list is checked for *CHANGE when the access
|
|
mode is O_RDWR or O_WRONLY.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>QDFTOWN becomes the owner of the file.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>No group ID is assigned to the file.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The permissions specified in the mode are ignored. The owner, primary
|
|
group, and public data authorities are set to RWX.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For newly created files, names are created in uppercase. No distinction is
|
|
made between uppercase and lowercase when searching for names.</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</li>
|
|
|
|
<li>Network File System Differences
|
|
|
|
<p>Local access to remote files through the Network File System may produce
|
|
unexpected results due to conditions at the server. The creation of a file may
|
|
fail if permissions and other attributes that are stored locally by the Network
|
|
File System are more restrictive than those at the server. A later attempt to
|
|
create a file can succeed when the locally stored data has been refreshed.
|
|
(Several options on the Add Mounted File System (ADDMFS) command determine the
|
|
time between refresh operations of local data.) The creation can also succeed
|
|
after the file system has been remounted.</p>
|
|
|
|
<p>If you try to re-create a file that was recently deleted, the request may
|
|
fail because data that was stored locally by the Network File System still has
|
|
a record of the file's existence. The creation succeeds when the locally stored
|
|
data has been updated.</p>
|
|
|
|
<p>Once a file is open, subsequent requests to perform operations on the file
|
|
can fail because file attributes are checked at the server on each request. If
|
|
permissions on the file are made more restrictive at the server or the file is
|
|
unlinked or made unavailable by the server for another client, your operation
|
|
on an open file descriptor will fail when the local Network File System
|
|
receives these updates. The local Network File System also impacts operations
|
|
that retrieve file attributes. Recent changes at the server may not be
|
|
available at your client yet, and old values may be returned from
|
|
operations.</p>
|
|
|
|
<p>The sharing modes O_SHARE_RDONLY, O_SHARE_WRONLY, and O_SHARE_NONE do not
|
|
provide the requested level of sharing. If any one of these share modes is
|
|
specified, the resulting share mode semantic will be equivalent to
|
|
O_SHARE_RDWR.</p>
|
|
</li>
|
|
|
|
<li>QNetWare File System Differences
|
|
|
|
<p>The QNetWare file system does not fully support mode bits. See <a href=
|
|
"../rzaef/rzaefoverview.htm">Netware on iSeries</a> in the iSeries Information
|
|
Center for more information.</p>
|
|
</li>
|
|
|
|
<li>This function will fail with the [EOVERFLOW] error if the specified file
|
|
exists and its size is too large to be represented in a variable of type off_t
|
|
(the file is larger than 2 GB minus 1 byte).<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>When you develop in C-based languages and an application is compiled with
|
|
the _LARGE_FILES macro defined, the <strong>open()</strong> API will be mapped
|
|
to a call to the <strong>open64()</strong> API.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>Using this function on the /dev/null or /dev/zero character special file,
|
|
the oflag values of O_CREAT and O_TRUNC have no effect.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The O_SYNC, O_DSYNC, and O_RSYNC open flags will not cause updates made to
|
|
the file via mapped access to be written to permanent storage.</li>
|
|
</ol>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>fcntl.h</strong>> file (see <a href="unix13.htm">Header
|
|
Files for UNIX-Type Functions</a>)
|
|
</li>
|
|
|
|
<li><a href="close.htm">close()</a>--Close File or Socket Descriptor
|
|
</li>
|
|
|
|
<li><a href="creat.htm">creat()</a>--Create or Rewrite File
|
|
</li>
|
|
|
|
<li><a href="dup.htm">dup()</a>--Duplicate Open File Descriptor
|
|
</li>
|
|
|
|
<li><a href="fcntl.htm">fcntl()</a>--Perform File Control Command
|
|
</li>
|
|
|
|
<li><a href=
|
|
"ifsopenexit.htm">Integrated File System Scan on Open Exit Programs</a>
|
|
</li>
|
|
|
|
<li><a href="lseek.htm">lseek()</a>--Set File Read/Write Offset
|
|
</li>
|
|
|
|
<li><a href="open64.htm">open64()</a>--Open File (Large File Enabled)
|
|
</li>
|
|
|
|
<li><a href="openu.htm">QlgOpen()</a>--Open a File (using NLS-enabled path
|
|
name)
|
|
</li>
|
|
|
|
<li><a href="read.htm">read()</a>--Read from Descriptor
|
|
</li>
|
|
|
|
<li><a href="stat.htm">stat()</a>--Get File Information
|
|
</li>
|
|
|
|
<li><a href="umask.htm">umask()</a>--Set Authorization Mask for Job
|
|
</li>
|
|
|
|
<li><a href="write.htm">write()</a>--Write to Descriptor</li>
|
|
</ul>
|
|
|
|
<br>
|
|
|
|
|
|
<h3><a name="examples">Examples</a></h3>
|
|
|
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
|
for information pertaining to code examples.</p>
|
|
|
|
<p>The following example opens an output file for appending. Because no sharing
|
|
mode is specified, the O_SHARE_RDWR sharing mode is used.</p>
|
|
|
|
<pre>
|
|
int fildes;
|
|
fildes = open("outfile",O_WRONLY | O_APPEND);
|
|
</pre>
|
|
|
|
<p>The following example creates a new file with read, write, and execute
|
|
permissions for the user creating the file. If the file already exists, the
|
|
<strong>open()</strong> fails. If the <strong>open()</strong> succeeds, the
|
|
file is opened for sharing with readers only.</p>
|
|
|
|
<pre>
|
|
fildes = open("newfile",O_WRONLY|O_CREAT|O_EXCL|O_SHARE_RDONLY,S_IRWXU);
|
|
</pre>
|
|
|
|
<p>This example first creates an output file for with a specified CCSID. The
|
|
file is then closed and opened again with data conversion. The <strong>
|
|
open()</strong> function is called twice because no data conversion would have
|
|
occurred when using the first open's descriptor on read or write operations,
|
|
even if O_TEXTDATA had been specified on that open; however, the second open
|
|
could be eliminated entirely by using O_TEXT_CREAT on the first open. This is
|
|
demonstrated in the code example immediately following this example. In this
|
|
example, EBCDIC data is written to the file and converted to ASCII.</p>
|
|
|
|
<pre>
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
int rc;
|
|
char name[]="/test.dat";
|
|
char data[]="abcdefghijk";
|
|
int oflag1 = O_CREAT | O_RDWR | O_CCSID;
|
|
int oflag2 = O_RDWR | O_TEXTDATA | O_CCSID;
|
|
mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR;
|
|
unsigned int file_ccsid = 819;
|
|
unsigned int open_ccsid = 37;
|
|
|
|
/***************************************************/
|
|
/* First create the file with the CCSID 819. */
|
|
/***************************************************/
|
|
|
|
if ((fd=open(name,oflag1,mode,file_ccsid)) < 0)
|
|
{
|
|
perror("open() for create failed");
|
|
return(0);
|
|
}
|
|
|
|
if (close(fd) < 0)
|
|
{
|
|
perror("close() failed.");
|
|
return(0);
|
|
}
|
|
|
|
/***************************************************/
|
|
/* Now open the file so EBCDIC (CCSID 37) data */
|
|
/* written will be converted to ASCII (CCSID 819).*/
|
|
/***************************************************/
|
|
|
|
if ((fd=open(name,oflag2,mode,open_ccsid)) < 0)
|
|
{
|
|
perror("open() with translation failed");
|
|
return(0);
|
|
}
|
|
|
|
/***************************************************/
|
|
/* Write some EBCDIC data. */
|
|
/***************************************************/
|
|
|
|
if (-1 == (rc=write(fd, data, strlen(data))))
|
|
{
|
|
perror("write failed");
|
|
return(0);
|
|
}
|
|
|
|
if (0 != (rc=close(fd)))
|
|
{
|
|
perror("close failed");
|
|
return(0);
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
<p>In this second example, EBCDIC data is written to the file and converted to
|
|
ASCII. This will produce the same results as the first example, except that it
|
|
did it by only using one open instead of two.</p>
|
|
|
|
<pre>
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
int rc;
|
|
char name[]="/test.dat";
|
|
char data[]="abcdefghijk";
|
|
int oflag1 = O_CREAT | O_RDWR | O_CCSID | O_TEXTDATA | O_TEXT_CREAT | O_EXCL;
|
|
mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR;
|
|
unsigned int file_ccsid = 819;
|
|
unsigned int open_ccsid = 37;
|
|
|
|
/***************************************************/
|
|
/* First create the file with the CCSID 819, and */
|
|
/* open it such that the data is converted */
|
|
/* between the the open CCSID of 37 and the */
|
|
/* file's CCSID of 819 when writing data to it. */
|
|
/***************************************************/
|
|
|
|
if ((fd=open(name,oflag1,mode,file_ccsid,open_ccsid)) < 0)
|
|
{
|
|
perror("open() for create failed");
|
|
return(0);
|
|
}
|
|
|
|
/***************************************************/
|
|
/* Write some EBCDIC data. */
|
|
/***************************************************/
|
|
|
|
if (-1 == (rc=write(fd, data, strlen(data))))
|
|
{
|
|
perror("write failed");
|
|
return(0);
|
|
}
|
|
|
|
/***************************************************/
|
|
/* Close the file. */
|
|
/***************************************************/
|
|
if (0 != (rc=close(fd)))
|
|
{
|
|
perror("close failed");
|
|
return(0);
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
<hr>
|
|
API introduced: V3R1
|
|
|
|
<hr>
|
|
<center>
|
|
<table align="center" cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|