mknodat()
Make a new filesystem entry at a given location
Synopsis:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int mknodat( int fd,
const char* path,
mode_t mode,
dev_t dev );
Arguments:
- fd
- A file descriptor that indicates the base directory for relative filepaths.
The pathname given in path is resolved by appending it to the directory associated with fd.
You can set this argument to AT_FDCWD to use the current working directory as the base directory.
Note:The QNX OS implementation of the *at() functions differ from the POSIX standards. You must use a file descriptor obtained from an open() or openat() call with the O_DIRECTORY flag set, rather than the O_SEARCH flag on POSIX. Otherwise, the function fails and sets errno to ENOTDIR.
If path specifies an absolute path, fd has no effect.
- path
- The pathname that you want to use for the file.
- mode
- A set of bits that define the file type and access permissions that you want to use.
The valid file types are:
- S_IFDIR — create a directory.
- S_IFIFO — create a FIFO.
For more information, see the entry for struct stat.
- dev
- Ignored.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The mknodat() function makes a file, named path, using the file type encoded in the mode argument. Supported file types are directories and FIFOs. The path argument can contain an absolute or relative path. In the latter case, the fd argument is used to resolve the pathname, as explained in this argument's description (above).
The function checks if directory searches are permitted using the current permissions of the directory underlying the file descriptor.
QNX OS has no concept of a path operation (open(), readlink(), etc.) that references a path relative to an already open file descriptor (for a directory), as far as the filesystem resource manager is concerned. Therefore, it's not possible to eliminate the race inherent in looking up a pathname with multiple intervening directories or symbolic links. However, mknodat() can still be used for maintaining a per-thread current working directory, using file descriptors maintained by the application.
mknodat (AT_FDCWD, name, S_IFDIR | 0777, 0);
Returns:
- 0
- Success.
- -1
- An error occurred (errno is set).
Errors:
- EACCES
- Search permission is denied on a component of the path prefix, write permission is denied on the parent directory of the path, or you don't have permission to search the directory underlying fd.
- EBADF
- The path argument does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor open for reading.
- EEXIST
- The named file already exists.
- EINVAL
- There's an invalid argument.
- EIO
- An I/O error occurred while accessing the filesystem.
- ELOOP
- During resolution of the path argument, a loop was found in the symbolic links or more than SYMLOOP_MAX symbolic links were encountered.
- EMLINK
- The link count of the parent directory would exceed LINK_MAX.
- ENAMETOOLONG
- The length of the path string exceeds PATH_MAX, or the resolution of a symbolic link within path produced a result longer than PATH_MAX.
- ENOENT
- A component of the path prefix doesn't exist, or the path argument points to an empty string.
- ENOSPC
- The filesystem doesn't contain enough space to hold the contents of the new directory or to extend the parent directory, or the maximum limit of files and directories has been reached.
- ENOSYS
- The mknodat() function isn't implemented for the filesystem underlying the specified path.
- ENOTDIR
- One of the following is true:
- A component of the path prefix names an existing file that is neither a directory nor a symbolic link to one.
- The path argument contains at least one non-slash character and ends with at least one slash character (/).
- The path argument isn't an absolute path and the fd file descriptor is associated with a non-directory file.
- The file descriptor in fd was created without O_DIRECTORY set.
- EPERM
- The calling process doesn't have appropriate privileges and the file type is not FIFO-special.
- EROFS
- The directory in which the file is to be created resides on a read-only filesystem.
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | Yes |
Thread | Yes |