Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pwrite(2) [hpux man page]

write(2)							System Calls Manual							  write(2)

NAME
write, writev, pwrite - write on a file SYNOPSIS
DESCRIPTION
The function attempts to write nbyte bytes from the buffer pointed to by buf to the file associated with the open file descriptor, fildes. If nbyte is 0, will return and have no other results if the file is a regular file. Otherwise, the results are unspecified. On a regular file or other file capable of seeking, the actual writing of data proceeds from the position in the file indicated by the file offset associated with fildes. Before successful return from the file offset is incremented by the number of bytes actually written. On a regular file, if this incremented file offset is greater than the length of the file, the length of the file will be set to this file off- set. For ordinary files, if the file status flag is set, the write does not return until both the file data and the file attributes required to retrieve the data are physically updated. If the flag is set, the behavior is identical to that of with the addition that all file attributes changed by the write operation, including access time, modification time and status change time, are also physically updated before returning to the calling process. For block special files, if the or the flag is set, the write does not return until the data is physically updated. How the data reaches the physical media is implementation and hardware dependent. A write to an ordinary file is prevented if enforcement-mode file and record locking is set, another process owns a lock on the segment of the file being written, and the following apply: o If or is set, the write returns and sets to o If and are clear, the write does not complete until the blocking record lock is removed. If the flag of the file status flags is set, the file offset will be set to the end of the file prior to each write and no intervening file modification operation will occur between changing the file offset and the write operation. If a requests that more bytes be written than there is room for, for example, the ulimit or the physical end of a medium, only as many bytes as there is room for will be written. For example, suppose there is space for 20 bytes more in a file before reaching a limit. A write of 512 bytes will return 20. The next write of a non-zero number of bytes will give a failure return (except as noted below) and the implementation will generate a signal for the process. If is interrupted by a signal it writes any data, it will return with set to If is interrupted by a signal it successfully writes some data, it will return the number of bytes written. If the value of nbyte is greater than the result is implementation dependent. After a to a regular file has successfully returned: o Any successful from each byte position in the file that was modified by that write will return the data specified by the for that position until such byte positions are again modified. o Any subsequent successful to the same byte position in the file will overwrite that file data. Write requests to a pipe or FIFO will be handled the same as a regular file with the following exceptions: o There is no file offset associated with a pipe, hence each write request will append to the end of the pipe. o The system-dependent maximum number of bytes that a pipe or FIFO can store is as defined in o The minimum value of on any HP-UX system is 8192. When writing a pipe with the or file status flag set, the following apply: o If nbyte is less than or equal to and sufficient room exists in the pipe or the succeeds and returns the number of bytes written. o If nbyte is less than or equal to but insufficient room exists in the pipe or the returns having written nothing. If is set, is returned and is set to If is set, is returned. o If nbyte is greater than and the pipe or FIFO is full, the write returns having written nothing. If is set, is returned and is set to If is set, is returned. o If nbyte is greater than and some room exists in the pipe or FIFO, as much data as fits in the pipe or FIFO is written, and returns the number of bytes actually written, an amount less than the number of bytes requested. When writing a pipe and the and file status flags are clear, the always executes correctly (blocking as necessary), and returns the number of bytes written. When attempting to write to a file descriptor (other than a pipe or FIFO) that supports non-blocking writes and cannot accept the data immediately, the following apply: o If the flag is clear, will block until the data can be accepted. o If the flag is set, will not block the process. If some data can be written without blocking the process, will write what it can and return the number of bytes written. Otherwise, it will return and will be set to Upon successful completion, where is greater than will mark for update the st_ctime and st_mtime fields of the file, and if the file is a regular file, the and bits of the file mode may be cleared. For character special devices, if the call was used on the same device after it was opened, returns sets to and issues the signal to the process. also clears the and privilege vectors on the file. If fildes refers to a STREAM, the operation of is determined by the values of the minimum and maximum nbyte range ("packet size") accepted by the STREAM. These values are determined by the topmost STREAM module. If nbyte falls within the packet size range, nbyte bytes will be written. If nbyte does not fall within the range and the minimum packet size value is 0, will break the buffer into maximum packet size segments prior to sending the data downstream (the last segment may contain less than the maximum packet size). If nbyte does not fall within the range and the minimum value is non-zero, will fail with set to Writing a zero-length buffer ( nbyte is 0) to a STREAMS device sends 0 bytes with 0 returned. However, writing a zero-length buffer to a STREAMS-based pipe or FIFO sends no message and is returned. The process may issue to enable zero-length messages to be sent across the pipe or FIFO. When writing to a STREAM, data messages are created with a priority band of 0. When writing to a STREAM that is not a pipe or FIFO, the following apply: o If is clear, and the cannot accept data (the write queue is full due to internal flow control conditions), will block until data can be accepted. o If is set and the cannot accept data, will return and set to o If is set and part of the buffer has been written while a condition in which the cannot accept additional data occurs, will ter- minate and return the number of bytes written. In addition, and will fail if the head had processed an asynchronous error before the call. In this case, the value of does not reflect the result of or but reflects the prior error. If the write is performed by any user other than the owner or a user who has appropriate privileges, clears the set-user-ID, set-group-ID, and sticky bits on all nondirectory files. If the write is performed by the owner or a user who has appropriate privileges, the behavior is file-system dependent. In some file systems, the write clears the set-user-ID, set-group-ID, and sticky bits on a nondirectory file. In other file systems, the write does not clear these bits on a nondirectory file. For directories, does not clear the set-user-ID, set-group-ID, and sticky bits. The function is equivalent to but gathers the output data from the iovcnt buffers specified by the members of the iov array: iov[0], iov[1], ..., iov[iovcnt-1]. iovcnt is valid if greater than 0 and less than or equal to as defined in Each iovec entry specifies the base address and length of an area in memory from which data should be written. The function will always write a complete area before proceeding to the next. The structure is defined in If fildes refers to a regular file and all of the iov_len members in the array pointed to by iov are 0, will return and have no other effect. For other file types, the behavior is unspecified. If the sum of the iov_len values is greater than the operation fails and no data is transferred. The function performs the same action as except that it writes into a given position without changing the file pointer. The first three arguments to are the same as with the addition of a fourth argument offset for the desired position inside the file. When a system call executes on a local file system and needs a new buffer to be allocated to hold the data, the buffer maps onto the disk at that time. If the disk is full, returns an error and is set to When a system call executes on an NFS file system, the allocates the new buffer without communicating with the NFS server to see if there is space for the buffer (to improve NFS performance). The disk-full condition is checked, only when the buffer is written to the server (at file close or the buffer is full). If the disk is full, returns an error. See close(2). RETURN VALUE
Upon successful completion, and will return the number of bytes actually written to the file associated with fildes. This number will never be greater than nbyte. Otherwise, is returned and is set to indicate the error. Upon successful completion, returns the number of bytes actually written. Otherwise, it returns a value of the file pointer remains unchanged, and is set to indicate an error. A write to a file may fail if an error message has been received at the head. In this case, is set to the value included in the error mes- sage. ERRORS
Under the following conditions, and fail and set to: The flag was set for the file descriptor and the process was delayed in the operation. Enforcement-mode file and record locking was set, was set, and there was a blocking record lock. The fildes argument was not a valid file descriptor open for writing. A resource deadlock would occur as a result of this operation (see lockf(2) and fcntl(2)). User's disk quota block limit has been reached for this file system. An attempt was made to write a file that exceeds the implementation-dependent maximum file size or the process' file size limit. The file is a regular file and nbyte is greater than zero and the starting position is greater than or equal to the offset maximum established in the open file description associated with fildes. The write operation was terminated due to the receipt of a signal, and no data was transferred. The or multiplexer referenced by fildes is linked (directly or indirectly) downstream from a multiplexer. A physical I/O error has occurred. The process is a member of a background process group attempting to write to its controlling terminal. is set, the process is neither ignoring nor blocking and the process group of the process is orphaned. This error may also be returned under implementation-dependent conditions. The system record lock table is full, preventing the write from sleeping until the blocking record lock is removed. Not enough space on the file system. The process does not possess the effective privilege to override this restriction. A request was made of a non-existent device, or the request was outside the capabilities of the device. A hangup occurred on the being written to. An attempt is made to write to a pipe or FIFO that is not open for reading by any process, or that only has one end open. A signal will also be sent to the process. The transfer request size was outside the range supported by the file associated with fildes. Under the following conditions, fails and sets to: iov_base or iov points outside of the allocated address space. The reliable detection of this error is implementation depen- dent. One of the iov_len values in the iov array is negative. The sum of the iov_len values in the iov array would overflow an ssize_t. Under the following conditions, the function may fail and set to: The iovcnt argument was less than or equal to 0, or greater than Under the following conditions, the function fails, the file pointer remains unchanged and is set to: The offset argument is invalid, and the value is negative. The fildes argument is associated with a pipe or FIFO. Under the following conditions, or fails, the file offset is updated to reflect the amount of data transferred and is set to: buf points outside the process's allocated address space. The reliable detection of this error is implementation depen- dent. EXAMPLES
Assuming a process opened a file for writing, the following call to attempts to write mybufsize bytes to the file from the buffer to which mybuf points. WARNINGS
Character special devices, and raw disks in particular, apply constraints on how can be used. See specific Section 7 manual entries for details on particular devices. AUTHOR
was developed by HP, AT&T, and the University of California, Berkeley. SEE ALSO
mkfs(1M), chmod(2), creat(2), dup(2), fcntl(2), getrlimit(2), lockf(2), lseek(2), open(2), pipe(2), ulimit(2), ustat(2), privileges(5), signal(5), <limits.h>, <stropts.h>, <sys/uio.h>, <unistd.h>. STANDARDS CONFORMANCE
write(2)
Man Page