1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>erl_prim_loader</title>
32
<module>erl_prim_loader</module>
33
<modulesummary>Low Level Erlang Loader</modulesummary>
35
<p><c>erl_prim_loader</c> is used to load all Erlang modules into
36
the system. The start script is also fetched with this low level
38
<p><c>erl_prim_loader</c> knows about the environment and how to
39
fetch modules. The loader could, for example, fetch files using
40
the file system (with absolute file names as input), or a
41
database (where the binary format of a module is stored).</p>
42
<p>The <c>-loader Loader</c> command line flag can be used to
43
choose the method used by the <c>erl_prim_loader</c>. Two
44
<c>Loader</c> methods are supported by the Erlang runtime system:
45
<c>efile</c> and <c>inet</c>. If another loader is required, then
46
it has to be implemented by the user. The <c>Loader</c> provided
47
by the user must fulfill the protocol defined below, and it is
48
started with the <c>erl_prim_loader</c> by evaluating
49
<c>open_port({spawn,Loader},[binary])</c>.</p>
51
<warning><p>The support for loading of code from archive files is
52
experimental. The sole purpose of releasing it before it is ready
53
is to obtain early feedback. The file format, semantics,
54
interfaces etc. may be changed in a future release. The functions
55
<c>list_dir/1</c> and <c>read_file_info/1</c> as well as the flag
56
<c>-loader_debug</c> are also experimental</p></warning>
61
<name>start(Id, Loader, Hosts) -> {ok, Pid} | {error, What}</name>
62
<fsummary>Start the Erlang low level loader</fsummary>
65
<v>Loader = atom() | string()</v>
72
<p>Starts the Erlang low level loader. This function is called
73
by the <c>init</c> process (and module). The <c>init</c>
74
process reads the command line flags <c>-id Id</c>,
75
<c>-loader Loader</c>, and <c>-hosts Hosts</c>. These are
76
the arguments supplied to the <c>start/3</c> function.</p>
77
<p>If <c>-loader</c> is not given, the default loader is
78
<c>efile</c> which tells the system to read from the file
80
<p>If <c>-loader</c> is <c>inet</c>, the <c>-id Id</c>,
81
<c>-hosts Hosts</c>, and <c>-setcookie Cookie</c> flags must
82
also be supplied. <c>Hosts</c> identifies hosts which this
83
node can contact in order to load modules. One Erlang
84
runtime system with a <c>erl_boot_server</c> process must be
85
started on each of hosts given in <c>Hosts</c> in order to
86
answer the requests. See <seealso
87
marker="erl_boot_server">erl_boot_server(3)</seealso>.</p>
88
<p>If <c>-loader</c> is something else, the given port program
89
is started. The port program is supposed to follow
90
the protocol specified below.</p>
94
<name>get_file(Filename) -> {ok, Bin, FullName} | error</name>
95
<fsummary>Get a file</fsummary>
97
<v>Filename = string()</v>
99
<v>FullName = string()</v>
102
<p>This function fetches a file using the low level loader.
103
<c>Filename</c> is either an absolute file name or just the name
104
of the file, for example <c>"lists.beam"</c>. If an internal
105
path is set to the loader, this path is used to find the file.
106
If a user supplied loader is used, the path can be stripped
107
off if it is obsolete, and the loader does not use a path.
108
<c>FullName</c> is the complete name of the fetched file.
109
<c>Bin</c> is the contents of the file as a binary.</p>
111
<p>The <c>Filename</c> can also be a file in an archive. For example
112
<c>/otp/root/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin/mnesia_backup.beam</c>
113
See <seealso marker="code">code(3)</seealso> about archive files.</p>
117
<name>get_path() -> {ok, Path}</name>
118
<fsummary>Get the path set in the loader</fsummary>
121
<v>Dir = string()</v>
124
<p>This function gets the path set in the loader. The path is
125
set by the <c>init</c> process according to information found
126
in the start script.</p>
130
<name>list_dir(Dir) -> {ok, Filenames} | error</name>
131
<fsummary>List files in a directory</fsummary>
134
<v>Filenames = [Filename]</v>
135
<v>Filename = string()</v>
138
<p>Lists all the files in a directory. Returns
139
<c>{ok, Filenames}</c> if successful. Otherwise, it returns
140
<c>error</c>. <c>Filenames</c> is a list of
141
the names of all the files in the directory. The names are
143
<p>The <c>Dir</c> can also be a directory in an archive. For example
144
<c>/otp/root/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin</c>
145
See <seealso marker="code">code(3)</seealso> about archive files.</p>
149
<name>read_file_info(Filename) -> {ok, FileInfo} | error</name>
150
<fsummary>Get information about a file</fsummary>
152
<v>Filename = name()</v>
153
<v>FileInfo = #file_info{}</v>
156
<p>Retrieves information about a file. Returns
157
<c>{ok, FileInfo}</c> if successful, otherwise
158
<c>error</c>. <c>FileInfo</c> is a record
159
<c>file_info</c>, defined in the Kernel include file
160
<c>file.hrl</c>. Include the following directive in the module
161
from which the function is called:</p>
163
-include_lib("kernel/include/file.hrl").</code>
164
<p>See <seealso marker="file">file(3)</seealso> for more info about
165
the record <c>file_info</c>.</p>
166
<p>The <c>Filename</c> can also be a file in an archive. For example
167
<c>/otp/root/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin/mnesia_backup.beam</c>
168
See <seealso marker="code">code(3)</seealso> about archive files.</p>
172
<name>set_path(Path) -> ok</name>
173
<fsummary>Set the path of the loader</fsummary>
176
<v>Dir = string()</v>
179
<p>This function sets the path of the loader if <c>init</c>
180
interprets a <c>path</c> command in the start script.</p>
186
<title>Protocol</title>
187
<p>The following protocol must be followed if a user provided
188
loader port program is used. The <c>Loader</c> port program is
189
started with the command
190
<c>open_port({spawn,Loader},[binary])</c>. The protocol is as
193
Function Send Receive
194
-------------------------------------------------------------
195
get_file [102 | FileName] [121 | BinaryFile] (on success)
198
stop eof terminate</pre>
202
<title>Command Line Flags</title>
203
<p>The <c>erl_prim_loader</c> module interprets the following
204
command line flags:</p>
206
<tag><c>-loader Loader</c></tag>
208
<p>Specifies the name of the loader used by
209
<c>erl_prim_loader</c>. <c>Loader</c> can be <c>efile</c>
210
(use the local file system), or <c>inet</c> (load using
211
the <c>boot_server</c> on another Erlang node). If
212
<c>Loader</c> is user defined, the defined <c>Loader</c> port
213
program is started.</p>
214
<p>If the <c>-loader</c> flag is omitted, it defaults to
217
<tag><c>-loader_debug</c></tag>
219
<p>Makes the <c>efile</c> loader write some debug information,
220
such as the reason for failures, while it handles files.</p>
222
<tag><c>-hosts Hosts</c></tag>
224
<p>Specifies which other Erlang nodes the <c>inet</c> loader
225
can use. This flag is mandatory if the <c>-loader inet</c>
226
flag is present. On each host, there must be on Erlang node
227
with the <c>erl_boot_server</c> which handles the load
228
requests. <c>Hosts</c> is a list of IP addresses (hostnames
229
are not acceptable).</p>
231
<tag><c>-id Id</c></tag>
233
<p>Specifies the identity of the Erlang runtime system. If
234
the system runs as a distributed node, <c>Id</c> must be
235
identical to the name supplied with the <c>-sname</c> or
236
<c>-name</c> distribution flags.</p>
238
<tag><c>-setcookie Cookie</c></tag>
240
<p>Specifies the cookie of the Erlang runtime system. This flag
241
is mandatory if the <c>-loader inet</c> flag is present.</p>
247
<title>SEE ALSO</title>
248
<p><seealso marker="init">init(3)</seealso>,
249
<seealso marker="erl_boot_server">erl_boot_server(3)</seealso></p>