helloSystem / Filer

A file manager that can also render the desktop
GNU General Public License v2.0
31 stars 9 forks source link

Show name of the volume instead of something like da0s1 #58

Closed probonopd closed 3 years ago

probonopd commented 3 years ago
% gpart show -l '/dev/da0s1'       
gpart: No such geom: /dev/da0s1.

% gpart show -l /dev/da0  
=>     32  1014752  da0  MBR  (496M)
       32       31       - free -  (16K)
       63  1014678    1  (null)  (495M)
  1014741       43       - free -  (22K)

Looks like this disk has no name ((null)), even though it has the name "FAT" which the Mac shows correctly...

probonopd commented 3 years ago

We are after the Volume label specifically.

https://en.wikipedia.org/wiki/Volume_(computing)#Volume_label

grahamperrin commented 3 years ago

How, precisely, was the disk formatted? Using what tool(s)?

probonopd commented 3 years ago

I don't remember. Possibly on a Mac with Disk Utility.

grahamperrin commented 3 years ago
  1. gpart show da0
  2. lsblk da0
  3. sudo gdisk /dev/da0
probonopd commented 3 years ago
% sudo hexdump -C /dev/da0 | grep FAT                 
00007e20  96 7b 0f 00 80 01 29 fb  07 d5 1d 46 41 54 20 20  |.{....)....FAT  |
probonopd commented 3 years ago
% gpart show da0
=>     32  1014752  da0  MBR  (496M)
       32       31       - free -  (16K)
       63  1014678    1  fat32  (495M)
  1014741       43       - free -  (22K)

% lsblk da0
DEVICE         MAJ:MIN SIZE TYPE                              LABEL MOUNT
da0              0:160 496M MBR                                   - -
  <FREE>         -:-    16K -                                     - -
  da0s1          0:161 495M fat32                                 - /media/da0s1
  <FREE>         -:-    22K -                                     - -

% sudo gdisk /dev/da0
sudo: gdisk: command not found
probonopd commented 3 years ago

This does the trick but for whatever reason needs sudo:

% fstyp -l /dev/da0s1 
fstyp: /dev/da0s1: Permission denied

% sudo fstyp -l /dev/da0s1
msdosfs FAT

Maybe @trasz knows why one needs sudo to find out the Volume label on FreeBSD...

probonopd commented 3 years ago

On the Mac, these "Volume labels" are used as the directory names for the mountpoints as well, unlike what we currently have:

image

If there is more than one disk with the same "Volume label" attached at the same time, then the Mac adds an appendix to the name of the mount point.

And the directories for the mount points get automatically deleted after unmounting so that the directory does not get cluttered up.

Something we should consider as well @vermaden?

grahamperrin commented 3 years ago

fstyp(8)

https://man.freebsd.org/fstyp(8)

If required: https://cgit.freebsd.org/src/tree/usr.sbin/fstyp

grahamperrin commented 3 years ago

glabel(8)

https://man.freebsd.org/glabel(8)

glabel list

… and so on.

Hint: you'll not get the label whilst the file system is mounted.

probonopd commented 3 years ago

Hint: you'll not get the label whilst the file system is mounted.

That kinda defeats the purpose then. After all we want Filer to display the "Volume labels" (LIVE, FAT,...) instead of those cryptic device names.

With sudo fstyp it works but I wonder why it needs sudo.

image

@DamjanJovanovic is this something bsdisks could help us with?

DamjanJovanovic commented 3 years ago

bsdisks already uses fstyp to find the filesystem type, so it knows which mount command to use, but there's no -l. It uses the GEOM label, but maybe should use something else, for the "IdLabel" property in:

sudo dbus-send --system --print-reply \
--dest=org.freedesktop.UDisks2 \
/org/freedesktop/UDisks2/block_devices/da1 \
org.freedesktop.DBus.Properties.GetAll \
string:org.freedesktop.UDisks2.Block

I'll do some further tests and let you know.

DamjanJovanovic commented 3 years ago

GEOM does expose the volume label, parse the XML output of sysctl kern.geom.confxml and look under the "LABEL" class. A "MYUSB" label on /dev/da1 has the form:

<class id="0xffffffff81afcda0">
    <name>LABEL</name>
    <geom id="0xfffff800c9aa9800">
        <name>da1</name>
        <provider id="0xfffff800ca320a00">
          <name>msdosfs/MYUSB</name>
          ...
        </provider>
        ...
    </geom>
    ...
</class>

Note that apart from trimming the filesystem prefix and slash, the label from GEOM has to be URL-decoded (unless your XML library already did that for you).

However that disappears when the filesystem is mounted.

bsdisks also exposes it over D-Bus, obtained from GEOM before mounting (for the filesystems it manages, anyway):

sudo dbus-send --system --print-reply \
--dest=org.freedesktop.UDisks2 \
/org/freedesktop/UDisks2/block_devices/da1 \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.UDisks2.Block \
string:IdLabel

If you need the label of a mounted filesystem even when unmanaged by bsdisks, I think fstyp -l is the only way.

ZFS volumes don't have labels, and their dataset names (eg. zroot/var/log) seem to come from the first string in the output of zfs get -H canmount instead.

grahamperrin commented 3 years ago

