On Thu Nov 26, 2026 at 8:07 AM CET, Amir Goldstein wrote: > On Wed, Nov 25, 2026 at 9:22 PM koraynilay wrote: >> >> On Wed Nov 25, 2026 at 5:51 PM CET, Amir Goldstein wrote: > ... >> >> >> >> My robot proposed 2 fixes: either don't introduce FS_XFLAG_PROJID >> >> (which, eh, not the best imo) >> > >> > Me neither. It's inconsistent IMO. >> > >> > But it is inconsistent in that we want to have a way for chattr -p to say with >> > the new API "set only projid", so we must have the flag, but we >> > mostly need it for the mask, we don't really care about its value in >> > fsx_flags. >> > >> >> or add a new flag to be used in at_flags, >> >> like AT_FILEATTR_MASKS, which would resolve all our legacy vs non-legacy >> >> problems, but it would be in *at*_flags, so doesn't really make sense >> >> semantically (but it would work well since file_getattr already rejects >> >> unknown at_flags, so it wouldn't cause problems for old programs). >> > >> > I think this is an overkill as well. >> >> Semantics issue aside, I think this shuold be the way to go, because >> it's explicit and doesn't rely on guessing based on struct size or mask >> values. >> > > Yes this is a good argument. > >> > We discussed this before. >> > >> > Attributes that have X_value like fsx_projid have few types: >> > 1. 0 means disabled (all existing values incl. projid) >> > 2. 0 is a valid value but cannot be unset (btime) >> > 3. 0 is a valid value and NULL/unset is also a valid value >> > >> > Only for type 3 does can the interpretation of >> > (!XFLAG_X && !fsx_X) be considered as an "unset" >> > and anyway, this will require support in individual fs. >> >> IMO !(xflags & XFLAG) && (rw_mask & XFLAG) should clear/unset the value >> in all cases, ignoring what's in fsx_X. >> >> And all existing values would be of type 1 for VER0, but of type 1 + 3 >> for VER1. >> > > I agree that this will be more consistent. > > With explicit opt-in to FILEATTR_MASKS API > vfs can determine that > (!XFLAG_X && !!fsx_X) is alway -EINVAL > > When fsx_X == 0, the value of XFLAG_X does not really matter > so filesystems can decide themselves if they want to act on > an "unset" flag or not. Hmm, I think fsx_xflags should have priority over the value in this _masks API. In my mind, to clear PROJID a userspace program would only need to do: struct file_attr fa = { .fsx_xflags = 0, .fsx_xflags_rw_mask = FS_XFLAG_PROJID }; file_setattr(&fa, AT_FILE_ATTR_MASKS); and have projid cleared (same for EXTSIZE/EXTSZINHERIT/COWEXTESIZE), while to set/change it: struct file_attr fa = { .fsx_xflags = FS_XFLAG_PROJID, .fsx_xflags_rw_mask = FS_XFLAG_PROJID, .fsx_projid = 67, }; file_setattr(&fa, AT_FILE_ATTR_MASKS); and this: struct file_attr fa = { .fsx_xflags = FS_XFLAG_PROJID, .fsx_xflags_rw_mask = FS_XFLAG_PROJID, .fsx_projid = 0, }; file_setattr(&fa, AT_FILE_ATTR_MASKS); would have the same result as the first snippet, but not the same meaning, since this would mean "set projid to 0" while the first snippet means "clear/unset projid" (but in this case, for projid and all the other already existing fsx_* it would have the same result). >> > fileattr_set_prepare() already treats the existing values as: >> > fsx_X == 0 => clear XFLAG_X >> > >> > And xfs returns EINVAL for !!(fsx_X) != !!(XFLAGX) >> > >> > A simple solution is to fix the flag according to val in fileattr_set_prepare() >> (This should be in file_attr_to_fileattr() I think, but yeah) >> > if rw_mask contains this flag: >> > >> > if (fa->fsx_xflags_rw_mask & FS_XFLAG_PROJID) { >> > /* Possibly legacy chattr -p compiled with new headers unaware of PROJID */ >> > if (fa->fsx_projid == 0) >> > fa->fsx_xflags &= ~FS_XFLAG_PROJID; >> > else >> > fa->fsx_xflags |= FS_XFLAG_PROJID; >> > } >> >> I think this would be a bit too overcomplicated to understand, and > > True > >> robot says (with the current v2 code at least) it would make e.g. ntfs >> return 0 instead of -EOPNOTSUPP for e.g. chattr +S. >> > > I suspected that existing filesystems may have different legacy behaviors.. (By the way I meant ntfs as in "mask aware filesystems" (I said ntfs because that was the robot's example since it's the only one currently implementing masks), but yeah) >> It also told me that statx already has AT_STATX_* flags that don't match >> the at_flags semantics (and indeed, AT_STATX_FORCE_SYNC/DONT_SYNC don't >> really make sense for "at"_flags semantics), so my only blocker for that >> solution is gone and I would really prefer that approach since it's way >> simpler and way cleaner. > > Git history claims that I suggested making this an official UAPI policy: > > b4fef22c2fb97 uapi: explain how per-syscall AT_* flags should be allocated > > So definitely no objection to AT_FILEATTR_ semantics. Oh, yes that's the comments I used as docs to add AT_FILE_ATTR_MASKS to fcntl.h ahah. >> >> One more thing gemini told me is that if we don't want to use AT_*, we >> have to choose between (copy-pasted, "ntfs" meaning any mask-aware fs): >> 1. Keep clamping fattr->fa_xflags & rw_user_mask (VER1 masked semantics >> are clean, but recompiled VER0 RMW tools setting unsupported >> flags/projid on ntfs silently return 0) >> 2. Reject unexpected non-zero bits/fields outside rw_user_mask | ro_mask >> (protects recompiled VER0 RMW error reporting on ntfs, at the cost that >> VER1 callers must zero or mask fa_xflags / fa_projid / fa_extsize >> themselves rather than expecting bits outside rw_mask to be ignored). >> >> So I would *really* prefer adding AT_FILEATTR_MASKS and setting >> has_masks based only on that. >> This way we can keep the whole legacy path frozen and not have to worry >> about weird edge cases (well, converters code aside of course). >> >> And personally in this way I can reason about the changes a lot more >> clearly and I can finally take a better look at the whole code and maybe >> simplify it in some cases (probably not, but I'll have to see). >> > > All very good reasons IMO. > >> (Unless there is something equivalent to AT_FILEATTR_MASKS to filter on, >> like maybe a FS_XFLAG_MASKS (?), but that would be even worse >> semantically I think) > > It's an option, but I think AT_FILEATTR_MASKS is cleaner. Yes I agree, I also thought a bit about other options, e.g. even having FS_XFLAGS_HASMASKS (like HASATTR), and stripping it right away in the syscall (or even using it instead of fa->has_masks) but they would all be worse options than AT_FILE_ATTR_MASKS. Today or tomorrow I'll send out v2. Thanks, koraynilay > Thanks, > Amir.