auto import from //branches/cupcake/...@131421
diff --git a/adb/log_service.c b/adb/log_service.c
index 8edf98f..6e9bdee 100644
--- a/adb/log_service.c
+++ b/adb/log_service.c
@@ -22,7 +22,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/socket.h>
-#include <utils/logger.h>
+#include <cutils/logger.h>
 #include "sysdeps.h"
 #include "adb.h"
 
diff --git a/include/cutils/logger.h b/include/cutils/logger.h
new file mode 100644
index 0000000..3a08019
--- /dev/null
+++ b/include/cutils/logger.h
@@ -0,0 +1,46 @@
+/* utils/logger.h
+** 
+** Copyright 2007, The Android Open Source Project
+**
+** This file is dual licensed.  It may be redistributed and/or modified
+** under the terms of the Apache 2.0 License OR version 2 of the GNU
+** General Public License.
+*/
+
+#ifndef _UTILS_LOGGER_H
+#define _UTILS_LOGGER_H
+
+#include <stdint.h>
+
+struct logger_entry {
+    uint16_t    len;    /* length of the payload */
+    uint16_t    __pad;  /* no matter what, we get 2 bytes of padding */
+    int32_t     pid;    /* generating process's pid */
+    int32_t     tid;    /* generating process's tid */
+    int32_t     sec;    /* seconds since Epoch */
+    int32_t     nsec;   /* nanoseconds */
+    char        msg[0]; /* the entry's payload */
+};
+
+#define LOGGER_LOG_MAIN		"log/main"
+#define LOGGER_LOG_RADIO	"log/radio"
+#define LOGGER_LOG_EVENTS	"log/events"
+
+#define LOGGER_ENTRY_MAX_LEN		(4*1024)
+#define LOGGER_ENTRY_MAX_PAYLOAD	\
+	(LOGGER_ENTRY_MAX_LEN - sizeof(struct logger_entry))
+
+#ifdef HAVE_IOCTL
+
+#include <sys/ioctl.h>
+
+#define __LOGGERIO	0xAE
+
+#define LOGGER_GET_LOG_BUF_SIZE		_IO(__LOGGERIO, 1) /* size of log */
+#define LOGGER_GET_LOG_LEN		_IO(__LOGGERIO, 2) /* used log len */
+#define LOGGER_GET_NEXT_ENTRY_LEN	_IO(__LOGGERIO, 3) /* next entry len */
+#define LOGGER_FLUSH_LOG		_IO(__LOGGERIO, 4) /* flush log */
+
+#endif // HAVE_IOCTL
+
+#endif /* _UTILS_LOGGER_H */
diff --git a/include/cutils/logprint.h b/include/cutils/logprint.h
index c010809..d6ec480 100644
--- a/include/cutils/logprint.h
+++ b/include/cutils/logprint.h
@@ -17,8 +17,8 @@
 #ifndef _LOGPRINT_H
 #define _LOGPRINT_H
 
-#include <utils/Log.h>
-#include <utils/logger.h>
+#include <cutils/log.h>
+#include <cutils/logger.h>
 #include <cutils/event_tag_map.h>
 #include <pthread.h>
 
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index e40d2ce..80867d1 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
-#include <utils/logger.h>
+#include <cutils/logger.h>
 #include <cutils/logd.h>
 
 #define LOG_BUF_SIZE	1024
diff --git a/libnetutils/dhcp_utils.c b/libnetutils/dhcp_utils.c
index ba98933..bad2e2f 100644
--- a/libnetutils/dhcp_utils.c
+++ b/libnetutils/dhcp_utils.c
@@ -170,14 +170,19 @@
  */
 int dhcp_stop(const char *interface)
 {
+    char result_prop_name[PROPERTY_KEY_MAX];
     const char *ctrl_prop = "ctl.stop";
     const char *desired_status = "stopped";
 
+    snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
+            DHCP_PROP_NAME_PREFIX,
+            interface);
     /* Stop the daemon and wait until it's reported to be stopped */
     property_set(ctrl_prop, DAEMON_NAME);
     if (wait_for_property(DAEMON_PROP_NAME, desired_status, 5) < 0) {
         return -1;
     }
+    property_set(result_prop_name, "failed");
     return 0;
 }
 
diff --git a/logcat/event-log-tags b/logcat/event-log-tags
index 4f17040..fb42bfe 100644
--- a/logcat/event-log-tags
+++ b/logcat/event-log-tags
@@ -191,10 +191,23 @@
 30030 am_create_service (Service Record|1|5),(Name|3),(Intent|3),(PID|1|5)
 # A service is being destroyed
 30031 am_destroy_service (Service Record|1|5),(Name|3),(PID|1|5)
+# A process has crashed too many times, it is being cleared
+30032 am_process_crashed_too_much (Name|3),(PID|1|5)
+# An unknown process is trying to attach to the activity manager
+30033 am_drop_process (PID|1|5)
+# A service has crashed too many times, it is being stopped
+30034 am_service_crashed_too_much (Crash Count|1|1),(Component Name|3),(PID|1|5)
+# A service is going to be restarted after its process went away
+30035 am_schedule_service_restart (Component Name|3),(Time|2|3)
+# A client was waiting for a content provider, but its process was lost
+30036 am_provider_lost_process (Package Name|3),(UID|1|5),(Name|3)
 
 # Out of memory for surfaces.
 31000 wm_no_surface_memory (Window|3),(PID|1|5),(Operation|3)
 
+# Re-connecting to input method service because we haven't received its interface
+32000 imf_force_reconnect_ime (IME|4),(Time Since Connect|2|3),(Showing|1|1)
+
 # dvm_gc_info: LIST (LONG, LONG, LONG)
 #
 # First LONG:
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index d9ca131..3130a1c 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -1,7 +1,6 @@
 // Copyright 2006 The Android Open Source Project
 
-#include <utils/misc.h>
-#include <utils/logger.h>
+#include <cutils/logger.h>
 #include <cutils/logd.h>
 #include <cutils/sockets.h>
 #include <cutils/logprint.h>
diff --git a/vold/ProcessKiller.c b/vold/ProcessKiller.c
index eeaae04..fc3eb37 100644
--- a/vold/ProcessKiller.c
+++ b/vold/ProcessKiller.c
@@ -112,7 +112,7 @@
         {
             char    name[PATH_MAX];
             GetProcessName(pid, name);
-            LOG_ERROR("process %s (%d) has open file %s\n", name, pid, link);
+            LOG_ERROR("process %s (%d) has open file %s", name, pid, link);
             fileOpen = true;
         }
     }
@@ -140,7 +140,7 @@
         {
             char    name[PATH_MAX];
             GetProcessName(pid, name);
-            LOG_ERROR("process %s (%d) has open file map for %s\n", name, pid, path);
+            LOG_ERROR("process %s (%d) has open file map for %s", name, pid, path);
             mapOpen = true;
         }
     }
@@ -159,7 +159,7 @@
     {
         char    name[PATH_MAX];
         GetProcessName(pid, name);
-        LOG_ERROR("process %s (%d) has %s in %s\n", name, pid, message, mountPoint);
+        LOG_ERROR("process %s (%d) has %s in %s", name, pid, message, mountPoint);
         return true;
     }
     else
@@ -182,7 +182,7 @@
     DIR*    dir;
     struct dirent* de;
 
-    LOG_ERROR("KillProcessesWithOpenFiles %s\n", mountPoint);
+    LOG_ERROR("KillProcessesWithOpenFiles %s", mountPoint);
     dir = opendir("/proc");
     if (!dir) return;
 
@@ -205,14 +205,14 @@
 
             for (i = 0; i < num_excluded; i++) {
                 if (pid == excluded[i]) {
-                    LOG_ERROR("I just need a little more TIME captain!\n");
+                    LOG_ERROR("I just need a little more TIME captain!");
                     hit = true;
                     break;
                 }
             }
 
             if (!hit) {
-                LOG_ERROR("Killing process %d\n", pid);
+                LOG_ERROR("Killing process %d", pid);
                 kill(pid, (sigkill ? SIGKILL : SIGTERM));
             }
         }
diff --git a/vold/blkdev.c b/vold/blkdev.c
index 39f415d..131fd5a 100644
--- a/vold/blkdev.c
+++ b/vold/blkdev.c
@@ -68,12 +68,12 @@
     devpath = blkdev_get_devpath(blk);
 
     if ((fd = open(devpath, O_RDONLY)) < 0) {
-        LOGE("Unable to open device '%s' (%s)\n", devpath, strerror(errno));
+        LOGE("Unable to open device '%s' (%s)", devpath, strerror(errno));
         return -errno;
     }
 
     if (ioctl(fd, BLKGETSIZE, &blk->nr_sec)) {
-        LOGE("Unable to get device size (%m)\n");
+        LOGE("Unable to get device size (%m)");
         return -errno;
     }
     close(fd);
