Open babaric-dev opened 1 year ago
Notes to self:
1) we read /proc/filesystems only if the function is invoked as disk_partitions(all=False)
; if all=True
, reading /proc/filesystems
is superfluous, so it should not raise exception
2) find out how /proc/filesystems
is written and provide a fallback function with hard-coded values in case of EPERM
@babaric-dev what happens if you call disk_partitions(all=True)
? Does the function succeed? I want to make sure there are no other permission errors
With or without all=True
, it shows the exact same error message.
>>> psutil.disk_partitions(all=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 2021, in disk_partitions
ret = _psplatform.disk_partitions(all)
File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 1275, in disk_partitions
with open_text("%s/filesystems" % procfs_path) as f:
File "/usr/lib/python3/dist-packages/psutil/_common.py", line 725, in open_text
return open(fname, "rt", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'
>>> psutil.disk_partitions(all=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 2021, in disk_partitions
ret = _psplatform.disk_partitions(all)
File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 1275, in disk_partitions
with open_text("%s/filesystems" % procfs_path) as f:
File "/usr/lib/python3/dist-packages/psutil/_common.py", line 725, in open_text
return open(fname, "rt", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'
>>>
As I said, /proc/filesystems
is unaccessible in Android. cat
or stat
ing it shows Permission Denied
too.
I just pushed 2da99502. Can you try installing psutil from latest master
branch and retry running disk_partitions(all=True)
? Run:
python3 -m pip install --upgrade git+https://github.com/giampaolo/psutil.git@master
python3 -c "import psutil; print(psutil.disk_partitions(all=True))"
Works! But after updating to git
version, I see it can't read /proc/stat
. Another error. I will open an issue for this later
Why can't we close this?
Because of:
2) find out how /proc/filesystems is written and provide a fallback function with hard-coded values in case of EPERM
For proot-distro, you can fix this issue by following these steps. First, download fake /proc files(proc.tar.xz) from here. And then extract file named filesystems to your termux home directory. Last, append this --bind ~/filesystems:/proc/filesystems
to the end of your proot-login line.
Summary
Description
I ran this in the Python interactive console of PRoot Ubuntu:
It shows
PermissionError
.True that we can't really access
/proc/filesystems
on Android. But at least handle the error withtry
except
and return[]
? Better solution: use another way of getting partitions.