OSDN Git Service

Add back "unmountable" volume state.
authorJeff Sharkey <jsharkey@android.com>
Sun, 5 Apr 2015 04:38:59 +0000 (21:38 -0700)
committerJeff Sharkey <jsharkey@android.com>
Sun, 5 Apr 2015 04:40:06 +0000 (21:40 -0700)
Also automatically unmount when format is requested.

Bug: 19993667
Change-Id: I2c81b7ccc9d69df61d7ae4df1e8224c02f260044

VolumeBase.cpp
VolumeBase.h

index 292a4cd..2590ecf 100644 (file)
@@ -145,8 +145,8 @@ status_t VolumeBase::doDestroy() {
 }
 
 status_t VolumeBase::mount() {
-    if (mState != State::kUnmounted) {
-        LOG(WARNING) << getId() << " mount requires state unmounted";
+    if ((mState != State::kUnmounted) && (mState != State::kUnmountable)) {
+        LOG(WARNING) << getId() << " mount requires state unmounted or unmountable";
         return -EBUSY;
     }
 
@@ -155,7 +155,7 @@ status_t VolumeBase::mount() {
     if (res == OK) {
         setState(State::kMounted);
     } else {
-        setState(State::kUnmounted);
+        setState(State::kUnmountable);
     }
 
     return res;
@@ -183,8 +183,12 @@ status_t VolumeBase::unmount() {
 }
 
 status_t VolumeBase::format() {
-    if (mState != State::kUnmounted) {
-        LOG(WARNING) << getId() << " format requires state unmounted";
+    if (mState == State::kMounted) {
+        unmount();
+    }
+
+    if ((mState != State::kUnmounted) && (mState != State::kUnmountable)) {
+        LOG(WARNING) << getId() << " format requires state unmounted or unmountable";
         return -EBUSY;
     }
 
index e3d91ff..465fc61 100644 (file)
@@ -63,11 +63,18 @@ public:
     };
 
     enum class State {
+        /* Next states: mounting, formatting */
         kUnmounted = 0,
+        /* Next states: mounted, unmountable */
         kMounting,
+        /* Next states: unmounting */
         kMounted,
+        /* Next states: unmounted */
         kFormatting,
+        /* Next states: unmounted */
         kUnmounting,
+        /* Next states: mounting, formatting */
+        kUnmountable,
     };
 
     const std::string& getId() { return mId; }