1 /**************************************************************************** 2 * include/nuttx/fs/automount.h 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one or more 5 * contributor license agreements. See the NOTICE file distributed with 6 * this work for additional information regarding copyright ownership. The 7 * ASF licenses this file to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance with the 9 * License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 * License for the specific language governing permissions and limitations 17 * under the License. 18 * 19 ****************************************************************************/ 20 21 #ifndef __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H 22 #define __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H 23 24 /**************************************************************************** 25 * Included Files 26 ****************************************************************************/ 27 28 #include "stdint.h" 29 30 31 #ifdef __cplusplus 32 #if __cplusplus 33 extern "C" { 34 #endif /* __cplusplus */ 35 #endif /* __cplusplus */ 36 37 /**************************************************************************** 38 * Pre-processor Definitions 39 ****************************************************************************/ 40 41 /* Configuration ************************************************************ 42 * Automounter configuration 43 * CONFIG_FS_AUTOMOUNTER - Enables automount support 44 * 45 * Prerequisites: 46 * CONFIG_SCHED_WORKQUEUE - Work queue support is required 47 * And others that would only matter if you are working in a very minimal 48 * configuration. 49 */ 50 51 /* Helper macros ************************************************************/ 52 53 #define AUTOMOUNT_ATTACH(s,isr,arg) ((s)->attach(s,isr,arg)) 54 #define AUTOMOUNT_DETACH(s) ((s)->attach(s,NULL,NULL)) 55 #define AUTOMOUNT_ENABLE(s) ((s)->enable(s,true)) 56 #define AUTOMOUNT_DISABLE(s) ((s)->enable(s,false)) 57 #define AUTOMOUNT_INSERTED(s) ((s)->inserted(s)) 58 59 /**************************************************************************** 60 * Public Types 61 ****************************************************************************/ 62 63 /* This is the type of the automount media change handler. The lower level 64 * code will intercept the interrupt and provide the upper level with the 65 * private data that was provided when the interrupt was attached and will 66 * also provide an indication if the media was inserted or removed. 67 */ 68 69 struct automount_lower_s; /* Forward reference. Defined below */ 70 71 typedef CODE int 72 (*automount_handler_t)(FAR const struct automount_lower_s *lower, 73 FAR void *arg, bool inserted); 74 75 /* A reference to a structure of this type must be passed to the FS 76 * automounter. This structure provides information about the volume to be 77 * mounted and provides board-specific hooks. 78 * 79 * Memory for this structure is provided by the caller. It is not copied 80 * by the automounter and is presumed to persist while the automounter 81 * is active. 82 */ 83 84 struct automount_lower_s 85 { 86 /* Volume characterization */ 87 88 FAR const char *fstype; /* Type of file system */ 89 FAR const char *blockdev; /* Path to the block device */ 90 FAR const char *mountpoint; /* Location to mount the volume */ 91 92 /* Debounce delay in system clock ticks. Automount operation will not 93 * be performed until the insertion/removal state has been unchanges 94 * for this duration. 95 */ 96 97 uint32_t ddelay; 98 99 /* Unmount delay time in system clock ticks. If a volume has open 100 * references at the time that the media is removed, then we will be 101 * unable to unmount it. In that case, hopefully, the clients of the 102 * mount will eventually fail with file access errors and eventually close 103 * their references. So, at some time later, it should be possible to 104 * unmount the volume. This delay specifies the time between umount 105 * retries. 106 */ 107 108 uint32_t udelay; 109 110 /* Interrupt related operations all hidden behind callbacks to isolate the 111 * automounter from differences in interrupt handling by varying boards 112 * and MCUs. Board interrupts should be configured both insertion and 113 * removal of the media can be detected. 114 * 115 * attach - Attach or detach the media change interrupt handler to the 116 * board level interrupt 117 * enable - Enable or disable the media change interrupt 118 */ 119 120 CODE int (*attach)(FAR const struct automount_lower_s *lower, 121 automount_handler_t isr, FAR void *arg); 122 CODE void (*enable)(FAR const struct automount_lower_s *lower, 123 bool enable); 124 CODE bool (*inserted)(FAR const struct automount_lower_s *lower); 125 }; 126 127 /**************************************************************************** 128 * Public Data 129 ****************************************************************************/ 130 131 #ifdef __cplusplus 132 #define EXTERN extern "C" 133 extern "C" 134 { 135 #else 136 #define EXTERN extern 137 #endif 138 139 /**************************************************************************** 140 * Public Function Prototypes 141 ****************************************************************************/ 142 143 /**************************************************************************** 144 * Name: automount_initialize 145 * 146 * Description: 147 * Configure the automounter. 148 * 149 * Input Parameters: 150 * lower - Persistent board configuration data 151 * 152 * Returned Value: 153 * A void* handle. 154 * The only use for this handle is with automount_uninitialize(). 155 * NULL is returned on any failure. 156 * 157 ****************************************************************************/ 158 159 FAR void *automount_initialize(FAR const struct automount_lower_s *lower); 160 161 /**************************************************************************** 162 * Name: automount_uninitialize 163 * 164 * Description: 165 * Stop the automounter and free resources that it used. NOTE that the 166 * mount is left in its last state mounted/unmounted state. 167 * 168 * Input Parameters: 169 * handle - The value previously returned by automount_initialize(); 170 * 171 * Returned Value: 172 * None 173 * 174 ****************************************************************************/ 175 176 void automount_uninitialize(FAR void *handle); 177 178 #undef EXTERN 179 #ifdef __cplusplus 180 } 181 #endif 182 #ifdef __cplusplus 183 #if __cplusplus 184 } 185 #endif /* __cplusplus */ 186 #endif /* __cplusplus */ 187 188 #endif /* __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H */ 189