vold: Bloat reduction
Signed-off-by: San Mehat <san@google.com>
diff --git a/CommandListener.cpp b/CommandListener.cpp
index e5ebb46..bb503d3 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -33,60 +33,69 @@
 
 CommandListener::CommandListener() :
                  FrameworkListener("vold") {
-    registerCmd(new ListVolumesCmd());
-    registerCmd(new MountCmd());
-    registerCmd(new UnmountCmd());
+    registerCmd(new VolumeCmd());
+    registerCmd(new AsecCmd());
     registerCmd(new ShareCmd());
-    registerCmd(new UnshareCmd());
-    registerCmd(new ShareAvailableCmd());
-    registerCmd(new SimulateCmd());
-    registerCmd(new FormatCmd());
-    registerCmd(new CreateAsecCmd());
-    registerCmd(new FinalizeAsecCmd());
-    registerCmd(new DestroyAsecCmd());
-    registerCmd(new MountAsecCmd());
-    registerCmd(new UnmountAsecCmd());
-    registerCmd(new RenameAsecCmd());
-    registerCmd(new ListAsecCmd());
-    registerCmd(new AsecPathCmd());
 }
 
-CommandListener::ListVolumesCmd::ListVolumesCmd() :
-                 VoldCommand("list_volumes") {
+CommandListener::VolumeCmd::VolumeCmd() :
+                 VoldCommand("volume") {
 }
 
-int CommandListener::ListVolumesCmd::runCommand(SocketClient *cli,
+int CommandListener::VolumeCmd::runCommand(SocketClient *cli,
                                                       int argc, char **argv) {
-    return VolumeManager::Instance()->listVolumes(cli);
-}
-
-CommandListener::MountCmd::MountCmd() :
-                 VoldCommand("mount") {
-}
-
-int CommandListener::MountCmd::runCommand(SocketClient *cli,
-                                                      int argc, char **argv) {
-    /* Synchronously mount a volume */
-    if (VolumeManager::Instance()->mountVolume(argv[1])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to mount volume.", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Volume mounted.", false);
+    if (argc < 2) {
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing Argument", false);
+        return 0;
     }
 
-    return 0;
-}
+    VolumeManager *vm = VolumeManager::Instance();
+    int rc = 0;
 
-CommandListener::UnmountCmd::UnmountCmd() :
-                 VoldCommand("unmount") {
-}
+    if (!strcmp(argv[1], "list")) {
+        return vm->listVolumes(cli);
+    } else if (!strcmp(argv[1], "mount")) {
+        rc = vm->mountVolume(argv[2]);
+    } else if (!strcmp(argv[1], "unmount")) {
+        rc = vm->unmountVolume(argv[2]);
+    } else if (!strcmp(argv[1], "format")) {
+        rc = vm->formatVolume(argv[2]);
+    } else if (!strcmp(argv[1], "share")) {
+        rc = vm->shareVolume(argv[1], argv[2]);
+    } else if (!strcmp(argv[1], "unshare")) {
+        rc = vm->unshareVolume(argv[1], argv[2]);
+    } else if (!strcmp(argv[1], "shared")) {
+        bool enabled = false;
 
-int CommandListener::UnmountCmd::runCommand(SocketClient *cli,
-                                                      int argc, char **argv) {
-    /* Synchronously unmount a volume */
-    if (VolumeManager::Instance()->unmountVolume(argv[1])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to unmount volume.", true);
+        if (vm->shareEnabled(argv[1], argv[2], &enabled)) {
+            cli->sendMsg(
+                    ResponseCode::OperationFailed, "Failed to determine share enable state", true);
+        } else {
+            cli->sendMsg(ResponseCode::ShareEnabledResult,
+                    (enabled ? "Share enabled" : "Share disabled"), false);
+        }
     } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Volume unmounted.", false);
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown volume cmd", false);
+    }
+
+    if (!rc) {
+        cli->sendMsg(ResponseCode::CommandOkay, "volume operation succeeded", false);
+    } else {
+        /*
+         * Failed
+         */
+        if (errno == ENODEV) {
+            rc = ResponseCode::OpFailedNoMedia;
+        } else if (errno == ENODATA) {
+            rc = ResponseCode::OpFailedMediaBlank;
+        } else if (errno == EIO) {
+            rc = ResponseCode::OpFailedMediaCorrupt;
+        } else if (errno == EBUSY) {
+            rc = ResponseCode::OpFailedVolBusy;
+        } else {
+            rc = ResponseCode::OperationFailed;
+        }
+        cli->sendMsg(rc, "volume operation failed", true);
     }
 
     return 0;
@@ -98,254 +107,149 @@
 
 int CommandListener::ShareCmd::runCommand(SocketClient *cli,
                                                       int argc, char **argv) {
-    if (VolumeManager::Instance()->shareVolume(argv[1], argv[2])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to share volume.", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Volume shared.", false);
-    }
-
-    return 0;
-}
-
-CommandListener::UnshareCmd::UnshareCmd() :
-                 VoldCommand("unshare") {
-}
-
-int CommandListener::UnshareCmd::runCommand(SocketClient *cli,
-                                                      int argc, char **argv) {
-    if (VolumeManager::Instance()->unshareVolume(argv[1], argv[2])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to unshare volume.", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Volume unshared.", false);
-    }
-
-    return 0;
-}
-
-CommandListener::ShareAvailableCmd::ShareAvailableCmd() :
-                 VoldCommand("share_available") {
-}
-
-int CommandListener::ShareAvailableCmd::runCommand(SocketClient *cli,
-                                                      int argc, char **argv) {
-    bool avail = false;
-
-    if (VolumeManager::Instance()->shareAvailable(argv[1], &avail)) {
-        cli->sendMsg(ResponseCode::OperationFailed,
-                     "Failed to determine share availability", true);
-    } else {
-        cli->sendMsg(ResponseCode::ShareAvailabilityResult,
-                     (avail ? "Share available" : "Share unavailable"),
-                     false);
-    }
-    return 0;
-}
-
-CommandListener::SimulateCmd::SimulateCmd() :
-                 VoldCommand("simulate") {
-}
-
-int CommandListener::SimulateCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (VolumeManager::Instance()->simulate(argv[1], argv[2])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to execute.", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Simulation executed.", false);
-    }
-
-    return 0;
-}
-
-CommandListener::FormatCmd::FormatCmd() :
-                 VoldCommand("format") {
-}
-
-int CommandListener::FormatCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (VolumeManager::Instance()->formatVolume(argv[1])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to format", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Volume formatted.", false);
-    }
-
-    return 0;
-}
-
-CommandListener::CreateAsecCmd::CreateAsecCmd() :
-                 VoldCommand("create_asec") {
-}
-
-int CommandListener::CreateAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 6) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: create_asec <namespace-id> <size_mb> <fstype> <key> <ownerUid>",
-                     false);
+    if (argc < 2) {
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing Argument", false);
         return 0;
     }
 
