termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
35.34k stars 3.72k forks source link

[Bug]: cp file to /sdcard permission error even though touch and mkdir work #2482

Closed xandro0777 closed 2 years ago

xandro0777 commented 2 years ago

Problem description

Hi,

Android 11, Realme - weird ermission problem accessing /sdcard

I read #157, wiki and all the various workarounds that I could find.

Steps to reproduce the behavior.

After performing mentioned workarounds this works:

mkdir /scdard/ekg
touch /sdcard/ekg/xx
rm /sdcard/ekg/xx

.. no problem so far. Now cp downloads/* /sdcard/ekg gives me "cp: cannot create regular file ...:Operation not permitted". The permissions of those files are 600

Scratching my head.. TiA for any help.

What is the expected behavior?

No response

System information

agnostic-apollo commented 2 years ago

hmmm, maybe try disabling storage permission from termux app info, then regrant it, then force stop termux, then try again.

xandro0777 commented 2 years ago

On December 20, 2021 3:49:09 PM GMT+01:00, agnostic-apollo @.***> wrote:

hmmm, maybe try disabling storage permission from termux app info, then regrant it, then force stop termux, then try again.

Already did that twice :( The weird thing is that mkdir, touch and rm work, but cp or move not.

agnostic-apollo commented 2 years ago

There use to be problems with copying attributes on older android versions. Check https://github.com/termux/termux-app/issues/2362#issuecomment-952824877. Maybe try with cp --no-preserve=all

agnostic-apollo commented 2 years ago

Also post output of /system/bin/ls -lrZ downloads (not just ls, it won't show selinux context)

xandro0777 commented 2 years ago

Maybe try with cp --no-preserve=all

Doesn't work, but just figured it out: file names contain semicolon which apparently isn't allowed on /sdcard which is of type sdcardfs here.

agnostic-apollo commented 2 years ago

Yeah, FAT rules would apply. Special characters like " * / : < > ? \ |, DEL (0x7F) and control characters from 0x00 - 0x1F are not allowed.

https://cs.android.com/android/platform/superproject/+/android-12.0.0_r4:frameworks/base/core/java/android/os/FileUtils.java;l=995

Semi colon ; may not be allowed either depending on os, apparently on your android too. But is working on Android 7.

https://en.wikipedia.org/wiki/Comparison_of_file_systems#cite_note-note-25-10

These are the restrictions imposed by the on-disk directory entry structures themselves. Particular Installable File System drivers may place restrictions of their own on file and directory names; operating systems may also place restrictions of their own, across all filesystems. DOS, Windows, and OS/2 allow only the following characters from the current 8-bit OEM codepage in SFNs: A-Z, 0-9, characters ! # $ % & ' ( ) - @ ^ _ ` { } ~, as well as 0x80-0xFF and 0x20 (SPACE). Specifically, lowercase letters a-z, characters " / : < > ? \ | + , . ; = [ ], control codes 0x00-0x1F, 0x7F and in some cases also 0xE5 are not allowed.) In LFNs, any UCS-2 Unicode except \ / : ? " > < | and NUL are allowed in file and directory names across all filesystems. Unix-like systems disallow the characters / and NUL in file and directory names across all filesystems.

Closing since not a termux issue.

xandro0777 commented 2 years ago

The filesystem is somewhat broken for returning EPERM instead of some more suitable error.