• Linux mount: What is the opposite of "nosuid" ?

    From Kenny McCormack@21:1/5 to All on Fri Apr 19 17:42:31 2024
    I have encountered an interesting situation. I have a USB disk drive auto-mounted (i.e, mounted by the automounter - I didn't explicitly mount it) and it is mounted with "nosuid" (which is normal). But I would like it to
    be mounted with suid working. It seems I should be able to do something
    like:

    # mount -o remount,suid /dev/sdb1

    but that generates err msg "invalid option or not mounted" (*) (as does
    every variation of the above that I've tried). I also tried "nonosuid",
    but that doesn't work either.

    (*) "mount" is notorious for giving "Ken Thompson style" error messages
    (i.e., the only error message you'll ever need is "No").

    Notes:
    1) Googling finds lots of stuff about how (and why) to mount nosuid,
    but not the opposite.
    2) (Obviously) I'm not interested in any solutions that need a time
    machine or involve editing /etc/fstab or that involve un-mounting
    it and mounting it over from scratch.

    It seems there should be a way with remount. "man mount" talks a fair bit about using "--bind" as an alternative to "-o remount", but I did not
    follow that very well. I've used "-o remount" many times in the past, successfully.

    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/Security

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Kenny McCormack on Fri Apr 19 18:28:51 2024
    On Fri, 19 Apr 2024 17:42:31 +0000, Kenny McCormack wrote:

    I have encountered an interesting situation. I have a USB disk drive auto-mounted (i.e, mounted by the automounter - I didn't explicitly mount it) and it is mounted with "nosuid" (which is normal). But I would like it to
    be mounted with suid working. It seems I should be able to do something like:

    # mount -o remount,suid /dev/sdb1

    but that generates err msg "invalid option or not mounted" (*) (as does
    every variation of the above that I've tried).

    That's strange. mount(8) explicitly names "suid" as an option, with the explanation:
    suid Allow set-user-identifier or set-group-identifier bits to take
    effect.

    BUT.... suid (like a number of other options) only applies iff the underlying filesystem supports set-user-identifier and set-group-identifier bits. Some filesystems don't (like FAT and NTFS-based filesystems).

    Are you trying to mount a non-unix filesystem?

    I also tried "nonosuid",
    but that doesn't work either.

    (*) "mount" is notorious for giving "Ken Thompson style" error messages (i.e., the only error message you'll ever need is "No").

    [snip]

    HTH
    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Fri Apr 19 20:39:51 2024
    In article <uvud53$30gsv$[email protected]>,
    Lew Pitcher <[email protected]> wrote:
    On Fri, 19 Apr 2024 17:42:31 +0000, Kenny McCormack wrote:

    I have encountered an interesting situation. I have a USB disk drive
    auto-mounted (i.e, mounted by the automounter - I didn't explicitly mount it)
    and it is mounted with "nosuid" (which is normal). But I would like it to >> be mounted with suid working. It seems I should be able to do something
    like:

    # mount -o remount,suid /dev/sdb1

    but that generates err msg "invalid option or not mounted" (*) (as does
    every variation of the above that I've tried).

    That's strange. mount(8) explicitly names "suid" as an option, with the >explanation:
    suid Allow set-user-identifier or set-group-identifier bits to take
    effect.

    OK - that's my reason for posting. To find out that it "should" work.
    That there is an option for it.

    Turns out that it works if I use the mount point rather than the device.
    I.e.,:

    # mount -o remount,suid /path/to/wherever/it/was/mounted

    works as expected. Strange, because for as long as I've been using
    "mount", it has always been OK to use either the device name or the mount
    point (for a mounted device - i.e., once it has been mounted); they are basically synonymous. But this seems to be an exception.

    --
    Kenny, I'll ask you to stop using quotes of mine as taglines.

    - Rick C Hodgin -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to Kenny McCormack on Sat Apr 20 03:30:03 2024
    Kenny McCormack <[email protected]> wrote at 20:39 this Friday (GMT):
    In article <uvud53$30gsv$[email protected]>,
    Lew Pitcher <[email protected]> wrote:
    On Fri, 19 Apr 2024 17:42:31 +0000, Kenny McCormack wrote:

    I have encountered an interesting situation. I have a USB disk drive
    auto-mounted (i.e, mounted by the automounter - I didn't explicitly mount it)
    and it is mounted with "nosuid" (which is normal). But I would like it to >>> be mounted with suid working. It seems I should be able to do something >>> like:

    # mount -o remount,suid /dev/sdb1

    but that generates err msg "invalid option or not mounted" (*) (as does
    every variation of the above that I've tried).

    That's strange. mount(8) explicitly names "suid" as an option, with the >>explanation:
    suid Allow set-user-identifier or set-group-identifier bits to take
    effect.

    OK - that's my reason for posting. To find out that it "should" work.
    That there is an option for it.

    Turns out that it works if I use the mount point rather than the device. I.e.,:

    # mount -o remount,suid /path/to/wherever/it/was/mounted

    works as expected. Strange, because for as long as I've been using
    "mount", it has always been OK to use either the device name or the mount point (for a mounted device - i.e., once it has been mounted); they are basically synonymous. But this seems to be an exception.


    Strange, I thought remount worked with the block device..
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to All on Sun Apr 21 01:54:30 2024
    candycanearter07 <[email protected]>
    writes:

    Kenny McCormack <[email protected]> wrote at 20:39 this Friday (GMT):
    In article <uvud53$30gsv$[email protected]>,
    Lew Pitcher <[email protected]> wrote:
    On Fri, 19 Apr 2024 17:42:31 +0000, Kenny McCormack wrote:

    I have encountered an interesting situation. I have a USB disk drive
    auto-mounted (i.e, mounted by the automounter - I didn't explicitly mount it)
    and it is mounted with "nosuid" (which is normal). But I would like it to >>>> be mounted with suid working. It seems I should be able to do something >>>> like:

    # mount -o remount,suid /dev/sdb1

    but that generates err msg "invalid option or not mounted" (*) (as does >>>> every variation of the above that I've tried).

    That's strange. mount(8) explicitly names "suid" as an option, with the >>>explanation:
    suid Allow set-user-identifier or set-group-identifier bits to take
    effect.

    OK - that's my reason for posting. To find out that it "should" work.
    That there is an option for it.

    Turns out that it works if I use the mount point rather than the device.
    I.e.,:

    # mount -o remount,suid /path/to/wherever/it/was/mounted

    works as expected. Strange, because for as long as I've been using
    "mount", it has always been OK to use either the device name or the mount
    point (for a mounted device - i.e., once it has been mounted); they are
    basically synonymous. But this seems to be an exception.

    Strange, I thought remount worked with the block device..

    I haven't used remount much but I'll make one observation... A block
    device can be mounted in more than one place, so it would make sense for remount to need the mount point rather than the device to be sure of
    what needs to be remounted.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Sun Apr 21 12:10:27 2024
    In article <uvvcrr$3euft$[email protected]>,
    candycanearter07 <[email protected]> wrote:
    ...
    Turns out that it works if I use the mount point rather than the device.
    I.e.,:

    # mount -o remount,suid /path/to/wherever/it/was/mounted

    works as expected. Strange, because for as long as I've been using
    "mount", it has always been OK to use either the device name or the mount
    point (for a mounted device - i.e., once it has been mounted); they are
    basically synonymous. But this seems to be an exception.


    Strange, I thought remount worked with the block device..

    Actually, it is pretty clear at this point (moreso now than when I started
    this thread - that is a Good Thing. I've learned some things from having launched this thread) that a "mount" is a data structure associated with a directory, not with a device. The device is one of the properties of the
    data structure (that isn't necessarily present, and isn't present in all mounts).

    So, it makes sense that you should have to specify the directory (referred
    to as "the target" in the man pages) in most cases. It turns out that the
    one exception to this - umount-ing - is actually an historical anomaly. According to "man 2 umount", umount used to be "umount(device)", but then
    they changed it to "umount(directory)" (for a while both were supported, at
    the system call level, but then the "device" form was dropped). So, I
    assume that, as a courtesy and for backward compatibility, the "umount"
    program substitutes the device name with the directory name before invoking
    the system call.

    --
    Most Southerners interest in, knowledge of, and participation in politics begins with
    and ends with: Screw the blacks. If a guy is onboard with that, he's our guy!

    Get them back in chains where they belong!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to Ben Bacarisse on Sun Apr 21 13:40:02 2024
    Ben Bacarisse <[email protected]> wrote at 00:54 this Sunday (GMT):
    candycanearter07 <[email protected]>
    writes:

    Kenny McCormack <[email protected]> wrote at 20:39 this Friday (GMT):
    In article <uvud53$30gsv$[email protected]>,
    Lew Pitcher <[email protected]> wrote:
    On Fri, 19 Apr 2024 17:42:31 +0000, Kenny McCormack wrote:

    I have encountered an interesting situation. I have a USB disk drive >>>>> auto-mounted (i.e, mounted by the automounter - I didn't explicitly mount it)
    and it is mounted with "nosuid" (which is normal). But I would like it to
    be mounted with suid working. It seems I should be able to do something >>>>> like:

    # mount -o remount,suid /dev/sdb1

    but that generates err msg "invalid option or not mounted" (*) (as does >>>>> every variation of the above that I've tried).

    That's strange. mount(8) explicitly names "suid" as an option, with the >>>>explanation:
    suid Allow set-user-identifier or set-group-identifier bits to take
    effect.

    OK - that's my reason for posting. To find out that it "should" work.
    That there is an option for it.

    Turns out that it works if I use the mount point rather than the device. >>> I.e.,:

    # mount -o remount,suid /path/to/wherever/it/was/mounted

    works as expected. Strange, because for as long as I've been using
    "mount", it has always been OK to use either the device name or the mount >>> point (for a mounted device - i.e., once it has been mounted); they are
    basically synonymous. But this seems to be an exception.

    Strange, I thought remount worked with the block device..

    I haven't used remount much but I'll make one observation... A block
    device can be mounted in more than one place, so it would make sense for remount to need the mount point rather than the device to be sure of
    what needs to be remounted.


    Oh, I never considered that. I don't think I've seen multiple mount
    points before.
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Mon Apr 29 00:11:20 2024
    On Sun, 21 Apr 2024 13:40:02 -0000 (UTC), candycanearter07 wrote:

    I don't think I've seen multiple mount points before

    Linux calls them “bind mounts”. Very handy, for example with containers,
    to give the guest userland visibility into selected parts of the host filesystem.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to Lawrence D'Oliveiro on Fri May 3 13:27:05 2024
    Lawrence D'Oliveiro <[email protected]d> wrote at 00:11 this Monday (GMT):
    On Sun, 21 Apr 2024 13:40:02 -0000 (UTC), candycanearter07 wrote:

    I don't think I've seen multiple mount points before

    Linux calls them “bind mounts”. Very handy, for example with containers, to give the guest userland visibility into selected parts of the host filesystem.


    Makes sense, since you can't hard link directories.
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From vallor@21:1/5 to [email protected] on Fri May 3 17:38:40 2024
    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07 <[email protected]> wrote in <v12on9$ihfm$[email protected]>:

    Lawrence D'Oliveiro <[email protected]d> wrote at 00:11 this Monday (GMT):
    On Sun, 21 Apr 2024 13:40:02 -0000 (UTC), candycanearter07 wrote:

    I don't think I've seen multiple mount points before

    Linux calls them “bind mounts”. Very handy, for example with
    containers,
    to give the guest userland visibility into selected parts of the host
    filesystem.


    Makes sense, since you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    bind mounts are different, because they don't alter the filesystem
    structure. Otherwise, you might end up with an un-fsck-able
    filesystem.

    --
    -v

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to vallor on Sat May 4 01:10:42 2024
    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07 <[email protected]> wrote in <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    bind mounts are different, because they don't alter the filesystem
    structure. Otherwise, you might end up with an un-fsck-able
    filesystem.

    Fun fact: Linux doesn’t actually distinguish between different mounts of
    the same filesystem (in the sense that one is the “original” mount and the others are not). That is, you can keep a later “bind” mount, and remove
    the original non-“bind” mount, and it still works.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johanne Fairchild@21:1/5 to Lawrence D'Oliveiro on Sat May 4 07:50:11 2024
    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07
    <[email protected]> wrote in
    <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea? Can you show examples? I can't see it. Thanks!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Sat May 4 11:50:22 2024
    In article <[email protected]>,
    Johanne Fairchild <[email protected]> wrote:
    ...
    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea? Can you show examples? I can't see it. Thanks!

    The poster who used too many "Very"s is a known crank.

    Generally, the more "Very"s you use, the worse is your argument.

    Or, as Mark Twain once put it:

    A young writer asked me how to edit his writing. I told him that he
    should go through and replace every occurrence of the word "very" with
    the word "damn". His editor would then remove every occurrence of the
    later word, and then things would be as they should be.

    So at our house, with this story in mind, whenever we use the word "very"
    in conversation, we immediately change it to "damn". So, the above would
    be:

    They are a damn, damn, damn, damn bad idea. And completely unnecessary.

    and after editing:

    They are a bad idea. And completely unnecessary.

    --
    Many (most?) Trump voters voted for him because they thought if they
    supported Trump enough, they'd get to *be* Trump.

    Similarly, Trump believes that if *he* praises Putin enough, he'll get to *be* Putin.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to [email protected] on Sat May 4 14:37:24 2024
    On 2024-05-04, [email protected] <[email protected]> wrote:
    Probably because there isn't much point (not that IMO there's much point to hard links anyway) as when you delete the directory you'll delete all the files inside but the now empty directory will still exist wherever its hard link
    is.

    This problem happens anyway when one or more processes have that
    directory as their root or cwd, referring to it by open inode.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Johanne Fairchild on Sat May 4 14:23:21 2024
    On Sat, 04 May 2024 07:50:11 -0300
    Johanne Fairchild <[email protected]> wrote:
    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07
    <[email protected]> wrote in
    <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea? Can you show examples? I can't see it. Thanks!

    Probably because there isn't much point (not that IMO there's much point to hard links anyway) as when you delete the directory you'll delete all the
    files inside but the now empty directory will still exist wherever its hard link
    is.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Johanne Fairchild on Sat May 4 14:39:28 2024
    On Sat, 04 May 2024 07:50:11 -0300, Johanne Fairchild wrote:

    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07
    <[email protected]> wrote in
    <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea? Can you show examples? I can't see it. Thanks!

    A hardlink introduces an undetectable cyclicity in the underlying filesystem.

    It must reference an inode within a specific filesystem (and, thus, cannot cross filesystems or mountpoints), and (unlike softlinks) has no other distinguishing feature. This means that you can only determine if a
    /directory/ hardlink has introduced a cyclical reference by actually
    traversing the hardlinked directory structures until you return to the
    starting link.

    On the other hand, you can detect both softlinks and bind mounts without directory traversal. A softlink inode contains a very specific flag to
    indicate that it contains a softlink, and the system records a bind mount
    in the its public mount records.

    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Lew Pitcher on Sat May 4 15:11:19 2024
    On 2024-05-04, Lew Pitcher <[email protected]> wrote:
    A hardlink introduces an undetectable cyclicity in the underlying filesystem.

    You mean, trouble some cyclicity that is detectable with a lot of
    annoying fuss, that has to be done wherever the filesystem is being
    recursively traversed.

    It must reference an inode within a specific filesystem (and, thus, cannot cross filesystems or mountpoints), and (unlike softlinks) has no other distinguishing feature. This means that you can only determine if a /directory/ hardlink has introduced a cyclical reference by actually traversing the hardlinked directory structures until you return to the starting link.

    If you keep the path of inodes you have visited in order to reach a
    certain directory, then you can detect a cycle by checking whether a
    newly visited directory is one of the elements of the path. Since
    paths are reasonably short, you don't need any fancy hash data structure
    for this; a linear scan will work fine in most cases, and so you can
    represent the path as a linked list that is allocated on the stack,
    if working in C.

    void recurse(..., visited_node *parent)
    {
    visited_node current = { .up = parent };
    // ...
    }

    The cyclic check is simply chasing the parent->up pointers to see if any
    of the visited nodes is the same object as the newly visited one.

    The problem is:

    1. Everything that performs traversals of the filesystem now *has* to do
    this, or risk being stuck in a loop. There is a bad habit in the
    Unix programming culture of people rolling their own filesystem
    traversal functions. Some of them would get it wrong, ending up in
    infinite loops.

    2. Even if you have cycle detection, you still have the problem that
    every recursive traversal performed anywhere runs the risk of
    potentially visiting the entire filesystem!

    Directory hard links could be restricted to being downward-only. So that
    is to say, if you create a P/C -> D hard link, then X is required to be
    a descendant of P, such as P/X/Y/D.

    To check that without race conditions, the kernel would have to lock
    down all operations on that filesystem during the link operation.
    Starting at D, it could navigate the parent .. links until it hits
    the root directory, P, or hits a mount point crossing. If it finds P,
    then it can conclude that the link can be made. (Without TOCtoTOU
    if things are properly locked down.)

    Holding a lock over a complex operation like that could open an avenue
    to a DOS attack against the filesystem. Imagine a swarm of threads doing directory linking operations, causing that lock to be excessively held.

    The descendant restriction would make directory hardlinks inapplicable
    to some people's use cases. (Oh well, they'd have to use symlinks
    for those situations.)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Lew Pitcher on Sat May 4 14:49:19 2024
    On Sat, 04 May 2024 14:39:28 +0000, Lew Pitcher wrote:

    On Sat, 04 May 2024 07:50:11 -0300, Johanne Fairchild wrote:

    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07
    <[email protected]> wrote in
    <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea? Can you show examples? I can't see it. Thanks!

    A hardlink introduces an undetectable cyclicity in the underlying filesystem.

    It must reference an inode within a specific filesystem (and, thus, cannot cross filesystems or mountpoints), and (unlike softlinks) has no other distinguishing feature. This means that you can only determine if a /directory/ hardlink has introduced a cyclical reference by actually traversing the hardlinked directory structures until you return to the starting link.

    Note that unix filesystems support a limited, controlled subset of hardlinks: the "." and ".." directories found in each directory. The OS controls the creation and deletion of /these/ hardlinks from within, as part of the mkdir(2) and rmdir(2) syscalls. And, the only cyclical hardlink (that I know of, anyway) lives as "/..", which links to itself.

    As for a cyclical hardlink, imagine the following:
    # Build a disposable directory
    mkdir /tmp/dumb

    # Populate the disposable directory with a cyclical hardlink
    ln /tmp/dumb /tmp/dumb/dumber

    # Now, let's empty the disposable directory
    rm -rf /tmp/dumb

    What does the "rm -rf" do when that "ln /tmp/dumb /tmp/dumb/dumber" actually creates a hardlink from /tmp/dumb/dumber to /tmp/dumb ?







    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Lew Pitcher on Sat May 4 22:46:10 2024
    On Sat, 4 May 2024 14:49:19 -0000 (UTC), Lew Pitcher wrote:

    Note that unix filesystems support a limited, controlled subset of
    hardlinks: the "." and ".." directories found in each directory.

    Even those are completely unnecessary. Their interpretation could easily
    be hard-coded into the path-interpretation routines in the kernel, instead
    of wasting space for these entries in every single directory on a
    filesystem.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Johanne Fairchild on Sat May 4 22:44:20 2024
    On Sat, 04 May 2024 07:50:11 -0300, Johanne Fairchild wrote:

    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    ... the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea?

    Consider these two questions:
    * How do you detect reference cycles?
    * What happens if you don’t?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johanne Fairchild@21:1/5 to [email protected] on Sat May 4 20:17:59 2024
    [email protected] writes:

    On Sat, 04 May 2024 07:50:11 -0300
    Johanne Fairchild <[email protected]> wrote:
    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07
    <[email protected]> wrote in
    <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary.

    Why are they a bad idea? Can you show examples? I can't see it. Thanks!

    Probably because there isn't much point (not that IMO there's much point to hard links anyway) as when you delete the directory you'll delete all the files inside but the now empty directory will still exist wherever its hard link
    is.

    Oh, I see. And if we were to fix this by removing the directory as well
    in the two or more places it was linked to? Wouldn't it be useful as a
    single directory that has two absolute paths? That seems useful to me.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johanne Fairchild@21:1/5 to Kaz Kylheku on Sat May 4 20:23:40 2024
    Kaz Kylheku <[email protected]> writes:

    On 2024-05-04, Lew Pitcher <[email protected]> wrote:
    A hardlink introduces an undetectable cyclicity in the underlying filesystem.

    You mean, trouble some cyclicity that is detectable with a lot of
    annoying fuss, that has to be done wherever the filesystem is being recursively traversed.

    It must reference an inode within a specific filesystem (and, thus, cannot >> cross filesystems or mountpoints), and (unlike softlinks) has no other
    distinguishing feature. This means that you can only determine if a
    /directory/ hardlink has introduced a cyclical reference by actually
    traversing the hardlinked directory structures until you return to the
    starting link.

    If you keep the path of inodes you have visited in order to reach a
    certain directory, then you can detect a cycle by checking whether a
    newly visited directory is one of the elements of the path. Since
    paths are reasonably short, you don't need any fancy hash data structure
    for this; a linear scan will work fine in most cases, and so you can represent the path as a linked list that is allocated on the stack,
    if working in C.

    void recurse(..., visited_node *parent)
    {
    visited_node current = { .up = parent };
    // ...
    }

    The cyclic check is simply chasing the parent->up pointers to see if any
    of the visited nodes is the same object as the newly visited one.

    The problem is:

    1. Everything that performs traversals of the filesystem now *has* to do
    this, or risk being stuck in a loop. There is a bad habit in the
    Unix programming culture of people rolling their own filesystem
    traversal functions. Some of them would get it wrong, ending up in
    infinite loops.

    2. Even if you have cycle detection, you still have the problem that
    every recursive traversal performed anywhere runs the risk of
    potentially visiting the entire filesystem!

    Directory hard links could be restricted to being downward-only. So that
    is to say, if you create a P/C -> D hard link, then X is required to be
    a descendant of P, such as P/X/Y/D.

    To check that without race conditions, the kernel would have to lock
    down all operations on that filesystem during the link operation.
    Starting at D, it could navigate the parent .. links until it hits
    the root directory, P, or hits a mount point crossing. If it finds P,
    then it can conclude that the link can be made. (Without TOCtoTOU
    if things are properly locked down.)

    Holding a lock over a complex operation like that could open an avenue
    to a DOS attack against the filesystem. Imagine a swarm of threads doing directory linking operations, causing that lock to be excessively held.

    The descendant restriction would make directory hardlinks inapplicable
    to some people's use cases. (Oh well, they'd have to use symlinks
    for those situations.)

    Thanks very much Lew Pitcher and Kaz Kylheku for the lecture. (Ignore
    my previous post on the thread asking further. It's all clear now.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johanne Fairchild@21:1/5 to Johanne Fairchild on Sat May 4 20:24:24 2024
    Johanne Fairchild <[email protected]> writes:

    [email protected] writes:

    On Sat, 04 May 2024 07:50:11 -0300
    Johanne Fairchild <[email protected]> wrote:
    Lawrence D'Oliveiro <[email protected]d> writes:

    On Fri, 3 May 2024 17:38:40 -0000 (UTC), vallor wrote:

    On Fri, 3 May 2024 13:27:05 -0000 (UTC), candycanearter07
    <[email protected]> wrote in
    <v12on9$ihfm$[email protected]>:

    ... you can't hard link directories.

    Sometimes, you can, depending on OS and filesystem:

    https://jameshunt.us/writings/linking-dirs-in-macos/

    IIRC, Apple's Time Machine uses this capability.

    BTW, I'm not mentioning this because I think it's a good idea;
    the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely unnecessary. >>>
    Why are they a bad idea? Can you show examples? I can't see it. Thanks! >>
    Probably because there isn't much point (not that IMO there's much point to >> hard links anyway) as when you delete the directory you'll delete all the
    files inside but the now empty directory will still exist wherever
    its hard link
    is.

    Oh, I see. And if we were to fix this by removing the directory as well
    in the two or more places it was linked to? Wouldn't it be useful as a single directory that has two absolute paths? That seems useful to me.

    Scratch all that. I should've read the entire subthread before asking.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Lawrence D'Oliveiro on Sun May 5 09:23:55 2024
    Lawrence D'Oliveiro <[email protected]d> writes:
    Johanne Fairchild wrote:
    Lawrence D'Oliveiro <[email protected]d> writes:
    vallor wrote:

    ... the Unix puritan in me abhors hard-linked directories.

    They are a very, very, very, very bad idea. And completely
    unnecessary.

    Why are they a bad idea?

    Consider these two questions:
    * How do you detect reference cycles?

    Multiple cycle-detection algorithms have been well known for decades.

    * What happens if you don’t?

    Something gets stuck in a loop.

    In the hypothetical where hard-link directories was possible, filesystem traversers would have to take into account the possibility of
    cycles. It’d be an extra implementation detail, comparable to the way
    real ones have to take into account the possibility of the filesystem
    changing as they progress, or accept with the consequences if they
    don’t.

    You’re on stronger grounds with “unnecessary” but a three-very bad idea? Insufficient evidence at best.

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Richard Kettlewell on Sun May 5 08:29:59 2024
    On Sun, 05 May 2024 09:23:55 +0100, Richard Kettlewell wrote:

    Lawrence D'Oliveiro <[email protected]d> writes:

    * How do you detect reference cycles?

    Multiple cycle-detection algorithms have been well known for decades.

    How many directories would you have to lock down while checking for cycles?

    How deep can your directory tree go?

    * What happens if you don’t?

    Something gets stuck in a loop.

    ...

    You’re on stronger grounds with “unnecessary” but a three-very bad idea?
    Insufficient evidence at best.

    You think getting “stuck in a loop” is not a bad idea?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Sun May 5 09:34:24 2024
    In article <v17g26$1onvc$[email protected]>,
    Lawrence D'Oliveiro <[email protected]d> wrote:
    ...
    You're on stronger grounds with unnecessary but a three-very bad idea?
    Insufficient evidence at best.

    You think getting stuck in a loop is not a bad idea?

    It *might* be a "bad idea", but it is hardly a damn, damn, damn bad idea.

    --
    The single most important statistic in the US today - the one that explains all the
    others - is this: 63 million people thought it was a good idea to vote for this clown
    (and will probably do so again). Everything else is secondary to that. Everything else
    could be fixed if we can revert this one statistic. Nothing can be fixed until we do.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrew Smallshaw@21:1/5 to Lawrence D'Oliveiro on Sun May 5 12:17:48 2024
    On 2024-05-04, Lawrence D'Oliveiro <[email protected]d> wrote:
    On Sat, 4 May 2024 14:49:19 -0000 (UTC), Lew Pitcher wrote:

    Note that unix filesystems support a limited, controlled subset of
    hardlinks: the "." and ".." directories found in each directory.

    Even those are completely unnecessary. Their interpretation could easily
    be hard-coded into the path-interpretation routines in the kernel, instead
    of wasting space for these entries in every single directory on a
    filesystem.

    But they're not: it goes to the core of the Unix "everything is a
    file" philosophy. Applications can and do read directories as
    regular files and extract the parent from them. No on DOS/Windows,
    you can't do that, you have to use a specific syscall. It's not
    "completely unnecessary", just a different way of acheiving the
    same effect.


    --
    Andrew Smallshaw
    [email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Andrew Smallshaw on Sun May 5 14:25:30 2024
    On 2024-05-05, Andrew Smallshaw <[email protected]> wrote:
    On 2024-05-04, Lawrence D'Oliveiro <[email protected]d> wrote:
    On Sat, 4 May 2024 14:49:19 -0000 (UTC), Lew Pitcher wrote:

    Note that unix filesystems support a limited, controlled subset of
    hardlinks: the "." and ".." directories found in each directory.

    Even those are completely unnecessary. Their interpretation could easily
    be hard-coded into the path-interpretation routines in the kernel, instead >> of wasting space for these entries in every single directory on a
    filesystem.

    But they're not: it goes to the core of the Unix "everything is a
    file" philosophy. Applications can and do read directories as
    regular files and extract the parent from them.

    Can you name one such application? Just as a warm up; then two more.

    No on DOS/Windows,
    you can't do that, you have to use a specific syscall. It's not
    "completely unnecessary", just a different way of acheiving the
    same effect.

    No, you can't just read a directory as a flat file, and expect your
    program to work on any file system.

    Modern (as in within the last 40 years) Unixes support multiple file
    systems including DOS. The directory representation is different in
    different file systems. Some use B-trees and hash tables and whatnot.

    On the Linux kernel, reading from a file descriptor that refers to a
    directory is not allowed; it fails with errno == EISDIR. (Not sure
    whether that's at the VFS layer, or whether specific filesystems refuse
    that individually.)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Lawrence D'Oliveiro on Sun May 5 15:52:18 2024
    Lawrence D'Oliveiro <[email protected]d> writes:
    Richard Kettlewell wrote:
    Lawrence D'Oliveiro <[email protected]d> writes:
    * How do you detect reference cycles?

    Multiple cycle-detection algorithms have been well known for decades.

    How many directories would you have to lock down while checking for cycles?

    Could be as little as 2. Depends on the algorithm used, what else you
    can assume about the filesystem, etc.

    How deep can your directory tree go?

    * What happens if you don’t?

    Something gets stuck in a loop.

    ...

    You’re on stronger grounds with “unnecessary” but a three-very bad idea?
    Insufficient evidence at best.

    You think getting “stuck in a loop” is not a bad idea?

    I think my previous posting adequately covers this question.

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Sun May 5 14:45:37 2024
    In article <[email protected]>,
    Kaz Kylheku <[email protected]> wrote:
    ...
    Even those are completely unnecessary. Their interpretation could easily >>> be hard-coded into the path-interpretation routines in the kernel, instead >>> of wasting space for these entries in every single directory on a
    filesystem.

    But they're not: it goes to the core of the Unix "everything is a
    file" philosophy. Applications can and do read directories as
    regular files and extract the parent from them.

    Can you name one such application? Just as a warm up; then two more.

    I think you're taking him too literally. There are interfaces for reading directories. Not specifically read(2), but you know better than to pick
    nits that way.

    No on DOS/Windows,
    you can't do that, you have to use a specific syscall. It's not
    "completely unnecessary", just a different way of acheiving the
    same effect.

    No, you can't just read a directory as a flat file, and expect your
    program to work on any file system.

    He never used the term "flat file". That is *your* construct.

    --
    I voted for Trump because I thought he'd make pussy grabbing legal.
    I honestly don't see any other way America could be made great again.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Kenny McCormack on Sun May 5 18:28:33 2024
    On 2024-05-05, Kenny McCormack <[email protected]> wrote:
    In article <[email protected]>,
    Kaz Kylheku <[email protected]> wrote:
    ...
    Even those are completely unnecessary. Their interpretation could easily >>>> be hard-coded into the path-interpretation routines in the kernel, instead >>>> of wasting space for these entries in every single directory on a
    filesystem.

    But they're not: it goes to the core of the Unix "everything is a
    file" philosophy. Applications can and do read directories as
    regular files and extract the parent from them.

    Can you name one such application? Just as a warm up; then two more.

    I think you're taking him too literally. There are interfaces for reading directories. Not specifically read(2), but you know better than to pick
    nits that way.

    No on DOS/Windows,
    you can't do that, you have to use a specific syscall. It's not
    "completely unnecessary", just a different way of acheiving the
    same effect.

    No, you can't just read a directory as a flat file, and expect your
    program to work on any file system.

    He never used the term "flat file". That is *your* construct.

    I don't believe you are correct; read the original points again.
    They are all quoted above, nothing snipped:

    - "Applications [on Unix] can and do read directories as
    regular files."

    (Regular files are flat: just bytes, so it is legitimate for me to use
    that word. That detail is neither here nor there anyway. You can't
    read a directory even if you know how to follow its tree structure
    or whatever it happens to be.)

    - "[O]n DOS/Windows [...] you can't do that, you have to use
    a specific syscall."

    (That lands under "interfacws for reading directories" that you
    allude to. So no, we don't just have to use those on Windows.)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Andrew Smallshaw on Sun May 5 20:23:37 2024
    On Sun, 5 May 2024 12:17:48 -0000 (UTC), Andrew Smallshaw wrote:

    On 2024-05-04, Lawrence D'Oliveiro <[email protected]d> wrote:

    On Sat, 4 May 2024 14:49:19 -0000 (UTC), Lew Pitcher wrote:

    Note that unix filesystems support a limited, controlled subset of
    hardlinks: the "." and ".." directories found in each directory.

    Even those are completely unnecessary. Their interpretation could
    easily be hard-coded into the path-interpretation routines in the
    kernel, instead of wasting space for these entries in every single
    directory on a filesystem.

    But they're not: it goes to the core of the Unix "everything is a
    file" philosophy. Applications can and do read directories as
    regular files and extract the parent from them.

    How do they find those directories? Via their pathname. How do you get a
    parent from a pathname? Simple: just drop off the last component. No need
    to even read anything from the directory.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Richard Kettlewell on Sun May 5 22:16:15 2024
    On Sun, 05 May 2024 15:52:18 +0100, Richard Kettlewell wrote:

    Lawrence D'Oliveiro <[email protected]d> writes:

    You think getting “stuck in a loop” is not a bad idea?

    [Non-answer]

    Consider three directories A, B and C which point to each other like this:

    A → B ↔ C

    Note this: the refcount of (number of pointers to) B is 2, and that of C
    is 1.

    Now consider what happens if B is removed from A. Its refcount goes to 1,
    so it is not deleted.

    B ↔ C

    But there is no way to access it! There are no other pointers to either B
    or C, so both of them are now effectively lost as far as users are concerned--yet their space cannot be reclaimed (or that of any items that
    might be in them).

    Not, that is, unless you run some kind of “garbage collection” pass over the filesystem, to reclaim orphaned storage. Filesystems are not typically designed with this sort of requirement in mind. Wonder why?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Cross@21:1/5 to [email protected] on Sun May 5 23:20:36 2024
    In article <[email protected]>,
    Kaz Kylheku <[email protected]> wrote:
    On 2024-05-05, Andrew Smallshaw <[email protected]> wrote:
    On 2024-05-04, Lawrence D'Oliveiro <[email protected]d> wrote:
    On Sat, 4 May 2024 14:49:19 -0000 (UTC), Lew Pitcher wrote:

    Note that unix filesystems support a limited, controlled subset of
    hardlinks: the "." and ".." directories found in each directory.

    Even those are completely unnecessary. Their interpretation could easily >>> be hard-coded into the path-interpretation routines in the kernel, instead >>> of wasting space for these entries in every single directory on a
    filesystem.

    But they're not: it goes to the core of the Unix "everything is a
    file" philosophy. Applications can and do read directories as
    regular files and extract the parent from them.

    Can you name one such application? Just as a warm up; then two more.

    Depends on the version of Unix. I'll pick 7th Ed. Here's three
    programs that could: `cat`, `dd`, and `od`. Of course, that's
    not what you mean, bt I think it's related.

    No on DOS/Windows,
    you can't do that, you have to use a specific syscall. It's not
    "completely unnecessary", just a different way of acheiving the
    same effect.

    No, you can't just read a directory as a flat file, and expect your
    program to work on any file system.

    Modern (as in within the last 40 years) Unixes support multiple file
    systems including DOS. The directory representation is different in
    different file systems. Some use B-trees and hash tables and whatnot.

    On the Linux kernel, reading from a file descriptor that refers to a >directory is not allowed; it fails with errno == EISDIR. (Not sure
    whether that's at the VFS layer, or whether specific filesystems refuse
    that individually.)

    Sure. But by the time that sort of support for multiple
    filesystem types came around, the structure of many Unix file
    systems (with hard links for "." and "..") had already existed,
    and there was desire to retain compatibility with existing
    on-disk filesystem images. So even though the landscape is
    radically different now, as you describe, history got us here.

    Btw, the bigger reason that hardlinks to directories are
    prohibited isn't because file tree walkers would have to be
    rewritten to take care when transversing such filesystems, but
    rather because automated filesystem checkers like `fsck` would
    have to be a _lot_ more sophisticated to cope, and they have
    the potential to do real, significant damage if they get it
    wrong.

    - Dan C.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Lawrence D'Oliveiro on Wed May 8 08:00:47 2024
    Lawrence D'Oliveiro <[email protected]d> writes:
    Not, that is, unless you run some kind of “garbage collection” pass over the filesystem, to reclaim orphaned storage. Filesystems are not typically designed with this sort of requirement in mind. Wonder why?

    Again, the techniques are well understood; GC has been used in other
    contexts for decades. In general you can’t reliably infer from something
    not being done that it would be a bad idea, merely that it hasn’t proved necessary.

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Richard Kettlewell on Wed May 8 08:30:57 2024
    On Wed, 08 May 2024 08:00:47 +0100, Richard Kettlewell wrote:

    GC has been used in other contexts for decades. In general you can’t reliably infer from something not being done that it would be a bad
    idea ...

    Hint: think about what’s different about filesystems versus management of main memory.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)