ISO icon indicating copy to clipboard operation
ISO copied to clipboard

Support .dmg disk images

Open probonopd opened this issue 4 years ago • 15 comments

A .dmg mounter (...) can be implemented using darling-dmg (tested; known to work).

References:

  • https://github.com/darlinghq/darling-dmg/pull/94
  • https://github.com/Martinfx/FreeBSD-Ports/tree/max-darling-dmg/darling-dmg
  • https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267207, thanks @Martinfx

probonopd avatar Oct 04 '21 18:10 probonopd

Make .dmg files mountable by double-click, like we do already for .iso and .img.

To make this happen using automount, we would need to:

  • Get .dmg files recognized with a MIME type that makes sense (file --mime-type Firefox\ 106.0.dmg currently gives Firefox 106.0.dmg: application/x-bzip2)
  • We need to claim them in /usr/local/share/applications/mount_md.desktop, so that this is reflected in /usr/local/share/applications/mimeinfo.cache
  • This will result in something like launch "Mount Disk Image" /tmp/darling-dmg/build/Firefox\ 106.0.dmg to be executed which in turn will create something like /dev/md1
  • automount should inspect /dev/md1, recognize that it is a dmg, and mount it using darling-dmg. Looking at strings /dev/md1 | more we see BZh91AY which appears to be a bz2 header

But apparently this is not how darling-dmg works, as it seems to work only on files and not on mdX devices:

FreeBSD% ./darling-dmg /dev/md1 /mnt
Error: Unsupported file format

Possible reasons:
1) The file is corrupt.
2) The file is not really a DMG file, although it resembles one.
3) There is a bug in darling-dmg.

The question is, does automount (intend to) use FUSE filesystems like darling-dmg? And if the answer is "yes", can it operate on the file directly rather than a /dev/mdX device`?

Possibly we should handle .dmg files more akin to .zip and other archives:

  • /usr/local/share/applications/mountarchive.desktop
  • Calls mountarchive %f
  • mountarchive is a PyQt5 script that uses fuse-archive to do the mounting without involving /dev/mdX. (We could probably extend it to use darling-dmg for .dmg files.)

However, in the case of a zip file, there is no icon shown on the desktop for the mounted file. Instead, double-clicking the file opens a Filer window at the mountpoint directly. In the case of .dmg and similar "image" files (as opposed to "archive" files), it is questionable whether this is desired. For .iso and .img, double-clicking those doesn't directly open a window that shows their contents, but they are mounted and shown on the desktop instead (like on the Mac). It is probably debatable whether the distinction between "archive" and "image" files is still relevant today and is understood by users; especially if we are technically treating "archive" files just like "image" files, namely, by mounting them.

We should align with @vermaden on whether he wants this kind of functionality (double-click on a .zip or .dmg or any other type of file that can be mounted using FUSE to get it automounted) in automount or not. If not, then the way we are currently doing it for .zip is perfectly fine for helloSystem.

probonopd avatar Oct 19 '22 16:10 probonopd

It is probably debatable whether the distinction between "archive" and "image" files is still relevant today and is understood by users; especially if we are technically treating "archive" files just like "image" files, namely, by mounting them.

Well, one "image" file can have multiple partitions (a.k.a. "volumes"); that's probably why double-clicking "image" files just mounts the volumes in those instead of opening a winow with their contents directly?

But then, darling-dmg (and macOS) only mount the main partition in .dmg files anyway...

probonopd avatar Oct 19 '22 18:10 probonopd

it seems to work only on files and not on mdX devices

Maybe we'd need to throw in fuseblk in there somehow; this seems to be the magic keyword at least on Linux for FUSE to work with block devices rather than with files.

If we even want to go down that path.

probonopd avatar Oct 19 '22 18:10 probonopd

Hi,

do you need anything from my side in this?

Regards.

vermaden avatar Oct 19 '22 21:10 vermaden

Hi @vermaden, just wanted to know whether mounting things like Mac .dmg disk image files with FUSE is in the scope of automount. Thanks!

probonopd avatar Oct 20 '22 07:10 probonopd

The automount(8) acts against devices - if we use md(4) to map that *.DMG to /dev/md* device then I have nothing against it.

vermaden avatar Oct 20 '22 07:10 vermaden

Description of the file format: http://newosxbook.com/DMG.html

commands such as "file" have a hard time identifying the DMG file type: In the absence of a fixed header, a DMG can start with any type of data (disk or partition headers), which can be further compressed by myriad means

In fact, there is no "header" but a "footer":

FreeBSD% tail -b 1  Downloads/Transmission-3.00.dmg | head -c 4 | strings
koly

If this returns koly, then it is a dmg.

Now, does the tail command even work on md(4) devices?

probonopd avatar Oct 20 '22 17:10 probonopd

This is the way.

% mdconfig.sh -l                              
md0     vnode    5564K  /home/vermaden/Transmission-3.00.dmg    

% SECTORS=$( diskinfo -v /dev/md0|awk '/mediasize in sectors/ {print $1}' ) 

% echo ${SECTORS}
11127

% SECTORSIZE=$( diskinfo -v /dev/md0 | awk '/sectorsize/ {print $1}' )

% echo ${SECTORSIZE}
512

% dd if=/dev/md0 skip=$(( ${SECTORS} - 1 )) bs=${SECTORSIZE} 2> /dev/null| strings | tail -1
koly

vermaden avatar Oct 20 '22 21:10 vermaden

Wow. But can you get mdX to mount with darling-dmg? It works for me on files but not on mdX devices...

probonopd avatar Oct 21 '22 17:10 probonopd

No such package:

% pkg search darling
% 

vermaden avatar Oct 21 '22 20:10 vermaden

Soon :) https://github.com/Martinfx/FreeBSD-Ports/pull/84 a.k.a. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267207

probonopd avatar Oct 21 '22 21:10 probonopd

Then please let me know when that 'soon' happens :)

vermaden avatar Oct 21 '22 21:10 vermaden

sysutils/darling-dmg

FUSE module for .dmg files (containing an HFS+ filesystem)

grahamperrin avatar Oct 22 '22 20:10 grahamperrin

Periodic reminder that I still has it in my TODO list :)

vermaden avatar Feb 16 '23 15:02 vermaden

Not possible with RAW devices:

Works with file:

% darling-dmg download/transmission-4.0.3.dmg /media/tmp
Skipping partition of type Primary GPT Header
Skipping partition of type Primary GPT Table
Skipping partition of type Apple_Free
Using partition #3 of type Apple_HFS
Everything looks OK, disk mounted

Does not work when device created from that file:

% mdconfig.sh -l                     
md0     vnode    7361K  /data/download/transmission-4.0.3.dmg   

% darling-dmg /dev/md0 /media/tmp   
Error: Unsupported file format

Possible reasons:
1) The file is corrupt.
2) The file is not really a DMG file, although it resembles one.
3) There is a bug in darling-dmg.

Sorry.

vermaden avatar Aug 23 '23 13:08 vermaden