1 | /* |
---|
2 | * This file emulates the old Classic RTEMS IO manager directives |
---|
3 | * which register and lookup names using the in-memory filesystem. |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | #include <sys/types.h> |
---|
18 | #include <sys/stat.h> |
---|
19 | #include <fcntl.h> |
---|
20 | #include <unistd.h> |
---|
21 | |
---|
22 | #include <assert.h> |
---|
23 | |
---|
24 | #include <rtems.h> |
---|
25 | #include "libio_.h" |
---|
26 | #include "imfs.h" |
---|
27 | |
---|
28 | #if defined(__linux__) |
---|
29 | #define S_IFCHR __S_IFCHR |
---|
30 | #endif |
---|
31 | |
---|
32 | /* |
---|
33 | * rtems_io_register_name |
---|
34 | * |
---|
35 | * This assumes that all registered devices are character devices. |
---|
36 | */ |
---|
37 | |
---|
38 | rtems_status_code rtems_io_register_name( |
---|
39 | char *device_name, |
---|
40 | rtems_device_major_number major, |
---|
41 | rtems_device_minor_number minor |
---|
42 | ) |
---|
43 | { |
---|
44 | #if !defined(RTEMS_UNIX) |
---|
45 | int status; |
---|
46 | dev_t dev; |
---|
47 | |
---|
48 | dev = rtems_filesystem_make_dev_t( major, minor ); |
---|
49 | status = mknod( device_name, 0777 | S_IFCHR, dev ); |
---|
50 | |
---|
51 | /* this is the only error returned by the old version */ |
---|
52 | if ( status ) |
---|
53 | return RTEMS_TOO_MANY; |
---|
54 | |
---|
55 | #endif |
---|
56 | return RTEMS_SUCCESSFUL; |
---|
57 | } |
---|
58 | |
---|
59 | /* |
---|
60 | * rtems_io_lookup_name |
---|
61 | * |
---|
62 | * This version is not reentrant. |
---|
63 | * |
---|
64 | * XXX - This is dependent upon IMFS and should not be. |
---|
65 | * Suggest adding a filesystem routine to fill in the device_info. |
---|
66 | */ |
---|
67 | |
---|
68 | rtems_status_code rtems_io_lookup_name( |
---|
69 | const char *name, |
---|
70 | rtems_driver_name_t **device_info |
---|
71 | ) |
---|
72 | { |
---|
73 | #if !defined(RTEMS_UNIX) |
---|
74 | IMFS_jnode_t *the_jnode; |
---|
75 | rtems_filesystem_location_info_t loc; |
---|
76 | static rtems_driver_name_t device; |
---|
77 | int result; |
---|
78 | rtems_filesystem_node_types_t node_type; |
---|
79 | |
---|
80 | result = rtems_filesystem_evaluate_path( name, 0x00, &loc, TRUE ); |
---|
81 | the_jnode = loc.node_access; |
---|
82 | |
---|
83 | node_type = (*loc.ops->node_type)( &loc ); |
---|
84 | |
---|
85 | if ( (result != 0) || node_type != RTEMS_FILESYSTEM_DEVICE ) { |
---|
86 | *device_info = 0; |
---|
87 | rtems_filesystem_freenode( &loc ); |
---|
88 | return RTEMS_UNSATISFIED; |
---|
89 | } |
---|
90 | |
---|
91 | device.device_name = (char *) name; |
---|
92 | device.device_name_length = strlen( name ); |
---|
93 | device.major = the_jnode->info.device.major; |
---|
94 | device.minor = the_jnode->info.device.minor; |
---|
95 | *device_info = &device; |
---|
96 | |
---|
97 | rtems_filesystem_freenode( &loc ); |
---|
98 | |
---|
99 | #endif |
---|
100 | return RTEMS_SUCCESSFUL; |
---|
101 | } |
---|