Android mass storage - g_file_storage.ko - Android Software/Hacking General [Developers Only]

Hello folks. First of all, I have to say that I do not own an Android phone, but
I might be getting a cheap one in the future for some tinkering. And I am simply curious.
So, I need to know some details about the mass-storage mode handling
and it would be cool if you guys could help me out.
Assuming I have rooted my device and created a file with dd or something
and I also set up a loop-device to correspond to this file (basically
a losetup /dev/loop0 /tmp/bla).
Can I expose it into mass-storage mode, like the normal partition where your files lay in? I mean I know from other
smartphone operating systems that this is possible with some shellscripts
which they prepared for this stuff. Those shellscripts basically use the g_file_storage kernel module
for that.
Now I searched the web and found some hints that this could also be the case for android. However,
a friend of mine checked his modules and nope, it seams that it does not exist on his device. I think
it should not not differ from device to device, am I right?.
How is android taking your file partition and enabling it for the usb mass storage mode?
Are there scripts for that? Is it somehow done internally within binaries which use syscalls and stuff like that?
Or: What exactly happens when I plug in the usb cable to the phone and then choose the "enable" button?

hey lawl0r,
i have come to the very same question since i want to try this on the galaxy nexus.
did you get any further with this?

Related

[Q] Default Linux users and USB Mode

I've tried a lot of different means but ultimately I want to make sure of something. In regards to Linux, in particular debian, does everyone else have issues with actually keeping the galaxy s 4g connected in USB mode? Here is a rundown of what happens.
1.) Plug in phone and start USB mode
2a.) If left idle all is well and the device stays connected.
2b.) Else the phone disconnects itself during data transfers.
Here are more details to my setup
~ I've experienced this problem with Fedora 14 >, OpenSuse, Ubuntu, Linux Mint
~ Currently using debian(latest version squeeze).
~ Phone is running FB VahallaBlack with Subtly Modified Stock with CWM5 + Voodoo Lagfix
~ USB Debug mode is off
~ There are no tweaks active to my knowledge.
That's all the information that comes to mind, if anything else is needed please let me know and I'll post it. I dual boot windows and debian and I'd rather my phone work on both OS and not just one.
I use Ubuntu and I have this same issue. I just began either syncing over Dropbox or plugging my sd card directly into the computer. I've tried Googling the issue, but was unable to find a solution. If you don't wanna do either of these, and you hate switching to Windows just to transfer **** (as I did), you should perhaps try running a virtual instance of Windows and transferring the files on that.
adobrakic said:
I use Ubuntu and I have this same issue. I just began either syncing over Dropbox or plugging my sd card directly into the computer. I've tried Googling the issue, but was unable to find a solution. If you don't wanna do either of these, and you hate switching to Windows just to transfer **** (as I did), you should perhaps try running a virtual instance of Windows and transferring the files on that.
Click to expand...
Click to collapse
Sad to say I've tried all of that. Virtual instances of windows are worse from my experience as there were time where the VM actually found the phone and there were times it didn't, mostly didn't. Best possible thing I see myself doing is using a SD converter to do the transfers. What I don't understand is that A LOT of this tech today uses linux in some way or another. Hell some of them have linux controlling the most basic level functions with another software to handle UI on top of it. Yet when it comes to actually working with linux through said UI you get issues like this. Thanks for the reply, I'll continue to check back here for most of the day but I'm assuming most of the replies will be the same.

USB Mass Storage

I did a search and couldn't find anything regarding this, but is there a working method to get USB Mass Storage for our device instead of MTP mode? I found an app for the International Version that requires Busy Box, but I didn't want to mess anything up on my phone if it doesn't work for Verizon devices.
EDIT: Looks like i was searching in the wrong forum.... I should have looked in Development instead of Q&A... who would have thought, lol. Anyway, if anyone else is curious, the method to enable USB Mass Storage is at http://forum.xda-developers.com/showthread.php?t=1785243&highlight=usb+mass+storage. However it is a lengthy process. Hopefully some devs can cook this feature into some ROMs in the future.
The initial setup takes a little time but once it's setup it's pretty simple. Just remember you have to run the script after every reboot.

