Android File system directory analysis (mobile system directory analysis)

Source: Internet
Author: User

# pwd && ls-a-L/

DRWXRWXRWT root root 2009-06-10 09:53 sqlite_stmt_journals

DRWXRWX---system cache 2008-09-06 22:51 Cache

D---rwxrwx system system 1970-01-01 SDcard

lrwxrwxrwx root root 2009-06-09 22:11 etc,/system/etc

Drwxr-xr-x root root 2008-09-06 22:45 system

Drwxr-xr-x root root 1970-01-01 sys

Drwxr-x---root root 1970-01-01 sbin

-rw-r--r--root root 117 1970-01-01 runme.sh

Dr-xr-xr-x root root 1970-01-01 proc

-rwxr-x---root root 1704 1970-01-01 init.trout.rc

-rwxr-x---root root 9329 1970-01-01 init.rc

-rwxr-x---root root 1677 1970-01-01 init.goldfish.rc

-rwxr-x---root root 106636 1970-01-01

-rw-r--r--root root 118 1970-01-01 Default.prop

Drwxrwx--x System system 2008-09-06 22:51 data

drwx------root root 2009-06-07 16:29 root

Drwxr-xr-x root root 2009-06-09 22:11 Dev


Sqlite_stmt_journals: A Tmpfs file system in a root directory that holds temporary file data. Cache: is a temporary folder, it is said that in addition to t-mobile OTA updates, not useful. SDcard: Is the directory attached to the FAT32 file system in the SD card

ETC: Point to/system/etc, a well-known configuration file storage directory

System: is a very important directory, most of the things are here, the following is the directory structure:

# ls-a-l/system


Drwxr-xr-x Root 208 1970-01-01 xbin

Drwxr-xr-x root root 1970-01-01 modules

Drwxr-xr-x root root 2008-08-01 20:00 framework

Drwxr-xr-x root root 2008-08-01 20:00 fonts

Drwxr-xr-x root root 2008-08-01 20:00 etc

-rw-r--r--root root 2197 2008-08-01 20:00 build.prop

Drwxr-xr-x root root 2008-08-01 20:00 Media

Drwxr-xr-x root Shell 2008-08-01 20:00 bin

Drwxr-xr-x root root 2008-08-01 20:00 usr

Drwxr-xr-x root root 2008-08-01 20:00 app

Drwxr-xr-x root root 2008-09-06 22:45 lost+found

Drwxr-xr-x root root 2008-08-01 20:00 Lib

Drwxr-xr-x root root 2008-08-01 20:00 SD

-rw-r--r--root root 145 2008-08-01 20:00 init.rc


SYS: used to mount the Sysfs file system. In the device model, the Sysfs file system is used to represent the structure of the device. The image of the hierarchy of the device is reflected in the user space. User space can modify the properties of a device by modifying the file properties in the Sysfs

Sbin: Only one ADBD program for debugging is placed.

Proc: The system information provided by various files under the/proc file system is not specific to a particular process, but can be used throughout the system-wide context.

Data: Store user-installed software and a variety of information. Root: Nothing at all.

Dev: Needless to say, the place where the device node files are stored. The following documents are not directories:

runme.sh script for automatic mount action of EXT2 file system in SD card.

INIT.TROUT.RC,INIT.RC,INIT.GOLDFISH.RC is the initialization file.

Init is the first program that runs when the system boots to the file system.

From the root of the above analysis, the Android root file system is not a standard Linux file system, so you have to carefully analyze the startup process in order to understand the Android system.

Today to analyze the structure of the Android file system's/system directory.

The/system directory is an important location in the Android file system, and basically all the tools and applications are in this directory, and I look like a real rootfs.

He is stored in the NAND Flash MTD3 in the Android phone, and is a YAFFS2 file system that is mounted in the root/system directory at boot time, which contains:

# pwd && ls-a-l/system


Drwxr-xr-x Root 208 1970-01-01 xbin

Drwxr-xr-x root root 1970-01-01 modules

