• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (C) 2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _VOLMGR_H
19 #define _VOLMGR_H
20 
21 #include <pthread.h>
22 
23 #include "vold.h"
24 #include "blkdev.h"
25 #include "media.h"
26 #include "devmapper.h"
27 
28 #define PROP_EXTERNAL_STORAGE_STATE "EXTERNAL_STORAGE_STATE"
29 
30 // these must match the corresponding states in the MediaState enum.
31 // A path to the volume mount point follows the colon
32 typedef enum volume_state {
33     volstate_unknown,
34 
35     volstate_nomedia,
36 #define VOLD_EVT_NOMEDIA       "volume_nomedia:"
37 #define VOLD_ES_PVAL_NOMEDIA   "removed"
38 
39     volstate_unmounted,
40 #define VOLD_EVT_UNMOUNTED     "volume_unmounted:"
41 #define VOLD_ES_PVAL_UNMOUNTED "unmounted"
42 
43     volstate_checking,
44 #define VOLD_EVT_CHECKING      "volume_checking:"
45 #define VOLD_ES_PVAL_CHECKING  "checking"
46 
47     volstate_mounted,
48 #define VOLD_EVT_MOUNTED       "volume_mounted:"
49 #define VOLD_ES_PVAL_MOUNTED   "mounted"
50 
51     volstate_mounted_ro,
52 #define VOLD_EVT_MOUNTED_RO     "volume_mounted_ro:"
53 #define VOLD_ES_PVAL_MOUNTED_RO "mounted_ro"
54 
55     volstate_badremoval,
56 #define VOLD_EVT_BADREMOVAL     "volume_badremoval:"
57 #define VOLD_ES_PVAL_BADREMOVAL "bad_removal"
58 
59     volstate_damaged,
60 #define VOLD_EVT_DAMAGED         "volume_damaged:"
61 #define VOLD_ES_PVAL_DAMAGED     "unmountable"
62 
63     volstate_nofs,
64 #define VOLD_EVT_NOFS            "volume_nofs:"
65 #define VOLD_ES_PVAL_NOFS        "nofs"
66 
67     volstate_ums,
68 #define VOLD_EVT_UMS             "volume_ums:"
69 #define VOLD_ES_PVAL_UMS         "shared"
70 
71     volstate_ejecting,
72 #define VOLD_EVT_EJECTING        "volume_ejecting:"
73 #define VOLD_ES_PVAL_EJECTING    "ejecting"
74 
75     volstate_formatting,
76 } volume_state_t;
77 
78 struct volume;
79 
80 struct volmgr_fstable_entry {
81     char *name;
82     int     (*identify_fn) (blkdev_t *dev);
83     int     (*check_fn) (blkdev_t *dev);
84     int     (*mount_fn) (blkdev_t *dev, struct volume *vol, boolean safe_mode);
85     boolean case_sensitive_paths;
86 };
87 
88 struct volmgr_start_args {
89     struct volmgr_fstable_entry *fs;
90     blkdev_t                    *dev;
91 };
92 
93 struct volmgr_reaper_args {
94     void (*cb) (struct volume *, void *);
95     void *cb_arg;
96 };
97 
98 #define VOLMGR_MAX_MEDIAPATHS_PER_VOLUME 8
99 
100 typedef struct volume {
101     char            *media_paths[VOLMGR_MAX_MEDIAPATHS_PER_VOLUME];
102 
103     media_type_t      media_type;
104     char              *mount_point;
105     char              *ums_path;
106     struct devmapping *dm;
107 
108     pthread_mutex_t          lock;
109     volume_state_t           state;
110     blkdev_t                 *dev;
111     pid_t                    worker_pid;
112     pthread_t                worker_thread;
113     union {
114         struct volmgr_start_args  start_args;
115         struct volmgr_reaper_args reaper_args;
116     } worker_args;
117     boolean                  worker_running;
118     pthread_mutex_t          worker_sem;
119 
120     struct volmgr_fstable_entry *fs;
121 
122     struct volume            *next;
123 } volume_t;
124 
125 int volmgr_consider_disk(blkdev_t *dev);
126 int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *));
127 int volmgr_send_states(void);
128 int volmgr_enable_ums(boolean enable);
129 int volmgr_stop_volume_by_mountpoint(char *mount_point);
130 int volmgr_start_volume_by_mountpoint(char *mount_point);
131 int volmgr_safe_mode(boolean enable);
132 int volmgr_format_volume(char *mount_point);
133 int volmgr_set_volume_key(char *mount_point, unsigned char *key);
134 void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded);
135 #endif
136