blob: 98c1561e8ff31a8a5eb066765fe64722130c0e01 [file] [log] [blame]
The Android Open Source Project8ac3a132009-01-20 14:04:01 -08001
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"
The Android Open Source Project13f797d2009-02-10 15:44:07 -080026#include "devmapper.h"
The Android Open Source Project8ac3a132009-01-20 14:04:01 -080027
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
32typedef 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"
The Android Open Source Project13f797d2009-02-10 15:44:07 -080074
75 volstate_formatting,
The Android Open Source Project8ac3a132009-01-20 14:04:01 -080076} volume_state_t;
77
78struct volume;
79
80struct volmgr_fstable_entry {
81 char *name;
The Android Open Source Project13f797d2009-02-10 15:44:07 -080082 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;
The Android Open Source Project8ac3a132009-01-20 14:04:01 -080086};
87
88struct volmgr_start_args {
89 struct volmgr_fstable_entry *fs;
90 blkdev_t *dev;
91};
92
The Android Open Source Project13f797d2009-02-10 15:44:07 -080093struct volmgr_reaper_args {
94 void (*cb) (struct volume *, void *);
95 void *cb_arg;
96};
97
98#define VOLMGR_MAX_MEDIAPATHS_PER_VOLUME 8
99
The Android Open Source Project8ac3a132009-01-20 14:04:01 -0800100typedef struct volume {
The Android Open Source Project13f797d2009-02-10 15:44:07 -0800101 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;
The Android Open Source Project8ac3a132009-01-20 14:04:01 -0800107
108 pthread_mutex_t lock;
109 volume_state_t state;
110 blkdev_t *dev;
111 pid_t worker_pid;
112 pthread_t worker_thread;
The Android Open Source Project13f797d2009-02-10 15:44:07 -0800113 union {
114 struct volmgr_start_args start_args;
115 struct volmgr_reaper_args reaper_args;
116 } worker_args;
The Android Open Source Project8ac3a132009-01-20 14:04:01 -0800117 boolean worker_running;
118 pthread_mutex_t worker_sem;
119
The Android Open Source Project13f797d2009-02-10 15:44:07 -0800120 struct volmgr_fstable_entry *fs;
121
122 unsigned char *key;
123 unsigned int keysize;
124
The Android Open Source Project8ac3a132009-01-20 14:04:01 -0800125 struct volume *next;
126} volume_t;
127
128int volmgr_consider_disk(blkdev_t *dev);
129int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *));
130int volmgr_send_states(void);
131int volmgr_enable_ums(boolean enable);
132int volmgr_stop_volume_by_mountpoint(char *mount_point);
133int volmgr_start_volume_by_mountpoint(char *mount_point);
The Android Open Source Project13f797d2009-02-10 15:44:07 -0800134int volmgr_safe_mode(boolean enable);
135int volmgr_format_volume(char *mount_point);
136int volmgr_set_volume_key(char *mount_point, unsigned char *key, unsigned int keysize);
The Android Open Source Project8ac3a132009-01-20 14:04:01 -0800137void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded);
138#endif