MTP Sucks

With the latest (and unfortunate) update from HTC, I have come to the conclusion that MTP is not the best protocol to transfer files between 2 devices. Why? It's much slower plus less secure. Maybe I just wanted to charge my device when hooking it up to the PC. With normal USB file transfer, by default, the phone does not mount and show its files to the PC. With MTP it does; and there's no way to stop it. MTP is also less stable. I had freeze ups many times when transferring large files where my computer no longer recognized the device. I had to unplug and restart.
Is anyone else having issues? Or is it just me being on Windows 8? Anyone know of a way to disable MTP and use the traditional way of mounting to sync? Thanks.
Just got an option I'm going to try. I worked on other devices I'll try ours:
"Use system tuner app. Go to startup button. Check for mtp. Click on it and find the exclude button. Click on it. Restart your tab. Connect to your charger and see if it works. For me it does, but you probably have to repeat the step because mtp might appear in your startup again (i don`t know how to kill it once for all)."
Source:
http://www.askmefast.com/How_to_disable_MTP_mode_on_samsung_galaxy-qna1310615.html#q750233
Will report back. For all you's who don't mind MTP, disregard this thread
Em can you explain the 'less secure' bit? But ya it sucks lol.
Closed Source Project said:
With the latest (and unfortunate) update from HTC, I have come to the conclusion that MTP is not the best protocol to transfer files between 2 devices. Why? It's much slower plus less secure. Maybe I just wanted to charge my device when hooking it up to the PC. With normal USB file transfer, by default, the phone does not mount and show its files to the PC. With MTP it does; and there's no way to stop it. MTP is also less stable. I had freeze ups many times when transferring large files where my computer no longer recognized the device. I had to unplug and restart.
Is anyone else having issues? Or is it just me being on Windows 8? Anyone know of a way to disable MTP and use the traditional way of mounting to sync? Thanks.
Click to expand...
Click to collapse
in windows 8 it sucks like hell, im with you, but in windows 7 is working fine and super fast, i pass large files from my pc to my phone, and when i say large, they are really large. i use my phone for movies, and i download movies from 5 to 6 GB, and it take a couple of seconds to get from my pc to my phone. you need updated drivers for it to make it work right.
blackwing182 said:
in windows 8 it sucks like hell, im with you, but in windows 7 is working fine and super fast, i pass large files from my pc to my phone, and when i say large, they are really large. i use my phone for movies, and i download movies from 5 to 6 GB, and it take a couple of seconds to get from my pc to my phone. you need updated drivers for it to make it work right.
Click to expand...
Click to collapse
Em what that just bs for a start the filesystem don't even support more the 4gb and then you got the fact there is no way it would copy over so fast that it puts my SSD drive to shame.
I always reboot to TWRP and use mount as old USB Mass Storage.
TheEndHK said:
I always reboot to TWRP and use mount as old USB Mass Storage.
Click to expand...
Click to collapse
Ya I do this too since the only thing that get put on there is roms which I'm about to flash.
blackwing182 said:
... but in windows 7 is working fine and super fast
Click to expand...
Click to collapse
Bull****.
MTP cant get over 2MB/sec even when using a high-end PC with SSD HDDs and USB3(yes i know the S doesnt support usb3, thats not the point), while USBMS easily do 10-15MB/sec, and ADB 5-6MB/sec.
MTP is worse than useless. Good thing I coded Quick ADB :silly:
MTP & the suck
I can agree on the initial frustration I had, trying to understand why my other android device allowed the copying of any file ext. onto the SD card. I bought a new phone with the same ICS os(phone did not come with a file manager), when I learned of MTP then what I learned now was that mass storage no longer exists . It is a more secure way the computer reads the device, so to avoid the blockade you'll need another device anything that has m-sd card capability so you can dump any one or more files onto it first off. Then goto googleplay and dl a good file manager program to use while accessing file in the phone. It should be simple from then in on to install any backed up .apk files or view any media(phone did not come with a versatile media player)files.
Closed Source Project said:
With the latest (and unfortunate) update from HTC, I have come to the conclusion that MTP is not the best protocol to transfer files between 2 devices. Why? It's much slower plus less secure. Maybe I just wanted to charge my device when hooking it up to the PC. With normal USB file transfer, by default, the phone does not mount and show its files to the PC. With MTP it does; and there's no way to stop it. MTP is also less stable. I had freeze ups many times when transferring large files where my computer no longer recognized the device. I had to unplug and restart.
Is anyone else having issues? Or is it just me being on Windows 8? Anyone know of a way to disable MTP and use the traditional way of mounting to sync? Thanks.
Click to expand...
Click to collapse
did not work for me, mtp still loaded!
i hate mtp, every time i copy a image file or video from my phone, it is corrupted, windows 7 or xp.
sometimes my wallpapers get corrupted just using es file explorer or just what seems randomly.
this is on my verizon note 2, running stock JB 4.1.2
anyone find a real solution yet?
if i have to root to get this solved, so be it, but i am about to do so any way since i miss having more control over my device.
turns out after testing, my sd card is a faked 64gb class 10, transfer rate suggests class 4 and 4gb of data was verified, good news is i can still get my money back and my friend who sold it to me may not have known it was a faked card.
MTP is completely retarded. UMS is a tried-and-tested protocol, this is the biggest sh*t sandwich Google has handed Android users so far.
MTP crashes every single time I try to use it. Try opening a folder that contains a large number of files. Explorer will freeze. Furthermore, MTP requres a device-specific driver, whereas UMS uses a standard driver. Oh this sucks so much!
Guys, I don't understand you really... In every ROM I've flashed lately being it AOSP or Sense based, there's an option to switch from MTP to the "old" UMS mode. In AOSP based ROMs it is usually located in Settings - Storage and you should open the menu there and you have USB Computer Connection where you can choose whatever you like. It is an option like any other options, you can use it or not
And yes I agree with you...it sucks
Rapier said:
Guys, I don't understand you really... In every ROM I've flashed lately being it AOSP or Sense based, there's an option to switch from MTP to the "old" UMS mode. In AOSP based ROMs it is usually located in Settings - Storage and you should open the menu there and you have USB Computer Connection where you can choose whatever you like. It is an option like any other options, you can use it or not
And yes I agree with you...it sucks
Click to expand...
Click to collapse
I am on a rooted S4 MINI using the original stock ROM. Other than this small niggle, after removing all the crapware I am pretty happy with what I have, although if there is a compatible ROM that would bring UMS to the table I'd be happy to try it. I just find it very annoying that earlier Samsung phones used to have the UMS option but recently they decided to get rid of it. That's as stupid as it can possibly get: a tried and tested, working feature that was already in place... WTF not just leave it there??
Scooxdroid said:
I am on a rooted S4 MINI using the original stock ROM. Other than this small niggle, after removing all the crapware I am pretty happy with what I have, although if there is a compatible ROM that would bring UMS to the table I'd be happy to try it. I just find it very annoying that earlier Samsung phones used to have the UMS option but recently they decided to get rid of it. That's as stupid as it can possibly get: a tried and tested, working feature that was already in place... WTF not just leave it there??
Click to expand...
Click to collapse
I know CM11 has the option included and I'm sure you have either an official or a CM11 port available for S4 mini
Rapier said:
I know CM11 has the option included and I'm sure you have either an official or a CM11 port available for S4 mini
Click to expand...
Click to collapse
I'll definitely look at it, thanks!
Scooxdroid said:
I'll definitely look at it, thanks!
Click to expand...
Click to collapse
Thx

