Hi,

I would like to change the owner of a directory on the sdcard /sdcard/aDirectory

I have a terminal installed on my Android 10 (LineageOS 17) com.android.terminal

sudo is not present so I use su and it works.

su
#Terminal was granted Superuser rights

cd /sdcard
chown 10:10 aDirectory
#I don't get any error message.

stat aDirectory
#Uid (0/root)

So the owner stay root no matter what I’m doing, any ideas ?

      • It doesn’t matter. FAT filesystems - which are usually the default on SD cards, simply do not support ownership or file permissions. Linux emulates these attributes at mount time, but they apply to the entire SD card. You can mount an SD card and tell Linux to act as if root owns everything on the card; you that you own everything on the card; and it will be so until you unmount it and remount it with a different ownership.

        These are filesystem level attributes, not device attributes. If you have a modern internal nvme drive and you format it with vfat, you will not be able to set permissions or ownership at the file level, but only at mount time, for the entire drive.

          • TrickDacy@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            3 months ago

            True, but presumably op probably has an sd card if they say they do.

            Edit: I see both ways of reading their statements on re-reading them.

          • You mean, they’re mounting something that isn’t an SD card to the /sdcard directory? Like something truly evil, such as mount -t btrfs -o subvol=@home / /sdcard? Or do you think there’s not anything mounted there; it’s just a directory in the root partition? None of that would make any sense.

            If they’re letting whatever automount tool (eg udevil) do its thing, this is practically impossible. And if they know enough to do it by hand, I think they’d have answered the direct question of “which filesystem” with a filesystem rather than a mount point. Don’t you think? We still don’t know what filesystem they’re working with, since they haven’t answered the question.

            • u/lukmly013 💾 (lemmy.sdf.org)@lemmy.sdf.org
              link
              fedilink
              English
              arrow-up
              2
              ·
              3 months ago

              something that isn’t an SD card to the /sdcard directory?

              Could be.

              On my phone (Poco X3 Pro - stock Android 11, MIUI 12) the /sdcard is a symlink pointing to /storage/self/primary which itself is a symlink pointing to /storage/emulated/0, which is /data/media, the user-accessible portion of internal storage.
              Though from what I can find it anyway is just emulated FAT filesystem which is actually ext4 under that.

              Something about backwards compatibility as the directory used to actually be used for SD cards in the past.

  • 9point6@lemmy.world
    link
    fedilink
    English
    arrow-up
    17
    ·
    edit-2
    3 months ago

    Unless the SD card is using a Linux filesystem, you won’t be able to use Linux access permissions.

    Most SD cards are preformatted to FAT or exFAT in order to maximise compatibility. If you don’t need to use the card on any non-linux devices you should be able to reformat it and gain the ability to chown/chmod (should go without saying, but back up any data on the card you want to keep before this)

    • TrickDacy@lemmy.world
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 months ago

      There are other comments here which might have some relevance but imo this one is the most likely the most applicable. I’ve had this experience with other filesystems over and over and it seems like it’s almost always a problem. Apparently NTFS supports permissions in a similar way to Linux if you set it up exactly right, but I’ve never taken the time to try that.

  • drwankingstein@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    12
    ·
    edit-2
    3 months ago

    Nine times out of ten, running chown on Android is an astronomically bad idea. 10 times of 10, what you’re trying to do right now, is an astronomically bad idea.

    What is it you are trying to do? Or rather, why?

  • chakli@lemmy.world
    link
    fedilink
    English
    arrow-up
    10
    ·
    3 months ago

    If you want to change the owner of fat partition, you can do it while mounting, e.g. mount -t fat -o uid=10,gid=10 ......

  • Rick_C137@programming.devOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    3 months ago

    Thanks all for your input !

    So yes /sdcard was /storage/emulated/0 and it’s a real sd-card.

    That was indeed formatted as FAT, I reformatted into EXT4 (from a desktop Linux) put the SD-card back into the phone and started the phone.

    Ive tried (in the phone)

    su
    chmod 777 /storage/emulated/0 #yes it's still mounted as emulated !
    stat /storage/emulated/0
    #...
    #Access: (0771)
    #....
    

    So I’m still blocked… any ideas ?

    Thanks.