1

Where are chflags system call flags constants are defined?

import "syscall"
...
flags := ???
err := syscall.Chflags("filename", flags)

In C language these constants are defined in sys/stat.h or unistd.h:

  • UF_NODUMP
  • UF_IMMUTABLE
  • UF_APPEND
  • UF_OPAQUE
  • UF_HIDDEN
  • SF_ARCHIVED
  • SF_IMMUTABLE
  • SF_APPEND
  • SF_DATALESS

Where these constants in Go?

7
  • 1
    Is this Linux, BSD, or Darwin? Because Linux doesn't implement the chflags syscall. You have to use iotctl instead.
    – Nick ODell
    Oct 12, 2021 at 14:27
  • 1
    @NickODell: darwin and bsd define that syscall
    – JimB
    Oct 12, 2021 at 14:30
  • The most complete syscall package will always be golang.org/x/sys/unix, and you can look there to see if they have been generated as part of the package. If not, you must assign the values yourself (or shell out to chflags on the cli, which is what most implementations do)
    – JimB
    Oct 12, 2021 at 14:33
  • In my case it is macOS Oct 12, 2021 at 14:34
  • Mostly what @JimB said. In fact, there exist a special standard package, syscall, which defines a minimal subset of syscall wrappers and constants—like those you're after,—but this subset is defined by the needs of the other standard library packages and the runtime. (Also, this package is highly GOOS/GOARCH-dependent.) Many other syscalls and related symbols found on Unix-like systems are indeed defined in golang.org/x/sys/unix, but not all possible. In case you need something not defined, just see how they are defined in the C code native to your platform and define your own symbols.
    – kostix
    Oct 12, 2021 at 18:30

1 Answer 1

1

You can refer to the link https://github.com/snapcore/snapd/blob/master/osutil/chattr.go if you want to get the constants of the flags you listed out above.

5
  • In case that link goes away in future, could you list the relevant value in your answer?
    – IMSoP
    Oct 12, 2021 at 14:33
  • I can take actual values, but where are these constants defined, so I could just use package? Oct 12, 2021 at 14:36
  • 1
    @user3431635 according to my understanding, no package is available now, you are encourage to create one and publish on GitHub, so that you can import it in your own program
    – Tony Yip
    Oct 12, 2021 at 14:40
  • I'd say those constants are for a Linux-specific syscall while the OP is after another—Mac OS X's specific syscall.
    – kostix
    Oct 12, 2021 at 18:34
  • @Tony Yip This kind of strange. Chflags system call exist, but constants for its parameters are not defined. I do not think that my package will have any sense as it should be part of standard library along with Chflags function. Oct 12, 2021 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.