vermaden / automount

Simple devd(8) based automounter for FreeBSD
66 stars 20 forks source link

Fix unmount messages and VOLUMENAME option. #8

Open gawen947 opened 8 years ago

gawen947 commented 8 years ago

Notify and wall on unmount expect $DEV and $MNT from __state_remove(). Fixed that.

Added an option to detect the volume name using the file command and mount the device under this name. If multiple devices are mounted with the same name, an integer suffix is appended.

vermaden commented 8 years ago

What is the benefit/profit of adding VOLUMENAME option?

Regards, vermaden

gawen947 commented 8 years ago

By default the dev name is used to create the mountpoint. With this option enabled it extracts the filesystem volume name using the file command and uses this name instead to create the mount point. For example a file system created with newfs -L usbkey /dev/da0 would be mounted on /media/usbkey instead of /media/da0.

This is useful to recognize multiple removable media mounted at the same time. Also it ensures a consistent mountpoint for a device regardless of the order in which the media are plugged in.

The option is there to ensure that the old behavior stays the default. I used VOLUMENAME for the option name to make the distinction from GEOM labels.

vermaden commented 8 years ago

Ok, thanks for exaplanation.

This REGEX does not work with FAT32/MSDOSFS filesystem: NAME=$( file -r -b -L -s ${1} | grep -Eo ", volume name [^,]*," | tr -d ',' | sed 's/^ volume name //' )

... because there is 'label:' instead of 'volume name': # file -r -b -L -s /dev/da0 DOS/MBR boot sector, code offset 0x58+2, OEM-ID "BSD4.4 ", sectors/cluster 64, sectors/track 63, heads 255, sectors 61457634 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 7501, serial number 0x70db12fb, label: "32G "

Also having several 'same' mounts as: - /media/label - /media/label1

... is not elegant solution for me, I would rather implement it as: - /media/da0s1-label - /media/da1-label

I would porbably also use 'native' tools to get FAT32 label, as mtools from Ports: # mlabel -s -i /dev/da0 :: Volume label is 32G

This probable would also have problem with EXT* filesystems label detection.

I will probably implement it with 'native' label detection using 'native' tools but sorry, I will not merge that one.

The name for mount point also have to be 'sanity checked' like: # echo NAME | tr -c -d 'a-zA-Z0-9_-'

Regards, vermaden `

gawen947 commented 8 years ago

Indeed, I only tested it against UFS. The idea behind file was to avoid dependencies, but I agree with you that native tools would be better. Here are the tools that could be used:

Also having several 'same' mounts as:

  • /media/label
  • /media/label1

... is not elegant solution for me, I would rather implement it as:

  • /media/da0s1-label
  • /media/da1-label

Do you intend to use this only in the case of a conflict? If so, what about a device labeled "da0s1-label"?