18

Would this save one bit per file, or is there necessary padding that has to be used anyways? And even if there is padding, why not still combine them and utilize the extra bit for a new feature?

  • 3
    The sticky bit does something on ordinary files. See en.wikipedia.org/wiki/Sticky_bit for the number of ways it's used. – Joshua Dec 27 '17 at 22:22
  • @Joshua That's interesting, and it is a good point that on non-Linux *nixes the behavior varies. But I had Linux in mind for this question. I wonder though if someone on a Linux kernel with BSD amd and ls could still depend on the sticky file bit? And I guess various userland programs could check for / act on it even though I don't know of any common ones that do. – Harry Dec 27 '17 at 22:43
26

For historical reasons. The sticky bit was originally used for a completely different purpose: if it was set on an executable file, it told the operating system to retain the text segment in swap. Thus the name "Sticky Bit".

  • Thank you, but does that preclude them from still being "one bit" internally? Or is a one-bit savings just not significant enough on the per-file level? – Harry Dec 27 '17 at 12:33
  • 6
    An executable file could have all four combinations of suid and sticky. – Johan Myréen Dec 27 '17 at 12:36
  • Yes, hence the original question. Maybe better phrased, why does the name (or past usage) of the sticky bit have anything to do with combining it with the suid bit today? Couldn't the functions of both bits be combined into one "sticky/suid" bit, which functions as suid when set on files but sticky when set on directories? – Harry Dec 27 '17 at 12:42
  • 17
    You would break backward compatibility if you shift bits around. chmod 4755 file sets the suid bit, and chmod 1755 dir sets the sticky bit. We don't want to break old scripts just for the sake of saving a single bit per file, do we? Of course, internally a file system is free to implement your optimization, as long as the external interface stays the same. – Johan Myréen Dec 27 '17 at 12:50
  • 6
    @Johan Myréen: And of course you wouldn't actually save that bit, it would become just an unused bit in the byte/word permission field. – jamesqf Dec 27 '17 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.