gtpc2m4tC/C++ Language Support User's Guide

mknod-Make a Character Special File

This function creates a special file.

Format

#include <sys/stat.h>
int mknod(const char *path, mode_t mode, rdev_t dev_identifier)

path
The name of the new node.

mode
Must be the value S_IFCHR (character special file) bitwise ORed with access mode.

dev_identifier
The major and minor device numbers of the new node. See TPF Concepts and Structures for more information about the major and minor device numbers for special files.

This function creates a new character special file with the path name specified in the path argument.

The mode argument determines the type of the special file and (along with the file creation mask) the file permissions of the special file. The TPF mknod function only supports the character type of special file: S_IFCHR. Bits set in the file creation mask are cleared in the file permissions. For more information about these symbols, see chmod-Change the Mode of a File or Directory.

The dev_identifier argument contains the major device number and the minor device number of the special file. The major device number identifies a device driver supporting a class of devices or pseudo devices such as input message devices. The minor device number identifies a specific device or pseudo device in the pertinent class.

When it has completed successfully, the mknod function updates the st_mtime field in the new file. It also updates the st_mtime field of the directory that contains the new file.

TPF deviation from POSIX

The TPF system does not support the atime (access time) or ctime (change time) time stamp.

Normal Return

If successful, the mknod function returns a value of 0.

Error Return

If unsuccessful, the mknod function returns a value of -1 and sets errno to one of the following:

EACCES
Search permission is denied on a component of path, or write permission is denied on the parent directory of the file to be created.

EEXIST
A file by that name already exists.

ELOOP
A loop exists in symbolic links. This error is issued if the number of symbolic links found while resolving the path argument is greater than POSIX_SYMLOOP.

EMLINK
The link count of the parent directory has already reached the maximum defined for the system.

ENAMETOOLONG
path is longer than PATH_MAX characters or some component of path is longer than NAME_MAX characters. For symbolic links, the length of the path name string substituted for a symbolic link exceeds PATH_MAX.

ENOENT
A component of path was not found or no path was specified.

ENOSPC
The file system does not have enough space to contain a new directory or the parent directory cannot be extended.

ENOTDIR
A component of path is not a directory.

Programming Considerations

 The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation. 

Because the mknod function requires an update to an existing directory file, new character special files cannot be created in 1052 or UTIL state.

Examples

The following example provides status information for a file.

#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
 
#define master 0x00070000
 
main() {
  char fn[]="char.spec";
 
  if (mknod(fn, S_IFCHR|S_IRUSR|S_IWUSR, master|0x0001) != 0
    perror("mknod() error");
  else if (unlink(fn) != 0)
    perror("unlink() error");
}

Related Information

See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.