简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM