1 | /* |
---|
2 | * This file contains the support infrastructure used to manage the |
---|
3 | * table of integer style file descriptors used by the low level |
---|
4 | * POSIX system calls like open(), read, fstat(), etc. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1999. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
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.rtems.com/license/LICENSE. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #if HAVE_CONFIG_H |
---|
17 | #include "config.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <rtems/libio_.h> /* libio_.h pulls in rtems */ |
---|
21 | #include <rtems.h> |
---|
22 | #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ |
---|
23 | |
---|
24 | #include <stdio.h> /* O_RDONLY, et.al. */ |
---|
25 | #include <fcntl.h> /* O_RDONLY, et.al. */ |
---|
26 | #include <assert.h> |
---|
27 | #include <errno.h> |
---|
28 | |
---|
29 | #include <errno.h> |
---|
30 | #include <string.h> /* strcmp */ |
---|
31 | #include <unistd.h> |
---|
32 | #include <stdlib.h> /* calloc() */ |
---|
33 | |
---|
34 | #include <rtems/libio.h> /* libio.h not pulled in by rtems */ |
---|
35 | |
---|
36 | /* |
---|
37 | * File descriptor Table Information |
---|
38 | */ |
---|
39 | |
---|
40 | rtems_id rtems_libio_semaphore; |
---|
41 | rtems_libio_t *rtems_libio_iops; |
---|
42 | rtems_libio_t *rtems_libio_iop_freelist; |
---|
43 | |
---|
44 | /* |
---|
45 | * rtems_libio_init |
---|
46 | * |
---|
47 | * Called by BSP startup code to initialize the libio subsystem. |
---|
48 | */ |
---|
49 | |
---|
50 | void rtems_libio_init( void ) |
---|
51 | { |
---|
52 | rtems_status_code rc; |
---|
53 | uint32_t i; |
---|
54 | rtems_libio_t *iop; |
---|
55 | |
---|
56 | if (rtems_libio_number_iops > 0) |
---|
57 | { |
---|
58 | rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, |
---|
59 | sizeof(rtems_libio_t)); |
---|
60 | if (rtems_libio_iops == NULL) |
---|
61 | rtems_fatal_error_occurred(RTEMS_NO_MEMORY); |
---|
62 | |
---|
63 | iop = rtems_libio_iop_freelist = rtems_libio_iops; |
---|
64 | for (i = 0 ; (i + 1) < rtems_libio_number_iops ; i++, iop++) |
---|
65 | iop->data1 = iop + 1; |
---|
66 | iop->data1 = NULL; |
---|
67 | } |
---|
68 | |
---|
69 | /* |
---|
70 | * Create the binary semaphore used to provide mutual exclusion |
---|
71 | * on the IOP Table. |
---|
72 | */ |
---|
73 | |
---|
74 | rc = rtems_semaphore_create( |
---|
75 | RTEMS_LIBIO_SEM, |
---|
76 | 1, |
---|
77 | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, |
---|
78 | RTEMS_NO_PRIORITY, |
---|
79 | &rtems_libio_semaphore |
---|
80 | ); |
---|
81 | if ( rc != RTEMS_SUCCESSFUL ) |
---|
82 | rtems_fatal_error_occurred( rc ); |
---|
83 | |
---|
84 | /* |
---|
85 | * Initialize the base file system infrastructure. |
---|
86 | */ |
---|
87 | |
---|
88 | if (rtems_fs_init_helper) |
---|
89 | (* rtems_fs_init_helper)(); |
---|
90 | } |
---|