@@ -84,7 +84,7 @@
      */
     devpath = blkdev_get_devpath(blk->disk);
     if ((fd = open(devpath, O_RDONLY)) < 0) {
-        LOGE("Unable to open device '%s' (%s)\n", devpath,
+        LOGE("Unable to open device '%s' (%s)", devpath,
              strerror(errno));
         free(devpath);
         return -errno;
@@ -93,7 +93,7 @@
     free(devpath);
 
     if ((rc = read(fd, block, 512)) != 512) {
-        LOGE("Unable to read device partition table (%d, %s)\n",
+        LOGE("Unable to read device partition table (%d, %s)",
              rc, strerror(errno));
         goto out;
     }
@@ -107,7 +107,7 @@
         blk->nr_parts = 0;
 
         if ((block[0x1fe] != 0x55) || (block[0x1ff] != 0xAA)) {
-            LOG_VOL("Disk %d:%d does not contain a partition table\n",
+            LOG_VOL("Disk %d:%d does not contain a partition table",
                     blk->major, blk->minor);
             goto out;
         }
@@ -120,10 +120,10 @@
                 struct fat_boot_sector *fb = (struct fat_boot_sector *) &block[0];
              
                 if (!i && fb->reserved && fb->fats && fat_valid_media(fb->media)) {
-                    LOG_VOL("Detected FAT filesystem in partition table\n");
+                    LOG_VOL("Detected FAT filesystem in partition table");
                     break;
                 } else {
-                    LOG_VOL("Partition table looks corrupt\n");
+                    LOG_VOL("Partition table looks corrupt");
                     break;
                 }
             }
@@ -152,9 +152,9 @@
                  ((blk->nr_sec * 512) / 1024) / 1024);
 
     if (blk->type == blkdev_disk) 
-        sprintf(tmp2, " %d partitions\n", blk->nr_parts);
+        sprintf(tmp2, " %d partitions", blk->nr_parts);
     else
-        sprintf(tmp2, " type 0x%x\n", blk->part_type);
+        sprintf(tmp2, " type 0x%x", blk->part_type);
 
     strcat(tmp, tmp2);
     LOG_VOL(tmp);
@@ -176,7 +176,7 @@
     struct blkdev_list *list_entry;
 
     if (disk && disk->type != blkdev_disk) {
-        LOGE("Non disk parent specified for blkdev!\n");
+        LOGE("Non disk parent specified for blkdev!");
         return NULL;
     }
 
@@ -220,7 +220,7 @@
 
     sprintf(nodepath, "%s/vold/%d:%d", DEVPATH, major, minor);
     if (mknod(nodepath, mode, dev) < 0) {
-        LOGE("Error making device nodes for '%s' (%s)\n",
+        LOGE("Error making device nodes for '%s' (%s)",
              nodepath, strerror(errno));
     }
 
@@ -229,7 +229,7 @@
     else if (!strcmp(type, "partition"))
         new->type = blkdev_partition;
     else {
-        LOGE("Unknown block device type '%s'\n", type);
+        LOGE("Unknown block device type '%s'", type);
         new->type = blkdev_unknown;
     }
 
diff --git a/vold/cmd_dispatch.c b/vold/cmd_dispatch.c
index 2ffb3f7..ab65fd9 100644
--- a/vold/cmd_dispatch.c
+++ b/vold/cmd_dispatch.c
@@ -51,7 +51,7 @@
     char buffer[101];
 
     if ((rc = read(socket, buffer, sizeof(buffer) -1)) < 0) {
-        LOGE("Unable to read framework command (%s)\n", strerror(errno));
+        LOGE("Unable to read framework command (%s)", strerror(errno));
         return -errno;
     } else if (!rc)
         return -ECONNRESET;
@@ -74,7 +74,7 @@
 {
     struct cmd_dispatch *c;
 
-    LOG_VOL("dispatch_cmd(%s):\n", cmd);
+    LOG_VOL("dispatch_cmd(%s):", cmd);
 
     for (c = dispatch_table; c->cmd != NULL; c++) {
         if (!strncmp(c->cmd, cmd, strlen(c->cmd))) {
@@ -83,7 +83,7 @@
         }
     }
 
-    LOGE("No cmd handlers defined for '%s'\n", cmd);
+    LOGE("No cmd handlers defined for '%s'", cmd);
 }
 
 static int do_send_ums_status(char *cmd)
diff --git a/vold/devmapper.c b/vold/devmapper.c
index c7fd167..ef44c90 100644
--- a/vold/devmapper.c
+++ b/vold/devmapper.c
@@ -26,6 +26,7 @@
 #include <sys/mount.h>
 
 #include <linux/loop.h>
+#include <linux/dm-ioctl.h>
 
 #include <cutils/config_utils.h>
 #include <cutils/properties.h>
@@ -35,6 +36,167 @@
 
 #define DEBUG_DEVMAPPER 1
 
+static void *_align(void *ptr, unsigned int a)
+{
+        register unsigned long agn = --a;
+
+        return (void *) (((unsigned long) ptr + agn) & ~agn);
+}
+
+static struct dm_ioctl *_dm_ioctl_setup(struct devmapping *dm, int flags)
+{
+    void *buffer;
+    void *p;
+    const size_t min_size = 16 * 1024;
+    size_t len = sizeof(struct dm_ioctl);
+    struct dm_ioctl *io;
+    struct dm_target_spec *tgt;
+    int i;
+    char params[1024];
+    char key[80];
+
+    key[0] = '\0';
+    for (i = 0; i < (int) sizeof(dm->key); i++) {
+        char tmp[8];
+
+        sprintf(tmp, "%02x", dm->key[i]);
+        strcat(key, tmp);
+    }
+
+    char srcdev[128];
+
+    // XXX: Handle non crypt targets and non twofish (use param)
+    if (dm->src_type == dmsrc_loopback)
+        strcpy(srcdev, dm->type_data.loop.loop_dev);
+    else if (dm->src_type == dmsrc_partition)
+        strcpy(srcdev, dm->type_data.part.part_dev);
+
+    sprintf(params, "twofish %s 0 %s 0", key, srcdev);
+
+LOG_VOL("Params = '%s'", params);
+
+    if (len < min_size)
+        len = min_size;
+
+    if (!(buffer = malloc(len))) {
+        LOGE("out of memory");
+        return NULL;
+    }
+
+    memset(buffer, 0, len);
+    io = buffer;
+    tgt = (struct dm_target_spec *) &buffer[sizeof(struct dm_ioctl)];
+
+    io->version[0] = 4;
+    io->version[1] = 0;
+    io->version[2] = 0;
+
+    io->data_size = len;
+    io->data_start = sizeof(struct dm_ioctl);
+
+    io->flags = flags;
+    io->dev = 0;
+
+    io->target_count = 1;
+    io->event_nr = 1;
+    strncpy(io->name, dm->target, sizeof(io->name));
+
+    tgt->status = 0;
+    tgt->sector_start = 0;
+    tgt->length = (dm->size_mb * (1024 * 1024)) / 512;
+    strncpy(tgt->target_type, "crypt", sizeof(tgt->target_type));
+
+    p = buffer + sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec);
+    strcpy((char *) p, params);
+    p+= strlen(params) + 1;
+
+    p = _align(p, 8);
+    tgt->next = p - buffer;
+
+    return io;
+}
+
+static int get_next_available_dm()
+{
+    int i;
+
+    for (i = 0; i < 8; i++) {
+        char path[255];
+        sprintf(path, "/dev/block/dm-%d", i);
+        if ((access(path, F_OK) < 0) && (errno == ENOENT))
+            return i;
+    }
+
+    LOGE("Out of device mapper numbers");
+    return -1;
+}
+
+static int create_devmapping(struct devmapping *dm)
+{
+    struct dm_ioctl *io;
+    int rc, fd;
+
+#if DEBUG_DEVMAPPER
+    LOG_VOL("create_devmapping():");
+#endif
+
+    if (dm->dm_no < 0) {
+        LOGE("Invalid dm_no set");
+        return -EINVAL;
+    }
+
+    if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
+        LOGE("Error opening device mapper (%d)", errno);
+        return -errno;
+    }
+
+    if (!(io = _dm_ioctl_setup(dm, 0))) {
+        LOGE("Unable to setup ioctl (out of memory)");
+        close(fd);
+        return -ENOMEM;
+    }
+
+    if ((rc = ioctl(fd, DM_DEV_CREATE, io)) < 0) {
+        LOGE("device-mapper create ioctl failed (%d)", errno);
+        rc = -errno;
+        goto out_free;
+    }
+
+    free(io);
+
+    if (!(io = _dm_ioctl_setup(dm, DM_STATUS_TABLE_FLAG))) {
+        LOGE("Unable to setup ioctl (out of memory)");
+        rc = -ENOMEM;
+        goto out_nofree;
+    }
+
+    if ((rc = ioctl(fd, DM_TABLE_LOAD, io)) < 0) {
+        LOGE("device-mapper load ioctl failed (%d)", errno);
+        rc = -errno;
+        goto out_free;
+    }
+
+    free(io);
+
+    if (!(io = _dm_ioctl_setup(dm, 0))) {
+        LOGE("Unable to setup ioctl (out of memory)");
+        rc = -ENOMEM;
+        goto out_nofree;
+    }
+
+    if ((rc = ioctl(fd, DM_DEV_SUSPEND, io)) < 0) {
+        LOGE("device-mapper resume ioctl failed (%d)", errno);
+        rc = -errno;
+        goto out_free;
+    }
+
+out_free:
+    free (io);
+out_nofree:
+    close (fd);
+    return rc;
+}
+
 static int loopback_start(struct devmapping *dm)
 {
     int i;
@@ -52,7 +214,7 @@
         sprintf(filename, "/dev/block/loop%d", i);
 
         if ((fd = open(filename, O_RDWR)) < 0) {
-            LOGE("Unable to open %s (%s)\n", filename, strerror(errno));
+            LOGE("Unable to open %s (%s)", filename, strerror(errno));
             return -errno;
         }
 
@@ -63,27 +225,27 @@
         close(fd);
 
         if (rc < 0) {
-            LOGE("Unable to get loop status for %s (%s)\n", filename,
+            LOGE("Unable to get loop status for %s (%s)", filename,
                  strerror(errno));
             return -errno;
         }
     }
 
     if (i == MAX_LOOP) {
-        LOGE("Out of loop devices\n");
+        LOGE("Out of loop devices");
         return -ENOSPC;
     }
 
     int file_fd;
 
     if ((file_fd = open(dm->type_data.loop.loop_src, O_RDWR)) < 0) {
-        LOGE("Unable to open %s (%s)\n", dm->type_data.loop.loop_src,
+        LOGE("Unable to open %s (%s)", dm->type_data.loop.loop_src,
              strerror(errno));
         return -errno;
     }
 
     if (ioctl(fd, LOOP_SET_FD, file_fd) < 0) {
-        LOGE("Error setting up loopback interface (%s)\n", strerror(errno));
+        LOGE("Error setting up loopback interface (%s)", strerror(errno));
         return -errno;
     }
 
@@ -94,7 +256,7 @@
     close(file_fd);
 
 #if DEBUG_DEVMAPPER
-    LOG_VOL("Loop setup on %s for %s\n", dm->type_data.loop.loop_dev,
+    LOG_VOL("Loop setup on %s for %s", dm->type_data.loop.loop_dev,
             dm->type_data.loop.loop_src);
 #endif
 
@@ -124,12 +286,17 @@
     /*
      * Configure the device mapper
      */
+    if ((rc = create_devmapping(dm)) < 0) {
+        LOGE("Failed to create devmapping (%d)", rc);
+        // XXX: if loopback then tear down
+        return rc;
+    }
 
     return 0;
 }
 
 struct devmapping *devmapper_init(char *src, char *src_type, uint32_t size_mb,
-                  char *target, char *params, char *tgt_fs)
+                  char *target, char *params, char *tgt_fs, char *mediapath)
 {
     struct devmapping *dm;
 
@@ -161,8 +328,136 @@
     dm->target = strdup(target);
     dm->params = strdup(params);
     dm->tgt_fs = strdup(tgt_fs);
+    
+    if ((dm->dm_no = get_next_available_dm()) < 0)
+        goto out_free;
+
+    sprintf(mediapath, "/devices/virtual/block/dm-%d", dm->dm_no);
+
+    if (!(dm->media = media_create(mediapath,
+                                   "unknown",
+                                   "unknown",
+                                   media_devmapper))) {
+        LOGE("Unable to create media");
+        goto out_free;
+    }
 
     return dm;
  out_free:
+    if (dm->target)
+        free(dm->target);
+    if (dm->params)
+        free(dm->params);
+    if (dm->tgt_fs)
+        free(dm->tgt_fs);
+
+    free(dm);
     return NULL;
 }
+
+int devmapper_genesis(struct devmapping *dm)
+{
+
+    if (dm->src_type == dmsrc_loopback) {
+        int fd;
+
+        LOG_VOL("devmapper_genesis(): Working on %s", 
+                dm->type_data.loop.loop_src);
+
+        unlink(dm->type_data.loop.loop_src);
+
+        LOG_VOL("devmapper_genesis(): Creating imagefile (%u MB)",
+                dm->size_mb);
+
+        if ((fd = creat(dm->type_data.loop.loop_src, 0600)) < 0) {
+            LOGE("Error creating imagefile (%s)", strerror(errno));
+            return -errno;
+        }
+
+        if (ftruncate(fd, (dm->size_mb * (1024 * 1024))) < 0) {
+            LOGE("Error truncating imagefile (%s)", strerror(errno));
+            close(fd);
+            return -errno;
+        }
+        close(fd);
+    } else if (dm->src_type == dmsrc_partition) {
+        LOGE("partition maps not yet supported");
+        return -ENOSYS;
+    }
+
+    return devmapper_start(dm);
+}
+
+static int destroy_devmapping(struct devmapping *dm)
+{
+    struct dm_ioctl       *io;
+    int                   dmFd;
+    int                   rc = 0;
+
+    LOG_VOL("destroy_devmapping():");
+
+    if ((dmFd = open("/dev/device-mapper", O_RDWR)) < 0) {
+        LOGE("Error opening device mapper (%d)", errno);
+        return -errno;
+    }
+
+    if (!(io = _dm_ioctl_setup(dm, DM_PERSISTENT_DEV_FLAG))) {
+        LOGE("Unable to setup ioctl (out of memory)");
+        rc = -ENOMEM;
+        goto out_nofree;
+    }
+
+    if ((rc = ioctl(dmFd, DM_DEV_REMOVE, io)) < 0) {
+        LOGE("device-mapper remove ioctl failed (%d)", errno);
+        rc = -errno;
+        goto out_free;
+    }
+
+out_free:
+    free (io);
+out_nofree:
+    close (dmFd);
+    return rc;
+}
+
+static int loopback_stop(struct devmapping *dm)
+{
+    char devname[255];
+    int device_fd;
+    int rc = 0;
+
+    LOG_VOL("loopback_stop():");
+
+    device_fd = open(dm->type_data.loop.loop_dev, O_RDONLY);
+    if (device_fd < 0) {
+        LOG_ERROR("Failed to open loop (%d)", errno);
+        return -errno;
+    }
+
+    if (ioctl(device_fd, LOOP_CLR_FD, 0) < 0) {
+        LOG_ERROR("Failed to destroy loop (%d)", errno);
+        rc = -errno;
+    }
+
+    close(device_fd);
+    return rc;
+}
+
+int devmapper_stop(struct devmapping *dm)
+{
+    int rc;
+
+    LOG_VOL("devmapper_stop():");
+
+    if ((rc = destroy_devmapping(dm)))
+        return rc;
+
+    if (dm->src_type == dmsrc_loopback) {
+        if ((rc = loopback_stop(dm)))
+            return rc;
+    } else if (dm->src_type == dmsrc_partition) {
+        LOGE("partition maps not yet supported");
+        return -ENOSYS;
+    }
+    return 0;
+}
diff --git a/vold/devmapper.h b/vold/devmapper.h
index bea8521..3d8cab3 100644
--- a/vold/devmapper.h
+++ b/vold/devmapper.h
@@ -56,9 +56,15 @@
 	char             *target;
         char             *params;
         char             *tgt_fs;
+
+        unsigned char key[16];
+        int           dm_no;
+
+        media_t *media;
 };
 
-struct devmapping *devmapper_init(char *, char *, unsigned int, char *, char *, char*);
+struct devmapping *devmapper_init(char *, char *, unsigned int, char *, char *, char *, char *);
 int devmapper_start(struct devmapping *);
 int devmapper_stop(struct devmapping *);
+int devmapper_genesis(struct devmapping *);
 #endif
diff --git a/vold/format.c b/vold/format.c
index b413cc7..dd0515c 100755
--- a/vold/format.c
+++ b/vold/format.c
@@ -27,31 +27,44 @@
 #include "logwrapper.h"
 
 static char MKDOSFS_PATH[] = "/system/bin/mkdosfs";
+static char MKE2FS_PATH[] = "/system/bin/mke2fs";
 
-int format_partition(blkdev_t *part)
+int format_partition(blkdev_t *part, char *type)
 {
     char *devpath;
-    char *args[7];
+    int rc = -EINVAL;
 
     devpath = blkdev_get_devpath(part);
 
-    args[0] = MKDOSFS_PATH;
-    args[1] = "-F 32";
-    args[2] = "-c 32";
-    args[3] = "-n 2";
-    args[4] = "-O android";
-    args[5] = devpath;
-    args[6] = NULL;
-
-    int rc = logwrap(6, args);
+    if (!strcmp(type, FORMAT_TYPE_FAT32)) {
+        char *args[7];
+        args[0] = MKDOSFS_PATH;
+        args[1] = "-F 32";
+        args[2] = "-c 32";
+        args[3] = "-n 2";
+        args[4] = "-O android";
+        args[5] = devpath;
+        args[6] = NULL;
+        rc = logwrap(6, args);
+    } else {
+        char *args[7];
+        args[0] = MKE2FS_PATH;
+        args[1] = "-b 4096";
+        args[2] = "-m 1";
+        args[3] = "-L android";
+        args[4] = "-v";
+        args[5] = devpath;
+        args[6] = NULL;
+        rc = logwrap(6, args);
+    }
  
     free(devpath);
 
     if (rc == 0) {
-        LOG_VOL("Filesystem formatted OK\n");
+        LOG_VOL("Filesystem formatted OK");
         return 0;
     } else {
-        LOGE("Format failed (unknokwn exit code %d)\n", rc);
+        LOGE("Format failed (unknokwn exit code %d)", rc);
         return -EIO;
     }
     return 0;
@@ -79,19 +92,19 @@
     dos_partition_enc(block + DOSPARTOFF, &part);
 
     if ((fd = open(devpath, O_RDWR)) < 0) {
-        LOGE("Error opening disk file (%s)\n", strerror(errno));
+        LOGE("Error opening disk file (%s)", strerror(errno));
         return -errno;
     }
     free(devpath);
 
     if (write(fd, block, sizeof(block)) < 0) {
-        LOGE("Error writing MBR (%s)\n", strerror(errno));
+        LOGE("Error writing MBR (%s)", strerror(errno));
         close(fd);
         return -errno;
     }
 
     if (ioctl(fd, BLKRRPART, NULL) < 0) {
-        LOGE("Error re-reading partition table (%s)\n", strerror(errno));
+        LOGE("Error re-reading partition table (%s)", strerror(errno));
         close(fd);
         return -errno;
     }
diff --git a/vold/format.h b/vold/format.h
index 3000b10..73cc012 100644
--- a/vold/format.h
+++ b/vold/format.h
@@ -18,6 +18,9 @@
 #ifndef _FORMAT_H
 #define _FORMAT_H
 
-int format_partition(blkdev_t *part);
+#define FORMAT_TYPE_EXT2  "ext2"
+#define FORMAT_TYPE_FAT32 "fat32"
+
+int format_partition(blkdev_t *part, char *type);
 int initialize_mbr(blkdev_t *disk);
 #endif
diff --git a/vold/logwrapper.c b/vold/logwrapper.c
index f803dba..25d2281 100644
--- a/vold/logwrapper.c
+++ b/vold/logwrapper.c
@@ -95,7 +95,7 @@
     // XXX: PROTECT FROM VIKING KILLER
     if (execvp(argv_child[0], argv_child)) {
         LOG(LOG_ERROR, "logwrapper",
-            "executing %s failed: %s\n", argv_child[0], strerror(errno));
+            "executing %s failed: %s", argv_child[0], strerror(errno));
         exit(-1);
     }
 }
