How does balena etcher get permission to unmount disks?

Hello, I am developing an application using https://github.com/balena-io-modules/etcher-sdk

when I run

MOUNTUTILS_DEBUG=1 npm start

and my code runs

etcherSDK.multiWrite.decompressThenFlash({...})

then I see in the log

[mountutils] Reading /proc/mounts
[mountutils] Mount point /dev/sdc2 belongs to drive /dev/sdc
[mountutils] Mount point /dev/sdc1 belongs to drive /dev/sdc
[mountutils] Closing /proc/mounts
[mountutils] Unmounting /media/forest/rootfs...
[mountutils] Unmount MNT_EXPIRE /media/forest/rootfs: EAGAIN
[mountutils] Unmount MNT_EXPIRE /media/forest/rootfs failed: Operation not permitted
[mountutils] Unmount MNT_DETACH /media/forest/rootfs failed: Operation not permitted
[mountutils] Unmount MNT_FORCE /media/forest/rootfs failed: Operation not permitted
[mountutils] Unmounting /media/forest/boot...
[mountutils] Unmount MNT_EXPIRE /media/forest/boot: EAGAIN
[mountutils] Unmount MNT_EXPIRE /media/forest/boot failed: Operation not permitted
[mountutils] Unmount MNT_DETACH /media/forest/boot failed: Operation not permitted
[mountutils] Unmount MNT_FORCE /media/forest/boot failed: Operation not permitted
[mountutils] Unmount complete

and onFail() gets called with “Unmount failed”. This seems weird to me because according to the C code it should return “Unmount failed, access denied” when its a permissions issue: https://github.com/balena-io-modules/mountutils/blob/master/src/worker-unmount.cpp#L28

I am curious how does this work in production for balena etcher? currently I am just debugging on linux but of course I want this to work cross platform later on… this should be documented on https://github.com/balena-io-modules/etcher-sdk!

I will do the work to document it, but help me help you: fill me in on how this works!

I cross posted this as a github issue since im not sure where to post.

never mind I found it ! https://github.com/balena-io/etcher/blob/master/lib/gui/app/modules/image-writer.ts#L216

I raised pull requests to document this


%Hi

It’s awesome when community members open up pull requests! I see that you have tagged some of our developers in GitHub. I’ll go ahead and close the forum post here, and we can continue using github for any additional discussion