Drwxr-xr-x root root 2008-08-01 20:00 framework

Drwxr-xr-x root root 2008-08-01 20:00 fonts

Drwxr-xr-x root root 2008-08-01 20:00 etc

-rw-r--r--root root 2197 2008-08-01 20:00 build.prop

Drwxr-xr-x root root 2008-08-01 20:00 Media

Drwxr-xr-x root Shell 2008-08-01 20:00 bin

Drwxr-xr-x root root 2008-08-01 20:00 usr

Drwxr-xr-x root root 2008-08-01 20:00 app

Drwxr-xr-x root root 2008-09-06 22:45 lost+found

Drwxr-xr-x root root 2008-08-01 20:00 Lib

Drwxr-xr-x root root 2008-08-01 20:00 SD

-rw-r--r--root root 145 2008-08-01 20:00 init.rc

The following is an analysis of each of these directories:

XBin: A lot of system management tools have been delegated, which are not links to toolbox, each of which is an executable program. If you see these commands you will find that they are not used at all, they are prepared for the system administrator, are some system management and configuration tools. This folder is equivalent to/sbin in the standard Linux file system. My mobile phone This directory has busybox, must be changed, should be added by the cracker.

Modules: Places that are used to store kernel modules (primarily FS and net) and module configuration files.

Framework: Some of the core files of the Java platform, which belong to the Java Platform System framework file. The files inside are. jar and. odex files.

Note: What is a Odex file? Odex is an optimized Java program file, usually about 4 times times the size of the. jar. Execution efficiency is higher than. jar.

Fonts: Obviously, this is the directory where the font library files are stored.

ETC: In this case, almost all the configuration files in the system are stored, and/etc in the root directory is linked here.

Build.prop: is a property file in the Android system. The prop file is important, recording the system settings and changes, similar to the files in/etc.

Media: The main inside is the system's ringtone, divided into notifications (notification), UI (interface), alarms (warning) and ringtones (ringtone), inside are. ogg audio files.

Bin: As we all know, is to store the user's Common tool program, most of which are links to toolbox (similar to BusyBox in embedded Linux). Toolbox should be the BusyBox of Google Lite, and I haven't studied it in depth.

USR: User profiles, such as keyboard layouts, shares, time zone files, and so on. You can take a look at cat.

App: As the name implies, it's a Java application that comes with Android.

Lost+found:yaffs file systems are inherently, like the Recycle Bin folder, only the Yaffs file system will have.

Lib: Stores almost all shared library (. so) files.

Mount Directory of the EXT2 partition in the SD:SD card

INIT.RC: An initialization script used to mount/system/modules and/system/xbin as Cramfs to avoid inadvertent damage to the system.

Well, the structure of the/system directory is simply analyzed here,

The following content reproduced from the largest CDMA mobile phone player Forum www.diypda.com.

1, Android file system structure Android source code after compiling to get system.img,ramdisk.img,userdata.img image file. Among them, ramdisk.img is emulator file system, SYSTEM.IMG includes the main package, library and other files, Userdata.img includes some user data, emulator load These 3 image files, will put system and The UserData are loaded into the system and UserData directories in the RAMDisk filesystem, respectively. Therefore, we can copy all the files in the ramdisk.img, system.img and userdata.img respectively to the system and UserData directories in the RAMDisk filesystem.


2. Separate Android file system out

The system.img,ramdisk.img,userdata.img image file is cpio packaged, gzip compressed, and can be verified by the file command:

File ramdisk.img, Output:

Ramdisk.img:gzip compressed data, from Unix, last modified:wed Mar 17:16:10 Android Source compiled in addition to generating system.img,userdata . IMG also generates system and UserData folders, so you don't need to unzip them. Android source code After compiling also generated the root folder, in fact, the root of the file and ramdisk.img files are the same, but here is how to extract ramdisk.img:

Copy ramdisk.img to any other directory, change its name to ramdisk.img.gz, and use the command gunzip ramdisk.img.gz