@@ -111,24 +111,24 @@
     /* Use ptty instead of socketpair so that STDOUT is not buffered */
     parent_ptty = open("/dev/ptmx", O_RDWR);
     if (parent_ptty < 0) {
-	LOG(LOG_ERROR, "logwrapper", "Cannot create parent ptty\n");
+	LOG(LOG_ERROR, "logwrapper", "Cannot create parent ptty");
 	return -errno;
     }
 
     if (grantpt(parent_ptty) || unlockpt(parent_ptty) ||
             ((child_devname = (char*)ptsname(parent_ptty)) == 0)) {
-	LOG(LOG_ERROR, "logwrapper", "Problem with /dev/ptmx\n");
+	LOG(LOG_ERROR, "logwrapper", "Problem with /dev/ptmx");
 	return -1;
     }
 
     pid = fork();
     if (pid < 0) {
-	LOG(LOG_ERROR, "logwrapper", "Failed to fork\n");
+	LOG(LOG_ERROR, "logwrapper", "Failed to fork");
         return -errno;
     } else if (pid == 0) {
         child_ptty = open(child_devname, O_RDWR);
         if (child_ptty < 0) {
-	    LOG(LOG_ERROR, "logwrapper", "Problem with child ptty\n");
+	    LOG(LOG_ERROR, "logwrapper", "Problem with child ptty");
             return -errno;
         }
 
diff --git a/vold/media.c b/vold/media.c
index 58eef82..40637ff 100644
--- a/vold/media.c
+++ b/vold/media.c
@@ -105,7 +105,7 @@
         list_scan = list_scan->next;
     }
 #if DEBUG_MEDIA
-    LOG_VOL("media_lookup_by_path(): No media found @ %s\n", devpath);
+    LOG_VOL("media_lookup_by_path(): No media found @ %s", devpath);
 #endif
     return NULL;
 }
@@ -115,7 +115,7 @@
     blkdev_list_t *list_entry;
 
     if (!(list_entry = malloc(sizeof(blkdev_list_t)))) {
-        LOGE("Out of memory\n");
+        LOGE("Out of memory");
         return -ENOMEM;
     }
     
diff --git a/vold/mmc.c b/vold/mmc.c
index dc19994..0f08964 100644
--- a/vold/mmc.c
+++ b/vold/mmc.c
@@ -43,7 +43,7 @@
     struct dirent *de;
 
     if (!(d = opendir(SYSFS_CLASS_MMC_PATH))) {
-        LOG_ERROR("Unable to open '%s' (%m)\n", SYSFS_CLASS_MMC_PATH);
+        LOG_ERROR("Unable to open '%s' (%m)", SYSFS_CLASS_MMC_PATH);
         return -errno;
     }
 
@@ -55,7 +55,7 @@
 
         sprintf(tmp, "%s/%s", SYSFS_CLASS_MMC_PATH, de->d_name);
         if (mmc_bootstrap_controller(tmp))
-            LOG_ERROR("Error bootstrapping controller '%s' (%m)\n", tmp);
+            LOG_ERROR("Error bootstrapping controller '%s' (%m)", tmp);
     }
 
     closedir(d);
@@ -69,10 +69,10 @@
     struct dirent *de;
 
 #if DEBUG_BOOTSTRAP
-    LOG_VOL("bootstrap_controller(%s):\n", sysfs_path);
+    LOG_VOL("bootstrap_controller(%s):", sysfs_path);
 #endif
     if (!(d = opendir(sysfs_path))) {
-        LOG_ERROR("Unable to open '%s' (%m)\n", sysfs_path);
+        LOG_ERROR("Unable to open '%s' (%m)", sysfs_path);
         return -errno;
     }
 
@@ -92,7 +92,7 @@
         sprintf(tmp, "%s/%s", sysfs_path, de->d_name);
 
         if (mmc_bootstrap_card(tmp) < 0)
-            LOG_ERROR("Error bootstrapping card '%s' (%m)\n", tmp);
+            LOG_ERROR("Error bootstrapping card '%s' (%m)", tmp);
     } // while
 
     closedir(d);
@@ -111,29 +111,29 @@
     ssize_t sz;
 
 #if DEBUG_BOOTSTRAP
-    LOG_VOL("bootstrap_card(%s):\n", sysfs_path);
+    LOG_VOL("bootstrap_card(%s):", sysfs_path);
 #endif
 
     /*
      * sysfs_path is based on /sys/class, but we want the actual device class
      */
     if (!getcwd(saved_cwd, sizeof(saved_cwd))) {
-        LOGE("Error getting working dir path\n");
+        LOGE("Error getting working dir path");
         return -errno;
     }
     
     if (chdir(sysfs_path) < 0) {
-        LOGE("Unable to chdir to %s (%m)\n", sysfs_path);
+        LOGE("Unable to chdir to %s (%m)", sysfs_path);
         return -errno;
     }
 
     if (!getcwd(new_cwd, sizeof(new_cwd))) {
-        LOGE("Buffer too small for device path\n");
+        LOGE("Buffer too small for device path");
         return -errno;
     }
 
     if (chdir(saved_cwd) < 0) {
-        LOGE("Unable to restore working dir\n");
+        LOGE("Unable to restore working dir");
         return -errno;
     }
 
@@ -162,7 +162,7 @@
     uevent_params[3] = (char *) NULL;
 
     if (simulate_uevent("mmc", devpath, "add", uevent_params) < 0) {
-        LOGE("Error simulating uevent (%m)\n");
+        LOGE("Error simulating uevent (%m)");
         return -errno;
     }
 
@@ -174,7 +174,7 @@
     sprintf(filename, "/sys%s/block", devpath);
     if (!access(filename, F_OK)) {
         if (mmc_bootstrap_block(tmp)) {
-            LOGE("Error bootstrapping block @ %s\n", tmp);
+            LOGE("Error bootstrapping block @ %s", tmp);
         }
     }
 
@@ -188,13 +188,13 @@
     struct dirent *de;
 
 #if DEBUG_BOOTSTRAP