-    unsigned int numSectors = (atoi(argv[2]) * (1024 * 1024)) / 512;
-    if (VolumeManager::Instance()->createAsec(argv[1], numSectors,
-                                              argv[3], argv[4],
-                                              atoi(argv[5]))) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Container creation failed", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Container created", false);
-    }
+    VolumeManager *vm = VolumeManager::Instance();
+    int rc = 0;
 
-    return 0;
-}
+    if (!strcmp(argv[1], "status")) {
+        bool avail = false;
 
-CommandListener::FinalizeAsecCmd::FinalizeAsecCmd() :
-                 VoldCommand("finalize_asec") {
-}
-
-int CommandListener::FinalizeAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 2) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: finalize_asec <namespace-id>", false);
-        return 0;
-    }
-
-    if (VolumeManager::Instance()->finalizeAsec(argv[1])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Container finalize failed", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Container finalized", false);
-    }
-    return 0;
-}
-
-CommandListener::DestroyAsecCmd::DestroyAsecCmd() :
-                 VoldCommand("destroy_asec") {
-}
-
-int CommandListener::DestroyAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 2) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: destroy_asec <namespace-id>", false);
-        return 0;
-    }
-
-    if (VolumeManager::Instance()->destroyAsec(argv[1])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Destroy failed", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Container Destroyed", false);
-    }
-    return 0;
-}
-
-CommandListener::MountAsecCmd::MountAsecCmd() :
-                 VoldCommand("mount_asec") {
-}
-
-int CommandListener::MountAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 4) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: mount_asec <namespace-id> <key> <ownerUid>", false);
-        return 0;
-    }
-
-    if (VolumeManager::Instance()->mountAsec(argv[1], argv[2], atoi(argv[3]))) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Mount failed", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Mount succeeded", false);
-    }
-    return 0;
-}
-
-CommandListener::UnmountAsecCmd::UnmountAsecCmd() :
-                 VoldCommand("unmount_asec") {
-}
-
-int CommandListener::UnmountAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 2) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: unmount_asec <namespace-id>", false);
-        return 0;
-    }
-
-    if (VolumeManager::Instance()->unmountAsec(argv[1])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Unmount failed", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Unmount succeeded", false);
-    }
-    return 0;
-}
-
-CommandListener::RenameAsecCmd::RenameAsecCmd() :
-                 VoldCommand("rename_asec") {
-}
-
-int CommandListener::RenameAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 3) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: rename_asec <id1> <id2>", false);
-        return 0;
-    }
-
-    if (VolumeManager::Instance()->renameAsec(argv[1], argv[2])) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Rename failed", true);
-    } else {
-        cli->sendMsg(ResponseCode::CommandOkay, "Rename succeeded", false);
-    }
-    return 0;
-}
-
-CommandListener::ListAsecCmd::ListAsecCmd() :
-                 VoldCommand("list_asec") {
-
-}
-
-int CommandListener::ListAsecCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    DIR *d = opendir("/sdcard/android_secure");
-
-    if (!d) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to open asec dir", true);
-        return 0;  
-    }
-
-    struct dirent *dent;
-    while ((dent = readdir(d))) {
-        if (dent->d_name[0] == '.')
-            continue;
-        if (!strcmp(&dent->d_name[strlen(dent->d_name)-5], ".asec")) {
-            char id[255];
-            memset(id, 0, sizeof(id));
-            strncpy(id, dent->d_name, strlen(dent->d_name) -5);
-            cli->sendMsg(ResponseCode::AsecListResult, id, false);
+        if (vm->shareAvailable(argv[2], &avail)) {
+            cli->sendMsg(
+                    ResponseCode::OperationFailed, "Failed to determine share availability", true);
+        } else {
+            cli->sendMsg(ResponseCode::ShareStatusResult,
+                    (avail ? "Share available" : "Share unavailable"), false);
         }
+    } else {
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown share cmd", false);
     }
-    closedir(d);
-    cli->sendMsg(ResponseCode::CommandOkay, "ASEC listing complete", false);
 
     return 0;
 }
 
-CommandListener::AsecPathCmd::AsecPathCmd() :
-                 VoldCommand("asec_path") {
+CommandListener::AsecCmd::AsecCmd() :
+                 VoldCommand("asec") {
 }
 
-int CommandListener::AsecPathCmd::runCommand(SocketClient *cli,
-                                            int argc, char **argv) {
-    if (argc != 2) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError,
-                     "Usage: asec_path <namespace-id>", false);
+int CommandListener::AsecCmd::runCommand(SocketClient *cli,
+                                                      int argc, char **argv) {
+    if (argc < 2) {
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing Argument", false);
         return 0;
     }
 
-    char mountPath[255];
+    VolumeManager *vm = VolumeManager::Instance();
+    int rc = 0;
 
-    if (VolumeManager::Instance()->getAsecMountPath(argv[1], mountPath,
-                                                    sizeof(mountPath))) {
-        cli->sendMsg(ResponseCode::OperationFailed, "Failed to get mount path", true);
+    if (!strcmp(argv[1], "list")) {
+        DIR *d = opendir("/sdcard/android_secure");
+
+        if (!d) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Failed to open asec dir", true);
+            return 0;
+        }
+
+        struct dirent *dent;
+        while ((dent = readdir(d))) {
+            if (dent->d_name[0] == '.')
+                continue;
+            if (!strcmp(&dent->d_name[strlen(dent->d_name)-5], ".asec")) {
+                char id[255];
+                memset(id, 0, sizeof(id));
+                strncpy(id, dent->d_name, strlen(dent->d_name) -5);
+                cli->sendMsg(ResponseCode::AsecListResult, id, false);
+            }
+        }
+        closedir(d);
+        cli->sendMsg(ResponseCode::CommandOkay, "ASEC listing complete", false);
+    } else if (!strcmp(argv[1], "create")) {
+        if (argc != 7) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError,
+                    "Usage: asec create <container-id> <size_mb> <fstype> <key> <ownerUid>", false);
+            return 0;
+        }
+
+        unsigned int numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512;
+        if (vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]))) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Container creation failed", true);
+        } else {
+            cli->sendMsg(ResponseCode::CommandOkay, "Container created", false);
+        }
+    } else if (!strcmp(argv[1], "finalize")) {
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec finalize <container-id>", false);
+            return 0;
+        }
+        if (vm->finalizeAsec(argv[2])) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Container finalize failed", true);
+        } else {
+            cli->sendMsg(ResponseCode::CommandOkay, "Container finalized", false);
+        }
+    } else if (!strcmp(argv[1], "destroy")) {
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec destroy <container-id>", false);
+            return 0;
+        }
+        if (vm->destroyAsec(argv[2])) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Container destroy failed", true);
+        } else {
+            cli->sendMsg(ResponseCode::CommandOkay, "Container destroyed", false);
+        }
+    } else if (!strcmp(argv[1], "mount")) {
+        if (argc != 5) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError,
+                    "Usage: asec mount <namespace-id> <key> <ownerUid>", false);
+            return 0;
+        }
+
+        int rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]));
+
+        if (rc < 0) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Mount failed", true);
+        } else {
+            cli->sendMsg(ResponseCode::CommandOkay, "Mount succeeded", false);
+        }
+
+    } else if (!strcmp(argv[1], "unmount")) {
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec unmount <container-id>", false);
+            return 0;
+        }
+        if (vm->unmountAsec(argv[2])) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Container unmount failed", true);
+        } else {
+            cli->sendMsg(ResponseCode::CommandOkay, "Container unmounted", false);
+        }
+    } else if (!strcmp(argv[1], "rename")) {
+        if (argc != 4) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError,
+                    "Usage: asec rename <old_id> <new_id>", false);
+            return 0;
+        }
+        if (vm->renameAsec(argv[2], argv[3])) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Container rename failed", true);
+        } else {
+            cli->sendMsg(ResponseCode::CommandOkay, "Container renamed", false);
+        }
+    } else if (!strcmp(argv[1], "path")) {
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec path <container-id>", false);
+            return 0;
+        }
+        char path[255];
+
+        if (vm->getAsecMountPath(argv[2], path, sizeof(path))) {
+            cli->sendMsg(ResponseCode::OperationFailed, "Failed to get path", true);
+        } else {
+            cli->sendMsg(ResponseCode::AsecPathResult, path, false);
+        }
     } else {
-        cli->sendMsg(ResponseCode::AsecPathResult, mountPath, false);
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown asec cmd", false);
     }
 
     return 0;
diff --git a/CommandListener.h b/CommandListener.h
index 571b81b..e6fa805 100644
--- a/CommandListener.h
+++ b/CommandListener.h
@@ -27,24 +27,10 @@
 
 private:
 
-    class ListVolumesCmd : public VoldCommand {
+    class VolumeCmd : public VoldCommand {
     public:
-        ListVolumesCmd();
-        virtual ~ListVolumesCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class MountCmd : public VoldCommand {
-    public:
-        MountCmd();
-        virtual ~MountCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class UnmountCmd : public VoldCommand {
-    public:
-        UnmountCmd();
-        virtual ~UnmountCmd() {}
+        VolumeCmd();
+        virtual ~VolumeCmd() {}
         int runCommand(SocketClient *c, int argc, char ** argv);
     };
 
@@ -55,87 +41,10 @@
         int runCommand(SocketClient *c, int argc, char ** argv);
     };
 
-    class UnshareCmd : public VoldCommand {
+    class AsecCmd : public VoldCommand {
     public:
-        UnshareCmd();
-        virtual ~UnshareCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class ShareAvailableCmd : public VoldCommand {
-    public:
-        ShareAvailableCmd();
-        virtual ~ShareAvailableCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class SimulateCmd : public VoldCommand {
-    public:
-        SimulateCmd();
-        virtual ~SimulateCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class FormatCmd : public VoldCommand {
-    public:
-        FormatCmd();
-        virtual ~FormatCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class CreateAsecCmd : public VoldCommand {
-    public:
-        CreateAsecCmd();
-        virtual ~CreateAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class FinalizeAsecCmd : public VoldCommand {
-    public:
-        FinalizeAsecCmd();
-        virtual ~FinalizeAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class DestroyAsecCmd : public VoldCommand {
-    public:
-        DestroyAsecCmd();
-        virtual ~DestroyAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class MountAsecCmd : public VoldCommand {
-    public:
-        MountAsecCmd();
-        virtual ~MountAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class UnmountAsecCmd : public VoldCommand {
-    public:
-        UnmountAsecCmd();
-        virtual ~UnmountAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class RenameAsecCmd : public VoldCommand {
-    public:
-        RenameAsecCmd();
-        virtual ~RenameAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class ListAsecCmd : public VoldCommand {
-    public:
-        ListAsecCmd();
-        virtual ~ListAsecCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
-    class AsecPathCmd : public VoldCommand {
-    public:
-        AsecPathCmd();
-        virtual ~AsecPathCmd() {}
+        AsecCmd();
+        virtual ~AsecCmd() {}
         int runCommand(SocketClient *c, int argc, char ** argv);
     };
 
diff --git a/ResponseCode.h b/ResponseCode.h
index bb27787..9d775f9 100644
--- a/ResponseCode.h
+++ b/ResponseCode.h
@@ -28,12 +28,18 @@
 
     // 200 series - Requested action has been successfully completed
     static const int CommandOkay              = 200;
-    static const int ShareAvailabilityResult  = 210;
+    static const int ShareStatusResult        = 210;
     static const int AsecPathResult           = 211;
+    static const int ShareEnabledResult       = 212;
 
     // 400 series - The command was accepted but the requested action
     // did not take place.
-    static const int OperationFailed = 400;
+    static const int OperationFailed          = 400;
+    static const int OpFailedNoMedia          = 401;
+    static const int OpFailedMediaBlank       = 402;
+    static const int OpFailedMediaCorrupt     = 403;
+    static const int OpFailedVolNotMounted    = 404;
+    static const int OpFailedVolBusy          = 405;
 
     // 500 series - The command was not accepted and the requested
     // action did not take place.
diff --git a/Volume.cpp b/Volume.cpp
index 6926d77..f1a9203 100644
--- a/Volume.cpp
+++ b/Volume.cpp
@@ -252,50 +252,31 @@
             if (errno == ENODATA) {
                 LOGW("%s does not contain a FAT filesystem\n", devicePath);
                 continue;
-            } else {
-                /* Badness - abort the mount */
-                LOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
-                snprintf(errmsg, sizeof(errmsg),
-                         "Volume %s %s mount failed - filesystem check failed",
-                         getLabel(), getMountpoint());
-                mVm->getBroadcaster()->sendBroadcast(
-                                         ResponseCode::VolumeMountFailedDamaged,
-                                         errmsg, false);
-                setState(Volume::State_Idle);
-                goto out;
             }
+            errno = EIO;
+            /* Badness - abort the mount */
+            LOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
+            setState(Volume::State_Idle);
+            return -1;
         }
 
         LOGI("%s checks out - attempting to mount\n", devicePath);
         errno = 0;
         if (!(rc = Fat::doMount(devicePath, getMountpoint(), false, false,
                                 1000, 1015, 0702, true))) {
-            LOGI("%s sucessfully mounted for volume %s\n", devicePath,
-                 getLabel());
+            LOGI("%s sucessfully mounted for volume %s\n", devicePath, getLabel());
             setState(Volume::State_Mounted);
             mCurrentlyMountedKdev = deviceNodes[i];
-            goto out;
+            return 0;
         }
 
         LOGW("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
     }
 
-    // XXX: Doesn't handle multiple partitions properly
-    if (errno == ENODATA) {
-        snprintf(errmsg, sizeof(errmsg),
-                 "Volume %s %s mount failed - no supported file-systems",
-                 getLabel(), getMountpoint());
-        mVm->getBroadcaster()->sendBroadcast(
-                                 ResponseCode::VolumeMountFailedBlank,
-                                 errmsg, false);
-    }
-   
-
     LOGE("Volume %s found no suitable devices for mounting :(\n", getLabel());
     setState(Volume::State_Idle);
 
-out:
-    return rc;
+    return -1;
 }
 
 int Volume::unmountVol() {
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 0b63c9f..40e3e1f 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -521,6 +521,27 @@
     return 0;
 }
 
+int VolumeManager::shareEnabled(const char *label, const char *method, bool *enabled) {
+    Volume *v = lookupVolume(label);
+
+    if (!v) {
+        errno = ENOENT;
+        return -1;
+    }
+
+    if (strcmp(method, "ums")) {
+        errno = ENOSYS;
+        return -1;
+    }
+
+    if (v->getState() != Volume::State_Shared) {
+        *enabled = true;
+    } else {
+        *enabled = false;
+    }
+    return 0;
+}
+
 int VolumeManager::simulate(const char *cmd, const char *arg) {
 
     if (!strcmp(cmd, "ums")) {
diff --git a/VolumeManager.h b/VolumeManager.h
index 07861d4..f989cdb 100644
--- a/VolumeManager.h
+++ b/VolumeManager.h
@@ -56,6 +56,7 @@
     int shareVolume(const char *label, const char *method);
     int unshareVolume(const char *label, const char *method);
     int shareAvailable(const char *method, bool *avail);
+    int shareEnabled(const char *path, const char *method, bool *enabled);
     int simulate(const char *cmd, const char *arg);
     int formatVolume(const char *label);
     int createAsec(const char *id, unsigned numSectors, const char *fstype,