erl_prim_loader — erts v15.0.1

Search documentation of erts

# View Source erl_prim_loader (erts v15.0.1)

The low-level Erlang loader. This module is used to load all Erlang modules into the system. The start script is also fetched with this low-level loader.

`erl_prim_loader` knows about the environment and how to fetch modules.

Command-line flag `-loader Loader` can be used to choose the method used by `erl_prim_loader`. Two `Loader` methods are supported by the Erlang runtime system: `efile` and `inet`.

## Command-Line Flags

The `erl_prim_loader` module interprets the following command-line flags:

- `-loader Loader` - Specifies the name of the loader used by `erl_prim_loader`. `Loader` can be `efile` (use the local file system) or `inet` (load using the `boot_server` on another Erlang node).

  If flag `-loader` is omitted, it defaults to `efile`.

- `-loader_debug` - Makes the `efile` loader write some debug information, such as the reason for failures, while it handles files.

- `-hosts Hosts` - Specifies which other Erlang nodes the `inet` loader can use. This flag is mandatory if flag `-loader inet` is present. On each host, there must be on Erlang node with the `erl_boot_server`, which handles the load requests. `Hosts` is a list of IP addresses (hostnames are not acceptable).

- `-setcookie Cookie` - Specifies the cookie of the Erlang runtime system. This flag is mandatory if flag `-loader inet` is present.

## See Also

`init`, `erl_boot_server`

# Summary

## Functions

get_file(Filename)

Use of this function is deprecated in favor of `read_file/1`.

get_path()

Use of this function is deprecated in favor of `code:get_path/0`.

list_dir(Dir)

Lists all the files in a directory.

read_file(Filename)

Reads a file using the low-level loader.

read_file_info(Filename)

Retrieves information about a file.

read_link_info(Filename)

Works like `read_file_info/1` except that if `Filename` is a symbolic link, information about the link is returned in the `file_info` record and the `type` field of the record is set to `symlink`.

set_path(Path)

Sets the path of the loader if `init` interprets a `path` command in the start script.

# Functions

Link to this function

# get_file(Filename)

View Source

    -spec get_file(Filename) -> {ok, Bin, FullName} | error
                      when Filename :: atom() | string(), Bin :: binary(), FullName :: string().

Use of this function is deprecated in favor of `read_file/1`.

Fetches a file using the low-level loader. `Filename` is either an absolute filename or only the name of the file, for example, `"lists.beam"`. If an internal path is set to the loader, this path is used to find the file. `FullName` is the complete name of the fetched file. `Bin` is the contents of the file as a binary.

`Filename` can also be a file in an archive, for example, `$OTPROOT/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin/mnesia.beam`. For information about archive files, see `code`.

Link to this function

# get_path()

View Source

    -spec get_path() -> {ok, Path} when Path :: [Dir :: string()].

Use of this function is deprecated in favor of `code:get_path/0`.

Gets the path set in the loader. The path is set by the `init` process according to information found in the start script.

Link to this function

# list_dir(Dir)

View Source

    -spec list_dir(Dir) -> {ok, Filenames} | error when Dir :: string(), Filenames :: [Filename :: string()].

Lists all the files in a directory.

Returns `{ok, Filenames}` if successful, otherwise `error`. `Filenames` is a list of the names of all the files in the directory. The names are not sorted.

`Dir` can also be a directory in an archive, for example, `$OTPROOT/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin`. For information about archive files, see `code`.

Link to this function

# read_file(Filename)

View Source (since OTP 27.0)

    -spec read_file(Filename) -> {ok, Bin} | error when Filename :: string(), Bin :: binary().

Reads a file using the low-level loader.

Returns `{ok, Bin}` if successful, otherwise `error`. `Bin` is the contents of the file as a binary.

`Filename` can also be a file in an archive, for example, `$OTPROOT/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin/mnesia.beam`. For information about archive files, see `code`.

Link to this function

# read_file_info(Filename)

View Source

    -spec read_file_info(Filename) -> {ok, FileInfo} | error
                            when Filename :: string(), FileInfo :: file:file_info().

Retrieves information about a file.

Returns `{ok, FileInfo}` if successful, otherwise `error`. `FileInfo` is a record `file_info`, defined in the Kernel include file `file.hrl`. Include the following directive in the module from which the function is called:

    -include_lib("kernel/include/file.hrl").

For more information about the record see `file:read_file_info/2`.

`Filename` can also be a file in an archive, for example, `$OTPROOT/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin/mnesia`. For information about archive files, see `code`.

Link to this function

# read_link_info(Filename)

View Source (since OTP 17.1.2)

    -spec read_link_info(Filename) -> {ok, FileInfo} | error
                            when Filename :: string(), FileInfo :: file:file_info().

Works like `read_file_info/1` except that if `Filename` is a symbolic link, information about the link is returned in the `file_info` record and the `type` field of the record is set to `symlink`.

If `Filename` is not a symbolic link, this function returns exactly the same result as `read_file_info/1`. On platforms that do not support symbolic links, this function is always equivalent to `read_file_info/1`.

Link to this function

# set_path(Path)

View Source

    -spec set_path(Path) -> ok when Path :: [Dir :: string()].

Sets the path of the loader if `init` interprets a `path` command in the start script.