1

I asked this on Stack Overflow and they told me ask this question here. I've searched the net for pages mentioning file attributes and system calls, but none of them ever say which system call is responsible for changing the various attributes of a file or a folder. It's been implied that fcntl() is what I'm looking for, but it lacks arguments for the path and the new set of file attributes.

closed as off-topic by Gilles, slm Dec 4 '14 at 1:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Gilles, slm

  • The person who refered you to this site was wrong. This question is at best borderline here: it is a programming question, and belongs on Stack Overflow. – Gilles Dec 3 '14 at 23:10
  • Is this the question that you're refering to? You asked a different question here: you can't use a system call if you're writing kernel code. Are you actually writing a kernel module, or do you want both pieces of information? – Gilles Dec 3 '14 at 23:11
  • Yes, I'm writing a kernel module. A simply one, but a kernel module nonetheless. – Melab Dec 11 '14 at 4:09
  • man7.org/linux/man-pages/man2/ioctl_iflags.2.html Change file attributes from userspace – 炸鱼薯条德里克 Feb 16 at 15:53
2

The chmod() and fchmod() system calls change the Posix-style attributes, the user-group-other, read/write/execute permissions. It looks like the ioctl() system call can be used to set the "linux file system attributes" that the chattr and lsattr commands set and list.

  • Given that chmod the command only can modify the file's permission bits, I'm guessing that fchmod() is related to the file attributes, then. So, would this mean I'd have to intercept both ioctl() and fchmod() to, say, prevent the flags for immutable and append-only from being changed? – Melab Dec 3 '14 at 1:06
  • @Melab - chmod() and fchmod() are supposed to act identically, according to the man page. The only difference is chmod() takes a file name, fchmod() takes a file descriptor. "immutable" and "append-only" are a few of the linux file system attributes, so hooking ioctl() would be enough to keep those from being changed. – Bruce Ediger Dec 3 '14 at 1:26
  • There isn't anyway a process could bypass ioctl() by using their own code, right? I think dd can. – Melab Dec 3 '14 at 2:54
  • @Melab any program with the right to access the disc directly can modify the bits if it knows how to find them. – Anthon Dec 3 '14 at 6:47
  • byte level writing to filesystem while it's mounted has 99.9% possibility to break your filesystem.@Melab – 炸鱼薯条德里克 Feb 16 at 15:55

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