On Dec 17, 2018, at 9:45 PM, Theodore Y. Ts'o <tytso@xxxxxxx> wrote: > > On Mon, Dec 17, 2018 at 03:53:46PM -0700, Andreas Dilger wrote: >>> +#define EXT4_IGET_NORMAL 1 >>> +#define EXT4_IGET_HANDLE 2 >> >> It would be better to make this: >> >> enum ext4_iget_flags { >> EXT4_IGET_RESERVED = 0x00, /* just guessing, see further below */ >> EXT4_IGET_NORMAL = 0x01, >> EXT4_IGET_HANDLE = 0x02, >> }; >> >>> - inode = ext4_iget(sb, ino); >>> + inode = ext4_iget(sb, ino, 0); >> >> What does "0" mean? It isn't in the list of EXT4_IGET_* flags. >> I'm guessing it means that access to reserved or otherwise invalid >> inodes is allowed? > > The flags are boolean OR'ed together, much like O_TRUNC | O_CREAT, > etc. So an enum isn't really appropriate. I don't think that it is verboten to use binary flag values in an enum, if you explicitly specify the values, which is why I used "0x01", "0x02" to make it more clear these are binary values. IMHO, using a named enum is a good way to annotate the function parameters rather than a generic "int flag" parameter that is ambiguous unless you look at the function code to see what the values of "flag" might be. > So 0 means we're not enforcing "must be a normal inode" rules, and > we're also not going to avoid throwing an EXT4_ERROR if the inode > number is invalid. So that matches what I reverse engineered, which was EXT4_IGET_RESERVED but might have a better name if you can think of it. I originally had EXT4_IGET_NONE = 0, but I don't think that is quite correct. > I had thought it was obvious that flags can be or'ed together, and > that "modes" are what might use an enum. Their definition as "1" and "2" didn't make it clear that the next possible value was "4" and not "3". > I personally like flags because the can be more expressive, although > I can see that "modes" are simpler since there is a much smaller set > of valid modes, and you don't have to worry about define what happens > when flags interact in unusual/unexpected ways. I'm not against flags, and I figured out that they were orthogonal flags after reading the whole patch. > It sounds like should add more explicit documentation at the very > least so it's more clear what's going on. > > - Ted Cheers, Andreas
Attachment:
signature.asc
Description: Message signed with OpenPGP