1 | /* |
---|
2 | * Base file system initialization |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2008. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #if HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <rtems.h> |
---|
19 | #include <rtems/libio.h> |
---|
20 | #include <rtems/libio_.h> |
---|
21 | |
---|
22 | /* |
---|
23 | * Default mode for created files. |
---|
24 | */ |
---|
25 | |
---|
26 | |
---|
27 | /* |
---|
28 | * rtems_filesystem_initialize |
---|
29 | * |
---|
30 | * Initialize the foundation of the file system. This is specified |
---|
31 | * by the structure rtems_filesystem_mount_table. The usual |
---|
32 | * configuration is a single instantiation of the IMFS or miniIMFS with |
---|
33 | * a single "/dev" directory in it. |
---|
34 | */ |
---|
35 | |
---|
36 | void rtems_filesystem_initialize( void ) |
---|
37 | { |
---|
38 | #if !defined(RTEMS_UNIX) |
---|
39 | int status; |
---|
40 | rtems_filesystem_mount_table_entry_t *entry; |
---|
41 | const rtems_filesystem_mount_table_t *mt; |
---|
42 | rtems_filesystem_location_info_t loc; |
---|
43 | |
---|
44 | /* |
---|
45 | * Set the default umask to "022". |
---|
46 | */ |
---|
47 | |
---|
48 | rtems_filesystem_umask = 022; |
---|
49 | |
---|
50 | |
---|
51 | init_fs_mount_table(); |
---|
52 | |
---|
53 | /* |
---|
54 | * mount the first filesystem. |
---|
55 | */ |
---|
56 | |
---|
57 | if ( rtems_filesystem_mount_table_size == 0 ) |
---|
58 | rtems_fatal_error_occurred( 0xABCD0001 ); |
---|
59 | |
---|
60 | mt = &rtems_filesystem_mount_table[0]; |
---|
61 | |
---|
62 | status = mount( |
---|
63 | &entry, mt->fs_ops, mt->fsoptions, mt->device, mt->mount_point ); |
---|
64 | |
---|
65 | if ( status == -1 ) |
---|
66 | rtems_fatal_error_occurred( 0xABCD0002 ); |
---|
67 | |
---|
68 | rtems_filesystem_link_counts = 0; |
---|
69 | |
---|
70 | /* setup the 'current' and 'root' directories |
---|
71 | * |
---|
72 | * NOTE: cloning the pathlocs is not strictly |
---|
73 | * necessary. Since we implicitely let |
---|
74 | * all threads that don't call |
---|
75 | * libio_set_private_env() share the same |
---|
76 | * (initial) 'root' and 'current' locs, |
---|
77 | * we (also implicitely) assume that the |
---|
78 | * root filesystem doesn't care about |
---|
79 | * reference counts. |
---|
80 | * I just inserted the code snippet below |
---|
81 | * to remind everybody of the fact by |
---|
82 | * making it more explicit... |
---|
83 | * Ideally, every thread would have to |
---|
84 | * call either share_private_env() or |
---|
85 | * set_private_env() - but then: that's |
---|
86 | * gonna hit performance. |
---|
87 | * |
---|
88 | * Till Straumann, 10/25/2002 |
---|
89 | */ |
---|
90 | rtems_filesystem_root = entry->mt_fs_root; |
---|
91 | /* Clone the root pathloc */ |
---|
92 | rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); |
---|
93 | rtems_filesystem_root = loc; |
---|
94 | /* One more clone for the current node */ |
---|
95 | rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); |
---|
96 | rtems_filesystem_current = loc; |
---|
97 | |
---|
98 | /* Note: the global_env's refcnt doesn't matter |
---|
99 | * as the global env is never released |
---|
100 | */ |
---|
101 | |
---|
102 | |
---|
103 | /* |
---|
104 | * Traditionally RTEMS devices are under "/dev" so install this directory. |
---|
105 | * |
---|
106 | * If the mkdir() fails, we can't print anything so just fatal error. |
---|
107 | * |
---|
108 | * NOTE: UNIX root is 755 and owned by root/root (0/0). It is actually |
---|
109 | * created that way by the IMFS. |
---|
110 | */ |
---|
111 | |
---|
112 | status = mkdir( "/dev", 0777); |
---|
113 | if ( status != 0 ) |
---|
114 | rtems_fatal_error_occurred( 0xABCD0003 ); |
---|
115 | |
---|
116 | /* |
---|
117 | * You can't mount another filesystem properly until the mount point |
---|
118 | * it will be mounted onto is created. Moreover, if it is going to |
---|
119 | * use a device, then it is REALLY unfair to attempt this |
---|
120 | * before device drivers are initialized. So we return via a base |
---|
121 | * filesystem image and nothing auto-mounted at this point. |
---|
122 | */ |
---|
123 | |
---|
124 | #endif |
---|
125 | } |
---|