DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

mknod(S)


mknod -- make a directory or a special or ordinary file or a FIFO

Syntax

cc ... -lc

#include <sys/types.h>
#include <sys/stat.h>

int mknod (path, mode, dev) char *path; mode_t mode; dev_t dev;

Description

The mknod system call creates a new file named by the pathname pointed to by path. The mode of the new file is initialized from mode. Where the value of mode is interpreted as follows:


0170000
file type; one of the following:

0010000
fifo special

0020000
character special

0040000
directory

0060000
block special

0100000
ordinary file

0000000
out-of-service inode

0004000
set user ID on execution

00020#0
set group ID on execution if # is 7, 5, 3, or 1
enable mandatory file/record locking if # is 6, 4, 2, or 0

0001000
save text image after execution

0000777
access permissions; constructed from the following:

0000400
read by owner

0000200
write by owner

0000100
execute (search on directory) by owner

0000070
read, write, execute (search) by group

0000007
read, write, execute (search) by others

Symbolic constants defining the value of the argument mode are in the <sys/stat.h> header file and should be used to construct mode. The value of the argument mode should be the logical OR of the values of the desired permissions:


Name
Description

S_ENFMT
record-locking enforced

S_IFBLK
block-special

S_IFCHR
character-special

S_IFDIR
directory node

S_IFIFO
FIFO-special

S_IFMT
file type; one of the following:

S_IFREG
ordinary-file

S_IRGRP
read by group

S_IROTH
read by others (that is, anyone else)

S_IRUSR
read by owner

S_ISGID
set group-ID on execution

S_ISUID
set user-ID on execution

S_ISVTX
(reserved)

S_IWGRP
write by group

S_IWOTH
write by others

S_IWUSR
write by owner

S_IXGRP
execute (search) by group

S_IXUSR
execute (search) by owner

S_IXOTH
execute (search) by others

The owner ID of the file is set to the effective user ID of the process. The group ID of the file is set to the effective group ID of the process.

Values of mode other than those above are undefined and should not be used. The low-order 9 bits of mode are modified by the process's file mode creation mask: all bits set in the process's file mode creation mask are cleared (see umask(S)). If mode indicates a block or character special file, dev is a configuration-dependent specification of a character or block I/O device. If mode does not indicate a block special or character special device, dev is ignored.

The mknod routine may be invoked only by the super user for file types other than FIFO special.

The mknod routine fails and the new file is not created if one or more of the following is true:


[EEXIST]
The named file exists.

[EFAULT]
path points outside the allocated address space of the process.

[EINTR]
A signal was caught during the mknod system call.

[EMULTIHOP]
Components of path require hopping to multiple remote machines.

[ENOENT]
A component of the path prefix does not exist.

[ENOTDIR]
A component of the path prefix is not a directory.

[ENOLINK]
path points to a remote machine and the link to that machine is no longer active.

[ENOSPC]
No space is available.

[EPERM]
The effective user ID of the process is not super user.

[EROFS]
The directory in which the file is to be created is located on a read-only file system.

Diagnostics

Upon successful completion a value of 0 is returned. Otherwise, a value of -1 is returned, and errno is set to indicate the error.

See also

chmod(S), exec(S), filesystem(FP), mkdir(C), umask(S)

Standards conformance

mknod is not part of any currently supported standard; it was developed by UNIX System Laboratories, Inc. and is maintained by The SCO Group.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003