Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to mount and unmount fuse file system in android6.0

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to mount and unmount the fuse file system in android6.0. It is very detailed and has a certain reference value. Interested friends must read it!

When android4.4, vold, which is also achieved by using the fuse file system, obtains the permission of the sd actual mount directory (mnt/media_rw) from the SD card directory (storage directory). But when android4.4, vold just writes the property, and then init monitors this property, and when the property changes, it will start the sdcard process.

Then android6.0 is directly in vold, and fork a process directly opens the sdcard process to mount the fuse file system. And when uninstalling sd, unmount the fuse file system in vold.

First, mount SD card

The following is the parsing android6.0vold, mounting SD card is a piece of code, let's take a look. Show mount SD card, and then fuse operation.

If (vfat::Mount (mDevPath, mRawPath, false, false, false,// mount SD cards AID_MEDIA_RW, AID_MEDIA_RW, 0007, true) {PLOG (ERROR) global- > gid); if (mount ("/ dev/fuse", fuse- > dest_path, "fuse", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts)! = 0) {ERROR ("failed to mount fuse filesystem:% s\ n", strerror (errno); return-1) } fuse- > gid = gid; fuse- > mask = mask; return 0;}

But although the default,read,write 3 fuse file systems are mounted.

But only default seems to be useful, because the default directory is mounted directly to storage in init.rc, and the application can only get the storage directory, so only default's fuse is actually useful.

On post-fs start logd # add for amt chmod 0755 / amt # once everything is setup, no need to modify / mount rootfs rootfs / ro remount # Mount shared so changes propagate into child namespaces mount rootfs rootfs / shared rec # Mount default storage into root namespace mount none / mnt/runtime/default / storage slave bind rec

II. SD card unloading process

Then let's take a look at the process of android unmounting the SD card. When uninstalling the SD card, the fuse file system is unmounted first, and then the mount address of the SD card is unmounted.

Status_t PublicVolume::doUnmount () {if (mFusePid > 0) {kill (mFusePid, SIGTERM); TEMP_FAILURE_RETRY (waitpid (mFusePid, nullptr, 0)); mFusePid = 0;} ForceUnmount (kAsecPath); ForceUnmount (mFuseDefault); ForceUnmount (mFuseRead); ForceUnmount (mFuseWrite); ForceUnmount (mRawPath); rmdir (mFuseDefault.c_str ()); rmdir (mFuseRead.c_str ()); rmdir (mFuseWrite.c_str ()); rmdir (mRawPath.c_str ()); mFuseDefault.clear () MFuseRead.clear (); mFuseWrite.clear (); mRawPath.clear (); return OK;}

It is well known that when you uninstall the mount address of the SD card, you will check which processes are using the files in the SD card.

How to check it? It is through the soft links of each file under the proc/pid, and then through readlink to find the real file address to determine whether the files in the SD card are being occupied.

But when you unmount the fuse file system, for example, if you have a process operating the files in the SD card, the storage directory of the SD card will fuse to the actual mount address of the SD card. In fact, the fuse file system is working, so it cannot be unmounted.

However, it is impossible to find out who occupies the fuse file at this time, because the process is operating the SD card file, which will lead to the operation of the fuse file system and will not uninstall the fuse file system. But the files that can be found can only be SD cards.

And actually encountered such a problem, so I think we should first kill the process of using the SD card, and then unmount the fuse file system. In this way, there will be no time for the process to manipulate the files in the SD card, resulting in the fuse file system being too busy to unmount. The problem I encountered was an SD card file occupied by the following process

Root@lte26007:/proc/2365/fd # ls-llrwx- root radio 2016-05-25 13:42 0-> / dev/nulllrwx- root radio 2016-05-25 13:42 1-> / dev/nulllrwx- root radio 2016-05-25 13:42 10-> / storage/2C10-0CCC 2016-05-25 13:42 11-> / storage/2C10-0CCCUniverse elogUniverse 20160525,134206Binlrwx root radio 2016-05-25 13:42 12-> / storage/2C10-0CCC root radio elogation 20160525 134206PHY1hand testworthy 20160525 134209 head.binlrwx2016-05-25 13:42 13-> / CCC-0CCC/elog/elog_20160525_134206/PHY1/test _ 20160525 "134209" 00.bindings lastcards 0lrwx-root radio 2016-05-25 13:42 14-> / storage/2C10-0CCCqqelogxx20160525" 134206According to PHY1 root radio up-dated data.datlrwx-root radio 2016-05-25 13:42 15-> / storage/2C10-0CCC pruning 20160525 134206PFMhand head.binlrwx2016-05-25 13:42 16 -> / storage/2C10-0CCCUniverse elogbind elogroup 20160525 134206qPFMUnitest0lrwx-root radio 2016-05-25 13:42 17-> / storage/2C10-0CCC Universe elogation 20160525 datlrwx-root radio 2016-05-25 13:42 18-> / CPM 2016-05-25 13:42 19-> / dev/TPC0lrwx- root radio 2016-05-25 13:42 2-> / dev/nulllrwx- root radio 2016-05-25 13:42 20-> / dev/modemlrwx- root radio 2016-05-25 13:42 21-> / dev/TPC1lrwx- root radio 2016-05-25 13:42 22-> / dev/modemlrwx- root radio 2016-05-25 13:42 23-> / dev/lmi9lrwx- root radio 2016-05-25 13:42 24-> socket: [14761] lrwx- root radio 2016-05-25 13:42 26-> socket: [14764] lrwx- root radio 2016-05-25 13:42 3-> socket: [15482] lrwx- root radio 2016-05-25 13:42 4-> / tmp/lc-elog.pidlrwx- root radio 2016 -05-25 13:42 5-> / storage/2C10-0CCC Universe 13:42 5-> / storage/2C10-0CCC root radio 20160525 134206 00.binlrwx-root radio 2016-05-25 13:42 6-> / HLS 0CCC/elog/elog_20160525_134206 20160525 134206 00.binlrwx root radio 2016-05-25 13:42 7-> / CCC-0CCC / HLS/log_up_data.datlrwx- root radio 2016-05-25 13:42 8-> / storage/2C10-0CCC storage/2C10-0CCC Placement elogName 20160525 "134206" PHY0 Melody TestOne 20160525 "134208" head.binlr root radio x-root radio 2016-05-25 13:42 9-> / CCC

As for how kill is using the SD card process:

Status_t PublicVolume::doUnmount () {if (mFusePid > 0) {kill (mFusePid, SIGTERM); TEMP_FAILURE_RETRY (waitpid (mFusePid, nullptr, 0)); mFusePid = 0;} ForceUnmount (kAsecPath); LOG (VERBOSE)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report