3

I've learned that besides the standard *nix file permissions, macOS also has file flags, and that they originated with BSD Unix. macOS's set of such flags is:

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 dis-played displayed played to the user.
SF_ARCHIVED    The file has been archived.
SF_IMMUTABLE   The file may not be changed.
SF_APPEND      The file may only be appended to.

You can see these extra flags with an extra switch to ls, though the switch varies:

  • ls -lo - BSD and perhaps older versions of macOS
  • ls -lO - current versions of macOS

You can change the flags with the commands the chflags command: FreeBSD man page

There are corresponding system calls chflags, lchflags, fchflags to change these flags: macOS man page

But I can't seem to find a system call to read the flags. Surely ls calls some function to get them? The syscalls that can change them don't seem to be able to also return their current state.

What am I missing?

(If this belongs on StackOverflow then please feel free to move it there.)

1 Answer 1

3

The flags can be read using stat on macOS and BSDs; they appear in the st_flags field.

2
  • As as happened a few times before, I found this a few minutes after crafting my question here, which I did only after wasting over an hour searching for the answer. But it always seems better to reward somebody else for knowing the answer. I don't know why the Mac man pages for chflags don't mention stat in its "See also" section. But I see that the BSD man pages do. Mar 22, 2021 at 6:40
  • 1
    Thanks! Going the other way, I found it amusing that the macOS stat page mentions chflags, but the OpenBSD one doesn’t... Mar 22, 2021 at 6:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .