29import org.jau.fs.CopyOptions;
30import org.jau.fs.DirItem;
31import org.jau.fs.FMode;
32import org.jau.fs.FileStats;
33import org.jau.fs.FileUtil;
34import org.jau.fs.MountFlags;
35import org.jau.fs.TraverseOptions;
36import org.jau.fs.UnmountFlags;
37import org.jau.io.PrintUtil;
38import org.jau.sys.PlatformProps;
39import org.jau.sys.PlatformTypes;
40import org.junit.Assert;
41import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
45import jau.pkg.PlatformRuntime;
47@FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 static final boolean DEBUG =
false;
51 private static boolean isFolderEmpty(
final String path) {
53 return null == files || 0 == files.size();
56 @Test(timeout = 10000)
62 Assert.assertTrue(
true == root_orig_stats.exists() );
63 Assert.assertTrue(
true == root_orig_stats.is_dir() );
67 final FileStats image_stats = getTestDataImageFile();
68 Assert.assertTrue( true == image_stats.exists() );
70 final String mount_point = root+
"_mount";
71 FileUtil.remove(mount_point, TraverseOptions.recursive);
72 Assert.assertTrue( true == FileUtil.mkdir(mount_point, FMode.def_dir) );
74 final MountFlags mount_flags;
75 if( PlatformProps.OS == PlatformTypes.OSType.LINUX ) {
76 mount_flags = new org.jau.fs.linux.MountFlags();
77 mount_flags.set(org.jau.fs.linux.MountFlags.Bit.rdonly);
79 mount_flags = new MountFlags();
82 final long mctx =
FileUtil.
mount_image(image_stats.path(), mount_point,
"squashfs", mount_flags,
"");
83 Assert.assertTrue( 0 != mctx );
84 Assert.assertFalse(isFolderEmpty(mount_point));
92 final String root_copy =
root+
"_copy_test50";
100 umount_flags.
set(org.jau.fs.linux.UnmountFlags.Bit.detach);
106 Assert.assertTrue(
true == umount_ok );
107 Assert.assertTrue(isFolderEmpty(mount_point));
113 static String test51_devname =
null;
114 static boolean test51_umount =
true;
116 @Test(timeout = 10000)
120 if(
null == test51_devname ) {
124 final String device_file = test51_devname;
125 final FileStats device_stats = new FileStats(device_file);
126 Assert.assertTrue( true == device_stats.exists() );
127 PrintUtil.println(System.err,
"Mount "+device_stats);
129 final String mount_point = root+
"_mount";
130 Assert.assertTrue(isFolderEmpty(mount_point));
131 FileUtil.remove(mount_point, TraverseOptions.recursive);
132 Assert.assertTrue( true == FileUtil.mkdir(mount_point, FMode.def_dir) );
134 final MountFlags mount_flags;
135 if( PlatformProps.OS == PlatformTypes.OSType.LINUX ) {
136 mount_flags = new org.jau.fs.linux.MountFlags();
137 mount_flags.set(org.jau.fs.linux.MountFlags.Bit.rdonly);
139 mount_flags = new MountFlags();
142 final long mctx =
FileUtil.
mount(device_stats.path(), mount_point,
"vfat", mount_flags,
"errors=continue,rodir,sys_immutable,usefree");
143 Assert.assertTrue( 0 != mctx );
144 Assert.assertFalse(isFolderEmpty(mount_point));
147 Assert.assertNotNull(files);
148 Assert.assertTrue(files.size() > 0 );
150 for(
final DirItem item : files) {
152 PrintUtil.fprintf_td(System.err,
"%,4d: %s\n", count, item);
155 if( test51_umount ) {
156 final UnmountFlags umount_flags;
157 if( PlatformProps.OS == PlatformTypes.OSType.LINUX ) {
158 umount_flags = new org.jau.fs.linux.UnmountFlags();
159 umount_flags.set(org.jau.fs.linux.UnmountFlags.Bit.detach);
161 umount_flags = new UnmountFlags();
164 final boolean umount_ok =
FileUtil.
umount(mount_point, umount_flags);
165 Assert.assertTrue(
true == umount_ok );
166 Assert.assertTrue(isFolderEmpty(mount_point));
173 public static void main(
final String args[]) {
174 final int argc = args.length;
175 for(
int i=0; i< argc; i++) {
176 final String arg = args[i];
177 if( arg.equals(
"-mount_device") && args.length > (i+1) ) {
178 test51_devname = args[++i];
179 }
else if( arg.equals(
"-no_umount") ) {
180 test51_umount =
false;
static final FileStats getTestDataDirStats()
void testxx_copy_r_p(final String title, final FileStats source, final int source_added_dead_links, final String dest, final CopyOptions copts, final boolean dest_is_vfat)
void test51_mount_device()
void test50_mount_copy_r_p()
static void main(final String args[])
Filesystem copy options used to copy() path elements.
CopyOptions set(final Bit bit)
Sets the given bit and returns this instance for chaining.
Representing a directory item split into dirname() and basename().
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
Native file types and functionality.
static long mount_image(final String image_path, final String target, final String fs_type, final MountFlags flags, final String fs_options)
Attach the filesystem image named in image_path to target using an intermediate platform specific fil...
static boolean umount(final long context, final UnmountFlags flags)
Detach the given mount_ctx context
static boolean remove(final String path, final TraverseOptions topts)
Remove the given path.
static native List< DirItem > get_dir_content(final String path)
Returns a list of directory elements excluding .
static long mount(final String source, final String target, final String fs_type, final MountFlags flags, final String fs_options)
Attach the filesystem named in source to target using the given filesystem source directly.
Filesystem traverse options used to visit() path elements.
static final TraverseOptions recursive
Generic flag bit class for umount() flags
UnmountFlags set(final Bit bit)
UnmountFlags(final int v)
static void println(final PrintStream out, final String msg)
Convenient PrintStream#println(String) invocation, prepending the elapsedTimeMillis() timestamp.
sync
Ensure data and meta-data file synchronization is performed via ::fsync() after asynchronous copy ope...
recursive
Traverse through directories, i.e.
preserve_all
Preserve uid and gid if allowed and access- and modification-timestamps, i.e.
verbose
Enable verbosity mode, show error messages on stderr.