Re: [PATCH v3 1/2] fs: New zonefs file system

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 2, 2020 at 1:36 PM Darrick J. Wong <darrick.wong@xxxxxxxxxx> wrote:
>
> /me shrugs, I guess we're not supposed to use S_* in code.  Sorry about
> the unnecessary churn. :/

The S_* constants are useful for things like file types etc - so you
very much _are_ supposed to use them for things like

    switch (mode & S_IFMT) {
    case S_IFREG: ...

etc.

But no, the permission _names_ are complete and utter garbage. Whoever
came up with them was just being silly and they are not to ever be
used. Yes, POSIX specifies them, and yes, if you are outside of Unix
environments maybe they can have some relevance, but in a Unixy
environment, the octal codes are a *lot* more legible.

So if you want "owner read-write, group/world read", you use 0644.
That can actually be parsed. And 0777 matches that pattern, unlike the
insane jumble of letters that is "S_IRWXUGO".

Seriously, anybody who thinks "S_IRWXUGO" is easier to read than 0777
is just wrong. It's just shorthand for S_IRWXU|S_IRWXG|S_IRWXO, which
is _also_ a complete and utter mess and insane.

Just say no to the permission names. They don't even cover all the
cases anyway (unless you start or'ing in the individual bits and make
them even less regible), and by the time you parse all the random
letters (and know enough to parse them right), you inevitably find the
octal representation a lot easier to parse anyway.

And if you don't know how the unix permission bits work, then neither
the symbolic names _nor_ the numbers make any sense, so just give up.

So use the octal numbers for the three groups of three bits - aka the
low 9 bits aka the "UGO" bits, and use the symbolic names for the
other bits. Everybody will be much happier.

                   Linus



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux