From 8ce1ed49dd5a8a13feb3eca8f36ca3ac0cc80a12 Mon Sep 17 00:00:00 2001 From: axtloss Date: Wed, 24 May 2023 22:48:05 +0200 Subject: Allow creating containers --- src/main/java/io/github/jshipit/Mount.java | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/main/java/io/github/jshipit/Mount.java (limited to 'src/main/java/io/github/jshipit/Mount.java') diff --git a/src/main/java/io/github/jshipit/Mount.java b/src/main/java/io/github/jshipit/Mount.java new file mode 100644 index 0000000..63b60dd --- /dev/null +++ b/src/main/java/io/github/jshipit/Mount.java @@ -0,0 +1,48 @@ +package io.github.jshipit; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.Platform; + +public class Mount { + public interface CLibrary extends Library { + int mount(String source, String target, + String filesystemtype, int mountflags, + String data); + + int umount(String target); + } + + public void mount(String source, String target, + String filesystemtype, int mountflags, + String data) { + CLibrary libc; + + if (Platform.isLinux()) { + libc = Native.load("c", CLibrary.class); + int result = libc.mount(source, target, filesystemtype, mountflags, data); + if (result == 0) { + System.out.println("Device mounted successfully."); + } else { + System.out.println("Device mount failed."); + } + } + } + + public void overlayMount(String[] lower, String upper, String target) { + CLibrary libc; + + if (Platform.isLinux()) { + libc = Native.load("c", CLibrary.class); + int result = libc.mount("overlay", target, "overlay", 0, "lowerdir="+String.join(":", lower)+",upperdir="+upper+",workdir="+target+"/work"); + if (result == 0) { + System.out.println("Device mounted successfully."); + } else { + System.out.println("Device mount failed."); + } + } else { + System.out.println("Platform not supported."); + System.out.println("mount -t overlay overlay -o lowerdir="+String.join(":", lower)+",upperdir="+upper+",workdir="+target+"/work "+target); + } + } +} -- cgit v1.2.3