Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Linux Kernel – How do Linux file flags work?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading