1 | /** |
---|
2 | * @file libfs/devfs/devfs.h |
---|
3 | * |
---|
4 | * This include file contains all constants and structures associated |
---|
5 | * with the 'device-only' filesystem. |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef _RTEMS_DEVFS_H |
---|
9 | #define _RTEMS_DEVFS_H |
---|
10 | |
---|
11 | #include <rtems/libio_.h> |
---|
12 | |
---|
13 | #ifdef __cplusplus |
---|
14 | extern "C" { |
---|
15 | #endif |
---|
16 | |
---|
17 | /** |
---|
18 | * This structure define the type of device table |
---|
19 | */ |
---|
20 | |
---|
21 | typedef struct |
---|
22 | { |
---|
23 | /** This member points to device name which is a null-terminated string */ |
---|
24 | char *device_name; |
---|
25 | /** This member is the name length of a device */ |
---|
26 | uint32_t device_name_length; |
---|
27 | /** major number of a device */ |
---|
28 | rtems_device_major_number major; |
---|
29 | /** minor number of a device */ |
---|
30 | rtems_device_minor_number minor; |
---|
31 | /** device creation mode, only device file can be created */ |
---|
32 | mode_t mode; |
---|
33 | |
---|
34 | } rtems_device_name_t; |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | * This routine associates RTEMS status code with errno |
---|
40 | */ |
---|
41 | |
---|
42 | extern int rtems_deviceio_errno(rtems_status_code code); |
---|
43 | |
---|
44 | |
---|
45 | /** |
---|
46 | * The following defines the device table size. This values |
---|
47 | * is configured during application configuration time by |
---|
48 | * the user. The default value is set to 4. |
---|
49 | */ |
---|
50 | |
---|
51 | extern uint32_t rtems_device_table_size; |
---|
52 | |
---|
53 | /** |
---|
54 | * This handler maps open operation to rtems_io_open. |
---|
55 | * @param iop This is the RTEMS's internal representation of file. |
---|
56 | * @param pathname a null-terminated string that starts with /dev. |
---|
57 | * @param flag access flags |
---|
58 | * @param mode access mode |
---|
59 | * @retval the same as open |
---|
60 | */ |
---|
61 | |
---|
62 | extern int devFS_open( |
---|
63 | rtems_libio_t *iop, |
---|
64 | const char *pathname, |
---|
65 | uint32_t flag, |
---|
66 | uint32_t mode |
---|
67 | ); |
---|
68 | |
---|
69 | |
---|
70 | /** |
---|
71 | * This handler maps close operation to rtems_io_close. |
---|
72 | * @param iop This is the RTEMS's internal representation of file |
---|
73 | * @retval the same as close |
---|
74 | */ |
---|
75 | |
---|
76 | |
---|
77 | extern int devFS_close( |
---|
78 | rtems_libio_t *iop |
---|
79 | ); |
---|
80 | |
---|
81 | |
---|
82 | /** |
---|
83 | * This handler maps read operation to rtems_io_read. |
---|
84 | * @param iop This is the RTEMS's internal representation of file |
---|
85 | * @param buffer memory location to store read data |
---|
86 | * @param count how many bytes to read |
---|
87 | * @retval On successful, this routine returns total bytes read. On error |
---|
88 | * it returns -1 and errno is set to proper value. |
---|
89 | */ |
---|
90 | |
---|
91 | extern ssize_t devFS_read( |
---|
92 | rtems_libio_t *iop, |
---|
93 | void *buffer, |
---|
94 | size_t count |
---|
95 | ); |
---|
96 | |
---|
97 | |
---|
98 | /** |
---|
99 | * This handler maps write operation to rtems_io_write. |
---|
100 | * @param iop This is the RTEMS's internal representation of file |
---|
101 | * @param buffer data to be written |
---|
102 | * @param count how many bytes to write |
---|
103 | * @retval On successful, this routine returns total bytes written. On error |
---|
104 | * it returns -1 and errno is set to proper value. |
---|
105 | */ |
---|
106 | |
---|
107 | extern ssize_t devFS_write( |
---|
108 | rtems_libio_t *iop, |
---|
109 | const void *buffer, |
---|
110 | size_t count |
---|
111 | ); |
---|
112 | |
---|
113 | |
---|
114 | /** |
---|
115 | * This handler maps ioctl operation to rtems_io_ioctl. |
---|
116 | * @param iop This is the RTEMS's internal representation of file |
---|
117 | * @param command io control command |
---|
118 | * @param buffer io control parameters |
---|
119 | * @retval On successful, this routine returns total bytes written. On error |
---|
120 | * it returns -1 and errno is set to proper value. |
---|
121 | */ |
---|
122 | |
---|
123 | extern int devFS_ioctl( |
---|
124 | rtems_libio_t *iop, |
---|
125 | uint32_t command, |
---|
126 | void *buffer |
---|
127 | ); |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | /** |
---|
133 | * This handler gets the device file information. This routine only set the following member of struct stat: |
---|
134 | * st_dev : device number |
---|
135 | * st_mode: device file creation mode, only two mode are accepted: |
---|
136 | * S_IFCHR: character device file |
---|
137 | * S_IFBLK: block device file |
---|
138 | * @param loc contains filesystem access information |
---|
139 | * @param buf buffer to hold the device file's information |
---|
140 | * @retval On successful, this routine returns 0. On error |
---|
141 | * it returns -1 and errno is set to proper value. |
---|
142 | */ |
---|
143 | |
---|
144 | extern int devFS_stat( |
---|
145 | rtems_filesystem_location_info_t *loc, |
---|
146 | struct stat *buf |
---|
147 | ); |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | /** |
---|
152 | * This routine is invoked upon determination of a node type. |
---|
153 | * Since this is a device-only filesystem, so there is only |
---|
154 | * one node type in the system. |
---|
155 | * |
---|
156 | * @param pathloc contains filesytem access information, this |
---|
157 | * parameter is ignored |
---|
158 | * @retval always returns RTEMS_FILESYSTEM_DEVICE |
---|
159 | */ |
---|
160 | |
---|
161 | extern int devFS_node_type( |
---|
162 | rtems_filesystem_location_info_t *pathloc |
---|
163 | ); |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | /** |
---|
168 | * This routine is invoked to determine if 'pathname' exists. |
---|
169 | * This routine first check access flags, then it searches |
---|
170 | * the device table to get the information. |
---|
171 | * |
---|
172 | * @param pathname device name to be searched |
---|
173 | * @param flags access flags |
---|
174 | * @param pathloc contains filesystem access information |
---|
175 | * @retval upon success(pathname exists), this routines |
---|
176 | * returns 0; if 'flag' is invalid, it returns -1 and errno |
---|
177 | * is set to EIO; otherwise, it returns -1 and errno is set to ENOENT |
---|
178 | */ |
---|
179 | |
---|
180 | extern int devFS_evaluate_path( |
---|
181 | const char *pathname, |
---|
182 | size_t pathnamelen, |
---|
183 | int flags, |
---|
184 | rtems_filesystem_location_info_t *pathloc |
---|
185 | ); |
---|
186 | |
---|
187 | |
---|
188 | /** |
---|
189 | * This routine is given a path to evaluate and a valid start |
---|
190 | * location. It is responsible for finding the parent node for |
---|
191 | * a requested make command, setting pathloc information to |
---|
192 | * identify the parent node, and setting the name pointer to |
---|
193 | * the first character of the name of the new node. In device |
---|
194 | * only filesystem, devices do not has a tree hierarchy, there |
---|
195 | * are no parent-child relationship. So this routine is rather |
---|
196 | * simple, it just set *name to path and returns |
---|
197 | * |
---|
198 | * @param path device path to be evaluated |
---|
199 | * @param pathloc contains filesystem access information, this |
---|
200 | * parameter is ignored |
---|
201 | * @param name |
---|
202 | * @retval always returns 0 |
---|
203 | */ |
---|
204 | |
---|
205 | extern int devFS_evaluate_for_make( |
---|
206 | const char *path, |
---|
207 | rtems_filesystem_location_info_t *pathloc, |
---|
208 | const char **name |
---|
209 | ); |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | /** |
---|
214 | * This routine is invoked upon registration of a new device |
---|
215 | * file. It is responsible for creating a item in the main |
---|
216 | * device table. This routine searches the device table in |
---|
217 | * sequential order, when found a empty slot, it fills the slot |
---|
218 | * with proper values. |
---|
219 | * |
---|
220 | * @param path the device file name to be registered |
---|
221 | * @param mode file mode, this parameter is ignored |
---|
222 | * @param dev device major and minor number |
---|
223 | * @param pathloc contains filesystem access information |
---|
224 | * @retval upon success, this routine returns 0; if 'path' |
---|
225 | * already exist, it returns -1 and errno is set to EEXIST; |
---|
226 | * if device table is full, it returns -1 and errno is set |
---|
227 | * to ENOMEM |
---|
228 | */ |
---|
229 | |
---|
230 | extern int devFS_mknod( |
---|
231 | const char *path, |
---|
232 | mode_t mode, |
---|
233 | dev_t dev, |
---|
234 | rtems_filesystem_location_info_t *pathloc |
---|
235 | ); |
---|
236 | |
---|
237 | |
---|
238 | /** |
---|
239 | * This routine is invoked upon rtems filesystem initialization. |
---|
240 | * It is responsible for creating the main device table, |
---|
241 | * initializing it to a known state, and set device file operation |
---|
242 | * handlers. After this, the device-only filesytem is ready for use |
---|
243 | * |
---|
244 | * @param mt_entry The filesystem mount table entry. |
---|
245 | * @param data Filesystem specific data. |
---|
246 | * @retval upon success, this routine returns 0; otherwise it returns |
---|
247 | * -1 and errno is set to proper value. The only error is when malloc |
---|
248 | * failed, and errno is set to NOMEM. |
---|
249 | */ |
---|
250 | |
---|
251 | extern int devFS_initialize( |
---|
252 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
253 | const void *data |
---|
254 | ); |
---|
255 | |
---|
256 | |
---|
257 | /** |
---|
258 | * This routine retrieves all the device registered in system, and |
---|
259 | * prints out their detail information. For example, on one system, |
---|
260 | * devFS_show will print out following message: |
---|
261 | * |
---|
262 | * /dev/console 0 0 |
---|
263 | * /dev/clock 1 0 |
---|
264 | * /dev/tty0 0 0 |
---|
265 | * /flash 2 0 |
---|
266 | * |
---|
267 | * This routine is intended for debugging, and can be used by shell |
---|
268 | * program to provide user with the system information. |
---|
269 | * |
---|
270 | * @retval 0 |
---|
271 | */ |
---|
272 | |
---|
273 | extern int devFS_Show(void); |
---|
274 | |
---|
275 | #ifdef __cplusplus |
---|
276 | } |
---|
277 | #endif |
---|
278 | |
---|
279 | #endif |
---|
280 | |
---|