1

I need to be able to write textfiles to the root directory of my Android device (as this related questions explains).

Can I change write permissions for root directory / and if so, how?

I tried pushing a file using adb, but it said file system was read-only =(

Its pretty annoying that I cannot control my own device, that everything is so restricted =(


EDIT 1: This thread has evolved into discussing Sygic Navigation and their API, which seems to be wrong when it comes to the Android platform. I have some other questions that discuss Sygic and their navigation software.

Community
  • 1
  • 1
Ted
  • 19,727
  • 35
  • 96
  • 154
  • 4
    You should review your design, not changing permissions on protected directories. – Diego Torres Milano Jan 18 '10 at 18:07
  • 1
    Why can't you simply save the file to a location on the file system you DO have write access to? – jason Jan 18 '10 at 18:31
  • Hey guys... Sorry if I sound a bit rude now, but I really dislike answers that doesnt answer the question but instead give some "smart" remark och "why dont you do THIS instead...". There are many different reasons why a developer needs to do certain things - thats just a fact. – Ted Jan 18 '10 at 18:55
  • In my case, im using an external app that I have no control over whatsoever, and according to their API: *The application reads and parses the .in file when it's placed in root directory on the mobile device.* And there we have the reason why I dont save the file anywhere else and I cannot "review" my design. – Ted Jan 18 '10 at 18:56
  • 3
    Ted, if you provided all the information you might not get these answers that you dislike. What is the specific application that is telling you it needs to read a file from the root directory? Are you certain it's not the root of the SD card that it is referring to? – Mark B Jan 18 '10 at 19:13
  • 2
    "In my case, im using an external app that I have no control over whatsoever, and according to their API: 'The application reads and parses the .in file when it's placed in root directory on the mobile device.'" -- Then stop using that "external app", whatever "external app" means. It clearly isn't an Android APK, as they wouldn't be shipping something that required the ability to write to the root directory. If the "external app" is some C app, you will need the source for it to convert it into an NDK library, anyway, and perhaps you can fix up its file access to be more sensible. – CommonsWare Jan 18 '10 at 19:24
  • mbaird: I have tried a few other locations, SD-card is one of them, and that doesnt work. So Im guessing that they are really talking about the root... – Ted Jan 18 '10 at 19:38
  • commonsware: its not like I have a choice. There are a very limited number of navigation software out there that runs on Android. No, I cannot use Google Maps since nav support must work even when they do not have GPRS/3G coverage. Yes, I can look for other nav software, but before I move on to do that, I really need to determine for sure that I cannot use this app (Sygic). Its not just to give up right off, then I might never find anything that works. – Ted Jan 18 '10 at 19:41
  • commonsware: Also, I have the application installed in my Android device as we speak. Im not sure how to determine if it is an "APK" or not. I can however start the specific Activity: *com.sygic.drive.SygicDriveActivity* ... – Ted Jan 18 '10 at 19:47
  • mbaird: I dont think that explaining every single detail every time I ask a question would be the best approach. That would be very lengthy. If I ask a question to do a specific thing, I have a reason for it. Its one thing to politely give a pointer, but not like "you should review your design" or "simple save the file somewhere else"... =) – Ted Jan 18 '10 at 19:55
  • 3
    But Ted, the people commenting here are right -- a design review *is* required. Now that you've given us sufficient info as to *why* you need to do this, we can definitely say it's the wrong approach -- by the third-party developer. :) Looking at their API documentation, there's no mention of Android so one can only assume (and hope) that they've not updated it for Android yet. I've used file-based "APIs" like this before for TomTom -- it's horrendous. On Android, there's at least a well-defined Service IPC mechanism that they could and should be using. – Christopher Orr Jan 18 '10 at 20:24
  • But Ted, the software isn't the *only* software that *might* work, because it **doesn't** work. I have other things to do than argue this point with you. You will eventually discover that this solution you are trying to hack together just wont cut it, as it requires you to do things that you should not be doing (Unless the company replies to you with another solution). Either that or you will decide to go a route similar to trying to root kit every potential device you want your software to run on, if so good luck. Oh and thanks for the down vote. – Tom Neyland Jan 18 '10 at 20:29
  • Christpher: yes, the API does not specifically mention Android, but I have been in contact with their support and they said nothing about it not working on android. Im am waiting for further replies from them, they are slow on email unfortunately... – Ted Jan 18 '10 at 20:46
  • Tnay: Im not forcing you to argue with me, its a free choice ;-) No, its not the only software that might work, but the only software that I found that comes close. Any other suggestions are appreciated. And as I said, and as you reiterated, the "rooting" of every device *can* be done but I dont think we will go down that path. basically, if I cant find a nav software that meets the requirements (as stated here http://stackoverflow.com/questions/2088863/offline-navigation-software-for-android-what-is-out-there) then we will have to drop the Android-platform and continue on Windows Mobile =( – Ted Jan 18 '10 at 20:50

8 Answers8

6

Only if you have root access.

Mark B
  • 183,023
  • 24
  • 297
  • 295
5

This worked with me:

mount -o rw,remount -t rootfs /

Got it from here: http://www.pocketmagic.net/?p=757

Mohamed Nour
  • 65
  • 1
  • 5
3

Not by default. The root filesystem shipped on official Android devices is read-only, and only certain well-constrained areas are writable by applications. There are root exploits for many Android devices available, however, which allow you to do whatever you want to your filesystem.

Andy Ross
  • 11,699
  • 1
  • 34
  • 31
  • Yes, unfortunately "rooting" every device that is to use this solution is probably not an option =( Damn, every single thing I try to do in android doesnt work for this or that reason =( – Ted Jan 18 '10 at 18:53
3

If you want to get creative and bypass the (idiotic) / requirement without root privileges, you could use fakechroot, an LD_PRELOAD library from debian.

Edit: this is probably impossible for a java program, due to the way vm instances are forked out. A native program would have to contend with an unhelpful linker (no LD_PRELOAD), but if arbitrary programs can be started, an alternative linker won't need root privileges.

Tobu
  • 24,771
  • 4
  • 91
  • 98
  • +1 I be interested to know if a solution like this will work. – Tom Neyland Jan 18 '10 at 21:18
  • Hmm, Im not a Linux-guy... so messing around with libraries from Debian seems like out of my area of knowledge unfortunately ;-) I'll give it a upvote for "good idea" and thinking out of the box anyways =) – Ted Jan 18 '10 at 21:23
2

the ROOT is called that for a reason, the ROOT user is called that for the same reason. Anyone other than ROOT that owned / would be wrong and violate every UNIX principal of security. You can't do this for a GOOD reason, trying to do this is BAD.

  • As I stated before: I dont have a choice. From what I can see from the API Im trying to use, I need to be able to write text files to root. I have contacted the company that has provided the app, but as it stands now... – Ted Jan 18 '10 at 20:12
  • I downvoted it, because it's wrong and pedantic. First, almost all deployed software is done via some interaction with the root environment. As it happens, Android specifically (not "every UNIX principle of security") disallows root access. For some good reasons, and some not-so-good reasons. Flaming the poster for wanting to do something useful with his phone is counterproductive, and designing according to rules like this ("don't use root?!") is going to lead to bad software. – Andy Ross Jan 18 '10 at 21:54
  • that is what sudo is for, telling someone that it is ok to chown ROOT is what is wrong –  Jan 19 '10 at 03:33
  • Yet android (the platform at hand) doesn't support sudo or root (note spelling: "ROOT" is not a standard user) access, thus the question, thus my response that your answer was missing the point. It's not about unix security models, it's a specific question about how Android (a rather different system, c.f. the ro-mounted root filesystem) implements it's own security model. – Andy Ross Jan 19 '10 at 18:54
2

I've had a quick look at the Sygic API Documentation. It does indeed say that input files come from the root directory. It also says that output files will be placed in the root directory. It even puts "root directory" in bold so you know that they're really serious that this is where the data files go.

As has been discussed, no Android application will have permission to write to this directory on a standard phone, so the Sygic documentation must be wrong. My guess is that this is the behaviour for other platform Sygic runs on but they haven't updated the documentation for Android.

I would hope they accept data via an Intent rather than a file, but without proper documentation is hard to know what you can do.

The API documentation does mention .out and .event files. Perhaps have a look around the file system on your device and see if you can find any. If you can, the .in files probably go in the same directory.

David Webb
  • 190,537
  • 57
  • 313
  • 299
  • Thanks Dave, yes I have learned that writing to the root cannot work "out of the box" from all the answers and objections =) I have emailed them with this issue and asked them to clarify the whole thing. I will take a close look to the directories I can access =) – Ted Jan 18 '10 at 21:06
