staticintdelete_crypto_blk_dev(constchar *name) { int fd; char buffer[DM_CRYPT_BUF_SIZE]; structdm_ioctl *io; int retval = -1; int err; int retries = 10;
if ((fd = open("/dev/device-mapper", O_RDWR|O_CLOEXEC)) < 0 ) { SLOGE("Cannot open device-mapper\n"); goto errout; }
down_write(&_hash_lock); hc = __find_device_hash_cell(param);
if (!hc) { DMDEBUG_LIMIT("device doesn't appear to be in the dev hash table."); up_write(&_hash_lock); return -ENXIO; }
md = hc->md;
/* * Ensure the device is not open and nothing further can open it. */ r = dm_lock_for_deletion(md, !!(param->flags & DM_DEFERRED_REMOVE), false); if (r) { if (r == -EBUSY && param->flags & DM_DEFERRED_REMOVE) { up_write(&_hash_lock); dm_put(md); return0; } DMDEBUG_LIMIT("unable to remove open device %s", hc->name); up_write(&_hash_lock); dm_put(md); return r; //tj: fail }
t = __hash_remove(hc); up_write(&_hash_lock);
if (t) { dm_sync_table(md); dm_table_destroy(t); }
param->flags &= ~DM_DEFERRED_REMOVE;
if (!dm_kobject_uevent(md, KOBJ_REMOVE, param->event_nr)) param->flags |= DM_UEVENT_GENERATED_FLAG;
dm_put(md); dm_destroy(md); return0; }
从代码看fail只有我标注fail的那里,进dm_lock_for_deletion里看下:
/* * Guarantees nothing is using the device before it's deleted. */ intdm_lock_for_deletion(struct mapped_device *md, bool mark_deferred, bool only_deferred) { int r = 0;
spin_lock(&_minor_lock);
if (dm_open_count(md)) { r = -EBUSY; if (mark_deferred) set_bit(DMF_DEFERRED_REMOVE, &md->flags); } elseif (only_deferred && !test_bit(DMF_DEFERRED_REMOVE, &md->flags)) r = -EEXIST; else set_bit(DMF_DELETING, &md->flags);
/* Queue event based on fs_mgr return code. * * code: return code of fs_mgr_mount_all * * This function might request a reboot, in which case it will * not return. * * return code is processed based on input code */ static Result<Success> queue_fs_event(int code){ std::string bootmode = GetProperty("ro.bootmode", ""); if (strncmp(bootmode.c_str(), "ffbm", strlen("ffbm")) == 0) { LOG(ERROR) << "ffbm mode, not start class main\n"; returnSuccess(); } if (code == FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION) { ActionManager::GetInstance().QueueEventTrigger("encrypt"); //here returnSuccess(); } elseif (code == FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED) {
/* mount_all <fstab> [ <path> ]* [--<options>]* * * This function might request a reboot, in which case it will * not return. */ static Result<Success> do_mount_all(const BuiltinArguments& args){ ... std::string prop_name = "ro.boottime.init.mount_all."s + prop_post_fix; android::base::Timer t; auto mount_fstab_return_code = mount_fstab(fstabfile, mount_mode); if (!mount_fstab_return_code) { returnError() << "mount_fstab() failed " << mount_fstab_return_code.error(); } property_set(prop_name, std::to_string(t.duration().count()));
if (import_rc) { /* Paths of .rc files are specified at the 2nd argument and beyond */ import_late(args.args, 2, path_arg_end); }
if (queue_event) { /* queue_fs_event will queue event based on mount_fstab return code * and return processed return code*/ auto queue_fs_result = queue_fs_event(*mount_fstab_return_code); if (!queue_fs_result) { returnError() << "queue_fs_event() failed: " << queue_fs_result.error(); } }
/* When multiple fstab records share the same mount_point, it will * try to mount each one in turn, and ignore any duplicates after a * first successful mount. * Returns -1 on error, and FS_MGR_MNTALL_* otherwise. */ intfs_mgr_mount_all(struct fstab *fstab, int mount_mode) {
可见,应该就是按fstab里的条目来依次mount,继续看:
mret = mount_with_alternatives(fstab, i, &last_idx_inspected, &attempted_idx); i = last_idx_inspected; mount_errno = errno;
/* Deal with encryptability. */ if (!mret) { int status = handle_encryptable(&fstab->recs[attempted_idx]);
// Check to see if a mountable volume has encryption requirements staticinthandle_encryptable(conststruct fstab_rec* rec) { /* If this is block encryptable, need to trigger encryption */ if (needs_block_encryption(rec)) { if (umount(rec->mount_point) == 0) { return FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION; } else { PWARNING << "Could not umount " << rec->mount_point << " - allow continue unencrypted"; return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; } }
check needs_block_encryption:
staticboolneeds_block_encryption(conststruct fstab_rec* rec) { if (android::base::GetBoolProperty("ro.vold.forceencryption", false) && fs_mgr_is_encryptable(rec)) returntrue; if (rec->fs_mgr_flags & MF_FORCECRYPT) returntrue;