summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/devfs/devfs.h
blob: b065489455e683501ef5dfe0dbc0ae668c76909c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/** 
*  @file  libfs/devfs/devfs.h
*
*  This include file contains all constants and structures associated
*  with the 'device-only' filesystem.
*/

#ifndef _RTEMS_DEVFS_H
#define _RTEMS_DEVFS_H

#include <rtems/libio_.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 *  This structure define the type of device table
 */

typedef struct 
{
  /** This member pointes to device name which is a null-terminated string */
  char                     *device_name;
  /** This member is the name length of a device */
  uint32_t                  device_name_length;
  /** major number of a device */
  rtems_device_major_number major;
  /** minor number of a device */
  rtems_device_minor_number minor;
  /** device creation mode, only device file can be created */
  mode_t                    mode;

} rtems_device_name_t;



/**
 *  This routine associates RTEMS status code with errno
 */

extern int rtems_deviceio_errno(rtems_status_code code);


/**
 *  The following defines the device table size. This values
 *  is configured during application configuration time by 
 *  the user. The default value is set to 4.
 */

extern uint32_t rtems_device_table_size;


/**
 *  The following defines the device-only filesystem operating
 *  handlers.
 */

extern rtems_filesystem_operations_table devFS_ops; 

/**
 *  The following defines the device-only filesystem operating
 *  handlers.
 */

extern rtems_filesystem_file_handlers_r  devFS_file_handlers; 


/**
 *  This handler maps open operation to rtems_io_open.
 *  @param iop This is the RTEMS's internal representation of file.
 *  @param pathname a null-terminated string that starts with /dev. 
 *  @param flag access flags
 *  @param mode access mode
 *  @retval the same as open
 */

extern int devFS_open(
  rtems_libio_t *iop,
  const char    *pathname,
  uint32_t       flag,
  uint32_t       mode
);


/**
 *  This handler maps close operation to rtems_io_close.
 *  @param iop This is the RTEMS's internal representation of file
 *  @retval the same as close
 */


extern int devFS_close(
  rtems_libio_t *iop
);


/**
 *  This handler maps read operation to rtems_io_read.
 *  @param iop This is the RTEMS's internal representation of file
 *  @param  buffer memory location to store read data
 *  @param  count  how many bytes to read
 *  @retval On successful, this routine returns total bytes read. On error
 *  it returns -1 and errno is set to proper value.
 */

extern ssize_t devFS_read(
  rtems_libio_t *iop,
  void          *buffer,
  size_t         count
);


/**
 *  This handler maps write operation to rtems_io_write.
 *  @param iop This is the RTEMS's internal representation of file
 *  @param buffer data to be written
 *  @param count  how many bytes to write
 *  @retval On successful, this routine returns total bytes written. On error
 *  it returns -1 and errno is set to proper value.
 */

extern ssize_t devFS_write(
  rtems_libio_t *iop,
  const void    *buffer,
  size_t         count
);


/**
 *  This handler maps ioctl operation to rtems_io_ioctl.
 *  @param iop This is the RTEMS's internal representation of file
 *  @param command io control command
 *  @param buffer  io control parameters
 *  @retval On successful, this routine returns total bytes written. On error
 *  it returns -1 and errno is set to proper value.
 */

extern int devFS_ioctl(
  rtems_libio_t *iop,
  uint32_t       command,
  void          *buffer
);




/**
 *  This handler gets the device file information. This routine only set the following member of struct stat:
 *  st_dev : device number
 *  st_mode: device file creation mode, only two mode are accepted:
 *           S_IFCHR: character device file
 *           S_IFBLK: block device file
 *  @param loc contains filesystem access information
 *  @param buf buffer to hold the device file's information
 *  @retval On successful, this routine returns 0. On error
 *  it returns -1 and errno is set to proper value.
 */

extern int devFS_stat(
  rtems_filesystem_location_info_t *loc,
  struct stat                      *buf
);



/**
 *  This routine is invoked upon determination of a node type.
 *  Since this is a device-only filesystem, so there is only 
 *  one node type in the system.
 *  
 *  @param pathloc contains filesytem access information, this 
 *         parameter is ignored
 *  @retval always returns RTEMS_FILESYSTEM_DEVICE
 */

extern int devFS_node_type(
  rtems_filesystem_location_info_t  *pathloc
);



/**
 *  This routine is invoked to determine if 'pathname' exists.
 *  This routine first check access flags, then it searches 
 *  the device table to get the information.
 * 
 *  @param pathname device name to be searched
 *  @param flags access flags
 *  @param pathloc contains filesystem access information
 *  @retval upon success(pathname exists), this routines 
 *  returns 0; if 'flag' is invalid, it returns -1 and errno 
 *  is set to EIO; otherwise, it returns -1 and errno is set to ENOENT
 */

extern int devFS_evaluate_path(
  const char                        *pathname,
  int                                flags,
  rtems_filesystem_location_info_t  *pathloc
);


/**
 *  This routine is given a path to evaluate and a valid start 
 *  location. It is responsible for finding the parent node for
 *  a requested make command, setting pathloc information to
 *  identify the parent node, and setting the name pointer to 
 *  the first character of the name of the new node. In device 
 *  only filesystem, devices do not has a tree hierarchy, there
 *  are no parent-child relationship. So this routine is rather 
 *  simple, it just set *name to path and returns
 *
 *  @param path device path to be evaluated
 *  @param pathloc contains filesystem access information, this 
 *         parameter is ignored
 *  @param name 
 *  @retval always returns 0
 */

extern int devFS_evaluate_for_make(
   const char                         *path,
   rtems_filesystem_location_info_t   *pathloc,
   const char                        **name
);



/**
 *  This routine is invoked upon registration of a new device
 *  file. It is responsible for creating a item in the main 
 *  device table. This routine searches the device table in 
 *  sequential order, when found a empty slot, it fills the slot 
 *  with proper values.
 *
 *  @param path the device file name to be registered
 *  @param mode file mode, this parameter is ignored
 *  @param dev  device major and minor number
 *  @param pathloc contains filesystem access information
 *  @retval upon success, this routine returns 0; if 'path'
 *  already exist, it returns -1 and errno is set to EEXIST;
 *  if device table is full, it returns -1 and errno is set 
 *  to ENOMEM
 */

extern int devFS_mknod(
   const char                        *path,
   mode_t                             mode, 
   dev_t                              dev,  
   rtems_filesystem_location_info_t  *pathloc 
);


/**
 *  This routine is invoked upon rtems filesystem initialization.
 *  It is responsible for creating the main device table,
 *  initializing it to a known state, and set device file operation
 *  handlers. After this, the device-only filesytem is ready for use
 * 
 *  @param  temp_mt_entry
 *  @retval upon success, this routine returns 0; otherwise it returns
 *  -1 and errno is set to proper value. The only error is when malloc 
 *  failed, and errno is set to NOMEM.
 */

extern int devFS_initialize(
  rtems_filesystem_mount_table_entry_t *temp_mt_entry
);


/**
 *  This routine retrieves all the device registered in system, and
 *  prints out their detail information. For example, on one system,
 *  devFS_show will print out following message:
 *  
 *  /dev/console     0  0
 *  /dev/clock       1  0
 *  /dev/tty0        0  0
 *  /flash           2  0
 * 
 *  This routine is intended for debugging, and can be used by shell 
 *  program to provide user with the system information.
 *  
 *  @param  none
 *  @retval 0
 */

extern int devFS_Show(void);

#ifdef __cplusplus
}
#endif

#endif