本文是基于android4.2.2的代码进行的调查分析,其他版本的android代码可能类似,但不一定会相同。

模拟器中/system/etc/目录下本应该有一个文件叫vold.fstab,但是某些情况下这个文件会缺失

那么这个文件是如何生成到system.img中的呢,下面我们来详细解释一下。


首先,在system/core/rootdir/etc/目录下有一个文件叫做vold.fstab,这个文件是一个教我们写vold.fstab的模板。模板内容如下:

## Vold 2.0 Generic fstab
## - San Mehat (san@android.com)
## 

#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...> 
## label        - Label for the volume
## mount_point  - Where the volume will be mounted
## part         - Partition # (1 based), or 'auto' for first usable partition.
## <sysfs_path> - List of sysfs paths to source devices
######################

## Example of a standard sdcard mount for the emulator / Dream
# Mounts the first usable partition of the specified device
dev_mount sdcard /mnt/sdcard auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1

## Example of a dual card setup
# dev_mount left_sdcard  /sdcard1  auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
# dev_mount right_sdcard /sdcard2  auto /devices/platform/goldfish_mmc.1 /devices/platform/msm_sdcc.3/mmc_host/mmc1

## Example of specifying a specific partition for mounts
# dev_mount sdcard /sdcard 2 /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1

关键的两句如下

Format: dev_mount <label> <mount_point> <part> <sysfs_path1...> 
dev_mount sdcard /mnt/sdcard auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1

dev_mount:挂载命令

<label>:sdcard 是挂载标签

<mount_point>: 挂载点,这里是/mnt/sdcard

<part> :子分区,这里是auto,为自定义选项可以为任何,但必须在system/vold/main.cpp里面自己判断,比如这里的意思为自动挂载

<sysfs_path1...>:设备在sysfs文件系统下的路径(可多个),这里是

/devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
两个目录为设备路径,第一个如果被占用会选择第二个


main.cpp中代码如下:

static int process_config(VolumeManager *vm) {
......
if (strcmp(part, "auto") && atoi(part) == 0) {
                SLOGE("Partition must either be 'auto' or 1 based index instead of '%s'", part);
                goto out_syntax;
            }
......

if (!strcmp(part, "auto")) {
                dv = new DirectVolume(vm, label, mount_point, -1);
            } else {
                dv = new DirectVolume(vm, label, mount_point, atoi(part));
            }

......
}

其次,系统会拷贝这个vold.fstab到out路径下,以备system.img生成时打包进去

更多相关文章

  1. 使用adb从android手机拉取文件到电脑
  2. Android Studio 集成 ShareSDK 如何 覆盖 文件夹
  3. Android 自动编译、打包生成apk文件 1 - 命令行方式
  4. 如何将文件路径从.java类文件传递到本机jni文件
  5. android MediaScanner 扫出来的ID3 MP3文件演唱者信息 乱码
  6. Android的支持库 && app/apk包进系统 && 预置so库进系统 && 预置
  7. 路径提供者文档目录是一个安全的位置吗?
  8. Android Studio Gradle 缓存文件夹设置
  9. NDK笔记---Android.mk文件

随机推荐

  1. golang协程如何关闭
  2. golang判断今天星期几
  3. golang 可以多继承吗
  4. golang的编译器是什么
  5. golang 如何判断文件是否存在
  6. golang 管道线程安全吗
  7. golang的zap怎么使用
  8. golang 如何模块化
  9. golang调试工具有哪些?
  10. golang的slice如何去重