1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Register IO Name |
---|
5 | * @ingroup ClassicIO |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * Modifications to support reference counting in the file system are |
---|
13 | * Copyright (c) 2012 embedded brains GmbH. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <sys/stat.h> |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | #include <rtems/libio_.h> |
---|
28 | |
---|
29 | rtems_status_code rtems_io_register_name( |
---|
30 | const char *device_name, |
---|
31 | rtems_device_major_number major, |
---|
32 | rtems_device_minor_number minor |
---|
33 | ) |
---|
34 | { |
---|
35 | int status; |
---|
36 | dev_t dev; |
---|
37 | |
---|
38 | dev = rtems_filesystem_make_dev_t( major, minor ); |
---|
39 | status = mknod( device_name, 0777 | S_IFCHR, dev ); |
---|
40 | |
---|
41 | /* this is the only error returned by the old version */ |
---|
42 | if ( status ) |
---|
43 | return RTEMS_TOO_MANY; |
---|
44 | |
---|
45 | return RTEMS_SUCCESSFUL; |
---|
46 | } |
---|
47 | |
---|
48 | rtems_status_code rtems_io_lookup_name( |
---|
49 | const char *name, |
---|
50 | rtems_driver_name_t *device_info |
---|
51 | ) |
---|
52 | { |
---|
53 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
54 | struct stat st; |
---|
55 | int rv = stat( name, &st ); |
---|
56 | |
---|
57 | if ( rv == 0 && S_ISCHR( st.st_mode ) ) { |
---|
58 | device_info->device_name = name; |
---|
59 | device_info->device_name_length = strlen( name ); |
---|
60 | device_info->major = rtems_filesystem_dev_major_t( st.st_rdev ); |
---|
61 | device_info->minor = rtems_filesystem_dev_minor_t( st.st_rdev ); |
---|
62 | } else { |
---|
63 | sc = RTEMS_UNSATISFIED; |
---|
64 | } |
---|
65 | |
---|
66 | return sc; |
---|
67 | } |
---|