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