The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef MOUNTD_H__ |
| 18 | #define MOUNTD_H__ |
| 19 | |
| 20 | #define LOG_TAG "mountd" |
| 21 | #include "cutils/log.h" |
| 22 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 23 | #include "ASEC.h" |
| 24 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 25 | typedef int boolean; |
| 26 | enum { |
| 27 | false = 0, |
| 28 | true = 1 |
| 29 | }; |
| 30 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 31 | #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) |
| 32 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 33 | // Set this for logging error messages |
| 34 | #define ENABLE_LOG_ERROR |
| 35 | |
| 36 | // set this to log automounter events |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 37 | #define ENABLE_LOG_MOUNT |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 38 | |
| 39 | // set this to log server events |
| 40 | //#define ENABLE_LOG_SERVER |
| 41 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 42 | // set this to log ASEC events |
| 43 | #define ENABLE_LOG_ASEC |
| 44 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 45 | #ifdef ENABLE_LOG_ERROR |
| 46 | #define LOG_ERROR(fmt, args...) \ |
| 47 | { LOGE(fmt , ## args); } |
| 48 | #else |
| 49 | #define LOG_ERROR(fmt, args...) \ |
| 50 | do { } while (0) |
| 51 | #endif /* ENABLE_LOG_ERROR */ |
| 52 | |
| 53 | #ifdef ENABLE_LOG_MOUNT |
| 54 | #define LOG_MOUNT(fmt, args...) \ |
| 55 | { LOGD(fmt , ## args); } |
| 56 | #else |
| 57 | #define LOG_MOUNT(fmt, args...) \ |
| 58 | do { } while (0) |
| 59 | #endif /* ENABLE_LOG_MOUNT */ |
| 60 | |
| 61 | #ifdef ENABLE_LOG_SERVER |
| 62 | #define LOG_SERVER(fmt, args...) \ |
| 63 | { LOGD(fmt , ## args); } |
| 64 | #else |
| 65 | #define LOG_SERVER(fmt, args...) \ |
| 66 | do { } while (0) |
| 67 | #endif /* ENABLE_LOG_SERVER */ |
| 68 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 69 | #ifdef ENABLE_LOG_ASEC |
| 70 | #define LOG_ASEC(fmt, args...) \ |
| 71 | { LOGD(fmt , ## args); } |
| 72 | #else |
| 73 | #define LOG_ASEC(fmt, args...) \ |
| 74 | do { } while (0) |
| 75 | #endif /* ENABLE_LOG_ASEC */ |
| 76 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | |
| 78 | typedef enum MediaState { |
| 79 | // no media in SD card slot |
| 80 | MEDIA_REMOVED, |
| 81 | |
| 82 | // media in SD card slot, but not mounted |
| 83 | MEDIA_UNMOUNTED, |
| 84 | |
| 85 | // media in SD card slot and mounted at its mount point |
| 86 | MEDIA_MOUNTED, |
| 87 | |
| 88 | // media in SD card slot, unmounted, and shared as a mass storage device |
| 89 | MEDIA_SHARED, |
| 90 | |
| 91 | // media was removed from SD card slot, but mount point was not unmounted |
| 92 | // this state is cleared after the mount point is unmounted |
| 93 | MEDIA_BAD_REMOVAL, |
| 94 | |
| 95 | // media in SD card slot could not be mounted (corrupt file system?) |
| 96 | MEDIA_UNMOUNTABLE, |
| 97 | } MediaState; |
| 98 | |
| 99 | // socket name for connecting to mountd |
| 100 | #define MOUNTD_SOCKET "mountd" |
| 101 | |
| 102 | // mountd commands |
| 103 | // these must match the corresponding strings in //device/java/android/android/os/UsbListener.java |
| 104 | #define MOUNTD_ENABLE_UMS "enable_ums" |
| 105 | #define MOUNTD_DISABLE_UMS "disable_ums" |
| 106 | #define MOUNTD_SEND_STATUS "send_status" |
| 107 | |
| 108 | // these commands should contain a mount point following the colon |
| 109 | #define MOUNTD_MOUNT_MEDIA "mount_media:" |
| 110 | #define MOUNTD_EJECT_MEDIA "eject_media:" |
| 111 | |
| 112 | // mountd events |
| 113 | // these must match the corresponding strings in //device/java/android/android/os/UsbListener.java |
| 114 | #define MOUNTD_UMS_ENABLED "ums_enabled" |
| 115 | #define MOUNTD_UMS_DISABLED "ums_disabled" |
| 116 | #define MOUNTD_UMS_CONNECTED "ums_connected" |
| 117 | #define MOUNTD_UMS_DISCONNECTED "ums_disconnected" |
| 118 | |
| 119 | // these events correspond to the states in the MediaState enum. |
| 120 | // a path to the mount point follows the colon. |
| 121 | #define MOUNTD_MEDIA_REMOVED "media_removed:" |
| 122 | #define MOUNTD_MEDIA_UNMOUNTED "media_unmounted:" |
| 123 | #define MOUNTD_MEDIA_MOUNTED "media_mounted:" |
| 124 | #define MOUNTD_MEDIA_MOUNTED_READ_ONLY "media_mounted_ro:" |
| 125 | #define MOUNTD_MEDIA_SHARED "media_shared:" |
| 126 | #define MOUNTD_MEDIA_BAD_REMOVAL "media_bad_removal:" |
| 127 | #define MOUNTD_MEDIA_UNMOUNTABLE "media_unmountable:" |
| 128 | |
| 129 | // this event sent to request unmount for media mount point |
| 130 | #define MOUNTD_REQUEST_EJECT "request_eject:" |
| 131 | |
| 132 | // system properties |
| 133 | // these must match the corresponding strings in //device/java/android/android/os/Environment.java |
| 134 | #define EXTERNAL_STORAGE_STATE "EXTERNAL_STORAGE_STATE" |
| 135 | #define EXTERNAL_STORAGE_REMOVED "removed" |
| 136 | #define EXTERNAL_STORAGE_UNMOUNTED "unmounted" |
| 137 | #define EXTERNAL_STORAGE_MOUNTED "mounted" |
| 138 | #define EXTERNAL_STORAGE_MOUNTED_READ_ONLY "mounted_ro" |
| 139 | #define EXTERNAL_STORAGE_SHARED "shared" |
| 140 | #define EXTERNAL_STORAGE_BAD_REMOVAL "bad_removal" |
| 141 | #define EXTERNAL_STORAGE_UNMOUNTABLE "unmountable" |
| 142 | |
| 143 | // AutoMount.c |
| 144 | |
| 145 | boolean IsMassStorageEnabled(); |
| 146 | boolean IsMassStorageConnected(); |
| 147 | |
| 148 | void MountMedia(const char* mountPoint); |
| 149 | void UnmountMedia(const char* mountPoint); |
| 150 | void EnableMassStorage(boolean enable); |
| 151 | |
| 152 | // call this before StartAutoMounter() to add a mount point to monitor |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 153 | void *AddMountPoint(const char* device, const char* mountPoint, const char* driverStorePath, |
| 154 | boolean enableUms); |
| 155 | |
| 156 | int AddAsecToMountPoint(void *Mp, const char *name, const char *backing_file, |
| 157 | const char *size, const char *mount_point, const char *crypt); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 158 | |
| 159 | // start automounter thread |
| 160 | void StartAutoMounter(); |
| 161 | |
| 162 | // check /proc/mounts for mounted file systems, and notify mount or unmount for any that are in our automount list |
| 163 | void NotifyExistingMounts(); |
| 164 | |
| 165 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 166 | // ASEC.c |
| 167 | |
| 168 | void *AsecInit(const char *Name, const char *SrcPath, const char *BackingFile, |
| 169 | const char *Size, const char *DstPath, const char *Crypt); |
| 170 | int AsecStart(void *Handle); |
| 171 | int AsecStop(void *Handle); |
| 172 | void AsecDeinit(void *Handle); |
| 173 | boolean AsecIsStarted(void *Handle); |
| 174 | const char *AsecMountPoint(void *Handle); |
| 175 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 176 | // ProcessKiller.c |
| 177 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 178 | void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, pid_t *excluded, int num_excluded); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 179 | |
| 180 | |
| 181 | // Server.c |
| 182 | |
| 183 | int RunServer(); |
| 184 | void SendMassStorageConnected(boolean connected); |
| 185 | void SendUnmountRequest(const char* path); |
| 186 | void NotifyMediaState(const char* path, MediaState state, boolean readOnly); |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame^] | 187 | void NotifyAsecState(AsecState state, const char *argument); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 188 | #endif // MOUNTD_H__ |