Then create a new folder, called RAMDisk Bar, enter, enter the command

Cpio-i-F. /ramdisk.img

This will enable you to see and manipulate the contents of the RAMDisk.

Then copy the files from the system and UserData generated by the Android source code to Ramdisk/system and Ramdisk/userdata. This will get a file system.


3. Mount the Android file system using the network File system mode

Therefore, we need to set up the/nfsroot directory, then build the/nfsroot/androidfs directory, rename the Android file system to Androidfs, and link to/nfsroot/androidfs


4. Android Kernel boot file system

After the Android kernel mounts the/nfsroot/androidfs, it initializes and loads the system libraries, programs, etc., according to Init.rc,init.goldfish.rc, until the boot is complete. The init.rc script includes many procedures for file system initialization and loading. Init.rc's work is mainly:

1) Set some environment variables

2) Create a directory of system, SDcard, data, cache, etc.

3) Mount some file systems to some directories, such as Mount Tmpfs tmpfs/sqlite_stmt_journals

4) Set up user groups, permissions for some files

5) set some thread parameters

6) Set the TCP cache size


5, some ways to operate Android you should already know, Android core operating system is Linux (now with the version is 2.6.25). Therefore, the internal file system, and the system directory, but also the relationship with Linux. How do you observe these system catalogs and what secrets are hidden?

In the eclipse environment, you can use DDMS to observe. But the speed of the DDMS on my computer is too slow.

My personal preference is to look directly at the ADB shell. To start the ADB shell, use the following:

1). In Windows, open a command-line window (or execute the Cmd.exe program)

2). CD <android-sdk-install_path>/tools 3). ADB shell

When you see this # hint character, it means that you have entered the simulator's system. Next, you can use the instructions on Linux to browse these directories. Like CD, LS, pwd, cat, RM and so on.

In this, there are several directories are related to Android, specifically to organize him down for your reference.

/system/app

Pre-loading the application execution file (*.apk), is placed here. Like alarm Clock, Browser, Contacts, Maps,... Wait a minute.

/system/framework

Here is the core library of the Android system. Like Core.jar, framework-res.apk, Com.google.android.gtalkservice.jar,... Wait a minute.

Although many libraries end in jars, Java classes still exists in the Dex format. /system/media/audio/(notification, alarms, ringtones, UI)

Here put the system's sound file, like the alarm bell, call ringtone and so on. These sound files are mostly in ogg format.

/data/anr/traces.txt

When your application has a ANR (application is not responding) error, Android automatically writes the code stack list of the problem point to the file, and you can see his content directly with the Cat command.

/data/app

/system/app is the application execution file that the system is pre-loaded. This is where the user installs the application execution file (*.apk).

/data/data/<app-package-name>

When you create a file in the program with Context.openfileoutput (), it is placed in the files subdirectory of this directory. The Preferences file (*.xml) created with context.getsharedpreferences () is placed in the Shared_pref subdirectory.

/data/location/gps

Here, it should be for GPS location provider.

The contents of the properties file are as follows: Requiresnetwork false requiressatellite false Requirescell false

Hasmonetarycost false Supportsaltitude True supportsbearing true supportsspeed true repeat true accuracy 100

Powerrequirement 1

If you're not mistaken, this should be used to describe the features of the GPS location provider.

/data/system/location/location.gps

This file is also a general text file. The main is to record the final latitude and longitude of the coordinates. Locationmanager.getlastknownlocation () is here to catch the value.

/data/property/persist.sys.timezone This file is also a general text file. The main record is the time zone used by the current system. On my simulator, he recorded the string Asia/taipei.

Finally, the following two instructions, also very useful. He can help you copy the external files to the emulator's system files directory, or you can copy the files in the simulator to the external system.

ADB push <local> <remote>-copy File/dir to device adb pull <remote> <local>-copy File/dir fro M device


Reference:

http://blog.csdn.net/zjg555543/article/details/7792079

http://pbad.blog.163.com/blog/static/69146437201361910419813/



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.