-    LOG_VOL("mmc_bootstrap_block(%s):\n", devpath);
+    LOG_VOL("mmc_bootstrap_block(%s):", devpath);
 #endif
 
     sprintf(blockdir_path, "/sys%s", devpath);
 
     if (!(d = opendir(blockdir_path))) {
-        LOGE("Failed to opendir %s\n", devpath);
+        LOGE("Failed to opendir %s", devpath);
         return -errno;
     }
 
@@ -205,7 +205,7 @@
             continue;
         sprintf(tmp, "%s/%s", devpath, de->d_name);
         if (mmc_bootstrap_mmcblk(tmp))
-            LOGE("Error bootstraping mmcblk @ %s\n", tmp);
+            LOGE("Error bootstraping mmcblk @ %s", tmp);
     }
     closedir(d);
     return 0;
@@ -218,11 +218,11 @@
     int rc;
 
 #if DEBUG_BOOTSTRAP
-    LOG_VOL("mmc_bootstrap_mmcblk(%s):\n", devpath);
+    LOG_VOL("mmc_bootstrap_mmcblk(%s):", devpath);
 #endif
 
     if ((rc = mmc_bootstrap_mmcblk_partition(devpath))) {
-        LOGE("Error bootstrapping mmcblk partition '%s'\n", devpath);
+        LOGE("Error bootstrapping mmcblk partition '%s'", devpath);
         return rc;
     }
 
@@ -238,7 +238,7 @@
 
             sprintf(part_devpath, "%s/%sp%d", devpath, mmcblk_devname, part_no);
             if (mmc_bootstrap_mmcblk_partition(part_devpath)) 
-                LOGE("Error bootstrapping mmcblk partition '%s'\n", part_devpath);
+                LOGE("Error bootstrapping mmcblk partition '%s'", part_devpath);
         }
     }
 
@@ -256,7 +256,7 @@
     char line[255];
 
 #if DEBUG_BOOTSTRAP
-    LOG_VOL("mmc_bootstrap_mmcblk_partition(%s):\n", devpath);
+    LOG_VOL("mmc_bootstrap_mmcblk_partition(%s):", devpath);
 #endif
 
     sprintf(tmp, "DEVPATH=%s", devpath);
@@ -264,7 +264,7 @@
 
     sprintf(filename, "/sys%s/uevent", devpath);
     if (!(fp = fopen(filename, "r"))) {
-        LOGE("Unable to open '%s' (%m)\n", filename);
+        LOGE("Unable to open '%s' (%m)", filename);
         return -errno;
     }
 
@@ -280,13 +280,13 @@
     fclose(fp);
 
     if (!uevent_params[1] || !uevent_params[2] || !uevent_params[3]) {
-        LOGE("mmcblk uevent missing required params\n");
+        LOGE("mmcblk uevent missing required params");
         return -1;
     }
     uevent_params[4] = '\0';
     
     if (simulate_uevent("block", devpath, "add", uevent_params) < 0) {
-        LOGE("Error simulating uevent (%m)\n");
+        LOGE("Error simulating uevent (%m)");
         return -errno;
     }
     return 0;
diff --git a/vold/switch.c b/vold/switch.c
index 72121d9..ba9ddb3 100644
--- a/vold/switch.c
+++ b/vold/switch.c
@@ -35,7 +35,7 @@
     struct dirent *de;
 
     if (!(d = opendir(SYSFS_CLASS_SWITCH_PATH))) {
-        LOG_ERROR("Unable to open '%s' (%m)\n", SYSFS_CLASS_SWITCH_PATH);
+        LOG_ERROR("Unable to open '%s' (%m)", SYSFS_CLASS_SWITCH_PATH);
         return -errno;
     }
 
@@ -47,7 +47,7 @@
 
         sprintf(tmp, "%s/%s", SYSFS_CLASS_SWITCH_PATH, de->d_name);
         if (mmc_bootstrap_switch(tmp))
-            LOG_ERROR("Error bootstrapping switch '%s' (%m)\n", tmp);
+            LOG_ERROR("Error bootstrapping switch '%s' (%m)", tmp);
     }
 
     closedir(d);
@@ -58,7 +58,7 @@
 static int mmc_bootstrap_switch(char *sysfs_path)
 {
 #if DEBUG_BOOTSTRAP
-    LOG_VOL("bootstrap_switch(%s):\n", sysfs_path);
+    LOG_VOL("bootstrap_switch(%s):", sysfs_path);
 #endif
 
     char filename[255];
@@ -74,12 +74,12 @@
      */
     sprintf(filename, "%s/name", sysfs_path);
     if (!(fp = fopen(filename, "r"))) {
-        LOGE("Error opening switch name path '%s' (%s)\n",
+        LOGE("Error opening switch name path '%s' (%s)",
              sysfs_path, strerror(errno));
        return -errno;
     }
     if (!fgets(name, sizeof(name), fp)) {
-        LOGE("Unable to read switch name\n");
+        LOGE("Unable to read switch name");
         fclose(fp);
         return -EIO;
     }
@@ -95,12 +95,12 @@
      */
     sprintf(filename, "%s/state", sysfs_path);
     if (!(fp = fopen(filename, "r"))) {
-        LOGE("Error opening switch state path '%s' (%s)\n",
+        LOGE("Error opening switch state path '%s' (%s)",
              sysfs_path, strerror(errno));
        return -errno;
     }
     if (!fgets(state, sizeof(state), fp)) {
-        LOGE("Unable to read switch state\n");
+        LOGE("Unable to read switch state");
         fclose(fp);
         return -EIO;
     }
@@ -113,7 +113,7 @@
     uevent_params[2] = (char *) NULL;
 
     if (simulate_uevent("switch", devpath, "add", uevent_params) < 0) {
-        LOGE("Error simulating uevent (%s)\n", strerror(errno));
+        LOGE("Error simulating uevent (%s)", strerror(errno));
         return -errno;
     }
 
diff --git a/vold/uevent.c b/vold/uevent.c
index e195066..3b7e53b 100644
--- a/vold/uevent.c
+++ b/vold/uevent.c
@@ -87,12 +87,12 @@
     int rc = 0;
 
     if ((count = recv(socket, buffer, sizeof(buffer), 0)) < 0) {
-        LOGE("Error receiving uevent (%s)\n", strerror(errno));
+        LOGE("Error receiving uevent (%s)", strerror(errno));
         return -errno;
     }
 
     if (!(event = malloc(sizeof(struct uevent)))) {
-        LOGE("Error allocating memory (%s)\n", strerror(errno));
+        LOGE("Error allocating memory (%s)", strerror(errno));
         return -errno;
     }
 
@@ -139,7 +139,7 @@
     int i, rc;
 
     if (!(event = malloc(sizeof(struct uevent)))) {
-        LOGE("Error allocating memory (%s)\n", strerror(errno));
+        LOGE("Error allocating memory (%s)", strerror(errno));
         return -errno;
     }
 
@@ -154,7 +154,7 @@
     else if (!strcmp(action, "remove"))
         event->action = action_remove;
     else {
-        LOGE("Invalid action '%s'\n", action);
+        LOGE("Invalid action '%s'", action);
         return -1;
     }
 
@@ -184,7 +184,7 @@
     }
 
 #if DEBUG_UEVENT
-    LOG_VOL("No uevent handlers registered for '%s' subsystem\n", event->subsystem);
+    LOG_VOL("No uevent handlers registered for '%s' subsystem", event->subsystem);
 #endif
     return 0;
 }
@@ -193,12 +193,12 @@
 {
     int i;
 
-    LOG_VOL("[UEVENT] Sq: %u S: %s A: %d P: %s\n",
+    LOG_VOL("[UEVENT] Sq: %u S: %s A: %d P: %s",
               event->seqnum, event->subsystem, event->action, event->path);
     for (i = 0; i < UEVENT_PARAMS_MAX; i++) {
         if (!event->param[i])
             break;
-        LOG_VOL("%s\n", event->param[i]);
+        LOG_VOL("%s", event->param[i]);
     }
 }
 
@@ -226,7 +226,7 @@
             return &event->param[i][strlen(param_name) + 1];
     }
 
-    LOGE("get_uevent_param(): No parameter '%s' found\n", param_name);
+    LOGE("get_uevent_param(): No parameter '%s' found", param_name);
     return NULL;
 }
 
@@ -248,7 +248,7 @@
             low_batt = true;
         else
             low_batt = false;
-LOG_VOL("handle_powersupply_event(): low_batt = %d, door_open = %d\n", low_batt, door_open);
+LOG_VOL("handle_powersupply_event(): low_batt = %d, door_open = %d", low_batt, door_open);
         volmgr_safe_mode(low_batt || door_open);
     }
     return 0;
@@ -272,10 +272,10 @@
             door_open = true;
         else
             door_open = false;
-LOG_VOL("handle_powersupply_event(): low_batt = %d, door_open = %d\n", low_batt, door_open);
+LOG_VOL("handle_powersupply_event(): low_batt = %d, door_open = %d", low_batt, door_open);
         volmgr_safe_mode(low_batt || door_open);
     } else
-        LOG_VOL("handle_switch_event(): Ignoring switch '%s'\n", name);
+        LOG_VOL("handle_switch_event(): Ignoring switch '%s'", name);
 
     return 0;
 }
@@ -296,12 +296,16 @@
     /*
      * Look for backing media for this block device
      */
-    if (!strcmp(get_uevent_param(event, "DEVTYPE"), "disk"))
+    if (!strncmp(get_uevent_param(event, "DEVPATH"),
+                 "/devices/virtual/",
+                 strlen("/devices/virtual/"))) {
+        n = 0;
+    } else if (!strcmp(get_uevent_param(event, "DEVTYPE"), "disk"))
         n = 2;
     else if (!strcmp(get_uevent_param(event, "DEVTYPE"), "partition"))
         n = 3;
     else {
-        LOGE("Bad blockdev type '%s'\n", get_uevent_param(event, "DEVTYPE"));
+        LOGE("Bad blockdev type '%s'", get_uevent_param(event, "DEVTYPE"));
         return -EINVAL;
     }
 
@@ -309,7 +313,7 @@
 
     if (!(media = media_lookup_by_path(mediapath, false))) {
 #if DEBUG_UEVENT
-        LOG_VOL("No backend media found @ device path '%s'\n", mediapath);
+        LOG_VOL("No backend media found @ device path '%s'", mediapath);
 #endif
         return 0;
     }
@@ -332,7 +336,7 @@
                                      min,
                                      media,
                                      get_uevent_param(event, "DEVTYPE")))) {
-            LOGE("Unable to allocate new blkdev (%m)\n");
+            LOGE("Unable to allocate new blkdev (%m)");
             return -1;
         }
 
@@ -343,17 +347,17 @@
          */
         int rc;
         if ((rc = media_add_blkdev(media, blkdev)) < 0) {
-            LOGE("Unable to add blkdev to card (%d)\n", rc);
+            LOGE("Unable to add blkdev to card (%d)", rc);
             return rc;
         }
 
-        LOG_VOL("New blkdev %d.%d on media %s, media path %s, Dpp %d\n",
+        LOG_VOL("New blkdev %d.%d on media %s, media path %s, Dpp %d",
                 blkdev->major, blkdev->minor, media->name, mediapath,
                 blkdev_get_num_pending_partitions(blkdev->disk));
 
         if (blkdev_get_num_pending_partitions(blkdev->disk) == 0) {
             if ((rc = volmgr_consider_disk(blkdev->disk)) < 0) {
-                LOGE("Volmgr failed to handle device (%d)\n", rc);
+                LOGE("Volmgr failed to handle device (%d)", rc);
                 return rc;
             }
         }
@@ -361,7 +365,7 @@
         if (!(blkdev = blkdev_lookup_by_devno(maj, min)))
             return 0;
 
-        LOG_VOL("Destroying blkdev %d.%d @ %s on media %s\n", blkdev->major,
+        LOG_VOL("Destroying blkdev %d.%d @ %s on media %s", blkdev->major,
                 blkdev->minor, blkdev->devpath, media->name);
         volmgr_notify_eject(blkdev, _cb_blkdev_ok_to_destroy);
 
@@ -369,13 +373,13 @@
         if (!(blkdev = blkdev_lookup_by_devno(maj, min)))
             return 0;
 
-        LOG_VOL("Modified blkdev %d.%d @ %s on media %s\n", blkdev->major,
+        LOG_VOL("Modified blkdev %d.%d @ %s on media %s", blkdev->major,
                 blkdev->minor, blkdev->devpath, media->name);
         
         blkdev_refresh(blkdev);
     } else  {
 #if DEBUG_UEVENT
-        LOG_VOL("No handler implemented for action %d\n", event->action);
+        LOG_VOL("No handler implemented for action %d", event->action);
 #endif
     }
     return 0;
@@ -413,25 +417,25 @@
                                    get_uevent_param(event, "MMC_NAME"),
                                    serial,
                                    media_mmc))) {
-            LOGE("Unable to allocate new media (%m)\n");
+            LOGE("Unable to allocate new media (%m)");
             return -1;
         }