Note 3 USB Mass Storage

Ladies and gents,
first post, I apologize if this has been covered in other threads/forums but I searched around and haven't found the right answer. So here's a little background:
I have an SM-N900 which I use for work and fun. I've been on stock A 4.4.2 and liked it a lot. Both the UI and the performance. I have now acquired a 64 gB microSD, which works great with windows on USB 3.0, but unfortunately I need UMS (USB mass storage) functionality as I retired my previous device fulfilling this role. MTP is of NO use to me. And since this is a work phone I need it to be absolutely stable and reliable.
To the point of this post, I'll update this post after a discussion on how to achieve UMS functionality on the SD card on the Note 3 (at least on the SM-N900) for others in the same predicament.
Things I have tried so far:
http://forum.xda-developers.com/showthread.php?t=2297888 <-- SG USM Enabler by MohammadAG with some tweeking both on Kitkat and Lollipop
http://forum.xda-developers.com/showthread.php?t=1785243 <-- These scripts. Only on Kitkat
http://forum.xda-developers.com/galaxy-s3/themes-apps/app-sgs3-easy-ums-mount-external-t1711009 <-- And these. Kitkat only as well.
Options at this point:
- Run a custom ROM: I've never gone this router before. As mentioned I need stability and maximum compatibility. I understand there a few ROMs out there that provide USM but I'm a little green on this front and I don't want to go about trying out different ones on a wild goose chase.
- Flash Lollipop and hope for the best: Pros and cons to this one. It is my understanding that Lollipop has brought back the possibility for apps to access SD storage. If that's true, I imagine it won't be long for some of you geniusis to script a solution to the problem. However, I really dislike the new UI. So much so that I've flashed back kitkat to try and find the solution under that OS.
- Give up. Keep stock kitkat which I really like and buy some old device that runs Gingerbread or Jellybean. <-- Not what I had in mind.
Please Note: I can run and edit some scripts but I have zero knowledge of custom loaders, linux, ext4, directories that start with a "" or a "." etc. So while I encourage a technical discussion if necessary, please bear in mind that some foreigners will be reading along so write in english too.
Personally (you'll get a better answer from somewhere else), I switch to 'camera mode' an option on the pull down menu on the phone once connected, and it comes up a lot closer to USM).
It was my biggest criticism of Android when they moved over to MTP
smeddy said:
Personally (you'll get a better answer from somewhere else), I switch to 'camera mode' an option on the pull down menu on the phone once connected, and it comes up a lot closer to USM).
It was my biggest criticism of Android when they moved over to MTP
Click to expand...
Click to collapse
Agreed.
Unfortunately, PTP is not UMS either and when connecting to non computer devices, that doesn't help either.
Another solution I've come up with is having a mass storage device, connect it to the phone with USB OTG, transfer the needed files and then plug that into said device. But that kinda defeats the purpose and implies carrying around an extra device anyway.
Anyone else? What about ROMs claiming to have UMS built into it? Has anyone had any experience with those?
Further research
CM12 apparently supports UMS. At least this article explains how to enable it on Android One devices. Could anyone confirm this?
Nightly builds of CM12 for Note 3 are posted here: http://download.cyanogenmod.org/?device=hlte
Could anyone please confirm if these will work on any Note 3 variant and chipset?
Also, could someone point me towards a crash course on system files/directories? See, I have reason to believe that the scripts I posted above do work but the lun file is located someplace else. So I'd like to look for it but I don't know how or where to start.
Much obliged.
New Update
Alright, so I got the SD to show up as a Mass Storage device with the following script:
script said:
setprop persist.sys.usb.config mass_storage,adb
echo /dev/block/vold/179:33 > /sys/devices/virtual/android_usb/android0/f_mass_storage/lun0/file
Click to expand...
Click to collapse
And return it to MTP though I got an error with it. Hang tight, I'm gonna crack this one. =D
Note: at this stage, the SD is still mounted on the device side so data corruption is a possibility.
Oh I forgot... 20 to 25 mB/s transfer speeds =D
Subscribing to this post!
Update
Fellas, here's where we stand on code: http://forum.xda-developers.com/showpost.php?p=58655257&postcount=130
If any of you is into scripting, I'd appreciate a hand.
Final update, for now...
I've run all the scripts and in different combinations on Android 5.0 and achieved exactly the same results as on A 4.4.2.
And those are as follows.
The best way to mount the SD card as a mass storage device is using this code:
Code:
echo 0 > /sys/devices/virtual/android_usb/android0/enable
umount /mnt/extSdCard/
echo "mass_storage,adb" > /sys/class/android_usb/android0/functions
echo "/dev/block/vold/179:33" > /sys/devices/virtual/android_usb/android0/f_mass_storage/lun0/file
echo 1 > /sys/devices/virtual/android_usb/android0/enable
This will unmount the card from the phone and enable mass storage mode. This will also ensure no corruption of the file table occurs.
As far as performance goes, it is as follows:
Read speed: 20 to 25 mB/s for sequential reading (large files). Smaller (pic sized) files will be carried over at about 17 to 20 mB/s
Write speed: 7 to 9 mB/s and 5 to 7 respectively.
The phone will NOT be recognized by non computer devices however. At this point, I think I've tried almost all I could think of and am really disappointed (actually I think the word is frustrated =P) as this was what I needed the most.
I think this has to do with the fact that you still need a "samsung mass storage driver" or something. Tried it on a couple of routers (different OSs), a smartTV and my car's stereo. NO LUCK.
So the best incentive at this point is transfer performance. If you, like me have a 64 gB SD card and regularly put boatloads of stuff on it, this will get you to your beer before it's warm.
To disable UMS, simply reboot the phone. Haven't been able to make the "return to mtp" script completely reliable.
Oh and the CyanogenMod is only intended for LTE devices so those of us with the Exynos chipset are outta luck.
Finally, if any of you guys thinks of something else or has a suggestion regarding the code, hit me up. I'de love to hear it!
You are forgetting about kernels. Try this: http://forum.xda-developers.com/showthread.php?t=2480353
Graffiti Exploit said:
You are forgetting about kernels. Try this: http://forum.xda-developers.com/showthread.php?t=2480353
Click to expand...
Click to collapse
I think those are all Snapdragon based. Not sure about the 900T but the 9005 has a Krait 400 with a Snapdragon chipset.
Thanks for the hint though!!
Oh sorry, forgot you had exynos.
Sent from my SM-N9005 using XDA Free mobile app
Probably you can try this as I used this on an MTP based mp3 player where I need to connect to my pc as a mass storage device, have not tried it though for the note.
Connect the note to the computer then once detected as an mtp device go to device manager amd locate the note 3 it may show up as an mtp device/portable device. Once you find it right click and update drivers then change the driver to mass storage device or usb device. If shows successful check and see if its now recognized as a mass storage device. Though it will only work on the computer where you change the driver sp if going to a different computer you will need to do the same thing.
I do apologize as I cannot try this as my computer is busted but if it does not work then you can just uninstall then reinstall the driver for the mtp device.
cryostasis25 said:
Probably you can try this as I used this on an MTP based mp3 player where I need to connect to my pc as a mass storage device, have not tried it though for the note.
Connect the note to the computer then once detected as an mtp device go to device manager amd locate the note 3 it may show up as an mtp device/portable device. Once you find it right click and update drivers then change the driver to mass storage device or usb device. If shows successful check and see if its now recognized as a mass storage device. Though it will only work on the computer where you change the driver sp if going to a different computer you will need to do the same thing.
I do apologize as I cannot try this as my computer is busted but if it does not work then you can just uninstall then reinstall the driver for the mtp device.
Click to expand...
Click to collapse
Thanks for the suggestion. But I really need it to work on non computer devices. That's why I was going for device side UMS.

Can usb debugging be enabled via adb/fastboot?

A friend has a stock S7 with a broken screen and USB debugging disabled.
I have read posts here about this situation and it looks like the prognosis is bleak, but it has been more than a year since the last one I found, and things do change with time as more is learned, especially on popular phones like the Galaxy line, so it seemed like a good idea to ask again. His wife has baby pictures on it that are worth a good bit to them. Why they weren't backed up to the cloud is anyone's guess - I get that some folks dislike sharing private lives with Google, but there are plenty of Boxcryptor type apps one can use - but the point is moot. They have their privacy and no baby pictures. It is what it is.
A quick Google search finds lots of proprietary software that claims that it doesn't need USB debugging to be enabled or that it can enable it, but the sparse details provided about this superhuman ability makes this seem unlikely.
Someone mentioned a way to sideload a custom kernel in order to somehow enable USB debugging via ADB. Is this possible? Can USB debugging be enabled from stock recovery on the S7, or any other route?
There are all sorts of Octopus / Miracle Box type gadgets and software packages that claim to make various phones dance and sing, but I can't find one that will recover files from the S7. It might be worth buying such a package, if it existed.
Some posts, articles and videos suggest using an OTG to connect a mouse or keyboard and navigate the broken screen, either from memory or by taking screenshots and retrieving them from phone storage. We have not tried this yet, and any tips specific to the S7 would be really appreciated.
Someone posted an application here, that is apparently intended to help with this situation, but mirroring a phone screen requires USB debugging to be enabled.
https://forum.xda-developers.com/showthread.php?t=2786395
Thanks to anyone who might be able to help, and I apologize for adding a redundant question. I am just hoping that there is something new in the Galaxy world that might have made this situation salvageable.
SmilingPerson said:
A friend has a stock S7 with a broken screen and USB debugging disabled.
I have read posts here about this situation and it looks like the prognosis is bleak, but it has been more than a year since the last one I found, and things do change with time as more is learned, especially on popular phones like the Galaxy line, so it seemed like a good idea to ask again. His wife has baby pictures on it that are worth a good bit to them. Why they weren't backed up to the cloud is anyone's guess - I get that some folks dislike sharing private lives with Google, but there are plenty of Boxcryptor type apps one can use - but the point is moot. They have their privacy and no baby pictures. It is what it is.
A quick Google search finds lots of proprietary software that claims that it doesn't need USB debugging to be enabled or that it can enable it, but the sparse details provided about this superhuman ability makes this seem unlikely.
Someone mentioned a way to sideload a custom kernel in order to somehow enable USB debugging via ADB. Is this possible? Can USB debugging be enabled from stock recovery on the S7, or any other route?
There are all sorts of Octopus / Miracle Box type gadgets and software packages that claim to make various phones dance and sing, but I can't find one that will recover files from the S7. It might be worth buying such a package, if it existed.
Some posts, articles and videos suggest using an OTG to connect a mouse or keyboard and navigate the broken screen, either from memory or by taking screenshots and retrieving them from phone storage. We have not tried this yet, and any tips specific to the S7 would be really appreciated.
Someone posted an application here, that is apparently intended to help with this situation, but mirroring a phone screen requires USB debugging to be enabled.
https://forum.xda-developers.com/showthread.php?t=2786395
Thanks to anyone who might be able to help, and I apologize for adding a redundant question. I am just hoping that there is something new in the Galaxy world that might have made this situation salvageable.
Click to expand...
Click to collapse
Try the solution in the link you've posted, i'm sure you no longer need debugging enabled.
Also the real issue is you need to unlock the phone, so if the screen is just black?? You can usualy guess where the patterns or numbers appear etc, easy if you have another s7 next to it.
Also other options here
cooltt said:
Try the solution in the link you've posted, i'm sure you no longer need debugging enabled.
Also the real issue is you need to unlock the phone, so if the screen is just black?? You can usualy guess where the patterns or numbers appear etc, easy if you have another s7 next to it.
"]here [/URL]
Click to expand...
Click to collapse
Thank you! This is very helpful.
I think debugging must be enabled for that solution, but I hadn't read far enough or close enough to find Msmtx's solution for enabling it from ADB.
https://forum.xda-developers.com/showpost.php?p=66731042&postcount=260
My blind spot now rectified, I am going to give this a try. I know nothing about stock recoveries - is the one in the S7 going to allow me to do this, or will I have to install or boot TWRP or Safestrap?
Thanks again mate, it will be great to get those pics back. I just hope they have learned from this the great value of backups...
Sent from my unknown using Tapatalk
Hi @SmilingPerson - Did you get this resolved? I'm facing the same issues, and on top of all the OTG ideas, the phone I need to access has a swipe lock, so I'm pretty sure connecting a mouse without seeing anything is useless. Would appreciate any tips.
I wish I could tell you something, but nothing worked, sadly, and I used the old phone for parts.
Good luck though, hope you fare better than I.

Categories

Resources