[0a7278e] | 1 | /** |
---|
[d40da79b] | 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 | |
---|
[d934b68] | 11 | #include <rtems/libio_.h> |
---|
| 12 | |
---|
[d40da79b] | 13 | #ifdef __cplusplus |
---|
| 14 | extern "C" { |
---|
| 15 | #endif |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * This structure define the type of device table |
---|
| 19 | */ |
---|
[3b7c123] | 20 | typedef struct { |
---|
| 21 | /** This member points to device name which is not a null-terminated string */ |
---|
| 22 | const char *name; |
---|
[d40da79b] | 23 | /** This member is the name length of a device */ |
---|
[3b7c123] | 24 | size_t namelen; |
---|
[d40da79b] | 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; |
---|
[3b7c123] | 31 | } devFS_node; |
---|
[d40da79b] | 32 | |
---|
[3b7c123] | 33 | typedef struct { |
---|
| 34 | devFS_node *nodes; |
---|
| 35 | size_t count; |
---|
| 36 | } devFS_data; |
---|
[d40da79b] | 37 | |
---|
[3b7c123] | 38 | /** |
---|
| 39 | * The following defines the device-only filesystem operating |
---|
| 40 | * operations. |
---|
| 41 | */ |
---|
[d40da79b] | 42 | |
---|
[3b7c123] | 43 | extern const rtems_filesystem_operations_table devFS_ops; |
---|
[d40da79b] | 44 | |
---|
| 45 | /** |
---|
[3b7c123] | 46 | * The following defines the device-only filesystem operating |
---|
| 47 | * handlers. |
---|
[d40da79b] | 48 | */ |
---|
| 49 | |
---|
[3b7c123] | 50 | extern const rtems_filesystem_file_handlers_r devFS_file_handlers; |
---|
[d40da79b] | 51 | |
---|
| 52 | /** |
---|
[3b7c123] | 53 | * This routine associates RTEMS status code with errno |
---|
[d40da79b] | 54 | */ |
---|
| 55 | |
---|
[3b7c123] | 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 loc->mt_entry->immutable_fs_info; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | extern void devFS_eval_path( |
---|
| 66 | rtems_filesystem_eval_path_context_t *ctx |
---|
| 67 | ); |
---|
[d40da79b] | 68 | |
---|
| 69 | /** |
---|
| 70 | * This handler maps open operation to rtems_io_open. |
---|
| 71 | * @param iop This is the RTEMS's internal representation of file. |
---|
[0a7278e] | 72 | * @param pathname a null-terminated string that starts with /dev. |
---|
[d40da79b] | 73 | * @param flag access flags |
---|
| 74 | * @param mode access mode |
---|
| 75 | * @retval the same as open |
---|
| 76 | */ |
---|
| 77 | |
---|
[d934b68] | 78 | extern int devFS_open( |
---|
[d40da79b] | 79 | rtems_libio_t *iop, |
---|
| 80 | const char *pathname, |
---|
[3b7c123] | 81 | int oflag, |
---|
| 82 | mode_t mode |
---|
[d40da79b] | 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 | |
---|
[d934b68] | 93 | extern int devFS_close( |
---|
[d40da79b] | 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 | |
---|
[d934b68] | 107 | extern ssize_t devFS_read( |
---|
[d40da79b] | 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 | |
---|
[d934b68] | 123 | extern ssize_t devFS_write( |
---|
[d40da79b] | 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 | |
---|
[d934b68] | 139 | extern int devFS_ioctl( |
---|
[d40da79b] | 140 | rtems_libio_t *iop, |
---|
| 141 | uint32_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 | |
---|
[d934b68] | 160 | extern int devFS_stat( |
---|
[3b7c123] | 161 | const rtems_filesystem_location_info_t *loc, |
---|
| 162 | struct stat *buf |
---|
[d40da79b] | 163 | ); |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * This routine is invoked upon determination of a node type. |
---|
[0a7278e] | 169 | * Since this is a device-only filesystem, so there is only |
---|
[d40da79b] | 170 | * one node type in the system. |
---|
[0a7278e] | 171 | * |
---|
[3b7c123] | 172 | * @param loc contains filesytem access information, this |
---|
[d40da79b] | 173 | * parameter is ignored |
---|
| 174 | * @retval always returns RTEMS_FILESYSTEM_DEVICE |
---|
| 175 | */ |
---|
| 176 | |
---|
[106d8f5] | 177 | extern rtems_filesystem_node_types_t devFS_node_type( |
---|
[3b7c123] | 178 | const rtems_filesystem_location_info_t*loc |
---|
[d40da79b] | 179 | ); |
---|
| 180 | |
---|
| 181 | /** |
---|
| 182 | * This routine is invoked upon registration of a new device |
---|
[0a7278e] | 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 |
---|
[d40da79b] | 186 | * with proper values. |
---|
| 187 | * |
---|
[3b7c123] | 188 | * @see rtems_filesystem_mknod_t. |
---|
[d40da79b] | 189 | */ |
---|
| 190 | |
---|
[d934b68] | 191 | extern int devFS_mknod( |
---|
[3b7c123] | 192 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 193 | const char *name, |
---|
| 194 | size_t namelen, |
---|
| 195 | mode_t mode, |
---|
| 196 | dev_t dev |
---|
[d40da79b] | 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 |
---|
[0a7278e] | 205 | * |
---|
[29e92b0] | 206 | * @param mt_entry The filesystem mount table entry. |
---|
| 207 | * @param data Filesystem specific data. |
---|
[d40da79b] | 208 | * @retval upon success, this routine returns 0; otherwise it returns |
---|
[0a7278e] | 209 | * -1 and errno is set to proper value. The only error is when malloc |
---|
[d40da79b] | 210 | * failed, and errno is set to NOMEM. |
---|
| 211 | */ |
---|
| 212 | |
---|
[d934b68] | 213 | extern int devFS_initialize( |
---|
[29e92b0] | 214 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 215 | const void *data |
---|
[d40da79b] | 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: |
---|
[0a7278e] | 223 | * |
---|
[d40da79b] | 224 | * /dev/console 0 0 |
---|
| 225 | * /dev/clock 1 0 |
---|
| 226 | * /dev/tty0 0 0 |
---|
| 227 | * /flash 2 0 |
---|
[0a7278e] | 228 | * |
---|
| 229 | * This routine is intended for debugging, and can be used by shell |
---|
[d40da79b] | 230 | * program to provide user with the system information. |
---|
| 231 | */ |
---|
| 232 | |
---|
[3b7c123] | 233 | extern void devFS_Show(void); |
---|
[d40da79b] | 234 | |
---|
| 235 | #ifdef __cplusplus |
---|
| 236 | } |
---|
| 237 | #endif |
---|
| 238 | |
---|
| 239 | #endif |
---|
| 240 | |
---|