// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/DirectoryFiller.java
// public interface DirectoryFiller {
// 
// 	int add(String name, Path path)
// 			throws IOException;
// 
// 	int addWithExtraSize(String name, Path path, long extraSize)
// 			throws IOException;
// }
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/FileSystem.java
// public interface FileSystem {
// 
// 	String getFSName();
// 
// 	int getattr(String path, StatFiller stat);
// 
// 	int readdir(String path, DirectoryFiller filler);
// 
// 	int readLink(String path, Consumer<String> buf, int size);
// 
// 	int open(String path, FileHandleFiller filler);
// 
// 	int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle);
// 
// 	int release(String path, int fileHandle);
// 
// 	void destroy();
// }


import jnr.ffi.types.off_t;
import jnr.ffi.types.size_t;
import ru.serce.jnrfuse.ErrorCodes;
import ru.serce.jnrfuse.FuseFillDir;
import ru.serce.jnrfuse.FuseStubFS;
import ru.serce.jnrfuse.struct.FileStat;
import ru.serce.jnrfuse.struct.FuseFileInfo;
import se.tfiskgul.mux2fs.fs.base.DirectoryFiller;
import se.tfiskgul.mux2fs.fs.base.FileSystem;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException;
import java.nio.file.Path;
import jnr.ffi.Pointer;
import jnr.ffi.Runtime;
/*
MIT License

Copyright (c) 2017 Carl-Frederik Hallberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 */
package se.tfiskgul.mux2fs.fs.jnrfuse;




public final class JnrFuseWrapperFileSystem extends FuseStubFS implements NamedJnrFuseFileSystem {

	private final FileSystem delegate;

	public JnrFuseWrapperFileSystem(FileSystem delegate) {
		this.delegate = delegate;
	}

	@Override
	public String getFSName() {
		return delegate.getFSName();
	}

	@Override
	public int getattr(String path, FileStat stat) {
		JnrFuseUnixFileStat unixFileStat = new JnrFuseUnixFileStat();
		int result = delegate.getattr(path, unixFileStat);
		if (result == 0) {
			unixFileStat.fill(stat);
		}
		return result;
	}

	@Override
	public int readdir(String path, Pointer buf, FuseFillDir filter, long offset, FuseFileInfo fi) {
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/DirectoryFiller.java
// public interface DirectoryFiller {
// 
// 	int add(String name, Path path)
// 			throws IOException;
// 
// 	int addWithExtraSize(String name, Path path, long extraSize)
// 			throws IOException;
// }
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/FileSystem.java
// public interface FileSystem {
// 
// 	String getFSName();
// 
// 	int getattr(String path, StatFiller stat);
// 
// 	int readdir(String path, DirectoryFiller filler);
// 
// 	int readLink(String path, Consumer<String> buf, int size);
// 
// 	int open(String path, FileHandleFiller filler);
// 
// 	int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle);
// 
// 	int release(String path, int fileHandle);
// 
// 	void destroy();
// }


// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/jnrfuse/JnrFuseWrapperFileSystem.java
import jnr.ffi.types.off_t;
import jnr.ffi.types.size_t;
import ru.serce.jnrfuse.ErrorCodes;
import ru.serce.jnrfuse.FuseFillDir;
import ru.serce.jnrfuse.FuseStubFS;
import ru.serce.jnrfuse.struct.FileStat;
import ru.serce.jnrfuse.struct.FuseFileInfo;
import se.tfiskgul.mux2fs.fs.base.DirectoryFiller;
import se.tfiskgul.mux2fs.fs.base.FileSystem;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException;
import java.nio.file.Path;
import jnr.ffi.Pointer;
import jnr.ffi.Runtime;

/*
MIT License

Copyright (c) 2017 Carl-Frederik Hallberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 */
package se.tfiskgul.mux2fs.fs.jnrfuse;




public final class JnrFuseWrapperFileSystem extends FuseStubFS implements NamedJnrFuseFileSystem {

	private final FileSystem delegate;

	public JnrFuseWrapperFileSystem(FileSystem delegate) {
		this.delegate = delegate;
	}

	@Override
	public String getFSName() {
		return delegate.getFSName();
	}

	@Override
	public int getattr(String path, FileStat stat) {
		JnrFuseUnixFileStat unixFileStat = new JnrFuseUnixFileStat();
		int result = delegate.getattr(path, unixFileStat);
		if (result == 0) {
			unixFileStat.fill(stat);
		}
		return result;
	}

	@Override
	public int readdir(String path, Pointer buf, FuseFillDir filter, long offset, FuseFileInfo fi) {
		DirectoryFiller filler = new FuseDirectoryFiller(buf, filter);