chflags, fchflags,
fchflagsat — set file
flags
#include
#include
int
chflags(const
char *path, u_int
flags);
int
fchflags(int
fd, u_int
flags);
int
fchflagsat(int
fd, const char
*path, u_int flags,
int flag);
The file whose name is given by path or
referenced by the descriptor fd has its flags changed
to flags.
The
fchflagsat()
is equivalent to
chflag()
except in the case where path specifies a relative
path. In this case the file to be changed is determined relative to the
directory associated with the file descriptor fd
instead of the current working directory. The values for the
flag are constructed by a bitwise-inclusive OR of
flags from the following list, defined in
<fcntl.h>:
AT_SYMLINK_NOFOLLOW
- If path names a symbolic link, then the flags of the
symbolic link is changed.
AT_SYMLINK_NOFOLLOW_ANY
- If path names a symbolic link, then the flags of the
symbolic link is changed and if the path has any other symbolic links, an
error is returned.
AT_RESOLVE_BENEATH
- If path does not reside in the hierarchy beneath the
starting directory, an error is returned.
If
fchflagsat()
is passed the special value AT_FDCWD in the
fd parameter, the current working directory is used.
If also flag is zero, the behavior is identical to a
call to chflags().
The flags specified are formed by
or'ing the following
values
- UF_NODUMP
- Do not dump the file.
- UF_IMMUTABLE
- The file may not be changed.
- UF_APPEND
- The file may only be appended to.
- UF_OPAQUE
- The directory is opaque when viewed through a union stack.
- UF_HIDDEN
- The file or directory is not intended to be displayed to the user.
- UF_COMPRESSED
- File is compressed at the file system level.
- SF_ARCHIVED
- The file has been archived.
- SF_IMMUTABLE
- The file may not be changed.
- SF_APPEND
- The file may only be appended to.
- SF_DATALESS
- The file is a dataless placeholder. The system will attempt to materialize
it when accessed according to the dataless file materialization policy of
the accessing thread or process. See
getiopolicy_np(3).
The “UF_IMMUTABLE”, “UF_APPEND”,
“UF_OPAQUE”, and “UF_HIDDEN” flags may be set or
unset by either the owner of a file or the super-user.
The “SF_ARCHIVED”, “SF_IMMUTABLE” and
“SF_APPEND” flags may only be set or unset by the
super-user.
The “SF_DATALESS” and
“UF_COMPRESSED” flags are internal flags and may not be set or
unset from user space. Attempting to modify them using
chflags()
will result in undefined behaviour.
Upon successful completion, a value of 0 is returned. Otherwise,
-1 is returned and the global variable errno is set to
indicate the error.
chflags() will fail if:
- [
ENOTDIR]
- A component of the path prefix of path names an
existing file that is neither a directory nor a symbolic link to a
directory, or path contains at least one
non-<slash> character and ends with one or more trailing
<slash> characters and the last pathname component names an existing
file that is neither a directory nor a symbolic link to a directory.
- [
ENAMETOOLONG]
- A component of a pathname exceeded
{NAME_MAX}
characters, or an entire path name exceeded
{PATH_MAX} characters.
- [
ENOENT]
- The named file does not exist.
- [
EACCES]
- Search permission is denied for a component of the path prefix.
- [
ELOOP]
- Too many symbolic links were encountered in translating the pathname.
- [
EPERM]
- The effective user ID does not match the owner of the file and the
effective user ID is not the super-user.
- [
EROFS]
- The named file resides on a read-only file system.
- [
EFAULT]
- Path points outside the process's allocated address
space.
- [
EIO]
- An I/O error occurred while reading from or writing to the file
system.
- [
ENOTSUP]
- The operation isn't supported by the filesystem.
fchflags() will fail if:
- [
EBADF]
- The descriptor is not valid.
- [
EINVAL]
- fd refers to a socket, not to a file.
- [
EPERM]
- The effective user ID does not match the owner of the file and the
effective user ID is not the super-user.
- [
EROFS]
- The file resides on a read-only file system.
- [
EIO]
- An I/O error occurred while reading from or writing to the file
system.
- [
ENOTSUP]
- The operation isn't supported by the filesystem.
In addition to the chflags() errors,
fchflagsat() fails if:
- [
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
searching.
- [
EINVAL]
- The value of the flag argument is not valid.
- [
ELOOP]
- If AT_SYMLINK_NOFOLLOW_ANY was passed and a symbolic link was encountered
in translating the pathname.
- [
ENOTDIR]
- The path argument is not an absolute path and
fd is neither
AT_FDCWD nor a
file descriptor associated with a directory.
- [
ENOTCAPABLE]
- if AT_RESOLVE_BENEATH was passed and path does not
reside in the directory hierarchy beneath the starting directory.
chflags(1), fflagstostr(3),
lchflags(3), strtofflags(3),
launchd(8)
The chflags() and
fchflags functions first appeared in 4.4BSD.
fchflagsat() system call appeared in macOS 27.0.