Re: parted is ALMOST suitable
Hi.
On Mon, Nov 07, 2016 at 04:05:17PM +0100, tomas@tuxteam.de wrote:
> On Mon, Nov 07, 2016 at 09:35:32AM -0500, Greg Wooledge wrote:
> > I started writing that in my previous message, but then I actually
> > tested it on my own system. Good thing I did, because I got the
> > same result as Richard: being in group disk, which has read/write
> > access on /dev/sda*, does NOT give you output in the FSTYPE and other
> > fields of lsblk -f. It certainly surprised me.
>
> Indeed. I suspect lsblk is checking the user ID itself instead of
> letting the OS do its thing. For whatever reasons I can't fathom.
According to the source (util-linux-2.25.2), '-f' flag should add these
to the output:
add_column(columns, ncolumns++, COL_NAME);
add_column(columns, ncolumns++, COL_FSTYPE);
add_column(columns, ncolumns++, COL_LABEL);
add_column(columns, ncolumns++, COL_UUID);
add_column(columns, ncolumns++, COL_TARGET);
To determine COL_FSTYPE, probe_device function is used.
The definition of this function contains this little gem (getuid call):
static void probe_device(struct blkdev_cxt *cxt)
{
...
/* try udev DB */
if (get_udev_properties(cxt) == 0)
return; /* success */
cxt->probed = 1;
/* try libblkid (fallback) */
if (getuid() != 0)
return; /* no permissions to read from the device */
pr = blkid_new_probe_from_filename(cxt->filename);
if (!pr)
return;
So whoever wrote this was either lazy or too smart or both, as
blkid_new_probe_from_filename does this:
blkid_probe blkid_new_probe_from_filename(const char *filename)
{
...
fd = open(filename, O_RDONLY|O_CLOEXEC);
if (fd < 0)
return NULL;
I.e. insufficient device permissions will return NULL anyway, so there's
little point of checking whenever the calling user is root or not.
Reco
Reply to: