Home > Blockchain >  Linux Kernel - How do Linux file flags work?
Linux Kernel - How do Linux file flags work?

Time:01-30

I am currently working on a custom kernel for a project, and one of the things I need is to create a new custom file flag(s), similar to this question: Passing custom flags to "open" in a device driver

I have been able to create them, and compile the kernel with no problems, however, I don't really get how these flags work in practice. Most of them seem to collide with each other, for example:

              [DEC]      [BIN]
O_CREAT:    00000100 | 01100100
O_EXCL:     00000200 | 11001000
                       -x------

As pointed out in that question, for testing whether the flags are unique it uses the Hamming weight of all the flags. However, I don't fully understand how to set and unset individual flags and how to test them properly, and why not use something much more trivial as bit flags, that can easily be distinguished with simple, cheap, bitwise operations.

CodePudding user response:

In C programming langauge, numbers starting with leading 0 are octal.

For example, 00000100 is octal number in base 8, not decimal. That's 0b1000000 in binary in base 2.

They do not conflict and are unique bits.

              [OCT]      [BIN]
O_CREAT:    00000100 | 01000000
O_EXCL:     00000200 | 10000000
  • Related