OPEN(2)

NAME
creat, open, mkdir, mknod - create or open a file, special file, or directory

SYNOPSIS
#include <sys/types.h>
#include <unistd>
int creat (const char *file_name, mode_t mode);
int mknod (const char *file_name, mode_t mode, dev_t dev);
int mkdir (const char *file_name, mode_t mode);
int open (const char *file_name, int flag, ...);

DESCRIPTION
open() opens the file specified by file_name , with modes set according to the flag parameter.

The bit fields of flag are :

O_RDONLY

O_WRONLY

O_RDWR

O_CREAT - create if it doesn't exist. Note that if this flag is specified, and additional parameter mode_t mode must be passed to open specifying permissions on the created file. This is modified by umask in the usual way, with the permissions of the created file becoming ( ~umask & mode )

O_EXCL

O_NOCTTY - not implemented.

O_TRUNC

O_APPEND

O_NONBLOCK

O_NDELAY - not implemented.

creat() is a more specific version of open() which is used to create file_name. The behavior of creat ( file_name, mode ) is the same as

open ( file_name, O_CREAT | O_WRONLY, O_TRUNC, mode );

mkdir() is identical to creat(), only a directory is created instead of a normal file.

mknod() is identical to creat(), only dev specifies the device number that is associated with file_name

ERRORS
-EACCESS is returned if the directory does not have execute permissions

-EINVAL is returned if there are no more filedescriptors available in the system or for the process. These maximums are specified in NR_OPEN and NR_FILE , both defined in linux/include/linux/fs.h with defaults of 20 and 64 respectively.

-EISDIR is returned if you attempt to open a directory with access flags of anything but O_RDONLY, or with O_CREATE, or O_TRUNC flags set.

-ELOOP is returned if circular links are encountered.

-ENOENT is returned if a portion of the specified path is missing.

-EPERM is returned if the permissions for the file or directory do not allow the requested action.

FILES
linux/fs/open.c
linux/fs/namei.c
/usr/include/linux/sys.h
/usr/include/unistd.h

SEE ALSO
close(2), fopen(3), link(2), unlink(2), umask(2)

BUGS
O_NCTTY , O_NDELAY are not yet implemented.

The stock distribution of linux supports a maximum of 20 open file descriptors per process, as specified in the NR_OPEN macro in linux/include/linux/fs.h This is easily expanded to 32, but since certain internal bitmaps are implemented in 32 bit integers, further expansion will prove difficult, although changing the close_on_exec field of task_struct, which is defined in linux/include/linux/sched.h and other related fields to be long long instead of long will allow a maximum of 64 file descriptors per process.

The stock persystem limit is 64 open file descriptors, as specified in the NR_FILES macro in linux/include/linux/fs.h. This is an artificial limit, and is easily circumvented by recompiling the kernel with a larger value.