1 | /** |
---|
2 | * @file rtems/fsmount.h |
---|
3 | * |
---|
4 | * @defgroup rtems_fstab File System Mount Support |
---|
5 | * |
---|
6 | * @ingroup FileSystemTypesAndMount |
---|
7 | * @brief File System Mount Functions |
---|
8 | * |
---|
9 | * This file contains the fsmount functions. These functions |
---|
10 | * are used to mount a list of filesystems (and create their mount |
---|
11 | * points before) |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | * |
---|
16 | * Copyright (c) 2003 IMD |
---|
17 | * |
---|
18 | * Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
---|
19 | * <Thomas.Doerfler@imd-systems.de> |
---|
20 | * all rights reserved |
---|
21 | * |
---|
22 | * The license and distribution terms for this file may be |
---|
23 | * found in the file LICENSE in this distribution or at |
---|
24 | * http://www.rtems.com/license/LICENSE. |
---|
25 | */ |
---|
26 | |
---|
27 | /*===============================================================*\ |
---|
28 | | Project: RTEMS fsmount | |
---|
29 | +-----------------------------------------------------------------+ |
---|
30 | | File: fsmount.h | |
---|
31 | +-----------------------------------------------------------------+ |
---|
32 | | Copyright (c) 2003 IMD | |
---|
33 | | Ingenieurbuero fuer Microcomputertechnik Th. Doerfler | |
---|
34 | | <Thomas.Doerfler@imd-systems.de> | |
---|
35 | | all rights reserved | |
---|
36 | +-----------------------------------------------------------------+ |
---|
37 | | this file contains the fsmount functions. These functions | |
---|
38 | | are used to mount a list of filesystems (and create their mount | |
---|
39 | | points before) | |
---|
40 | | | |
---|
41 | | The license and distribution terms for this file may be | |
---|
42 | | found in the file LICENSE in this distribution or at | |
---|
43 | | http://www.rtems.com/license/LICENSE. | |
---|
44 | | | |
---|
45 | +-----------------------------------------------------------------+ |
---|
46 | | date history ID | |
---|
47 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
---|
48 | | 02.07.03 creation doe | |
---|
49 | \*===============================================================*/ |
---|
50 | |
---|
51 | #ifndef _FSMOUNT_H |
---|
52 | #define _FSMOUNT_H |
---|
53 | |
---|
54 | #include <rtems.h> |
---|
55 | #include <rtems/libio.h> |
---|
56 | #include <rtems/libcsupport.h> |
---|
57 | |
---|
58 | #ifdef __cplusplus |
---|
59 | extern "C" { |
---|
60 | #endif |
---|
61 | |
---|
62 | /** |
---|
63 | * @defgroup rtems_fstab File System Mount Support |
---|
64 | * |
---|
65 | * @ingroup FileSystemTypesAndMount |
---|
66 | * |
---|
67 | * @{ |
---|
68 | */ |
---|
69 | |
---|
70 | /** |
---|
71 | * File system mount report and abort condition flags. |
---|
72 | * |
---|
73 | * The flags define, which conditions will cause a report during the mount |
---|
74 | * process (via printf()) or abort the mount process. |
---|
75 | * |
---|
76 | * @see rtems_fstab_entry and rtems_fsmount(). |
---|
77 | */ |
---|
78 | typedef enum { |
---|
79 | /** |
---|
80 | * No conditions. |
---|
81 | */ |
---|
82 | RTEMS_FSTAB_NONE = 0U, |
---|
83 | |
---|
84 | /** |
---|
85 | * Complete mount process was successful. |
---|
86 | */ |
---|
87 | RTEMS_FSTAB_OK = 0x1U, |
---|
88 | |
---|
89 | /** |
---|
90 | * Mount point creation failed. |
---|
91 | */ |
---|
92 | RTEMS_FSTAB_ERROR_MOUNT_POINT = 0x2U, |
---|
93 | |
---|
94 | /** |
---|
95 | * File system mount failed. |
---|
96 | */ |
---|
97 | RTEMS_FSTAB_ERROR_MOUNT = 0x4U, |
---|
98 | |
---|
99 | /** |
---|
100 | * Something failed. |
---|
101 | */ |
---|
102 | RTEMS_FSTAB_ERROR = RTEMS_FSTAB_ERROR_MOUNT_POINT | RTEMS_FSTAB_ERROR_MOUNT, |
---|
103 | |
---|
104 | /** |
---|
105 | * Any condition. |
---|
106 | */ |
---|
107 | RTEMS_FSTAB_ANY = RTEMS_FSTAB_OK | RTEMS_FSTAB_ERROR |
---|
108 | } rtems_fstab_conditions; |
---|
109 | |
---|
110 | /** |
---|
111 | * File system table entry. |
---|
112 | */ |
---|
113 | typedef struct { |
---|
114 | /** |
---|
115 | * Source for the mount. |
---|
116 | */ |
---|
117 | const char *source; |
---|
118 | |
---|
119 | /** |
---|
120 | * Target for the mount. |
---|
121 | */ |
---|
122 | const char *target; |
---|
123 | |
---|
124 | /** |
---|
125 | * File system operations. |
---|
126 | */ |
---|
127 | const char *type; |
---|
128 | |
---|
129 | /** |
---|
130 | * File system mount options. |
---|
131 | */ |
---|
132 | rtems_filesystem_options_t options; |
---|
133 | |
---|
134 | /** |
---|
135 | * Report @ref rtems_fstab_conditions "condition flags". |
---|
136 | */ |
---|
137 | uint16_t report_reasons; |
---|
138 | |
---|
139 | /** |
---|
140 | * Abort @ref rtems_fstab_conditions "condition flags". |
---|
141 | */ |
---|
142 | uint16_t abort_reasons; |
---|
143 | } rtems_fstab_entry; |
---|
144 | |
---|
145 | /** |
---|
146 | * @brief Mounts the file systems listed in the file system mount table. |
---|
147 | * |
---|
148 | * Mounts the file systems listed in the file system mount table @a fstab of |
---|
149 | * size @a size. |
---|
150 | * |
---|
151 | * Each file system will be mounted according to its table entry parameters. |
---|
152 | * In case of an abort condition the corresponding table index will be reported |
---|
153 | * in @a abort_index. The pointer @a abort_index may be @c NULL. The mount |
---|
154 | * point paths will be created with rtems_mkdir() and need not exist |
---|
155 | * beforehand. |
---|
156 | * |
---|
157 | * On success, zero is returned. On error, -1 is returned, and @c errno is set |
---|
158 | * appropriately. |
---|
159 | * |
---|
160 | * @see rtems_bdpart_register_from_disk(). |
---|
161 | * |
---|
162 | * The following example code tries to mount a FAT file system within a SD |
---|
163 | * Card. Some cards do not have a partition table so at first it tries to find |
---|
164 | * a file system inside the hole disk. If this is successful the mount process |
---|
165 | * will be aborted because the @ref RTEMS_FSTAB_OK condition is true. If this |
---|
166 | * did not work it tries to mount the file system inside the first partition. |
---|
167 | * If this fails the mount process will not be aborted (this is already the |
---|
168 | * last entry), but the last error status will be returned. |
---|
169 | * |
---|
170 | * @code |
---|
171 | * #include <stdio.h> |
---|
172 | * #include <string.h> |
---|
173 | * #include <errno.h> |
---|
174 | * |
---|
175 | * #include <rtems.h> |
---|
176 | * #include <rtems/bdpart.h> |
---|
177 | * #include <rtems/error.h> |
---|
178 | * #include <rtems/fsmount.h> |
---|
179 | * |
---|
180 | * static const rtems_fstab_entry fstab [] = { |
---|
181 | * { |
---|
182 | * .source = "/dev/sd-card-a", |
---|
183 | * .target = "/mnt", |
---|
184 | * .type = "dosfs", |
---|
185 | * .options = RTEMS_FILESYSTEM_READ_WRITE, |
---|
186 | * .report_reasons = RTEMS_FSTAB_ANY, |
---|
187 | * .abort_reasons = RTEMS_FSTAB_OK |
---|
188 | * }, { |
---|
189 | * .source = "/dev/sd-card-a1", |
---|
190 | * .target = "/mnt", |
---|
191 | * .type = "dosfs", |
---|
192 | * .options = RTEMS_FILESYSTEM_READ_WRITE, |
---|
193 | * .report_reasons = RTEMS_FSTAB_ANY, |
---|
194 | * .abort_reasons = RTEMS_FSTAB_NONE |
---|
195 | * } |
---|
196 | * }; |
---|
197 | * |
---|
198 | * static void my_mount(void) |
---|
199 | * { |
---|
200 | * rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
201 | * int rv = 0; |
---|
202 | * size_t abort_index = 0; |
---|
203 | * |
---|
204 | * sc = rtems_bdpart_register_from_disk("/dev/sd-card-a"); |
---|
205 | * if (sc != RTEMS_SUCCESSFUL) { |
---|
206 | * printf("read partition table failed: %s\n", rtems_status_text(sc)); |
---|
207 | * } |
---|
208 | * |
---|
209 | * rv = rtems_fsmount(fstab, sizeof(fstab) / sizeof(fstab [0]), &abort_index); |
---|
210 | * if (rv != 0) { |
---|
211 | * printf("mount failed: %s\n", strerror(errno)); |
---|
212 | * } |
---|
213 | * printf("mount aborted at %zu\n", abort_index); |
---|
214 | * } |
---|
215 | * @endcode |
---|
216 | */ |
---|
217 | int rtems_fsmount( const rtems_fstab_entry *fstab, size_t size, size_t *abort_index); |
---|
218 | |
---|
219 | /** @} */ |
---|
220 | |
---|
221 | typedef rtems_fstab_entry fstab_t; |
---|
222 | |
---|
223 | #define FSMOUNT_MNT_OK RTEMS_FSTAB_OK |
---|
224 | |
---|
225 | #define FSMOUNT_MNTPNT_CRTERR RTEMS_FSTAB_ERROR_MOUNT_POINT |
---|
226 | |
---|
227 | #define FSMOUNT_MNT_FAILED RTEMS_FSTAB_ERROR_MOUNT |
---|
228 | |
---|
229 | #ifdef __cplusplus |
---|
230 | } |
---|
231 | #endif |
---|
232 | |
---|
233 | #endif /* _FSMOUNT_H */ |
---|