1

You say 'The application reads and parses the .in file when it's placed in root directory on the mobile device.'

I highly doubt this application is able to read the true root directory of your phone. I think it may be the root directory exposed to it over usb mass storage, aka /sdcard/.

sargas
  • 1,113
  • 12
  • 20
  • Thanks sargas. I have tried som different locations, none work so far. I am hoping to get an answer from Sygic soon =) – Ted Jan 18 '10 at 21:04
0

Short answer: No you can't.

Long answer: No you can not, and should not.

Rant:


I am sorry that you may dislike some of the answers you are receiving here, but they are not as you put it 'smart remarks' (well they are smart, but not smart alec).

Instead what you are seeing is other developers, likely with more experience on the platform, giving you genuine warnings and good advice. They are warning you that the path that you are on reflects some poor design decisions.

You stated that:

Im using an external app that I have no control over whatsoever, and according to their API: The application reads and parses the .in file when it's placed in root directory on the mobile device. And there we have the reason why I dont save the file anywhere else and I cannot "review" my design

But commonsware.com is exactly right when they say:

Then stop using that "external app", whatever "external app" means. It clearly isn't an Android APK, as they wouldn't be shipping something that required the ability to write to the root directory.

Additionally, you commented in frustration that:

Yes, unfortunately "rooting" every device that is to use this solution is probably not an option =( Damn, every single thing I try to do in android doesnt work for this or that reason =(

There are so many reasons that the Android OS does not and should not allow every developer and their grandmother to have full control over root/system directories, but instead of listing some off the top of my head I will ask you this (rhetorically):

Why even bother having access control, and permissions, if any piece of software could change those settings whenever it feels like doing so?

I for one would never feel comfortable downloading an application for my smartphone if I knew it could have the ability to thrash about my entire device like a drunken elephant.

I could keep ranting but I will stop myself here...

Tom Neyland
  • 6,860
  • 2
  • 36
  • 52
  • 1
    Hello... Well, it just dont cut it saying "then dont use the application". At first I thought that you havent read what I wrote about me not having control over the other app, but apparently you did read that. Which makes your answer even more annoying, sorry to say. *NO* I cant just "stop using" that app since at the time being, I have no other to choose from! Why is it so hard for ppl to understand such basic things? Its not "good advice" if you tell someone to stop using the *only* software that might just work! Is that good advice? I think not. – Ted Jan 18 '10 at 20:15
  • 1
    But Ted, the software isn't the *only* software that *might* work, because it **doesn't** work. I have other things to do than argue this point with you. You will eventually discover that this solution you are trying to hack together just wont cut it, as it requires you to do things that you should not be doing (Unless the company replies to you with another solution). Either that or you will decide to go a route similar to trying to root kit every potential device you want your software to run on, if so good luck. Oh and thanks for the down vote. – Tom Neyland Jan 18 '10 at 20:27
  • And regarding the down vote: its nothing personal, but I get down-voted all the time for asking "tough" questions that the Linux-fanatics dont like. However, the answer you gave was the typical "no-answer", "smart remark" and fairly arrogant Im afraid. But just to make you happy again, Im removing the down vote, my point is made anyways... – Ted Jan 18 '10 at 20:57
  • Jeff: well, this should be done if that is the only option I have! If I have to choose between *not getting the solution out there* (out of pure principle because the objections you have is nothing else than a principle) - or to break the precious principle and deliver something that works, I definately know what I'd choose... – Ted Jan 18 '10 at 21:00