rfjakob / gocryptfs

Encrypted overlay filesystem written in Go
https://nuetzlich.net/gocryptfs/
MIT License
3.4k stars 244 forks source link

Avoid duplicate kernel options #854

Open JokerQyou opened 4 weeks ago

JokerQyou commented 4 weeks ago

This is a follow-up to #557. I would like to know if the proposed changes are acceptable.

The -ko volname=XXX does not work, because gocryptfs sets volname to directory base name of the mountpoint first, then expect to override it with duplicate option-value pair. Relevant codes:

https://github.com/rfjakob/gocryptfs/blob/f06f27e7bc098e334024c365004f9303e79997d9/mount.go#L437-L442

https://github.com/rfjakob/gocryptfs/blob/f06f27e7bc098e334024c365004f9303e79997d9/mount.go#L467-L473

Basically, it would produce -o volname=BaseNameOfMountPoint,volname=CustomVolName option for macFUSE. This appears logical at first glance, but it doesn't work as expected. macFUSE only reads the initial volname value set by gocryptfs and does not check for updates to this option later on.

I swapped these two code blocks and test on macOS Sonoma and it works as expected, the volname option can now be overridden correctly.

I think it's worth rewriting this part of gocryptfs so it only sets each option exactly once - use only user-provided option if possible, only inject stock options if they are not provided.