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 | |
| 23 | typedef int boolean; |
| 24 | enum { |
| 25 | false = 0, |
| 26 | true = 1 |
| 27 | }; |
| 28 | |
| 29 | // Set this for logging error messages |
| 30 | #define ENABLE_LOG_ERROR |
| 31 | |
| 32 | // set this to log automounter events |
| 33 | //#define ENABLE_LOG_MOUNT |
| 34 | |
| 35 | // set this to log server events |
| 36 | //#define ENABLE_LOG_SERVER |
| 37 | |
| 38 | #ifdef ENABLE_LOG_ERROR |
| 39 | #define LOG_ERROR(fmt, args...) \ |
| 40 | { LOGE(fmt , ## args); } |
| 41 | #else |
| 42 | #define LOG_ERROR(fmt, args...) \ |
| 43 | do { } while (0) |
| 44 | #endif /* ENABLE_LOG_ERROR */ |
| 45 | |
| 46 | #ifdef ENABLE_LOG_MOUNT |
| 47 | #define LOG_MOUNT(fmt, args...) \ |
| 48 | { LOGD(fmt , ## args); } |
| 49 | #else |
| 50 | #define LOG_MOUNT(fmt, args...) \ |
| 51 | do { } while (0) |
| 52 | #endif /* ENABLE_LOG_MOUNT */ |
| 53 | |
| 54 | #ifdef ENABLE_LOG_SERVER |
| 55 | #define LOG_SERVER(fmt, args...) \ |
| 56 | { LOGD(fmt , ## args); } |
| 57 | #else |
| 58 | #define LOG_SERVER(fmt, args...) \ |
| 59 | do { } while (0) |
| 60 | #endif /* ENABLE_LOG_SERVER */ |
| 61 | |
| 62 | |
| 63 | typedef enum MediaState { |
| 64 | // no media in SD card slot |
| 65 | MEDIA_REMOVED, |
| 66 | |
| 67 | // media in SD card slot, but not mounted |
| 68 | MEDIA_UNMOUNTED, |
| 69 | |
| 70 | // media in SD card slot and mounted at its mount point |
| 71 | MEDIA_MOUNTED, |
| 72 | |
| 73 | // media in SD card slot, unmounted, and shared as a mass storage device |
| 74 | MEDIA_SHARED, |
| 75 | |
| 76 | // media was removed from SD card slot, but mount point was not unmounted |
| 77 | // this state is cleared after the mount point is unmounted |
| 78 | MEDIA_BAD_REMOVAL, |
| 79 | |
| 80 | // media in SD card slot could not be mounted (corrupt file system?) |
| 81 | MEDIA_UNMOUNTABLE, |
| 82 | } MediaState; |
| 83 | |
| 84 | // socket name for connecting to mountd |
| 85 | #define MOUNTD_SOCKET "mountd" |
| 86 | |
| 87 | // mountd commands |
| 88 | // these must match the corresponding strings in //device/java/android/android/os/UsbListener.java |
| 89 | #define MOUNTD_ENABLE_UMS "enable_ums" |
| 90 | #define MOUNTD_DISABLE_UMS "disable_ums" |
| 91 | #define MOUNTD_SEND_STATUS "send_status" |
| 92 | |
| 93 | // these commands should contain a mount point following the colon |
| 94 | #define MOUNTD_MOUNT_MEDIA "mount_media:" |
| 95 | #define MOUNTD_EJECT_MEDIA "eject_media:" |
| 96 | |
| 97 | // mountd events |
| 98 | // these must match the corresponding strings in //device/java/android/android/os/UsbListener.java |
| 99 | #define MOUNTD_UMS_ENABLED "ums_enabled" |
| 100 | #define MOUNTD_UMS_DISABLED "ums_disabled" |
| 101 | #define MOUNTD_UMS_CONNECTED "ums_connected" |
| 102 | #define MOUNTD_UMS_DISCONNECTED "ums_disconnected" |
| 103 | |
| 104 | // these events correspond to the states in the MediaState enum. |
| 105 | // a path to the mount point follows the colon. |
| 106 | #define MOUNTD_MEDIA_REMOVED "media_removed:" |
| 107 | #define MOUNTD_MEDIA_UNMOUNTED "media_unmounted:" |
| 108 | #define MOUNTD_MEDIA_MOUNTED "media_mounted:" |
| 109 | #define MOUNTD_MEDIA_MOUNTED_READ_ONLY "media_mounted_ro:" |
| 110 | #define MOUNTD_MEDIA_SHARED "media_shared:" |
| 111 | #define MOUNTD_MEDIA_BAD_REMOVAL "media_bad_removal:" |
| 112 | #define MOUNTD_MEDIA_UNMOUNTABLE "media_unmountable:" |
| 113 | |
| 114 | // this event sent to request unmount for media mount point |
| 115 | #define MOUNTD_REQUEST_EJECT "request_eject:" |
| 116 | |
| 117 | // system properties |
| 118 | // these must match the corresponding strings in //device/java/android/android/os/Environment.java |
| 119 | #define EXTERNAL_STORAGE_STATE "EXTERNAL_STORAGE_STATE" |
| 120 | #define EXTERNAL_STORAGE_REMOVED "removed" |
| 121 | #define EXTERNAL_STORAGE_UNMOUNTED "unmounted" |
| 122 | #define EXTERNAL_STORAGE_MOUNTED "mounted" |
| 123 | #define EXTERNAL_STORAGE_MOUNTED_READ_ONLY "mounted_ro" |
| 124 | #define EXTERNAL_STORAGE_SHARED "shared" |
| 125 | #define EXTERNAL_STORAGE_BAD_REMOVAL "bad_removal" |
| 126 | #define EXTERNAL_STORAGE_UNMOUNTABLE "unmountable" |
| 127 | |
| 128 | // AutoMount.c |
| 129 | |
| 130 | boolean IsMassStorageEnabled(); |
| 131 | boolean IsMassStorageConnected(); |
| 132 | |
| 133 | void MountMedia(const char* mountPoint); |
| 134 | void UnmountMedia(const char* mountPoint); |
| 135 | void EnableMassStorage(boolean enable); |
| 136 | |
| 137 | // call this before StartAutoMounter() to add a mount point to monitor |
| 138 | void AddMountPoint(const char* device, const char* mountPoint, boolean enableUms); |
| 139 | |
| 140 | // start automounter thread |
| 141 | void StartAutoMounter(); |
| 142 | |
| 143 | // check /proc/mounts for mounted file systems, and notify mount or unmount for any that are in our automount list |
| 144 | void NotifyExistingMounts(); |
| 145 | |
| 146 | |
| 147 | // ProcessKiller.c |
| 148 | |
| 149 | void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill); |
| 150 | |
| 151 | |
| 152 | // Server.c |
| 153 | |
| 154 | int RunServer(); |
| 155 | void SendMassStorageConnected(boolean connected); |
| 156 | void SendUnmountRequest(const char* path); |
| 157 | void NotifyMediaState(const char* path, MediaState state, boolean readOnly); |
| 158 | |
| 159 | #endif // MOUNTD_H__ |