helloSystem / Filer

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

Make it possible to rename disks #124

Closed probonopd closed 2 years ago

probonopd commented 2 years ago

With https://github.com/vermaden/automount/issues/30 well underway, it should become possible to rename disks ("volume labels") in the exact same way it is possible to rename folders and documents.

image

This is a prime example for basic things that should be simple, yet are surprisingly difficult anywhere but on the Mac.

probonopd commented 2 years ago

On the Mac, you simply can do

diskutil  rename  /dev/diskXsY   "Macintosh HD"

But what is the equivalent for this on FreeBSD?

https://www.freebsd.org/cgi/man.cgi?glabel says:

 This GEOM class also provides volume label detection for file systems.
     Those labels cannot be set with glabel, but must be set with the appro-
     priate file system utility, e.g. for UFS the file system label is set
     with tunefs(8). Currently supported file systems are:

       +o   UFS1 volume names (directory /dev/ufs/).
       +o   UFS2 volume names (directory /dev/ufs/).
           ...
       +o   MSDOSFS (FAT12, FAT16, FAT32) (directory    /dev/msdosfs/).
       +o   CD ISO9660 (directory /dev/iso9660/).
       +o   EXT2FS (directory /dev/ext2fs/).
       +o   REISERFS    (directory /dev/reiserfs/).
       +o   NTFS (directory /dev/ntfs/).

Unfortunately, "the appropriate file system utility" is not further elaborated upon. So we need to cobble this inormation together:

What about

There should be a unified command line tool to rename volume labels for all sorts of filesystems on all sorts of Unix-like OSes. Then Filer could simply invoke that tool. If you know of such a tool, please let us know.


For Ubuntu, https://wiki.ubuntuusers.de/Labels/#Dateisystem-Label states:

image

Wow, it really seems to be that complicated. How many file managers expose this functionality in an easy-to-use way?


Side note: A neat way to quickly get all volume labels seems to be blkid:

FreeBSD% blkid
/dev/da0: LABEL="AIRYX" TYPE="iso9660" 
/dev/da0p1: SEC_TYPE="msdos" LABEL="MY DISK" UUID="1F23-1D1C" TYPE="vfat"

It can also be used to find the device name(s) of the volume(s) with a given name:

FreeBSD% blkid | grep 'LABEL="AIRYX"' | cut -d ":" -f 1              
/dev/da0
probonopd commented 2 years ago

This works for MSDOSFS:

FreeBSD% sudo pkg install -y mtools

FreeBSD% mount
/dev/da0p1 on /media/da0p1 (msdosfs, local, noatime)

FreeBSD% fstyp -l /dev/da0p1
msdosfs ESP

FreeBSD% sudo mlabel -i /dev/da0p1 ::MYDISK
Can't open /dev/da0p1: Operation not permitted
Cannot initialize '::'
mlabel: Cannot initialize drive

FreeBSD% sudo umount /dev/da0p1

FreeBSD% sudo mlabel -i /dev/da0p1 ::MYDISK

FreeBSD% fstyp -l /dev/da0p1
msdosfs MYDISK

Works. How about longer names with spaces in them?

FreeBSD% sudo mlabel -i /dev/da0p1 ::'My Disk'

FreeBSD% fstyp -l /dev/da0p1                  
msdosfs My Disk

But fsck_msdosfs doesn't seem to like long names as volume labels, as can be seen in /var/log/automount.log:

/dev/da0p1: fsck_msdosfs Invalid long filename entry for volume label

It is still there, though...

FreeBSD% fstyp -l /dev/da0p1                  
msdosfs My Disk
probonopd commented 2 years ago

Here we go with a small command line tool that can serve as a stand-in for diskutil rename:

https://github.com/helloSystem/ISO/blob/11f0cada085a5d1f66e1f65214139048412cf76f/overlays/uzip/hello/files/usr/local/sbin/diskutil

Any thoughts appreciated.

I would like to replace the mount command at the end with something that triggers the same notification that would get triggered if the device was plugged in, so that @vermaden's automount can do its thing... how?

Next step will be for Filer to invoke diskutil rename to rename disks if the user does this in the GUI.

vermaden commented 2 years ago

You can invoke the same automount behavior that devd(8) would with these:

# /usr/local/sbin/automount da0 detach
# /usr/local/sbin/automount da0 attach
probonopd commented 2 years ago

...and we have something that is beginning to work.

image

But those - instead of spaces...

You can invoke the same automount behavior that devd(8) would with these

That is exactly how I am doing it now - but this creates a hard dependency on automount, making things less than portable.

probonopd commented 2 years ago

For now, error messages are passed through from the diskutil command line tool:

image

Power of the launch command :-)