Open arudyavsky opened 1 week ago
I did a quick test on Debian 11.11 and I was able to get a correct output from GetDisks()
without root access. When you're running the df -T -B1 --exclude-type=tmpfs --exclude-type=devtmpfs --exclude-type=udev
command in the terminal, did you run it as normal user or with sudo?
I have written a simple bash test:
#!/bin/sh
out=`df -T -B1 --exclude-type=tmpfs --exclude-type=devtmpfs --exclude-type=udev`
echo "err: ", $?
echo "out: ", ${out}
As user - test return 1 as error As root - test has no errors
In both cases, information about the disks is present in the output.
I ran your script on a Debian 11 VM. Exit code for with and without root privileges are same, 0.
I ran test Go program to check the module as well, it also shows the disks info properly without root access.
Can you give me some more info about your setup if possible?
I have a standard Debian 11 installation by default. Everything is like yours...
$df --version
df (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.
$lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
My df -h
output (as user):
$df -h
df: /run/user/1000/doc: Operation not permitted
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 1.4M 1.6G 1% /run
/dev/sda1 213G 152G 51G 75% /
tmpfs 7.8G 713M 7.1G 9% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.6G 108K 1.6G 1% /run/user/1000
A strange message is df: /run/user/1000/doc: Operation not permitted
. If run sudo df -h
this message not emited. Maybe this is the reason for the error?
GetDisks() returns an empty array on my Debian 11. This is probably because exec.Command() returns an "exit status 1" error. In the terminal, the "df -T -B1 --exclude-type=tmpfs --exclude-type=devtmpfs --exclude-type=udev" command itself executes and has the correct output. A possible fix is to ignore the error. Maybe superuser rights are required?