Hello everyone, I developed an app which utilizes database.
I implemented a method for backing up the database from /data/data/package_name/databases to the SDCARD wiith the following code
Code:
try {
File path_to_sd = Environment.getExternalStorageDirectory();
File path_to_data = Environment.getDataDirectory();
String current_db_path = "//data//" + getPackageName() + "//databases//";
String path_to_database = path_to_data.getAbsolutePath() + current_db_path;
String backup_name = "backup.db";
File current_db = new File(path_to_database, database_name);
File db_backup = new File(path_to_sd, backup_name);
FileChannel src = new FileInputStream(current_db).getChannel();
FileChannel dst = new FileOutputStream(db_backup).getChannel();
if(!db_backup.exists()){
try {
db_backup.createNewFile();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Exporting database done successfully!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
the thing is that the above code did the job but created a file with the following permissions ---rwxr-x
so my method for importing the database file from the SDCARD back to the /data/data/pachage_name/databases fail at the line
FileChannel src = new FileInputStream(current_db).getChannel();
and the error is that, no read permission for this file.
How can I fix this issue?
thanks a lot.
needed root
shakash3obd said:
Hello everyone, I developed an app which utilizes database.
I implemented a method for backing up the database from /data/data/package_name/databases to the SDCARD wiith the following code
Code:
try {
File path_to_sd = Environment.getExternalStorageDirectory();
File path_to_data = Environment.getDataDirectory();
String current_db_path = "//data//" + getPackageName() + "//databases//";
String path_to_database = path_to_data.getAbsolutePath() + current_db_path;
String backup_name = "backup.db";
File current_db = new File(path_to_database, database_name);
File db_backup = new File(path_to_sd, backup_name);
FileChannel src = new FileInputStream(current_db).getChannel();
FileChannel dst = new FileOutputStream(db_backup).getChannel();
if(!db_backup.exists()){
try {
db_backup.createNewFile();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Exporting database done successfully!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
the thing is that the above code did the job but created a file with the following permissions ---rwxr-x
so my method for importing the database file from the SDCARD back to the /data/data/pachage_name/databases fail at the line
FileChannel src = new FileInputStream(current_db).getChannel();
and the error is that, no read permission for this file.
How can I fix this issue?
thanks a lot.
Click to expand...
Click to collapse
since u r trying to copy files to /data/data which is only read only mode ... so u need root access to do your job.....
i have attached a a zip file that contains 4 java files and can be included in your project...
it gives you root access... but writing to /data/data must be implemented by u...
Thank you so much anurag.dev1512.
I will take a look at the files you provided.
I will not be able to get back to you about the result soon since it's almost finals time so I will be busy until December
again, thanks a lot.:good:
How to install this:
1. put copymodulecrc to the /data/local/tmp folder and chmod them to 755
(adb shell chmod 755 /data/local/tmp/copymodulecrc)
2. put ntfs-3g and ntfsmount to the folder /system/bin and chmod them to 755
(adb shell chmod 755 /system/bin/ntfs-3g)
(adb shell chmod 755 /system/bin/ntfsmount)
3. put sdcardfs.ko to the folder /system/lib/modules and chmod them to 644
(adb shell chmod 644 /system/lib/modules/sdcardfs.ko)
What is next? Next:
1. in order to get it working, sdcardfs.ko must be patched to match your kernel version since every kernel modules is paired with kernel by version string, so if version string not match module version it will not work! So you must patch sdcardfs.ko module using tool called copymodulecrc! Copymodulecrc will extract version string from any module of the your stockrom kernel modules and copy them directly to the sdcardfs.ko (patch them). First of all you need to look into your /system/lib/modules folder and use any .ko file NAME for referencie in next commands:
Code:
adb shell /data/local/tmp/copymodulecrc /system/lib/modules/PUT_NAME_OF_THE_KO_YOU_FOUND_IN_STOCK_ROM_KERNEL_MODULES /system/lib/modules/sdcardfs.ko
So replace PUT_NAME_OF_THE_KO_YOU_FOUND_IN_STOCK_ROM_KERNEL_MODULES with the name of the any module you found in modules folder! Done.
2. if you completed step 1 without errors you are ready for this step. You need to locate script called install-recovery.sh (on most devices it is in folder /system/etc) and add next lines:
Code:
insmod /system/lib/modules/sdcardfs.ko
Done. On every next reboot sdcardfs kernel module will be automatically included in your kernel.
3. if you get error in patching sdcardfs.ko whole thing will not work! So these step is important! You can verify success by command: (su -c "insmod /system/lib/modules/sdcardfs.ko") , if you see error than sdcardfs is not working, if you see nothing than it is working
Since you completed these 3 things, you are ready to use NTFS volumes on your device! To understand these things:
1. first of all, you can not mount ntfs volume regulary trought settings menu since android not support ntfs by default! You must mount/umount your ntfs volume manually (you can use for example android terminal emulator when you need to mount/umount ntfs). You will not see any details about ntfs volume in settings menu since android not support ntfs by default, you can see details in most file managers only.
How to mount and unmount:
1. to mount (first connect your usb ntfs volume to your device usb port) :
Code:
su -c "ntfsmount mount"
Done! Your ntfs volume by these command is mounted and you are ready to read/write them using your faworite file manager
2. To umount (do in mind - every time before you going to remove ntfs volume from your device you must unmount it!):
Code:
su -c "ntfsmount umount"
Done! You are ready to remove ntfs volume from your usb port.
NTFS on sdcard? Yes but you need to modify a bit ntfsnount script! Don't ask me how ypu can modify them, do it byself!
Since somebody complain here about gpl licence, I am not ready ready to share sdcardfs source code with you since it is not gpl licenced, instead it is apache 2.0 licenced by Samsung guys @ 2013 and I no need to share it with you since you wanted to see them forced! I not like when somebody forcing me for something! Find it, patch them, make module of them byself
ntfs-3g is not compiled by me, it is used from here -> http://forum.xda-developers.com/showthread.php?t=1724078
ntfsmount script is created by me.
Copymodulecrc I do not know where I found them but here is source code:
Code:
/* copymodulecrc */
/*
* Copyright (C) 2014 CUBE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
int main(int argc, char **argv) {
struct stat st;
off_t filesize;
int fd;
char *data, *pos;
unsigned int i;
int bFound;
unsigned long crcval;
if (argc != 3) {
printf("usage: copymodulecrc [modulename(src)] [modulename(dst)]\n");
return -1;
}
if (stat(argv[1], &st) != 0) {
fprintf(stderr, "module1 stat failed.\n");
return -1;
}
filesize = st.st_size;
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "module1 open failed.\n");
return -1;
}
data = mmap(NULL, filesize, PROT_READ, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "module1 mmap failed.\n");
close(fd);
return -1;
}
pos = data;
bFound = 0;
for (i = 0; i < (filesize - 12); ++i) {
if (memcmp((void *)pos, (void *)"module_layout", 13) == 0) {
bFound = 1;
break;
}
pos++;
}
if (bFound == 0) {
fprintf(stderr, "module1 crc not found.\n");
munmap(data, filesize);
close(fd);
return -1;
}
pos -= 4;
memcpy((void *)&crcval, (void *)pos, 4);
munmap(data, filesize);
close(fd);
printf("module crc=%08x\n", (unsigned int)crcval);
if (stat(argv[2], &st) != 0) {
fprintf(stderr, "module2 stat failed.\n");
return -1;
}
filesize = st.st_size;
fd = open(argv[2], O_RDWR);
if (fd < 0) {
fprintf(stderr, "module2 open failed.\n");
return -1;
}
data = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "module2 mmap failed.\n");
close(fd);
return -1;
}
pos = data;
bFound = 0;
for (i = 0; i < (filesize - 12); ++i) {
if (memcmp((void *)pos, (void *)"module_layout", 13) == 0) {
bFound = 1;
break;
}
pos++;
}
if (bFound == 0) {
fprintf(stderr, "module2 crc not found.\n");
munmap(data, filesize);
close(fd);
return -1;
}
pos -= 4;
memcpy((void *)pos, (void *)&crcval, 4);
munmap(data, filesize);
close(fd);
printf("module crc copied.\n");
return 0;
}
And finaly, files you need to install is in attachment, enjoy!
Will try late-night. Just asking, will it work on Galaxy S3-GTi9300?
Just need some clarification, when you say NTFS support, do you mean read and write or just read-only?
munjeni said:
Not going to explain in details, here is my tool which will add ntfs support to your android, run them and folow instructions! If you unable to patch sdcardfs.ko kernel module (giving you error when you doing insmod) than the whole things will not work on your device Curntly tested device is Xperia Z1 Compact on android version 14.4.A.0.108! Important thing is having sdcardfs installable, the rest is easy.
In order to have sdcardfs module insmoded on every reboot, you need to add one line into /system/etc/install-recovery.sh :
The rest of the tutorial you can see under application. Enjoy if you find this usefull!
Click to expand...
Click to collapse
/system/etc/install-recovery.sh :-
- install-recovery.sh file is not available at /system/etc/.
- Is it possible to create the file and then we can insert the line?
Am using AOSP - Carbon ROM on Xperia Z..
Thank you!!
'A Munjeni Work' again!
Thanks a lot! :victory:
Looking forward for what all can I do with it.
Wow this will be amazing, cant wait to try...
anonyo said:
Just need some clarification, when you say NTFS support, do you mean read and write or just read-only?
Click to expand...
Click to collapse
+1
anonyo said:
Just need some clarification, when you say NTFS support, do you mean read and write or just read-only?
Click to expand...
Click to collapse
Quote!
Just a heads up..
On Xperia Z2 tablet with 4.4.2, connected to 1tb NTFS drive.
After modding the ko and setting all permissions, rebooting, will only "half-mount" the drive. It sees it, recognizes it, but claims drive is empty (wants to format it).
Status bar displays "Empty USB Storage"
In settings, when selecting Mount USB Storage, it briefly acts like it will mount. for a split second.
Any files I can get that can possibly help?
UPDATE: After running the mount commands via terminal, now it seems to mount it via ES File explorer. Although it sometimes still gives me the message in statusbar.
But seems to be working well.
Seeing as this patches a kernel module will it work on rooted phones with a locked bootloader?
Aborto said:
Seeing as this patches a kernel module will it work on rooted phones with a locked bootloader?
Click to expand...
Click to collapse
My Z2 Tablet has a locked bootloader. So yes, it should. There's nothing going on that warrants an unlocked bootloader. Just the addition of some files and permission changes, which are normal with a rooted device.
Also note, that in the Settings\Storage, it will not show up as being "mounted". At least not in my case. However, ES File Explorer has no issue with it, and shows as a USB 1052 drive under the "Local" menu. Navigation seems normal within the drive.
I get the "USB Drive Empty or Unsupported" message in the status bar, for a few seconds, but the ES FE displays the drive contents, and the message goes away after it reads drive contents. Note that it may assign a different drive identifier each time you use it.
In testing I have found apps from the market;
StickMount does not work at all on my Stock OS.
Paragon NTFS mount works, but it runs as a system process using memory and probably battery.
This mod seems to work, for the most part, as long as you use ES File Explorer.
OP - you must provide the source for any modified code covered by the GPL that you are distributing - that includes the sdcardfs kernel module, and the ntfs-3g binary. Packing them in an encrypted Windows executable does not help.
spoidar said:
OP - you must provide the source for any modified code covered by the GPL that you are distributing - that includes the sdcardfs kernel module, and the ntfs-3g binary. Packing them in an encrypted Windows executable does not help.
Click to expand...
Click to collapse
No he doesn't. Only the zimage (kernel) is covered under GPL.
UPDATE: Just to clarify, the matter "Has" been brought to the Developers Committee to address any possible GPL violations. The DC is more informed on GPL.
Moscow Desire said:
No he doesn't. Only the zimage (kernel) is covered under GPL.
Click to expand...
Click to collapse
What? No. The ntfs-3g project is licensed under the GPL. And so is the sdcardfs driver. You can't generate binaries from GPL code and distribute them without providing the source.
Need help here
After i Copy copymodulecrc and sdcardfs.ko to /data/local/tmp and gave the permission as rwx-r-r to copymodulecrc. how to run it? can anybody help me here to patch sdcardfs.ko
coolrevi said:
After i Copy copymodulecrc and sdcardfs.ko to /data/local/tmp and gave the permission as rwx-r-r to copymodulecrc. how to run it? can anybody help me here to patch sdcardfs.ko
Click to expand...
Click to collapse
First off, permissions must be set to 755 (rwx-rx-rx) if I'm not mistaken. Root Explorer converts it to the numerical format when you change permissions.
Next, use a terminal program (available from the play store) Make sure you run it as SU. (type SU + Enter, you will get the # sign) Then type in the commands and paths as indicated. (I copied and pasted my paths)
Moscow Desire said:
First off, permissions must be set to 755 (rwx-rx-rx) if I'm not mistaken. Root Explorer converts it to the numerical format when you change permissions.
Next, use a terminal program (available from the play store) Make sure you run it as SU. (type SU + Enter, you will get the # sign) Then type in the commands and paths as indicated. (I copied and pasted my paths)
Click to expand...
Click to collapse
I got it till replacing a line in install-recovery.sh but i am stuck there as there is no line called ntfs.ko to replace with
Thanks for posting this up, can't wait to get home and test this out.
I am recieving the error in the screenshot
The device that i am using is Lenovo A3500HV which contains a Jellybean 4.2.2 AOSP ROM (Hardly any modification)
Please Help
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Hi together,
last year I've installed a 1st-Gen FireTV with Kodi in combination with a 4TB USB HDD for my parents RV. Don't exactly remember how I got the 4TB disk to fat32, but google should provide the answer, since it did for me than. The bigger issue anyway was to get files bigger than 4GB on the disk. The trick for my was to find out, that Kodi can access *.rar archives as if it was a file. So I wrote a java "dirtyhack": It uses a combination of java and WinRAR. Java to determine if a file is bigger than 4GB or not. If it is smaller, just copy the file, if it is bigger, call WinRAR with the right parameters to create a splittet archive consisting of parts smaller than 4GB on the HDD.
So first you choose a source-folder, than select a destination-folder (should be the Disk ) and all files get copied recursively.
As I'm currently updating the HDD and have unsuccessfully searched for an easier way (after I've installed all updates on the ftv *doh!*) I thought I could share my Code, so here you go:
Code:
import javax.swing.*;
import java.io.IOException;
import java.io.*;
/**
* @author der-gee
*
*/
public class Copy {
static int amountFiles = 0;
static long limit = 4294967295L;
/**
* Lists all files from a given folder, recursively
*
* @param dir
* Prints a list of files > 4GB and sums them up
*/
public static void listDir(File dir) {
File[] files = dir.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
listDir(files[i]); // calls itself
} else {
if (files[i].length() > limit) {
System.out.println(files[i].getAbsolutePath());
amountFiles++;
}
}
}
}
}
/**
* Shows a select file dialog and returns the choosen one ^^
*
* @param title
* Title to be shown by the "choose file dialog"
* @return The directory as file
*/
static public File getFolder(String title) {
JFileChooser chooser;
chooser = new JFileChooser();
chooser.setCurrentDirectory(File.listRoots()[0]);
chooser.setDialogTitle(title);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
return chooser.getSelectedFile();
} else {
System.out.println("No Selection ");
return null;
}
}
/**
* Copies directories and files smaller than 4GB
*
* @param src
* @param dest
* @throws IOException
*/
public static void copyFolder(File src, File dest) throws IOException {
if (src.isDirectory()) {
// if directory not exists, create it
if (!dest.exists()) {
dest.mkdir();
System.out.println("Directory copied from " + src + " to "
+ dest);
}
// list all the directory contents
String files[] = src.list();
for (String file : files) {
// construct the src and dest file structure
File srcFile = new File(src, file);
File destFile = new File(dest, file);
// recursive copy
copyFolder(srcFile, destFile);
}
} else {
// if file, then copy it
// Use bytes stream to support all file types
// If file is t large for Fat32 -> rar it
if (src.length() >= limit)
rarThis(src, dest);
else {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
// copy the file content in bytes
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
System.out.println("File copied from " + src + " to " + dest);
System.out.println("Size from: " + src + ":" +src.length());
}
}
}
/**
* Should use a combination of cmd and winrar to create splitted archives,
* so that they can be stored to a fat32 drive.
*
* @param src
* @param dest
*/
public static void rarThis(File src, File dest) {
String[] command = {
"\"" + "C:\\Program Files\\WinRAR\\rar.exe" + "\"",
"a", "-m0", //a = Archive, -m0 = compressionMode store
"-v3.999g", "-y", //v = VolSize, y = always answer yes
"-ep", //ep = noPath in archive
"\"" + dest.getAbsolutePath().replace("mkv", "rar") + "\"",
"\"" + src.getAbsolutePath() + "\"" };
Runtime rt = Runtime.getRuntime();
try {
Process rar = rt.exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(rar.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
System.out.println("WinRAR: " + line);
rar.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
}
}
/**
* Main program. Initiates the whole thing :)
*
* @param s
* @throws IOException
*/
public static void main(String s[]) throws IOException {
System.out.println("Size limit: " + limit);
File sourcePath = getFolder("Source");
if (sourcePath != null) {
listDir(sourcePath);
System.out.println("Amount files > 4GB: " + amountFiles);
}
File targetPath = getFolder("Destination");
copyFolder(sourcePath, targetPath);
System.out.println("Finished!");
}
}
I wrote this for Windows, using the x64 Version of WinRar, so if you are using the 32-bit version, you have to adjust the rar folder in the rarThis function. Feel free to use and share. If you have improvements, please share
Interesting. When I came to this problem of HD files larger than 4 GB I decided to use the NTFS format and then use Paragon to mount the external HDD on my rooted Fire TV.
PhoenixMark said:
Interesting. When I came to this problem of HD files larger than 4 GB I decided to use the NTFS format and then use Paragon to mount the external HDD on my rooted Fire TV.
Click to expand...
Click to collapse
Hehe, I would have done the same, but I checked for root after upgrading to the very last fw version
PhoenixMark said:
Interesting. When I came to this problem of HD files larger than 4 GB I decided to use the NTFS format and then use Paragon to mount the external HDD on my rooted Fire TV.
Click to expand...
Click to collapse
Was this on the latest rooted firmware? I have a AFTV2 running the latest prerooted rom from rbox
deanr1977 said:
Was this on the latest rooted firmware? I have a AFTV2 running the latest prerooted rom from rbox
Click to expand...
Click to collapse
I'm using 5.0.5 because I like using FireStarter, but I don't see why you can't still do this on 5.0.5.1 as well as there is a pre rooted rom for it. Only difference is you need the A to A USB cable to root 5.0.5.1.