From baaeae3f6f300db837cbb9d1d71d079c2923febf Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Sat, 30 Sep 2023 14:16:09 +0200 Subject: [PATCH] add flag to explicitly enable xattr depending on the mount provider (due to problems with fuse-t) --- .../cryptomator/frontend/fuse/ReadOnlyAdapter.java | 9 ++++++--- .../frontend/fuse/ReadWriteAdapter.java | 14 ++++++++------ .../frontend/fuse/mount/FuseTMountProvider.java | 2 +- .../fuse/mount/LinuxFuseMountProvider.java | 2 +- .../frontend/fuse/mount/MacFuseMountProvider.java | 2 +- .../frontend/fuse/mount/WinFspMountProvider.java | 2 +- .../fuse/AccessPatternIntegrationTest.java | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java b/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java index 0590412..9c2d833 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java +++ b/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java @@ -45,6 +45,7 @@ public sealed class ReadOnlyAdapter implements FuseNioAdapter permits ReadWriteA protected final Path root; private final int maxFileNameLength; protected final FileStore fileStore; + protected final boolean enableXattr; protected final LockManager lockManager; protected final OpenFileFactory openFiles; protected final FileNameTranscoder fileNameTranscoder; @@ -53,12 +54,13 @@ public sealed class ReadOnlyAdapter implements FuseNioAdapter permits ReadWriteA private final ReadOnlyLinkHandler linkHandler; private final BooleanSupplier hasOpenFiles; - protected ReadOnlyAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadOnlyDirectoryHandler dirHandler, ReadOnlyFileHandler fileHandler) { + protected ReadOnlyAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadOnlyDirectoryHandler dirHandler, ReadOnlyFileHandler fileHandler, boolean enableXattr) { this.errno = errno; this.root = root; this.maxFileNameLength = maxFileNameLength; this.fileNameTranscoder = fileNameTranscoder; this.fileStore = fileStore; + this.enableXattr = enableXattr; this.lockManager = new LockManager(); this.openFiles = openFiles; this.dirHandler = dirHandler; @@ -67,13 +69,13 @@ protected ReadOnlyAdapter(Errno errno, Path root, int maxFileNameLength, FileNam this.hasOpenFiles = () -> openFiles.getOpenFileCount() != 0; } - public static ReadOnlyAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder) { + public static ReadOnlyAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, boolean enableXattr) { try { var fileStore = Files.getFileStore(root); var openFiles = new OpenFileFactory(); var dirHandler = new ReadOnlyDirectoryHandler(fileNameTranscoder); var fileHandler = new ReadOnlyFileHandler(openFiles); - return new ReadOnlyAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler); + return new ReadOnlyAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler, enableXattr); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -86,6 +88,7 @@ public Errno errno() { @Override public Set supportedOperations() { + // FIXME: respect enableXattr return Set.of(Operation.ACCESS, Operation.CHMOD, Operation.CREATE, diff --git a/src/main/java/org/cryptomator/frontend/fuse/ReadWriteAdapter.java b/src/main/java/org/cryptomator/frontend/fuse/ReadWriteAdapter.java index b3cf37a..98d1864 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/ReadWriteAdapter.java +++ b/src/main/java/org/cryptomator/frontend/fuse/ReadWriteAdapter.java @@ -39,18 +39,18 @@ public final class ReadWriteAdapter extends ReadOnlyAdapter { private static final Logger LOG = LoggerFactory.getLogger(ReadWriteAdapter.class); private final ReadWriteFileHandler fileHandler; - private ReadWriteAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadWriteDirectoryHandler dirHandler, ReadWriteFileHandler fileHandler) { - super(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler); + private ReadWriteAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadWriteDirectoryHandler dirHandler, ReadWriteFileHandler fileHandler, boolean enableXattr) { + super(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler, enableXattr); this.fileHandler = fileHandler; } - public static ReadWriteAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder) { + public static ReadWriteAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, boolean enableXattr) { try { var fileStore = Files.getFileStore(root); var openFiles = new OpenFileFactory(); var dirHandler = new ReadWriteDirectoryHandler(fileNameTranscoder); var fileHandler = new ReadWriteFileHandler(openFiles); - return new ReadWriteAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler); + return new ReadWriteAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler, enableXattr); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -64,15 +64,17 @@ public Set supportedOperations() { ops.add(Operation.CREATE); //ops.add(Operation.FSYNC); ops.add(Operation.MKDIR); - ops.add(Operation.REMOVE_XATTR); ops.add(Operation.RENAME); ops.add(Operation.RMDIR); - ops.add(Operation.SET_XATTR); ops.add(Operation.SYMLINK); ops.add(Operation.TRUNCATE); ops.add(Operation.UNLINK); ops.add(Operation.UTIMENS); ops.add(Operation.WRITE); + if (enableXattr) { + ops.add(Operation.SET_XATTR); + ops.add(Operation.REMOVE_XATTR); + } return ops; } diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java index acccf6a..e8deaf5 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java @@ -120,7 +120,7 @@ public Mount mount() throws MountFailedException { var builder = Fuse.builder(); builder.setLibraryPath(DYLIB_PATH); var filenameTranscoder = FileNameTranscoder.transcoder().withFuseNormalization(Normalizer.Form.NFD); - var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder); + var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder, false); var fuse = builder.build(fuseAdapter); try { fuse.mount("fuse-nio-adapter", mountPoint, combinedMountFlags().toArray(String[]::new)); diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java index 158052e..ea16e06 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java @@ -119,7 +119,7 @@ public Mount mount() throws MountFailedException { if (mountFlags.contains("-oallow_other") || mountFlags.contains("-oallow_root")) { LOG.warn("Mounting with flag -oallow_other or -oallow_root. Ensure that in /etc/fuse.conf option user_allow_other is enabled."); } - var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder()); + var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder(), true); var fuse = builder.build(fuseAdapter); try { fuse.mount("fuse-nio-adapter", mountPoint, mountFlags.toArray(String[]::new)); diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java index e6ee4ef..ca9120d 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java @@ -115,7 +115,7 @@ public Mount mount() throws MountFailedException { var builder = Fuse.builder(); builder.setLibraryPath(DYLIB_PATH); var filenameTranscoder = FileNameTranscoder.transcoder().withFuseNormalization(Normalizer.Form.NFD); - var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder); + var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder, true); var fuse = builder.build(fuseAdapter); try { fuse.mount("fuse-nio-adapter", mountPoint, combinedMountFlags().toArray(String[]::new)); diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/WinFspMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/WinFspMountProvider.java index 10bdf53..16824f4 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/WinFspMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/WinFspMountProvider.java @@ -119,7 +119,7 @@ public Mount mount() throws MountFailedException { var builder = Fuse.builder(); var libPath = WinfspUtil.getWinFspInstallDir() + "bin\\" + (OS_ARCH.contains("aarch64") ? "winfsp-a64.dll" : "winfsp-x64.dll"); builder.setLibraryPath(libPath); - var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder()); + var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder(), true); try { var fuse = builder.build(fuseAdapter); fuse.mount("fuse-nio-adapter", mountPoint, combinedMountFlags().toArray(String[]::new)); diff --git a/src/test/java/org/cryptomator/frontend/fuse/AccessPatternIntegrationTest.java b/src/test/java/org/cryptomator/frontend/fuse/AccessPatternIntegrationTest.java index 3983878..a28b314 100644 --- a/src/test/java/org/cryptomator/frontend/fuse/AccessPatternIntegrationTest.java +++ b/src/test/java/org/cryptomator/frontend/fuse/AccessPatternIntegrationTest.java @@ -32,7 +32,7 @@ public class AccessPatternIntegrationTest { @BeforeEach void setup(@TempDir Path tmpDir) { var builder = Fuse.builder(); - adapter = ReadWriteAdapter.create(builder.errno(), tmpDir, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder()); + adapter = ReadWriteAdapter.create(builder.errno(), tmpDir, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder(), true); } @Test