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)
57 public
void test50_mount_copy_r_p() {
61 final FileStats root_orig_stats = getTestDataDirStats();
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";
76 mount_flags =
new org.jau.fs.linux.
MountFlags();
77 mount_flags.
set(org.jau.fs.linux.MountFlags.Bit.rdonly);
83 Assert.assertTrue( 0 != mctx );
84 Assert.assertFalse(isFolderEmpty(mount_point));
92 final String root_copy = root+
"_copy_test50";
94 testxx_copy_r_p(
"test50_mount_copy_r_p",
new FileStats(mount_point), 1 , root_copy, copts,
false );
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)
117 public
void test51_mount_device() {
120 if(
null == test51_devname ) {
124 final String device_file = test51_devname;
126 Assert.assertTrue(
true == device_stats.
exists() );
129 final String mount_point = root+
"_mount";
130 Assert.assertTrue(isFolderEmpty(mount_point));
136 mount_flags =
new org.jau.fs.linux.
MountFlags();
137 mount_flags.
set(org.jau.fs.linux.MountFlags.Bit.rdonly);
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) {
155 if( test51_umount ) {
159 umount_flags.
set(org.jau.fs.linux.UnmountFlags.Bit.detach);
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 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().
Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.
static final FMode def_dir
Default directory protection bit: Safe default: POSIX S_IRWXU | S_IRGRP | S_IXGRP or rwx_usr | read_g...
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
String path()
Returns the unix path representation.
boolean exists()
Returns true if entity does not exist, exclusive bit.
boolean is_dir()
Returns true if entity is a directory, might be in combination with is_link().
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 mkdir(final String path, final FMode mode)
Create directory.
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.
Generic flag bit values for mount() flags.
MountFlags set(final Bit bit)
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 fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
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.