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) {
52 final List<DirItem> files = FileUtil.get_dir_content(path);
53 return null == files || 0 == files.size();
56 @Test(timeout = 10000)
57 public
void test50_mount_copy_r_p() {
58 PlatformRuntime.checkInitialized();
59 PrintUtil.println(System.err,
"test50_mount_copy_r_p\n");
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";
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();
81 PrintUtil.println(System.err,
"MountFlags for "+PlatformProps.OS+
": "+mount_flags);
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));
86 final CopyOptions copts =
new CopyOptions();
87 copts.set(CopyOptions.Bit.recursive);
88 copts.set(CopyOptions.Bit.preserve_all);
89 copts.set(CopyOptions.Bit.sync);
90 copts.set(CopyOptions.Bit.verbose);
92 final String root_copy = root+
"_copy_test50";
93 FileUtil.remove(root_copy, TraverseOptions.recursive);
94 testxx_copy_r_p(
"test50_mount_copy_r_p",
new FileStats(mount_point), 1 , root_copy, copts,
false );
95 Assert.assertTrue(
true == FileUtil.remove(root_copy, TraverseOptions.recursive) );
97 final UnmountFlags umount_flags;
98 if( PlatformProps.OS == PlatformTypes.OSType.LINUX ) {
99 umount_flags =
new org.jau.fs.linux.UnmountFlags();
100 umount_flags.set(org.jau.fs.linux.UnmountFlags.Bit.detach);
102 umount_flags =
new UnmountFlags();
104 PrintUtil.println(System.err,
"UnmountFlags for "+PlatformProps.OS+
": "+umount_flags);
105 final boolean umount_ok = FileUtil.umount(mctx, umount_flags);
106 Assert.assertTrue(
true == umount_ok );
107 Assert.assertTrue(isFolderEmpty(mount_point));
109 Assert.assertTrue(
true == FileUtil.remove(mount_point, TraverseOptions.recursive) );
113 static String test51_devname =
null;
114 static boolean test51_umount =
true;
116 @Test(timeout = 10000)
117 public
void test51_mount_device() {
118 PlatformRuntime.checkInitialized();
119 PrintUtil.println(System.err,
"test51_mount_device\n");
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();
141 PrintUtil.println(System.err,
"MountFlags for "+PlatformProps.OS+
": "+mount_flags);
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));
146 final List<DirItem> files = FileUtil.get_dir_content(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();
163 PrintUtil.println(System.err,
"UnmountFlags for "+PlatformProps.OS+
": "+umount_flags);
164 final boolean umount_ok = FileUtil.umount(mount_point, umount_flags);
165 Assert.assertTrue(
true == umount_ok );
166 Assert.assertTrue(isFolderEmpty(mount_point));
168 Assert.assertTrue(
true == FileUtil.remove(mount_point, TraverseOptions.recursive) );
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[])