-        LOG_VOL("New MMC card '%s' (serial %u) added @ %s\n", media->name,
+        LOG_VOL("New MMC card '%s' (serial %u) added @ %s", media->name,
                   media->serial, media->devpath);
     } else if (event->action == action_remove) {
         media_t *media;
 
         if (!(media = media_lookup_by_path(event->path, false))) {
-            LOGE("Unable to lookup media '%s'\n", event->path);
+            LOGE("Unable to lookup media '%s'", event->path);
             return -1;
         }
 
-        LOG_VOL("MMC card '%s' (serial %u) @ %s removed\n", media->name, 
+        LOG_VOL("MMC card '%s' (serial %u) @ %s removed", media->name, 
                   media->serial, media->devpath);
         media_destroy(media);
     } else {
 #if DEBUG_UEVENT
-        LOG_VOL("No handler implemented for action %d\n", event->action);
+        LOG_VOL("No handler implemented for action %d", event->action);
 #endif
     }
 
diff --git a/vold/ums.c b/vold/ums.c
index 2686b6f..4d0fc25 100644
--- a/vold/ums.c
+++ b/vold/ums.c
@@ -45,7 +45,7 @@
 void ums_hostconnected_set(boolean connected)
 {
 #if DEBUG_UMS
-    LOG_VOL("ums_hostconnected_set(%d):\n", connected);
+    LOG_VOL("ums_hostconnected_set(%d):", connected);
 #endif
     host_connected = connected;
 
@@ -56,19 +56,19 @@
 
 int ums_enable(char *dev_fspath, char *lun_syspath)
 {
-    LOG_VOL("ums_enable(%s, %s):\n", dev_fspath, lun_syspath);
+    LOG_VOL("ums_enable(%s, %s):", dev_fspath, lun_syspath);
 
     int fd;
     char filename[255];
 
     sprintf(filename, "/sys/%s/file", lun_syspath);
     if ((fd = open(filename, O_WRONLY)) < 0) {
-        LOGE("Unable to open '%s' (%s)\n", filename, strerror(errno));
+        LOGE("Unable to open '%s' (%s)", filename, strerror(errno));
         return -errno;
     }
 
     if (write(fd, dev_fspath, strlen(dev_fspath)) < 0) {
-        LOGE("Unable to write to ums lunfile (%s)\n", strerror(errno));
+        LOGE("Unable to write to ums lunfile (%s)", strerror(errno));
         close(fd);
         return -errno;
     }
@@ -80,7 +80,7 @@
 int ums_disable(char *lun_syspath)
 {
 #if DEBUG_UMS
-    LOG_VOL("ums_disable(%s):\n", lun_syspath);
+    LOG_VOL("ums_disable(%s):", lun_syspath);
 #endif
 
     int fd;
@@ -88,14 +88,14 @@
 
     sprintf(filename, "/sys/%s/file", lun_syspath);
     if ((fd = open(filename, O_WRONLY)) < 0) {
-        LOGE("Unable to open '%s' (%s)\n", filename, strerror(errno));
+        LOGE("Unable to open '%s' (%s)", filename, strerror(errno));
         return -errno;
     }
 
     char ch = 0;
 
     if (write(fd, &ch, 1) < 0) {
-        LOGE("Unable to write to ums lunfile (%s)\n", strerror(errno));
+        LOGE("Unable to write to ums lunfile (%s)", strerror(errno));
         close(fd);
         return -errno;
     }
@@ -114,7 +114,7 @@
     int rc;
 
 #if DEBUG_UMS
-    LOG_VOL("ums_send_status():\n");
+    LOG_VOL("ums_send_status():");
 #endif
 
     rc = send_msg(ums_enabled_get() ? VOLD_EVT_UMS_ENABLED :
diff --git a/vold/vold.c b/vold/vold.c
index 4c74136..17331ac 100644
--- a/vold/vold.c
+++ b/vold/vold.c
@@ -60,7 +60,7 @@
     struct sockaddr_nl nladdr;
     int uevent_sz = 64 * 1024;
 
-    LOG_VOL("Android Volume Daemon version %d.%d\n", ver_major, ver_minor);
+    LOG_VOL("Android Volume Daemon version %d.%d", ver_major, ver_minor);
 
     /*
      * Create all the various sockets we'll need
@@ -68,13 +68,13 @@
 
     // Socket to listen on for incomming framework connections
     if ((door_sock = android_get_control_socket(VOLD_SOCKET)) < 0) {
-        LOGE("Obtaining file descriptor socket '%s' failed: %s\n",
+        LOGE("Obtaining file descriptor socket '%s' failed: %s",
              VOLD_SOCKET, strerror(errno));
         exit(1);
     }
 
     if (listen(door_sock, 4) < 0) {
-        LOGE("Unable to listen on fd '%d' for socket '%s': %s\n", 
+        LOGE("Unable to listen on fd '%d' for socket '%s': %s", 
              door_sock, VOLD_SOCKET, strerror(errno));
         exit(1);
     }
@@ -89,18 +89,18 @@
 
     if ((uevent_sock = socket(PF_NETLINK,
                              SOCK_DGRAM,NETLINK_KOBJECT_UEVENT)) < 0) {
-        LOGE("Unable to create uevent socket: %s\n", strerror(errno));
+        LOGE("Unable to create uevent socket: %s", strerror(errno));
         exit(1);
     }
 
     if (setsockopt(uevent_sock, SOL_SOCKET, SO_RCVBUFFORCE, &uevent_sz,
                    sizeof(uevent_sz)) < 0) {
-        LOGE("Unable to set uevent socket options: %s\n", strerror(errno));
+        LOGE("Unable to set uevent socket options: %s", strerror(errno));
         exit(1);
     }
 
     if (bind(uevent_sock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) {
-        LOGE("Unable to bind uevent socket: %s\n", strerror(errno));
+        LOGE("Unable to bind uevent socket: %s", strerror(errno));
         exit(1);
     }
 
@@ -123,7 +123,7 @@
     /*
      * Main loop
      */
-    LOG_VOL("Bootstrapping complete\n");
+    LOG_VOL("Bootstrapping complete");
     while(1) {
         fd_set read_fds;
         struct timeval to;
@@ -148,7 +148,7 @@
         }
 
         if ((rc = select(max + 1, &read_fds, NULL, NULL, &to)) < 0) {
-            LOGE("select() failed (%s)\n", strerror(errno));
+            LOGE("select() failed (%s)", strerror(errno));
             sleep(1);
             continue;
         }
@@ -164,30 +164,30 @@
             alen = sizeof(addr);
 
             if (fw_sock != -1) {
-                LOGE("Dropping duplicate framework connection\n");
+                LOGE("Dropping duplicate framework connection");
                 int tmp = accept(door_sock, &addr, &alen);
                 close(tmp);
                 continue;
             }
 
             if ((fw_sock = accept(door_sock, &addr, &alen)) < 0) {
-                LOGE("Unable to accept framework connection (%s)\n",
+                LOGE("Unable to accept framework connection (%s)",
                      strerror(errno));
             }
-            LOG_VOL("Accepted connection from framework\n");
+            LOG_VOL("Accepted connection from framework");
             if ((rc = volmgr_send_states()) < 0) {
-                LOGE("Unable to send volmgr status to framework (%d)\n", rc);
+                LOGE("Unable to send volmgr status to framework (%d)", rc);
             }
         }
 
         if (FD_ISSET(fw_sock, &read_fds)) {
             if ((rc = process_framework_command(fw_sock)) < 0) {
                 if (rc == -ECONNRESET) {
-                    LOGE("Framework disconnected\n");
+                    LOGE("Framework disconnected");
                     close(fw_sock);
                     fw_sock = -1;
                 } else {
-                    LOGE("Error processing framework command (%s)\n",
+                    LOGE("Error processing framework command (%s)",
                          strerror(errno));
                 }
             }
@@ -195,7 +195,7 @@
 
         if (FD_ISSET(uevent_sock, &read_fds)) {
             if ((rc = process_uevent_message(uevent_sock)) < 0) {
-                LOGE("Error processing uevent msg (%s)\n", strerror(errno));
+                LOGE("Error processing uevent msg (%s)", strerror(errno));
             }
         }
     } // while
@@ -208,7 +208,7 @@
 
     pthread_mutex_lock(&write_mutex);
 
-    LOG_VOL("send_msg(%s):\n", message);
+    LOG_VOL("send_msg(%s):", message);
 
     if (fw_sock >= 0)
         result = write(fw_sock, message, strlen(message) + 1);
@@ -224,7 +224,7 @@
 
     char* buffer = (char *)alloca(strlen(message) + strlen(data) + 1);
     if (!buffer) {
-        LOGE("alloca failed in send_msg_with_data\n");
+        LOGE("alloca failed in send_msg_with_data");
         return -1;
     }
 
diff --git a/vold/volmgr.c b/vold/volmgr.c
index 8e79b38..0cec825 100644
--- a/vold/volmgr.c
+++ b/vold/volmgr.c
@@ -103,7 +103,7 @@
     char line[1024];
 
     if (!(fp = fopen("/proc/mounts", "r"))) {
-        LOGE("Error opening /proc/mounts (%s)\n", strerror(errno));
+        LOGE("Error opening /proc/mounts (%s)", strerror(errno));
         return false;
     }
 
@@ -125,22 +125,20 @@
  * Public functions
  */
 
-int volmgr_set_volume_key(char *mount_point, unsigned char *key, unsigned int keysize)
+int volmgr_set_volume_key(char *mount_point, unsigned char *key)
 {
     volume_t *v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
  
     if (!v)
         return -ENOENT;
 
-    if (v->key)
-        free(v->key);
-
-    if (!(v->key = malloc(keysize))) {
+    if (v->media_type != media_devmapper) {
+        LOGE("Cannot set key on a non devmapper volume");
         pthread_mutex_unlock(&v->lock);
-        return -ENOMEM;
+        return -EINVAL;
     }
 
-    memcpy(v->key, key, keysize);
+    memcpy(v->dm->key, key, sizeof(v->dm->key));
     pthread_mutex_unlock(&v->lock);
     return 0;
 }
@@ -150,31 +148,41 @@
     int rc;
     volume_t *v;
 
-    LOG_VOL("volmgr_format_volume(%s):\n", mount_point);
+    LOG_VOL("volmgr_format_volume(%s):", mount_point);
 
     v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
 
     if (!v)
         return -ENOENT;
 
-
     if (v->state == volstate_mounted ||
         v->state == volstate_mounted_ro ||
         v->state == volstate_ums ||
         v->state == volstate_checking) {
-            LOGE("Can't format '%s', currently in state %d\n", mount_point, v->state);
+            LOGE("Can't format '%s', currently in state %d", mount_point, v->state);
             pthread_mutex_unlock(&v->lock);
             return -EBUSY;
-        } else if (v->state == volstate_nomedia) {
-            LOGE("Can't format '%s', (no media)\n", mount_point);
+        } else if (v->state == volstate_nomedia &&
+                   v->media_type != media_devmapper) {
+            LOGE("Can't format '%s', (no media)", mount_point);
             pthread_mutex_unlock(&v->lock);
             return -ENOMEDIUM;
         }
 
-    if ((rc = initialize_mbr(v->dev->disk)) < 0) {
-        LOGE("MBR init failed for %s (%d)\n", mount_point, rc);
-        pthread_mutex_unlock(&v->lock);
-         return rc;
+    // XXX:Reject if the underlying source media is not present
+
+    if (v->media_type == media_devmapper) {
+        if ((rc = devmapper_genesis(v->dm)) < 0) {
+            LOGE("devmapper genesis failed for %s (%d)", mount_point, rc);
+            pthread_mutex_unlock(&v->lock);
+            return rc;
+        }
+    } else {
+        if ((rc = initialize_mbr(v->dev->disk)) < 0) {
+            LOGE("MBR init failed for %s (%d)", mount_point, rc);
+            pthread_mutex_unlock(&v->lock);
+            return rc;
+        }
     }
 
     volume_setstate(v, volstate_formatting);
@@ -187,7 +195,7 @@
     int rc;
 
     if ((rc = volmgr_readconfig("/system/etc/vold.conf")) < 0) {
-        LOGE("Unable to process config\n");
+        LOGE("Unable to process config");
         return rc;
     }
 
@@ -197,7 +205,7 @@
     volume_t *v = vol_root;
     while (v) {
         if (_mountpoint_mounted(v->mount_point)) {
-            LOG_VOL("Volume '%s' already mounted at startup\n", v->mount_point);
+            LOG_VOL("Volume '%s' already mounted at startup", v->mount_point);
             v->state = volstate_mounted;
         }
         v = v->next;
@@ -221,9 +229,9 @@
         if (v->state == volstate_mounted && v->fs) {
             rc = v->fs->mount_fn(v->dev, v, safe_mode);
             if (!rc) {
-                LOG_VOL("Safe mode %s on %s\n", (enable ? "enabled" : "disabled"), v->mount_point);
+                LOG_VOL("Safe mode %s on %s", (enable ? "enabled" : "disabled"), v->mount_point);
             } else {
-                LOGE("Failed to %s safe-mode on %s (%s)\n",
+                LOGE("Failed to %s safe-mode on %s (%s)",
                      (enable ? "enable" : "disable" ), v->mount_point, strerror(-rc));
             }
         }
@@ -243,7 +251,7 @@
     while (vol_scan) {
         pthread_mutex_lock(&vol_scan->lock);
         if ((rc = volume_send_state(vol_scan)) < 0) {
-            LOGE("Error sending state to framework (%d)\n", rc);
+            LOGE("Error sending state to framework (%d)", rc);
         }
         pthread_mutex_unlock(&vol_scan->lock);
         vol_scan = vol_scan->next;
@@ -267,7 +275,7 @@
     pthread_mutex_lock(&vol->lock);
 
     if (vol->state == volstate_mounted) {
-        LOGE("Volume %s already mounted (did we just crash?)\n", vol->mount_point);
+        LOGE("Volume %s already mounted (did we just crash?)", vol->mount_point);
         pthread_mutex_unlock(&vol->lock);
         return 0;
     }
@@ -281,26 +289,24 @@
 { 
     volume_t *v;
 
-LOG_VOL("volmgr_start_volume_by_mountpoint(%s):", mount_point);
     v = volmgr_lookup_volume_by_mountpoint(mount_point, true);
     if (!v)
         return -ENOENT;
 
-LOG_VOL("volmgr_start_volume_by_mountpoint(%s): got %p", mount_point, v);
     if (v->media_type == media_devmapper) {
         if (devmapper_start(v->dm) < 0)  {
-            LOGE("volmgr failed to start devmapper volume '%s'\n",
+            LOGE("volmgr failed to start devmapper volume '%s'",
                  v->mount_point);
         }
     } else if (v->media_type == media_mmc) {
         if (!v->dev) {
-            LOGE("Cannot start volume '%s' (volume is not bound)\n", mount_point);
+            LOGE("Cannot start volume '%s' (volume is not bound)", mount_point);
             pthread_mutex_unlock(&v->lock);
             return -ENOENT;
         }
 
         if (_volmgr_consider_disk_and_vol(v, v->dev->disk) < 0) {
-            LOGE("volmgr failed to start volume '%s'\n", v->mount_point);
+            LOGE("volmgr failed to start volume '%s'", v->mount_point);
         }
     }
 
@@ -308,6 +314,13 @@
     return 0;
 }
 
+static void _cb_volstopped_for_devmapper_teardown(volume_t *v, void *arg)
+{
+    devmapper_stop(v->dm);
+    volume_setstate(v, volstate_nomedia);
+    pthread_mutex_unlock(&v->lock);
+}
+
 int volmgr_stop_volume_by_mountpoint(char *mount_point)
 {
     int rc;
@@ -320,7 +333,10 @@
     if (v->state == volstate_mounted)
         volmgr_send_eject_request(v);
 
-    rc = volmgr_shutdown_volume(v, NULL, true);
+    if (v->media_type == media_devmapper)
+        rc = volmgr_shutdown_volume(v, _cb_volstopped_for_devmapper_teardown, false);
+    else
+        rc = volmgr_shutdown_volume(v, NULL, true);
 
     /*
      * If shutdown returns -EINPROGRESS,
@@ -329,7 +345,7 @@
      */
     if (rc != -EINPROGRESS) {
         if (rc)
-            LOGE("unable to shutdown volume '%s'\n", v->mount_point);
+            LOGE("unable to shutdown volume '%s'", v->mount_point);
         pthread_mutex_unlock(&v->lock);
     }
     return 0;
@@ -337,7 +353,7 @@
 
 int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *))
 {
-    LOG_VOL("Volmgr notified of %d:%d eject\n", dev->major, dev->minor);
+    LOG_VOL("Volmgr notified of %d:%d eject", dev->major, dev->minor);
 
     volume_t *v;
 
@@ -362,7 +378,7 @@
          * The device is being ejected due to
          * kernel disk revalidation.
          */
-        LOG_VOL("Volmgr ignoring eject of %d:%d (volume formatting)\n",
+        LOG_VOL("Volmgr ignoring eject of %d:%d (volume formatting)",
                 dev->major, dev->minor);
         if (cb)
             cb(dev);
@@ -378,7 +394,7 @@
         int rc = volmgr_stop_volume(v, _cb_volume_stopped_for_eject, cb, false);
         if (rc != -EINPROGRESS) {
             if (rc)
-                LOGE("unable to shutdown volume '%s'\n", v->mount_point);
+                LOGE("unable to shutdown volume '%s'", v->mount_point);
             pthread_mutex_unlock(&v->lock);
         }
     }
@@ -390,7 +406,7 @@
     void (* eject_cb) (blkdev_t *) = arg;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("Volume %s has been stopped for eject\n", v->mount_point);
+    LOG_VOL("Volume %s has been stopped for eject", v->mount_point);
 #endif
 
     eject_cb(v->dev);
@@ -422,7 +438,7 @@
                 rc = volmgr_shutdown_volume(v, _cb_volstopped_for_ums_enable, false);
                 if (rc != -EINPROGRESS) {
                     if (rc)
-                        LOGE("unable to shutdown volume '%s'\n", v->mount_point);
+                        LOGE("unable to shutdown volume '%s'", v->mount_point);
                     pthread_mutex_unlock(&v->lock);
                 }
             } else {
@@ -434,16 +450,16 @@
                 }
 
                 if ((rc = ums_disable(v->ums_path)) < 0) {
-                    LOGE("unable to disable ums on '%s'\n", v->mount_point);
+                    LOGE("unable to disable ums on '%s'", v->mount_point);
                     pthread_mutex_unlock(&v->lock);
                     continue;
                 }
 
-                LOG_VOL("Kick-starting volume %d:%d after UMS disable\n",
+                LOG_VOL("Kick-starting volume %d:%d after UMS disable",
                         v->dev->disk->major, v->dev->disk->minor);
                 // Start volume
                 if ((rc = _volmgr_consider_disk_and_vol(v, v->dev->disk)) < 0) {
-                    LOGE("volmgr failed to consider disk %d:%d\n",
+                    LOGE("volmgr failed to consider disk %d:%d",
                          v->dev->disk->major, v->dev->disk->minor);
                 }
                 pthread_mutex_unlock(&v->lock);
@@ -470,7 +486,7 @@
     int rc = 0;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("volmgr_consider_disk_and_vol(%s, %d:%d):\n", vol->mount_point,
+    LOG_VOL("volmgr_consider_disk_and_vol(%s, %d:%d):", vol->mount_point,
             dev->major, dev->minor); 
 #endif
 
@@ -478,13 +494,13 @@
         vol->state == volstate_mounted ||
         vol->state == volstate_mounted_ro ||
         vol->state == volstate_damaged) {
-        LOGE("Cannot consider volume '%s' because it is in state '%d\n", 
+        LOGE("Cannot consider volume '%s' because it is in state '%d", 
              vol->mount_point, vol->state);
         return -EADDRINUSE;
     }
 
     if (vol->state == volstate_formatting) {
-        LOG_VOL("Evaluating dev '%s' for formattable filesystems for '%s'\n",
+        LOG_VOL("Evaluating dev '%s' for formattable filesystems for '%s'",
                 dev->devpath, vol->mount_point);
         /*
          * Since we only support creating 1 partition (right now),
@@ -492,24 +508,29 @@
          */
         blkdev_t *part = blkdev_lookup_by_devno(dev->major, 1);
         if (!part) {
-            LOGE("Can't find partition to format!\n");
-            return -ENOENT;
+            part = blkdev_lookup_by_devno(dev->major, 0);
+            if (!part) {
+                LOGE("Unable to find device to format");
+                return -ENODEV;
+            }
         }
 
-        if ((rc = format_partition(part)) < 0) {
-            LOGE("format failed (%d)\n", rc);
+        if ((rc = format_partition(part,
+                                   vol->media_type == media_devmapper ?
+                                   FORMAT_TYPE_EXT2 : FORMAT_TYPE_FAT32)) < 0) {
+            LOGE("format failed (%d)", rc);
             return rc;
         }
         
     }
 
-    LOG_VOL("Evaluating dev '%s' for mountable filesystems for '%s'\n",
+    LOG_VOL("Evaluating dev '%s' for mountable filesystems for '%s'",
             dev->devpath, vol->mount_point);
 
     if (dev->nr_parts == 0) {
         rc = _volmgr_start(vol, dev);
 #if DEBUG_VOLMGR
-        LOG_VOL("_volmgr_start(%s, %d:%d) rc = %d\n", vol->mount_point,
+        LOG_VOL("_volmgr_start(%s, %d:%d) rc = %d", vol->mount_point,
                 dev->major, dev->minor, rc);
 #endif
     } else {
@@ -524,12 +545,12 @@
         for (i = 0; i < dev->nr_parts; i++) {
             blkdev_t *part = blkdev_lookup_by_devno(dev->major, (i+1));
             if (!part) {
-                LOGE("Error - unable to lookup partition for blkdev %d:%d\n", dev->major, (i+1));
+                LOGE("Error - unable to lookup partition for blkdev %d:%d", dev->major, (i+1));
                 continue;
             }
             rc = _volmgr_start(vol, part);
 #if DEBUG_VOLMGR
-            LOG_VOL("_volmgr_start(%s, %d:%d) rc = %d\n",
+            LOG_VOL("_volmgr_start(%s, %d:%d) rc = %d",
                     vol->mount_point, part->major, part->minor, rc);
 #endif
             if (!rc) 
@@ -538,13 +559,13 @@
 
         if (rc == -ENODEV) {
             // Assert to make sure each partition had a backing blkdev
-            LOGE("Internal consistency error\n");
+            LOGE("Internal consistency error");
             return 0;
         }
     }
 
     if (rc == -ENODATA) {
-        LOGE("Device %d:%d contains no usable filesystems\n",
+        LOGE("Device %d:%d contains no usable filesystems",
              dev->major, dev->minor);
         rc = 0;
     }
@@ -554,7 +575,7 @@
 
 static void volmgr_reaper_thread_sighandler(int signo)
 {
-    LOGE("Volume reaper thread got signal %d\n", signo);
+    LOGE("Volume reaper thread got signal %d", signo);
 }
 
 static void __reaper_cleanup(void *arg)
@@ -590,7 +611,7 @@
     actions.sa_handler = volmgr_reaper_thread_sighandler;
     sigaction(SIGUSR1, &actions, NULL);
 
-    LOG_VOL("Reaper here - working on %s\n", vol->mount_point);
+    LOG_VOL("Reaper here - working on %s", vol->mount_point);
 
     boolean send_sig_kill = false;
     int i, rc;
@@ -598,7 +619,7 @@
     for (i = 0; i < 10; i++) {
         errno = 0;
         rc = umount(vol->mount_point);
-        LOG_VOL("volmngr reaper umount(%s) attempt %d (%s)\n",
+        LOG_VOL("volmngr reaper umount(%s) attempt %d (%s)",
                 vol->mount_point, i + 1, strerror(errno));
         if (!rc)
             break;
@@ -615,11 +636,11 @@
     }
 
     if (!rc) {
-        LOG_VOL("Reaper sucessfully unmounted %s\n", vol->mount_point);
+        LOG_VOL("Reaper sucessfully unmounted %s", vol->mount_point);
         vol->fs = NULL;
         volume_setstate(vol, volstate_unmounted);
     } else {
-        LOGE("Unable to unmount!! (%d)\n", rc);
+        LOGE("Unable to unmount!! (%d)", rc);
     }
 
  out:
@@ -633,9 +654,9 @@
 {
 
     if (vol->worker_running) {
-        LOGE("Worker thread is currently running.. waiting..\n");
+        LOGE("Worker thread is currently running.. waiting..");
         pthread_mutex_lock(&vol->worker_sem);
-        LOG_VOL("Worker thread now available\n");
+        LOG_VOL("Worker thread now available");
     }
 
     vol->worker_args.reaper_args.cb = cb;
@@ -664,7 +685,7 @@
                 break;
             }
 
-            LOG_VOL("volmngr quick stop umount(%s) attempt %d (%s)\n",
+            LOG_VOL("volmngr quick stop umount(%s) attempt %d (%s)",
                     v->mount_point, i + 1, strerror(errno));
 
             if (i == 0)
@@ -674,7 +695,7 @@
         }
 
         if (!rc) {
-            LOG_VOL("volmgr_stop_volume(%s): Volume unmounted sucessfully\n",
+            LOG_VOL("volmgr_stop_volume(%s): Volume unmounted sucessfully",
                     v->mount_point);
             if (emit_statechange)
                 volume_setstate(v, volstate_unmounted);
@@ -686,16 +707,16 @@
          * Since the volume is still in use, dispatch the stopping to
          * a thread
          */
-        LOG_VOL("Volume %s is busy (%d) - uncaging the reaper\n", v->mount_point, rc);
+        LOG_VOL("Volume %s is busy (%d) - uncaging the reaper", v->mount_point, rc);
         volmgr_uncage_reaper(v, cb, arg);
         return -EINPROGRESS;
     } else if (v->state == volstate_checking) {
         volume_setstate(v, volstate_unmounted);
         if (v->worker_running) {
-            LOG_VOL("Cancelling worker thread\n");
+            LOG_VOL("Cancelling worker thread");
             pthread_kill(v->worker_thread, SIGUSR1);
         } else
-            LOGE("Strange... we were in checking state but worker thread wasn't running..\n");
+            LOGE("Strange... we were in checking state but worker thread wasn't running..");
         goto out_cb_immed;
     }
 
@@ -722,11 +743,12 @@
     void (* shutdown_cb) (volume_t *) = arg;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("Volume %s has been stopped for shutdown\n", v->mount_point);
+    LOG_VOL("Volume %s has been stopped for shutdown", v->mount_point);
 #endif
     shutdown_cb(v);
 }
 
+
 /*
  * Called when a volume is sucessfully unmounted for UMS enable
  */
@@ -736,13 +758,13 @@
     char *devdir_path;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("_cb_volstopped_for_ums_enable(%s):\n", v->mount_point);
+    LOG_VOL("_cb_volstopped_for_ums_enable(%s):", v->mount_point);
 #endif
     devdir_path = blkdev_get_devpath(v->dev->disk);
 
     if ((rc = ums_enable(devdir_path, v->ums_path)) < 0) {
         free(devdir_path);
-        LOGE("Error enabling ums (%d)\n", rc);
+        LOGE("Error enabling ums (%d)", rc);
         return;
     }
     free(devdir_path);
@@ -762,7 +784,7 @@
         if (!strncmp(node->name, "volume_", 7))
             volmgr_config_volume(node);
         else
-            LOGE("Skipping unknown configuration node '%s'\n", node->name);
+            LOGE("Skipping unknown configuration node '%s'", node->name);
         node = node->next;
     }
     return 0;
@@ -773,7 +795,7 @@
     int i;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("volmgr_add_mediapath_to_volume(%p, %s):\n", v, media_path);
+    LOG_VOL("volmgr_add_mediapath_to_volume(%p, %s):", v, media_path);
 #endif
     for (i = 0; i < VOLMGR_MAX_MEDIAPATHS_PER_VOLUME; i++) {
         if (!v->media_paths[i]) {
@@ -781,7 +803,7 @@
             return;
         }
     }
-    LOGE("Unable to add media path '%s' to volume (out of media slots)\n", media_path);
+    LOGE("Unable to add media path '%s' to volume (out of media slots)", media_path);
 }
 
 static int volmgr_config_volume(cnode *node)
@@ -794,7 +816,7 @@
 
     dm_src = dm_src_type = dm_tgt = dm_param = dm_tgtfs = NULL;
 #if DEBUG_VOLMGR
-    LOG_VOL("volmgr_configure_volume(%s):\n", node->name);
+    LOG_VOL("volmgr_configure_volume(%s):", node->name);
 #endif
     if (!(new = malloc(sizeof(volume_t))))
         return -ENOMEM;
@@ -817,7 +839,7 @@
             else if (!strcmp(child->value, "devmapper"))
                 new->media_type = media_devmapper;
             else {
-                LOGE("Invalid media type '%s'\n", child->value);
+                LOGE("Invalid media type '%s'", child->value);
                 rc = -EINVAL;
                 goto out_free;
             }
@@ -838,29 +860,32 @@
         else if (!strcmp(child->name, "dm_target_fs")) 
             dm_tgtfs = strdup(child->value);
         else
-            LOGE("Ignoring unknown config entry '%s'\n", child->name);
+            LOGE("Ignoring unknown config entry '%s'", child->name);
         child = child->next;
     }
 
     if (new->media_type == media_mmc) {
         if (!new->media_paths[0] || !new->mount_point || new->media_type == media_unknown) {
-            LOGE("Required configuration parameter missing for mmc volume\n");
+            LOGE("Required configuration parameter missing for mmc volume");
             rc = -EINVAL;
             goto out_free;
         }
     } else if (new->media_type == media_devmapper) {
         if (!dm_src || !dm_src_type || !dm_tgt ||
             !dm_param || !dm_tgtfs || !dm_size_mb) {
-            LOGE("Required configuration parameter missing for devmapper volume\n");
+            LOGE("Required configuration parameter missing for devmapper volume");
             rc = -EINVAL;
             goto out_free;
         }
+
+        char dm_mediapath[255];
         if (!(new->dm = devmapper_init(dm_src, dm_src_type, dm_size_mb,
-                                       dm_tgt, dm_param, dm_tgtfs))) {
+                                       dm_tgt, dm_param, dm_tgtfs, dm_mediapath))) {
             LOGE("Unable to initialize devmapping");
-           goto out_free;
+            goto out_free;
         }
-        
+        LOG_VOL("media path for devmapper volume = '%s'", dm_mediapath);
+        volmgr_add_mediapath_to_volume(new, dm_mediapath);
     }
 
     if (!vol_root)
@@ -932,6 +957,7 @@
                 pthread_mutex_unlock(&v->lock);
             return v;
         }
+        pthread_mutex_unlock(&v->lock);
         v = v->next;
     }
     return NULL;
@@ -971,12 +997,12 @@
     int rc = ENODATA;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("_volmgr_start(%s, %d:%d):\n", vol->mount_point,
+    LOG_VOL("_volmgr_start(%s, %d:%d):", vol->mount_point,
             dev->major, dev->minor);
 #endif
 
     if (vol->state == volstate_mounted) {
-        LOGE("Unable to start volume '%s' (already mounted)\n", vol->mount_point);
+        LOGE("Unable to start volume '%s' (already mounted)", vol->mount_point);
         return -EBUSY;
     }
 
@@ -986,7 +1012,7 @@
     }
 
     if (!fs) {
-        LOGE("No supported filesystems on %d:%d\n", dev->major, dev->minor);
+        LOGE("No supported filesystems on %d:%d", dev->major, dev->minor);
         volume_setstate(vol, volstate_nofs);
         return -ENODATA;
     }
@@ -1002,9 +1028,9 @@
      */
 
     if (vol->worker_running) {
-        LOGE("Worker thread is currently running.. waiting..\n");
+        LOGE("Worker thread is currently running.. waiting..");
         pthread_mutex_lock(&vol->worker_sem);
-        LOG_VOL("Worker thread now available\n");
+        LOG_VOL("Worker thread now available");
     }
 
     vol->dev = dev; 
@@ -1026,7 +1052,7 @@
     volume_t *vol = (volume_t *) arg;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("__start_fs_thread_lock_cleanup(%s):\n", vol->mount_point);
+    LOG_VOL("__start_fs_thread_lock_cleanup(%s):", vol->mount_point);
 #endif
 
     vol->worker_running = false;
@@ -1061,13 +1087,13 @@
     int                          rc;
   
 #if DEBUG_VOLMGR
-    LOG_VOL("Worker thread pid %d starting %s fs %d:%d on %s\n", getpid(),
+    LOG_VOL("Worker thread pid %d starting %s fs %d:%d on %s", getpid(),
              fs->name, dev->major, dev->minor, vol->mount_point);
 #endif
 
     if (fs->check_fn) {
 #if DEBUG_VOLMGR
-        LOG_VOL("Starting %s filesystem check on %d:%d\n", fs->name,
+        LOG_VOL("Starting %s filesystem check on %d:%d", fs->name,
                 dev->major, dev->minor);
 #endif
         volume_setstate(vol, volstate_checking);
@@ -1075,12 +1101,12 @@
         rc = fs->check_fn(dev);
         pthread_mutex_lock(&vol->lock);
         if (vol->state != volstate_checking) {
-            LOG_VOL("filesystem check aborted\n");
+            LOG_VOL("filesystem check aborted");
             goto out;
         }
         
         if (rc < 0) {
-            LOGE("%s filesystem check failed on %d:%d (%s)\n", fs->name,
+            LOGE("%s filesystem check failed on %d:%d (%s)", fs->name,
                     dev->major, dev->minor, strerror(-rc));
             if (rc == -ENODATA) {
                volume_setstate(vol, volstate_nofs);
@@ -1089,14 +1115,14 @@
             goto out_unmountable;
         }
 #if DEBUG_VOLMGR
-        LOG_VOL("%s filesystem check of %d:%d OK\n", fs->name,
+        LOG_VOL("%s filesystem check of %d:%d OK", fs->name,
                 dev->major, dev->minor);
 #endif
     }
 
     rc = fs->mount_fn(dev, vol, safe_mode);
     if (!rc) {
-        LOG_VOL("Sucessfully mounted %s filesystem %d:%d on %s (safe-mode %s)\n",
+        LOG_VOL("Sucessfully mounted %s filesystem %d:%d on %s (safe-mode %s)",
                 fs->name, dev->major, dev->minor, vol->mount_point,
                 (safe_mode ? "on" : "off"));
         vol->fs = fs;
@@ -1104,7 +1130,7 @@
         goto out;
     }
 
-    LOGE("%s filesystem mount of %d:%d failed (%d)\n", fs->name, dev->major,
+    LOGE("%s filesystem mount of %d:%d failed (%d)", fs->name, dev->major,
          dev->minor, rc);
 
  out_unmountable:
@@ -1117,7 +1143,7 @@
 
 static void volmgr_start_fs_thread_sighandler(int signo)
 {
-    LOGE("Volume startup thread got signal %d\n", signo);
+    LOGE("Volume startup thread got signal %d", signo);
 }
 
 static void volume_setstate(volume_t *vol, volume_state_t state)
@@ -1126,7 +1152,7 @@
         return;
 
 #if DEBUG_VOLMGR
-    LOG_VOL("Volume %s state change from %d -> %d\n", vol->mount_point, vol->state, state);
+    LOG_VOL("Volume %s state change from %d -> %d", vol->mount_point, vol->state, state);
 #endif
     
     vol->state = state;
diff --git a/vold/volmgr.h b/vold/volmgr.h
index 98c1561..2c7ec50 100644
--- a/vold/volmgr.h
+++ b/vold/volmgr.h
@@ -119,9 +119,6 @@
 
     struct volmgr_fstable_entry *fs;
 
-    unsigned char            *key;
-    unsigned int             keysize;
-
     struct volume            *next;
 } volume_t;
 
@@ -133,6 +130,6 @@
 int volmgr_start_volume_by_mountpoint(char *mount_point);
 int volmgr_safe_mode(boolean enable);
 int volmgr_format_volume(char *mount_point);
-int volmgr_set_volume_key(char *mount_point, unsigned char *key, unsigned int keysize);
+int volmgr_set_volume_key(char *mount_point, unsigned char *key);
 void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded);
 #endif
diff --git a/vold/volmgr_ext3.c b/vold/volmgr_ext3.c
index 3af113f..680be21 100644
--- a/vold/volmgr_ext3.c
+++ b/vold/volmgr_ext3.c
@@ -43,26 +43,26 @@
     char *devpath;
 
 #if EXT_DEBUG
-    LOG_VOL("ext_identify(%d:%d):\n", dev-major, dev->minor);
+    LOG_VOL("ext_identify(%d:%d):", dev-major, dev->minor);
 #endif
 
     devpath = blkdev_get_devpath(dev);
 
     if ((fd = open(devpath, O_RDWR)) < 0) {
-        LOGE("Unable to open device '%s' (%s)\n", devpath,
+        LOGE("Unable to open device '%s' (%s)", devpath,
              strerror(errno));
         free(devpath);
         return -errno;
     }
 
     if (lseek(fd, 1024, SEEK_SET) < 0) {
-        LOGE("Unable to lseek to get superblock (%s)\n", strerror(errno));
+        LOGE("Unable to lseek to get superblock (%s)", strerror(errno));
         rc =  -errno;
         goto out;
     }
 
     if (read(fd, &sb, sizeof(sb)) != sizeof(sb)) {
-        LOGE("Unable to read superblock (%s)\n", strerror(errno));
+        LOGE("Unable to read superblock (%s)", strerror(errno));
         rc =  -errno;
         goto out;
     }
@@ -75,7 +75,7 @@
 
  out:
 #if EXT_DEBUG
-    LOG_VOL("ext_identify(%s): rc = %d\n", devpath, rc);
+    LOG_VOL("ext_identify(%s): rc = %d", devpath, rc);
 #endif
     free(devpath);
     close(fd);
@@ -87,13 +87,13 @@
     char *devpath;
 
 #if EXT_DEBUG
-    LOG_VOL("ext_check(%s):\n", dev->dev_fspath);
+    LOG_VOL("ext_check(%s):", dev->dev_fspath);
 #endif
 
     devpath = blkdev_get_devpath(dev);
 
     if (access(E2FSCK_PATH, X_OK)) {
-        LOGE("ext_check(%s): %s not found (skipping checks)\n",
+        LOGE("ext_check(%s): %s not found (skipping checks)",
              devpath, E2FSCK_PATH);
         free(devpath);
         return 0;
@@ -110,21 +110,21 @@
     int rc = logwrap(4, args);
 
     if (rc == 0) {
-        LOG_VOL("filesystem '%s' had no errors\n", devpath);
+        LOG_VOL("filesystem '%s' had no errors", devpath);
     } else if (rc == 1) {
-        LOG_VOL("filesystem '%s' had corrected errors\n", devpath);
+        LOG_VOL("filesystem '%s' had corrected errors", devpath);
         rc = 0;
     } else if (rc == 2) {
-        LOGE("VOL volume '%s' had corrected errors (system should be rebooted)\n", devpath);
+        LOGE("VOL volume '%s' had corrected errors (system should be rebooted)", devpath);
         rc = -EIO;
     } else if (rc == 4) {
-        LOGE("VOL volume '%s' had uncorrectable errors\n", devpath);
+        LOGE("VOL volume '%s' had uncorrectable errors", devpath);
         rc = -EIO;
     } else if (rc == 8) {
-        LOGE("Operational error while checking volume '%s'\n", devpath);
+        LOGE("Operational error while checking volume '%s'", devpath);
         rc = -EIO;
     } else {
-        LOGE("Unknown e2fsck exit code (%d)\n", rc);
+        LOGE("Unknown e2fsck exit code (%d)", rc);
         rc = -EIO;
     }
     free(devpath);
@@ -134,7 +134,7 @@
 int ext_mount(blkdev_t *dev, volume_t *vol, boolean safe_mode)
 {
 #if EXT_DEBUG
-    LOG_VOL("ext_mount(%s, %s, %d):\n", dev->dev_fspath, vol->mount_point, safe_mode);
+    LOG_VOL("ext_mount(%s, %s, %d):", dev->dev_fspath, vol->mount_point, safe_mode);
 #endif
 
     char *fs[] = { "ext3", "ext2", NULL };
@@ -150,7 +150,7 @@
         flags |= MS_SYNCHRONOUS;
 
     if (vol->state == volstate_mounted) {
-        LOG_VOL("Remounting %s on %s, safe mode %d\n", devpath,
+        LOG_VOL("Remounting %s on %s, safe mode %d", devpath,
                 vol->mount_point, safe_mode);
         flags |= MS_REMOUNT;
     }
@@ -159,13 +159,13 @@
     for (f = fs; *f != NULL; f++) {
         rc = mount(devpath, vol->mount_point, *f, flags, NULL);
         if (rc && errno == EROFS) {
-            LOGE("ext_mount(%s, %s): Read only filesystem - retrying mount RO\n",
+            LOGE("ext_mount(%s, %s): Read only filesystem - retrying mount RO",
                  devpath, vol->mount_point);
             flags |= MS_RDONLY;
             rc = mount(devpath, vol->mount_point, *f, flags, NULL);
         }
 #if EXT_DEBUG
-        LOG_VOL("ext_mount(%s, %s): %s mount rc = %d\n", devpath, *f,
+        LOG_VOL("ext_mount(%s, %s): %s mount rc = %d", devpath, *f,
                 vol->mount_point, rc);
 #endif
         if (!rc)
@@ -176,7 +176,7 @@
     // Chmod the mount point so that its a free-for-all.
     // (required for consistency with VFAT.. sigh)
     if (chmod(vol->mount_point, 0777) < 0) {
-        LOGE("Failed to chmod %s (%s)\n", vol->mount_point, strerror(errno));
+        LOGE("Failed to chmod %s (%s)", vol->mount_point, strerror(errno));
         return -errno;
     }
     
diff --git a/vold/volmgr_vfat.c b/vold/volmgr_vfat.c
index 7a1cf81..1dc4c8d 100644
--- a/vold/volmgr_vfat.c
+++ b/vold/volmgr_vfat.c
@@ -31,7 +31,7 @@
 int vfat_identify(blkdev_t *dev)
 {
 #if VFAT_DEBUG
-    LOG_VOL("vfat_identify(%d:%d):\n", dev->major, dev->minor);
+    LOG_VOL("vfat_identify(%d:%d):", dev->major, dev->minor);
 #endif
     return 0; // XXX: Implement
 }
@@ -41,11 +41,11 @@
     int rc;
 
 #if VFAT_DEBUG
-    LOG_VOL("vfat_check(%d:%d):\n", dev->major, dev->minor);
+    LOG_VOL("vfat_check(%d:%d):", dev->major, dev->minor);
 #endif
 
     if (access(FSCK_MSDOS_PATH, X_OK)) {
-        LOGE("vfat_check(%d:%d): %s not found (skipping checks)\n",
+        LOGE("vfat_check(%d:%d): %s not found (skipping checks)",
              dev->major, dev->minor, FSCK_MSDOS_PATH);
         return 0;
     }
@@ -74,21 +74,21 @@
 #endif
 
     if (rc == 0) {
-        LOG_VOL("Filesystem check completed OK\n");
+        LOG_VOL("Filesystem check completed OK");
         return 0;
     } else if (rc == 1) {
-        LOG_VOL("Filesystem check failed (general failure)\n");
+        LOG_VOL("Filesystem check failed (general failure)");
         return -EINVAL;
     } else if (rc == 2) {
-        LOG_VOL("Filesystem check failed (invalid usage)\n");
+        LOG_VOL("Filesystem check failed (invalid usage)");
         return -EIO;
     } else if (rc == 4) {
-        LOG_VOL("Filesystem check completed (errors fixed)\n");
+        LOG_VOL("Filesystem check completed (errors fixed)");
     } else if (rc == 8) {
-        LOG_VOL("Filesystem check failed (not a FAT filesystem)\n");
+        LOG_VOL("Filesystem check failed (not a FAT filesystem)");
         return -ENODATA;
     } else {
-        LOG_VOL("Filesystem check failed (unknown exit code %d)\n", rc);
+        LOG_VOL("Filesystem check failed (unknown exit code %d)", rc);
         return -EIO;
     }
     return 0;
@@ -102,7 +102,7 @@
     devpath = blkdev_get_devpath(dev);
 
 #if VFAT_DEBUG
-    LOG_VOL("vfat_mount(%d:%d, %s, %d):\n", dev->major, dev->minor, vol->mount_point, safe_mode);
+    LOG_VOL("vfat_mount(%d:%d, %s, %d):", dev->major, dev->minor, vol->mount_point, safe_mode);
 #endif
 
     flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;
@@ -110,7 +110,7 @@
     if (safe_mode)
         flags |= MS_SYNCHRONOUS;
     if (vol->state == volstate_mounted) {
-        LOG_VOL("Remounting %d:%d on %s, safe mode %d\n", dev->major,
+        LOG_VOL("Remounting %d:%d on %s, safe mode %d", dev->major,
                 dev->minor, vol->mount_point, safe_mode);
         flags |= MS_REMOUNT;
     }
@@ -119,7 +119,7 @@
                "utf8,uid=1000,gid=1000,fmask=711,dmask=700");
 
     if (rc && errno == EROFS) {
-        LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO\n",
+        LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO",
              dev->major, dev->minor, vol->mount_point);
         flags |= MS_RDONLY;
         rc = mount(devpath, vol->mount_point, "vfat", flags,
@@ -127,7 +127,7 @@
     }
 
 #if VFAT_DEBUG
-    LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d\n", dev->major,k dev->minor,
+    LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d", dev->major,k dev->minor,
             vol->mount_point, rc);
 #endif
     free (devpath);