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