A PCManFM-Qt view of a non-mounted ZFS file system in my copperbowl pool:

PCManFM-Qt

Ambiguity can be problematic:

image

probonopd commented 3 years ago

@DamjanJovanovic unfortunately this does not work for me:

% sysctl kern.geom.confxml | grep '<label'    
            <label></label>
            <label>zfs0</label>
            <label>gptboot0</label>
            <label>efiboot0</label>

% sudo dbus-send --system --print-reply \
--dest=org.freedesktop.UDisks2 \
/org/freedesktop/UDisks2/block_devices/da0s1 \
org.freedesktop.DBus.Properties.GetAll \
string:org.freedesktop.UDisks2.Block
method return time=1617007998.984579 sender=:1.14 -> destination=:1.16 serial=23 reply_serial=2
   array [
      dict entry(
         string "Configuration"
         variant             array [
            ]
      )
      dict entry(
         string "CryptoBackingDevice"
         variant             object path "/"
      )
      dict entry(
         string "Device"
         variant             array of bytes "/dev/da0s1"
      )
      dict entry(
         string "DeviceNumber"
         variant             uint64 0
      )
      dict entry(
         string "Drive"
         variant             object path "/org/freedesktop/UDisks2/drives/da0"
      )
      dict entry(
         string "HintAuto"
         variant             boolean false
      )
      dict entry(
         string "HintIconName"
         variant             string ""
      )
      dict entry(
         string "HintIgnore"
         variant             boolean false
      )
      dict entry(
         string "HintName"
         variant             string ""
      )
      dict entry(
         string "HintPartitionable"
         variant             boolean false
      )
      dict entry(
         string "HintSymbolicIconName"
         variant             string ""
      )
      dict entry(
         string "HintSystem"
         variant             boolean false
      )
      dict entry(
         string "Id"
         variant             string "0000000000000000000"
      )
      dict entry(
         string "IdLabel"
         variant             string ""
      )
      dict entry(
         string "IdType"
         variant             string "vfat"
      )
      dict entry(
         string "IdUUID"
         variant             string ""
      )
      dict entry(
         string "IdUsage"
         variant             string "filesystem"
      )
      dict entry(
         string "IdVersion"
         variant             string ""
      )
      dict entry(
         string "MDRaid"
         variant             object path "/"
      )
      dict entry(
         string "MDRaidMember"
         variant             object path "/"
      )
      dict entry(
         string "PreferredDevice"
         variant             array of bytes "/dev/da0s1"
      )
      dict entry(
         string "ReadOnly"
         variant             boolean false
      )
      dict entry(
         string "Size"
         variant             uint64 519515136
      )
      dict entry(
         string "Symlinks"
         variant             array [
            ]
      )
   ]

This does:

% sudo fstyp -l /dev/da0s1
msdosfs FAT

The label is FAT.

probonopd commented 3 years ago

According to @crees

fstyp -l /dev/disk gets you the label but you will have to be in group operator or just put in devfs rules to give 644 rather than just 640 on drive nodes are you're all good

So changing to 644 in https://github.com/helloSystem/ISO/blob/experimental/overlays/uzip/furybsd-settings/files/etc/devfs.rules should do the trick?

ls -l /dev/da0* should be or crw-r--r---

Also see https://www.youtube.com/watch?v=U1fzMjj4Gv8

Trying 0666, sudo /etc/rc.d/devfs restart, re-plug USB drive, ls -h still shows crw-r----- :-(

vermaden commented 3 years ago

I am using device nodes as mount point as its consistent and I that way each devices behaves the same.

Remember that:

I have better proposal ... leave the 'technical' mount points as they are now - they are sure to work properly - and change these names in the graphical/presentation layer. For example you can display different names (labels or model) on the desktop then the actual mountpoint. You can also leave current device naming and add caption (text displayed after on-mounse-over a device) with its label and/or model.

probonopd commented 3 years ago

Needed to run sudo devfs ruleset 10, now I get

% fstyp -l /dev/da0s1
msdosfs FAT
probonopd commented 3 years ago

Need in /etc/rc.conf:

devfs_load_rulesets="YES"
devfs_system_ruleset="system"

Then the following seems to work: /etc/devfs.rules

[system=10]
add path 'acd*'         mode 0644 group operator
add path 'cd*'          mode 0644 group operator
add path 'da*'          mode 0644 group operator
add path 'pass*'        mode 0644 group operator
add path 'xpt*'         mode 0644 group operator
add path 'fd*'          mode 0644 group operator
add path 'md*'          mode 0644 group operator
add path 'uscanner*'    mode 0644 group operator
add path 'ugen*'        mode 0644 group operator
add path 'video*'       mode 0644 group operator
add path 'cuse*'        mode 0644 group operator
add path 'usb*'        mode 0644 group operator
# https://www.freebsd.org/doc/en_US.ISO8859-1/articles/cups/printing-cups-configuring-server.html
add path 'lpt*'         mode 0644 group cups
add path 'ulpt*'        mode 0644 group cups
add path 'unlpt*'       mode 0644 group cups

Is this the correct way to do this?

probonopd commented 3 years ago

In perparation for this, I committed

Possibly we also need to edit

probonopd commented 3 years ago

We are getting somewhere.

image