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