1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Device Only File System |
---|
5 | * |
---|
6 | * This include file contains all constants and structures associated |
---|
7 | * with the 'device-only' filesystem. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef _RTEMS_DEVFS_H |
---|
11 | #define _RTEMS_DEVFS_H |
---|
12 | |
---|
13 | #include <rtems/libio_.h> |
---|
14 | |
---|
15 | /** |
---|
16 | * @defgroup DevFsDeviceTable Device Only File System |
---|
17 | * |
---|
18 | * @ingroup FileSystemTypesAndMount |
---|
19 | * |
---|
20 | * @brief This structure defines the type of device table |
---|
21 | */ |
---|
22 | /**@{*/ |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif |
---|
26 | |
---|
27 | /** |
---|
28 | * @brief Per Device Node Control Structure |
---|
29 | * |
---|
30 | * This structure is instanced per device node and contains all information |
---|
31 | * used by this file system implementation to manage that device node. |
---|
32 | */ |
---|
33 | typedef struct { |
---|
34 | /** This member points to device name which is not a null-terminated string */ |
---|
35 | const char *name; |
---|
36 | /** This member is the name length of a device */ |
---|
37 | size_t namelen; |
---|
38 | /** major number of a device */ |
---|
39 | rtems_device_major_number major; |
---|
40 | /** minor number of a device */ |
---|
41 | rtems_device_minor_number minor; |
---|
42 | /** device creation mode, only device file can be created */ |
---|
43 | mode_t mode; |
---|
44 | } devFS_node; |
---|
45 | |
---|
46 | typedef struct { |
---|
47 | devFS_node *nodes; |
---|
48 | size_t count; |
---|
49 | } devFS_data; |
---|
50 | |
---|
51 | /** |
---|
52 | * The following defines the device-only filesystem operating |
---|
53 | * operations. |
---|
54 | */ |
---|
55 | extern const rtems_filesystem_operations_table devFS_ops; |
---|
56 | |
---|
57 | /** |
---|
58 | * The following defines the device-only filesystem operating |
---|
59 | * handlers. |
---|
60 | */ |
---|
61 | extern const rtems_filesystem_file_handlers_r devFS_file_handlers; |
---|
62 | |
---|
63 | /** |
---|
64 | * @brief Obtain Immutable Pointer to Immutable File System Data |
---|
65 | * |
---|
66 | * This methods returns the immutable file system specific information |
---|
67 | * associated with this file. |
---|
68 | */ |
---|
69 | static inline const devFS_data *devFS_get_data( |
---|
70 | const rtems_filesystem_location_info_t *loc |
---|
71 | ) |
---|
72 | { |
---|
73 | return (const devFS_data *) loc->mt_entry->immutable_fs_info; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * @brief Evaluate Path |
---|
78 | */ |
---|
79 | extern void devFS_eval_path( |
---|
80 | rtems_filesystem_eval_path_context_t *ctx |
---|
81 | ); |
---|
82 | |
---|
83 | /** |
---|
84 | * @brief Maps Open Operation to rtems_io_open |
---|
85 | * |
---|
86 | * This handler maps open operation to rtems_io_open. |
---|
87 | * |
---|
88 | * @param iop This is the RTEMS's internal representation of file. |
---|
89 | * @param pathname a null-terminated string that starts with /dev. |
---|
90 | * @param oflag access flags |
---|
91 | * @param mode access mode |
---|
92 | * |
---|
93 | * @retval the same as open |
---|
94 | */ |
---|
95 | extern int devFS_open( |
---|
96 | rtems_libio_t *iop, |
---|
97 | const char *pathname, |
---|
98 | int oflag, |
---|
99 | mode_t mode |
---|
100 | ); |
---|
101 | |
---|
102 | |
---|
103 | /** |
---|
104 | * @brief Maps Close Operation to rtems_io_close |
---|
105 | * |
---|
106 | * This handler maps close operation to rtems_io_close. |
---|
107 | * |
---|
108 | * @param iop This is the RTEMS's internal representation of file |
---|
109 | * |
---|
110 | * @retval the same as close |
---|
111 | */ |
---|
112 | extern int devFS_close( |
---|
113 | rtems_libio_t *iop |
---|
114 | ); |
---|
115 | |
---|
116 | /** |
---|
117 | * @brief Maps Read Operation to rtems_io_read |
---|
118 | * |
---|
119 | * This handler maps read operation to rtems_io_read. |
---|
120 | * |
---|
121 | * @param iop This is the RTEMS's internal representation of file |
---|
122 | * @param buffer memory location to store read data |
---|
123 | * @param count how many bytes to read |
---|
124 | * |
---|
125 | * @retval On successful, this routine returns total bytes read. On error |
---|
126 | * it returns -1 and errno is set to proper value. |
---|
127 | */ |
---|
128 | extern ssize_t devFS_read( |
---|
129 | rtems_libio_t *iop, |
---|
130 | void *buffer, |
---|
131 | size_t count |
---|
132 | ); |
---|
133 | |
---|
134 | /** |
---|
135 | * @brief Writes Operation to rtems_io_write |
---|
136 | * |
---|
137 | * This handler maps write operation to rtems_io_write. |
---|
138 | * |
---|
139 | * @param iop This is the RTEMS's internal representation of file |
---|
140 | * @param buffer data to be written |
---|
141 | * @param count how many bytes to write |
---|
142 | * |
---|
143 | * @retval On successful, this routine returns total bytes written. On error |
---|
144 | * it returns -1 and errno is set to proper value. |
---|
145 | */ |
---|
146 | extern ssize_t devFS_write( |
---|
147 | rtems_libio_t *iop, |
---|
148 | const void *buffer, |
---|
149 | size_t count |
---|
150 | ); |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief Maps ioctl Operation to rtems_io_ioctl |
---|
154 | * |
---|
155 | * This handler maps ioctl operation to rtems_io_ioctl. |
---|
156 | * |
---|
157 | * @param iop This is the RTEMS's internal representation of file |
---|
158 | * @param command io control command |
---|
159 | * @param buffer io control parameters |
---|
160 | * |
---|
161 | * @retval On successful, this routine returns total bytes written. On error |
---|
162 | * it returns -1 and errno is set to proper value. |
---|
163 | */ |
---|
164 | extern int devFS_ioctl( |
---|
165 | rtems_libio_t *iop, |
---|
166 | ioctl_command_t command, |
---|
167 | void *buffer |
---|
168 | ); |
---|
169 | |
---|
170 | /** |
---|
171 | * @brief Gets the Device File Information |
---|
172 | * |
---|
173 | * This handler gets the device file information. This routine only |
---|
174 | * set the following member of struct stat: |
---|
175 | * |
---|
176 | * - st_dev: device number |
---|
177 | * - st_mode: device file creation mode, only two mode are accepted: |
---|
178 | * + S_IFCHR: character device file |
---|
179 | * + S_IFBLK: block device file |
---|
180 | * |
---|
181 | * @param loc contains filesystem access information |
---|
182 | * @param buf buffer to hold the device file's information |
---|
183 | * |
---|
184 | * @retval On successful, this routine returns 0. On error |
---|
185 | * it returns -1 and errno is set to proper value. |
---|
186 | */ |
---|
187 | extern int devFS_stat( |
---|
188 | const rtems_filesystem_location_info_t *loc, |
---|
189 | struct stat *buf |
---|
190 | ); |
---|
191 | |
---|
192 | /** |
---|
193 | * @brief Creates an item in the main device table. |
---|
194 | * |
---|
195 | * This routine is invoked upon registration of a new device |
---|
196 | * file. It is responsible for creating a item in the main |
---|
197 | * device table. This routine searches the device table in |
---|
198 | * sequential order, when found a empty slot, it fills the slot |
---|
199 | * with proper values. |
---|
200 | * |
---|
201 | * @see rtems_filesystem_mknod_t. |
---|
202 | */ |
---|
203 | extern int devFS_mknod( |
---|
204 | const rtems_filesystem_location_info_t *parentloc, |
---|
205 | const char *name, |
---|
206 | size_t namelen, |
---|
207 | mode_t mode, |
---|
208 | dev_t dev |
---|
209 | ); |
---|
210 | |
---|
211 | /** |
---|
212 | * @brief Creates the Main Device Table |
---|
213 | * |
---|
214 | * This routine is invoked upon rtems filesystem initialization. |
---|
215 | * It is responsible for creating the main device table, |
---|
216 | * initializing it to a known state, and set device file operation |
---|
217 | * handlers. After this, the device-only filesytem is ready for use |
---|
218 | * |
---|
219 | * @param mt_entry The filesystem mount table entry. |
---|
220 | * @param data Filesystem specific data. |
---|
221 | * |
---|
222 | * @retval upon success, this routine returns 0; otherwise it returns |
---|
223 | * -1 and errno is set to proper value. The only error is when malloc |
---|
224 | * failed, and errno is set to NOMEM. |
---|
225 | */ |
---|
226 | extern int devFS_initialize( |
---|
227 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
228 | const void *data |
---|
229 | ); |
---|
230 | |
---|
231 | /** |
---|
232 | * @brief Retrieves and Prints all the Device Registered in System |
---|
233 | * |
---|
234 | * This routine retrieves all the device registered in system, and |
---|
235 | * prints out their detail information. For example, on one system, |
---|
236 | * devFS_show will print out following message: |
---|
237 | * |
---|
238 | * @code |
---|
239 | * /dev/console 0 0 |
---|
240 | * /dev/clock 1 0 |
---|
241 | * /dev/tty0 0 0 |
---|
242 | * /flash 2 0 |
---|
243 | * @endcode |
---|
244 | * |
---|
245 | * This routine is intended for debugging, and can be used by shell |
---|
246 | * program to provide user with the system information. |
---|
247 | */ |
---|
248 | extern void devFS_Show(void); |
---|
249 | |
---|
250 | #ifdef __cplusplus |
---|
251 | } |
---|
252 | #endif |
---|
253 | /**@}*/ |
---|
254 | #endif |
---|
255 | |
---|